summaryrefslogtreecommitdiffstats
path: root/generic/tclIORChan.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-04-15 16:09:28 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-04-15 16:09:28 (GMT)
commitd25403a5a8b4f784566eb15f30b46ed568efc478 (patch)
tree45b647e651408983ccc93c3ec3b23ca9476fdaf4 /generic/tclIORChan.c
parentc5510a29171fa3a62f7a51af11bea2772bf10e3e (diff)
downloadtcl-d25403a5a8b4f784566eb15f30b46ed568efc478.zip
tcl-d25403a5a8b4f784566eb15f30b46ed568efc478.tar.gz
tcl-d25403a5a8b4f784566eb15f30b46ed568efc478.tar.bz2
[88aef05cda] Stop reentrancy segfault in reflected channels by managing
callbacks as (copies of) lists, not shared Tcl_Obj arrays. Still could use cleanup and improvements.
Diffstat (limited to 'generic/tclIORChan.c')
-rw-r--r--generic/tclIORChan.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/generic/tclIORChan.c b/generic/tclIORChan.c
index affed02..2d712a2 100644
--- a/generic/tclIORChan.c
+++ b/generic/tclIORChan.c
@@ -110,6 +110,7 @@ typedef struct {
* plus 4 placeholders for method, channel,
* and at most two varying (method specific)
* words. */
+ Tcl_Obj *cmd; /* */
int methods; /* Bitmask of supported methods */
/*
@@ -2044,6 +2045,10 @@ NewReflectedChannel(
*/
/* ASSERT: cmdpfxObj is a Tcl List */
+ rcPtr->cmd = TclListObjCopy(NULL, cmdpfxObj);
+ Tcl_ListObjAppendElement(NULL, rcPtr->cmd, Tcl_NewObj());
+ Tcl_ListObjAppendElement(NULL, rcPtr->cmd, handleObj);
+ Tcl_IncrRefCount(rcPtr->cmd);
Tcl_ListObjGetElements(interp, cmdpfxObj, &listc, &listv);
@@ -2158,6 +2163,7 @@ FreeReflectedChannel(
*/
Tcl_DecrRefCount(rcPtr->argv[n+1]);
+ Tcl_DecrRefCount(rcPtr->cmd);
ckfree((char*) rcPtr->argv);
ckfree((char*) rcPtr);
@@ -2200,6 +2206,8 @@ InvokeTclMethod(
Tcl_InterpState sr; /* State of handler interp */
int result; /* Result code of method invokation */
Tcl_Obj *resObj = NULL; /* Result of method invokation. */
+ Tcl_Obj *cmd;
+ int len;
if (!rcPtr->interp) {
/*
@@ -2236,6 +2244,11 @@ InvokeTclMethod(
Tcl_IncrRefCount(methObj);
rcPtr->argv[rcPtr->argc - 2] = methObj;
+ cmd = TclListObjCopy(NULL, rcPtr->cmd);
+ ListObjLength(cmd, len);
+ Tcl_ListObjReplace(NULL, cmd, len - 2, 1, 1, &methObj);
+
+
/*
* Append the additional argument containing method specific details
* behind the channel id. If specified.
@@ -2244,9 +2257,11 @@ InvokeTclMethod(
cmdc = rcPtr->argc;
if (argOneObj) {
rcPtr->argv[cmdc] = argOneObj;
+ Tcl_ListObjAppendElement(NULL, cmd, argOneObj);
cmdc++;
if (argTwoObj) {
rcPtr->argv[cmdc] = argTwoObj;
+ Tcl_ListObjAppendElement(NULL, cmd, argTwoObj);
cmdc++;
}
}
@@ -2256,9 +2271,11 @@ InvokeTclMethod(
* existing state intact.
*/
+ Tcl_IncrRefCount(cmd);
sr = Tcl_SaveInterpState(rcPtr->interp, 0 /* Dummy */);
Tcl_Preserve(rcPtr->interp);
- result = Tcl_EvalObjv(rcPtr->interp, cmdc, rcPtr->argv, TCL_EVAL_GLOBAL);
+// result = Tcl_EvalObjv(rcPtr->interp, cmdc, rcPtr->argv, TCL_EVAL_GLOBAL);
+ result = Tcl_GlobalEvalObj(rcPtr->interp, cmd);
/*
* We do not try to extract the result information if the caller has no
@@ -2284,7 +2301,7 @@ InvokeTclMethod(
*/
if (result != TCL_ERROR) {
- Tcl_Obj *cmd = Tcl_NewListObj(cmdc, rcPtr->argv);
+// Tcl_Obj *cmd = Tcl_NewListObj(cmdc, rcPtr->argv);
int cmdLen;
const char *cmdString = Tcl_GetStringFromObj(cmd, &cmdLen);
@@ -2303,6 +2320,7 @@ InvokeTclMethod(
}
Tcl_IncrRefCount(resObj);
}
+ Tcl_DecrRefCount(cmd);
Tcl_RestoreInterpState(rcPtr->interp, sr);
Tcl_Release(rcPtr->interp);