Tcl Source Code

Artifact [5673e5195a]
Login

Artifact 5673e5195a4f3bfa01c127523b58464136a15615:

Attachment "coro.diff" to ticket [3008307fff] added by msofer 2010-06-01 00:44:55.
Index: generic/tclBasic.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclBasic.c,v
retrieving revision 1.456
diff -u -r1.456 tclBasic.c
--- generic/tclBasic.c	3 May 2010 14:36:41 -0000	1.456
+++ generic/tclBasic.c	31 May 2010 17:37:59 -0000
@@ -8710,6 +8710,7 @@
     TclCleanupCommandMacro(cmdPtr);
 
     corPtr->eePtr->corPtr = NULL;
+    TclPopStackFrame(interp);
     TclDeleteExecEnv(corPtr->eePtr);
     corPtr->eePtr = NULL;
 
@@ -8790,6 +8791,7 @@
      */
 
     SAVE_CONTEXT(corPtr->caller);
+    corPtr->base.framePtr->callerPtr = iPtr->framePtr;
     RESTORE_CONTEXT(corPtr->running);
     corPtr->auxNumLevels = iPtr->numLevels;
     iPtr->numLevels += nestNumLevels;
@@ -8819,6 +8821,8 @@
     const char *procName;
     Namespace *nsPtr, *altNsPtr, *cxtNsPtr;
     Tcl_DString ds;
+    Tcl_CallFrame *framePtr;
+    
 
     if (objc < 3) {
 	Tcl_WrongNumArgs(interp, 1, objv, "name cmd ?arg ...?");
@@ -8922,11 +8926,31 @@
     }
 
     /*
+     * Create the coro's execEnv and switch to it so that any CallFrames or
+     * callbacks refer to the new execEnv's stack. 
+     */
+
+    corPtr->eePtr = TclCreateExecEnv(interp, CORO_STACK_INITIAL_SIZE);
+    corPtr->callerEEPtr = iPtr->execEnvPtr;
+    corPtr->eePtr->corPtr = corPtr;
+    iPtr->execEnvPtr = corPtr->eePtr;
+
+    /* push a base call frame; save the current namespace to do a correct
+     * command lookup.
+     */
+
+    nsPtr = iPtr->varFramePtr->nsPtr;
+    TclPushStackFrame(interp, &framePtr,
+	    (Tcl_Namespace *) iPtr->globalNsPtr, 0);
+    iPtr->varFramePtr = iPtr->rootFramePtr;
+    
+    /*
      * Save the base context. The base cmdFramePtr is unknown at this time: it
      * will be allocated in the Tcl stack. So signal TEBC that it has to
      * initialize the base cmdFramePtr by setting it to NULL.
      */
 
+    SAVE_CONTEXT(corPtr->base);
     corPtr->base.cmdFramePtr = NULL;
     corPtr->running = NULL_CONTEXT;
     corPtr->stackLevel = NULL;
@@ -8944,20 +8968,13 @@
     cmdObjPtr->typePtr = NULL;
 
     /*
-     * Create the coro's execEnv and switch to it so that any CallFrames or
-     * callbacks refer to the new execEnv's stack. Add the exit callback, then
-     * the callback to eval the coro body.
+     * Add the exit callback, then the callback to eval the coro body
      */
 
-    corPtr->eePtr = TclCreateExecEnv(interp, CORO_STACK_INITIAL_SIZE);
-    corPtr->callerEEPtr = iPtr->execEnvPtr;
-    corPtr->eePtr->corPtr = corPtr;
-    iPtr->execEnvPtr = corPtr->eePtr;
-
     TclNRAddCallback(interp, NRCoroutineExitCallback, corPtr,
 	    NULL, NULL, NULL);
     iPtr->evalFlags |= TCL_EVAL_REDIRECT;
-    iPtr->lookupNsPtr = iPtr->varFramePtr->nsPtr;
+    iPtr->lookupNsPtr = nsPtr;
     TclNREvalObjEx(interp, cmdObjPtr, 0, NULL, 0);
 
     return TCL_OK;
Index: generic/tclExecute.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
retrieving revision 1.484
diff -u -r1.484 tclExecute.c
--- generic/tclExecute.c	31 May 2010 08:54:15 -0000	1.484
+++ generic/tclExecute.c	31 May 2010 17:38:01 -0000
@@ -2084,13 +2084,11 @@
 	     *  - base.cmdFramePtr not set
 	     *  - need to monkey-patch the BP chain
 	     *  - set the running level for the coroutine
-	     *  - insure that the coro runs in #0
 	     */
 
 	    corPtr->base.cmdFramePtr = bcFramePtr;
 	    corPtr->callerBPPtr = &BP->prevBottomPtr;
 	    corPtr->stackLevel = &TAUX;
-	    iPtr->varFramePtr = iPtr->rootFramePtr;
 	}
 
 	if (iPtr->execEnvPtr->rewind) {