Skip to content

Commit

Permalink
* ext/tk/tcltklib.c (ip_finalize): better modification than the
Browse files Browse the repository at this point in the history
  previous commit [ruby-dev:26029].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8312 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nagai committed Apr 12, 2005
1 parent b346101 commit c594a95
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
Tue Apr 12 15:33:09 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>

* ext/tk/tcltklib.c (ip_finalize): better modification than the
previous commit [ruby-dev:26029].

Tue Apr 12 12:38:06 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>

* ext/tk/tcltklib.c (ip_finalize): fix SEGV when Tcl_GlobalEval()
Expand Down
44 changes: 32 additions & 12 deletions ext/tk/tcltklib.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit c594a95

Please sign in to comment.