Skip to content

Commit 66269ae

Browse files
Fixes FFI boxing issue segfault with C strings
1 parent 8cf815b commit 66269ae

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/cocoa_object.m

+8-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,14 @@
396396
args[0] = arg_type_class;
397397
marg = mrb_funcall_argv(mrb, marg, sym_to_ffi_value, 1, args);
398398
}
399-
values[i + SELF_AND_SEL] = cfunc_pointer_ptr(marg);
399+
const char *argtype = [signature getArgumentTypeAtIndex:i + SELF_AND_SEL];
400+
if (strlen(argtype) > 1 && argtype[strlen(argtype)-1] == '*') {
401+
void *dataptr = cfunc_pointer_ptr(marg);
402+
values[i + SELF_AND_SEL] = mrb_malloc(mrb, sizeof(void*));
403+
*((void***)values)[i + SELF_AND_SEL] = dataptr;
404+
} else {
405+
values[i + SELF_AND_SEL] = cfunc_pointer_ptr(marg);
406+
}
400407
}
401408

402409
values[0] = mrb_malloc(mrb, sizeof(void*));

0 commit comments

Comments
 (0)