summaryrefslogtreecommitdiff
path: root/ext/tcltklib/tcltklib.c
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-04-12 06:36:22 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-04-12 06:36:22 +0000
commitb49927429469a8d6ef4459022502304d8151b4b5 (patch)
treeda545147ca51148e643d7029ed39d0491a46bb98 /ext/tcltklib/tcltklib.c
parent51d360be64a371d036b1b6314f2afaefa7bbb701 (diff)
* ext/tcltklib/tcltklib.c (ip_finalize): better modification than the
previous commit [ruby-dev:26029]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tcltklib/tcltklib.c')
-rw-r--r--ext/tcltklib/tcltklib.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c
index f598ed4a0d..49667427f5 100644
--- a/ext/tcltklib/tcltklib.c
+++ b/ext/tcltklib/tcltklib.c
@@ -115,6 +115,36 @@ static VALUE ip_invoke _((int, VALUE*, VALUE));
static VALUE tk_funcall _((VALUE(), int, VALUE*, VALUE));
+/* safe Tcl_Eval and Tcl_GlobalEval */
+static int
+tcl_eval(interp, cmd)
+ Tcl_Interp *interp;
+ const char *cmd; /* don't have to be writable */
+{
+ char *buf = strdup(cmd);
+ const int ret = Tcl_Eval(interp, buf);
+ free(buf);
+ return ret;
+}
+
+#undef Tcl_Eval
+#define Tcl_Eval tcl_eval
+
+static int
+tcl_global_eval(interp, cmd)
+ Tcl_Interp *interp;
+ const char *cmd; /* don't have to be writable */
+{
+ char *buf = strdup(cmd);
+ const int ret = Tcl_GlobalEval(interp, buf);
+ free(buf);
+ return ret;
+}
+
+#undef Tcl_GlobalEval
+#define Tcl_GlobalEval tcl_global_eval
+
+
/* from tkAppInit.c */
#if TCL_MAJOR_VERSION < 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION < 4)
@@ -4420,22 +4450,12 @@ ip_finalize(ip)
Tcl_GlobalEval(ip, finalize_hook_name);
}
- DUMP1("cancel after callbacks");
-#define AFTER_CANCEL_CMD "foreach id [after info] {after cancel $id}"
DUMP1("check `foreach' & `after'");
if ( Tcl_GetCommandInfo(ip, "foreach", &info)
&& Tcl_GetCommandInfo(ip, "after", &info) ) {
- char *cmd;
- if ((cmd = Tcl_Alloc(strlen(AFTER_CANCEL_CMD) + 1)) == (char*)NULL) {
- DUMP1("cancel after callbacks : cannot allocate memory");
- } else {
- DUMP1("call `foreach' & `after'");
- strcpy(cmd, AFTER_CANCEL_CMD);
- Tcl_GlobalEval(ip, cmd);
- Tcl_Free(cmd);
- }
+ DUMP1("cancel after callbacks");
+ Tcl_GlobalEval(ip, "foreach id [after info] {after cancel $id}");
}
-#undef AFTER_CANCEL_CMD
Tcl_Release(ip);