summaryrefslogtreecommitdiffstats
path: root/generic/tclBasic.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2013-08-28 02:44:50 (GMT)
committerdgp <dgp@users.sourceforge.net>2013-08-28 02:44:50 (GMT)
commit3aa655bce1d9e291450cc8bdfe5890058dcf1700 (patch)
tree1aec06d5f76306a84f366535ea490824efcc5bbf /generic/tclBasic.c
parent9ba19b667f4232117cc4abd68576dead47e19c10 (diff)
downloadtcl-3aa655bce1d9e291450cc8bdfe5890058dcf1700.zip
tcl-3aa655bce1d9e291450cc8bdfe5890058dcf1700.tar.gz
tcl-3aa655bce1d9e291450cc8bdfe5890058dcf1700.tar.bz2
Clarfy and prettify influence of flag settings and command lookups.
Diffstat (limited to 'generic/tclBasic.c')
-rw-r--r--generic/tclBasic.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 3f579d1..af747cd 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -4121,13 +4121,21 @@ EvalObjvCore(
Tcl_Interp *interp,
int result)
{
- Command *cmdPtr = data[0];
+ Command *cmdPtr = NULL, *preCmdPtr = data[0];
int flags = PTR2INT(data[1]);
int objc = PTR2INT(data[2]);
Tcl_Obj **objv = data[3];
Interp *iPtr = (Interp *) interp;
+
+ /*
+ * Capture the namespace we should do command name resolution in, as
+ * instructed by our caller sneaking it in to us in a private interp
+ * field. Clear that field right away so we cannot possibly have its
+ * use leak where it should not. The sneaky message pass is done.
+ */
+
Namespace *lookupNsPtr = iPtr->lookupNsPtr;
- int weLookUp = (cmdPtr == NULL);
+ iPtr->lookupNsPtr = NULL;
if (TCL_OK != TclInterpReady(interp)) {
return TCL_ERROR;
@@ -4141,8 +4149,6 @@ EvalObjvCore(
return TCL_ERROR;
}
- iPtr->lookupNsPtr = NULL;
-
/*
* Push records for task to be done on return, in INVERSE order. First, if
* needed, the exception handlers (as they should happen last).
@@ -4152,45 +4158,43 @@ EvalObjvCore(
TEOV_PushExceptionHandlers(interp, objc, objv, flags);
}
- if (!weLookUp) {
- goto commandFound;
- }
-
- /*
- * Configure evaluation context to match the requested flags.
- */
-
- if ((flags & TCL_EVAL_INVOKE) || lookupNsPtr) {
- if (!lookupNsPtr) {
- lookupNsPtr = iPtr->globalNsPtr;
- }
+ if (preCmdPtr) {
+ cmdPtr = preCmdPtr;
} else {
- if (flags & TCL_EVAL_GLOBAL) {
- TEOV_SwitchVarFrame(interp);
- lookupNsPtr = iPtr->globalNsPtr;
- }
/*
- * TCL_EVAL_INVOKE was not set: clear rewrite rules
+ * Configure evaluation context to match the requested flags.
*/
- iPtr->ensembleRewrite.sourceObjs = NULL;
- }
+ if (lookupNsPtr) {
+ /*
+ * Do nothing. Caller gave us the lookup namespace. Use it.
+ * Overrides TCL_EVAL_GLOBAL. For both lookup and eval.
+ */
+ } else if (flags & TCL_EVAL_INVOKE) {
+ lookupNsPtr = iPtr->globalNsPtr;
+ } else {
- /*
- * Lookup the command
- */
+ /*
+ * TCL_EVAL_INVOKE was not set: clear rewrite rules
+ */
- cmdPtr = TEOV_LookupCmdFromObj(interp, objv[0], lookupNsPtr);
- if (!cmdPtr) {
- return TEOV_NotFound(interp, objc, objv, lookupNsPtr);
- }
+ iPtr->ensembleRewrite.sourceObjs = NULL;
- /*
- * Found a command! The real work begins now ...
- */
+ if (flags & TCL_EVAL_GLOBAL) {
+ /* TODO: Check we do this whenever needed. */
+ TEOV_SwitchVarFrame(interp);
+ lookupNsPtr = iPtr->globalNsPtr;
+ }
+ }
+
+ cmdPtr = TEOV_LookupCmdFromObj(interp, objv[0], lookupNsPtr);
+ if (!cmdPtr) {
+ return TEOV_NotFound(interp, objc, objv, lookupNsPtr);
+ }
+
+ }
- commandFound:
if (iPtr->tracePtr || (cmdPtr->flags & CMD_HAS_EXEC_TRACES)) {
/*
* Call enter traces. They will schedule a call to the leave traces if
@@ -4244,7 +4248,7 @@ EvalObjvCore(
* If we got the trace command by looking up a command name, we
* should just look it up again.
*/
- if (weLookUp) {
+ if (preCmdPtr == NULL) {
cmdPtr = TEOV_LookupCmdFromObj(interp, objv[0], lookupNsPtr);
} else {
@@ -4273,7 +4277,7 @@ EvalObjvCore(
}
if (cmdPtr == NULL) {
- if (weLookUp) {
+ if (preCmdPtr == NULL) {
return TEOV_NotFound(interp, objc, objv, lookupNsPtr);
}
/* Is this right??? */
@@ -4798,7 +4802,6 @@ TEOV_LookupCmdFromObj(
if (lookupNsPtr) {
iPtr->varFramePtr->nsPtr = lookupNsPtr;
- iPtr->lookupNsPtr = NULL;
}
cmdPtr = (Command *) Tcl_GetCommandFromObj(interp, namePtr);
iPtr->varFramePtr->nsPtr = savedNsPtr;