summaryrefslogtreecommitdiff
path: root/ext/fiddle/closure.c
diff options
context:
space:
mode:
authorSutou Kouhei <kou@clear-code.com>2020-12-25 06:02:19 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-05-18 12:48:40 +0900
commit881b2dc89865c1b7a7fbc2c89e13789a068f335d (patch)
treef260f58a809a6b7df12c978f02847894a5eb5f26 /ext/fiddle/closure.c
parentb2de5999d88d81310b3c9f0c1f14451d7eca8e6e (diff)
[ruby/fiddle] closure: add support for const char *
GitHub: fix GH-62 Reported by Cody Krieger. Thanks!!! https://github.com/ruby/fiddle/commit/284b820f2d
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4506
Diffstat (limited to 'ext/fiddle/closure.c')
-rw-r--r--ext/fiddle/closure.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/ext/fiddle/closure.c b/ext/fiddle/closure.c
index fc2965591e..3679e5c9ad 100644
--- a/ext/fiddle/closure.c
+++ b/ext/fiddle/closure.c
@@ -130,6 +130,10 @@ with_gvl_callback(void *ptr)
rb_ary_push(params, ULL2NUM(*(unsigned LONG_LONG *)x->args[i]));
break;
#endif
+ case TYPE_CONST_STRING:
+ rb_ary_push(params,
+ rb_str_new_cstr(*((const char **)(x->args[i]))));
+ break;
default:
rb_raise(rb_eRuntimeError, "closure args: %d", type);
}
@@ -175,6 +179,10 @@ with_gvl_callback(void *ptr)
*(unsigned LONG_LONG *)x->resp = NUM2ULL(ret);
break;
#endif
+ case TYPE_CONST_STRING:
+ /* Dangerous. Callback must keep reference of the String. */
+ *((const char **)(x->resp)) = StringValueCStr(ret);
+ break;
default:
rb_raise(rb_eRuntimeError, "closure retval: %d", type);
}