Skip to content

Commit

Permalink
Allow for Magic#load to take nil as valid argument.
Browse files Browse the repository at this point in the history
This will also make Magic::new accept nil, which can be handy at some
very specific occasions i.e. passing default argument, etc.

Signed-off-by: Krzysztof Wilczynski <[email protected]>
  • Loading branch information
kwilczynski committed Mar 30, 2014
1 parent 4217876 commit 42c9859
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/magic/ruby-magic.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static VALUE magic_return(VALUE value, void *data);
VALUE
rb_mgc_initialize(VALUE object, VALUE arguments)
{
VALUE mutex;
VALUE mutex = Qnil;

magic_arguments_t ma;
const char *klass = NULL;
Expand Down Expand Up @@ -300,7 +300,7 @@ rb_mgc_load(VALUE object, VALUE arguments)
CHECK_MAGIC_OPEN(object);
MAGIC_COOKIE(ma.cookie);

if (!RARRAY_EMPTY_P(arguments)) {
if (!RARRAY_EMPTY_P(arguments) && !NIL_P(RARRAY_FIRST(arguments))) {
value = magic_join(arguments, CSTR2RVAL(":"));
ma.data.file.path = RVAL2CSTR(value);
}
Expand Down
1 change: 1 addition & 0 deletions ext/magic/ruby-magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern "C" {

#define RSTRING_EMPTY_P(s) (RSTRING_LEN(s) == 0)
#define RARRAY_EMPTY_P(a) (RARRAY_LEN(a) == 0)
#define RARRAY_FIRST(a) (RARRAY_EMPTY_P(a) ? Qnil : RARRAY_PTR(a)[0])

#define NOGVL_FUNCTION (VALUE (*)(void *))

Expand Down

0 comments on commit 42c9859

Please sign in to comment.