Skip to content

Commit 42c9859

Browse files
committed
Allow for Magic#load to take nil as valid argument.
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 <krzysztof.wilczynski@linux.com>
1 parent 4217876 commit 42c9859

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

ext/magic/ruby-magic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static VALUE magic_return(VALUE value, void *data);
8383
VALUE
8484
rb_mgc_initialize(VALUE object, VALUE arguments)
8585
{
86-
VALUE mutex;
86+
VALUE mutex = Qnil;
8787

8888
magic_arguments_t ma;
8989
const char *klass = NULL;
@@ -300,7 +300,7 @@ rb_mgc_load(VALUE object, VALUE arguments)
300300
CHECK_MAGIC_OPEN(object);
301301
MAGIC_COOKIE(ma.cookie);
302302

303-
if (!RARRAY_EMPTY_P(arguments)) {
303+
if (!RARRAY_EMPTY_P(arguments) && !NIL_P(RARRAY_FIRST(arguments))) {
304304
value = magic_join(arguments, CSTR2RVAL(":"));
305305
ma.data.file.path = RVAL2CSTR(value);
306306
}

ext/magic/ruby-magic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extern "C" {
5858

5959
#define RSTRING_EMPTY_P(s) (RSTRING_LEN(s) == 0)
6060
#define RARRAY_EMPTY_P(a) (RARRAY_LEN(a) == 0)
61+
#define RARRAY_FIRST(a) (RARRAY_EMPTY_P(a) ? Qnil : RARRAY_PTR(a)[0])
6162

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

0 commit comments

Comments
 (0)