Skip to content

Commit 3b6e3ce

Browse files
committed
Avoid the use of the rb_eval_cmd_kw function if it is not available
Fixes #75
1 parent 6f35a07 commit 3b6e3ce

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

ext/tk/tkutil/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
begin
33
require 'mkmf'
44

5+
have_func("rb_eval_cmd_kw", "ruby.h")
56
have_func("rb_obj_instance_exec", "ruby.h")
67
have_func("rb_sym2str", "ruby.h")
78
have_func("rb_id2str", "ruby.h")

ext/tk/tkutil/tkutil.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,19 @@ tk_eval_cmd(int argc, VALUE *argv, VALUE self)
174174

175175
rb_scan_args(argc, argv, "1*", &cmd, &rest);
176176
#ifdef RB_PASS_KEYWORDS
177+
# ifdef HAVE_RB_EVAL_CMD_KW
177178
return rb_eval_cmd_kw(cmd, rest, 0);
179+
# else
180+
if (RB_TYPE_P(cmd, T_STRING)) {
181+
VALUE val = rb_funcallv_kw(rb_const_get(rb_cObject, rb_intern("TOPLEVEL_BINDING")), rb_intern("eval"), 1, &cmd, 0);
182+
RB_GC_GUARD(cmd);
183+
return val;
184+
} else {
185+
VALUE val = rb_funcallv_kw(cmd, rb_intern("call"), RARRAY_LENINT(rest), RARRAY_CONST_PTR(rest), 0);
186+
RB_GC_GUARD(rest);
187+
return val;
188+
}
189+
# endif
178190
#else
179191
return rb_eval_cmd(cmd, rest, 0);
180192
#endif

0 commit comments

Comments
 (0)