Index: generic/xotcl.c =================================================================== diff -u -rda3eff74a0a1f600806b41b54f9e18043b5ba1a7 -r8ddbf5cdc1dd1f9e0d9c429a8c3f6d279c97bd8e --- generic/xotcl.c (.../xotcl.c) (revision da3eff74a0a1f600806b41b54f9e18043b5ba1a7) +++ generic/xotcl.c (.../xotcl.c) (revision 8ddbf5cdc1dd1f9e0d9c429a8c3f6d279c97bd8e) @@ -629,7 +629,50 @@ #endif +#if defined(TCL85STACK) +void tcl85showStack(Tcl_Interp *interp) { + Tcl_CallFrame *framePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + /*for (; framePtr; framePtr = Tcl_CallFrame_callerPtr(framePtr)) { + fprintf(stderr, "... frame %p flags %.6x cd %p objv[0] %s\n", + framePtr, Tcl_CallFrame_isProcCallFrame(framePtr), + Tcl_CallFrame_clientData(framePtr), + Tcl_CallFrame_objc(framePtr) ? ObjStr(Tcl_CallFrame_objv(framePtr)[0]) : "(null)"); + }*/ + framePtr = (Tcl_CallFrame *)Tcl_Interp_framePtr(interp); + for (; framePtr; framePtr = Tcl_CallFrame_callerPtr(framePtr)) { + fprintf(stderr, "... var frame %p flags %.6x cd %.8p ns %.8p %s objv[0] %s\n", + framePtr, Tcl_CallFrame_isProcCallFrame(framePtr), + Tcl_CallFrame_clientData(framePtr), + Tcl_CallFrame_nsPtr(framePtr), Tcl_CallFrame_nsPtr(framePtr)->fullName, + Tcl_CallFrame_objc(framePtr) ? ObjStr(Tcl_CallFrame_objv(framePtr)[0]) : "(null)"); + + } +} +Tcl_CallFrame * +nonXotclObjectProcFrame(Tcl_CallFrame *framePtr) { + for (; framePtr; framePtr = Tcl_CallFrame_callerPtr(framePtr)) { + if (Tcl_CallFrame_isProcCallFrame(framePtr) & FRAME_IS_PROC) break; + if ((Tcl_CallFrame_isProcCallFrame(framePtr) & FRAME_IS_XOTCL_OBJECT) == 0) break; + } + return framePtr; +} +Tcl_Namespace * +currentNonFakeNamespace(Tcl_Interp *interp) { + CallFrame *varFramePtr = (CallFrame *)Tcl_Interp_varFramePtr(interp); + for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { + fprintf(stderr, "nsptr %p fake %p flags %.6x\n",varFramePtr->nsPtr,RUNTIME_STATE(interp)->fakeNS,Tcl_CallFrame_isProcCallFrame(varFramePtr)); + if (Tcl_CallFrame_isProcCallFrame(varFramePtr) & FRAME_IS_XOTCL_OBJECT) continue; + break; + /*if (varFramePtr->nsPtr == RUNTIME_STATE(interp)->fakeNS) + continue;*/ + } + return varFramePtr ? varFramePtr->nsPtr : NULL; +} +#else +Tcl_CallFrame * nonXotclObjectProcFrame(Tcl_CallFrame *framePtr) {return framePtr;} +Tcl_Namespace *currentNonFakeNamespace(Tcl_Interp *interp) {return Tcl_GetCurrentNamespace(interp);} +#endif /* @@ -1774,13 +1817,13 @@ * directly (by digging into compiled and non-compiled locals etc.), * however, it would cause further code redundance. */ - varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); - /* - fprintf(stderr,"varFramePtr=%p, isProcCallFrame=%d %p\n",varFramePtr, - varFramePtr != NULL ? Tcl_CallFrame_isProcCallFrame(varFramePtr): 0, - varFramePtr != NULL ? Tcl_CallFrame_procPtr(varFramePtr): 0 - ); - */ + /*tcl85showStack(interp);*/ + varFramePtr = nonXotclObjectProcFrame((Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp)); + + /*fprintf(stderr,"varFramePtr=%p, isProcCallFrame=%.6x %p\n",varFramePtr, + varFramePtr ? Tcl_CallFrame_isProcCallFrame(varFramePtr): 0, + varFramePtr ? Tcl_CallFrame_procPtr(varFramePtr): 0);*/ + if (varFramePtr && Tcl_CallFrame_isProcCallFrame(varFramePtr)) { /*fprintf(stderr, "proc-scoped var detected '%s' in NS '%s'\n", name, varFramePtr->nsPtr->fullName);*/ @@ -9472,52 +9515,14 @@ return result; } -#if defined(TCL85STACK) -void tcl85showStack(Tcl_Interp *interp) { - Tcl_CallFrame *framePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); - for (; framePtr; framePtr = Tcl_CallFrame_callerPtr(framePtr)) { - fprintf(stderr, "... frame %p flags %.6x cd %p objv[0] %s\n", - framePtr, Tcl_CallFrame_isProcCallFrame(framePtr), - Tcl_CallFrame_clientData(framePtr), - Tcl_CallFrame_objc(framePtr) ? ObjStr(Tcl_CallFrame_objv(framePtr)[0]) : "(null)"); - } - framePtr = (Tcl_CallFrame *)Tcl_Interp_framePtr(interp); - for (; framePtr; framePtr = Tcl_CallFrame_callerPtr(framePtr)) { - fprintf(stderr, "... var frame %p flags %.6x cd %p objv[0] %s\n", - framePtr, Tcl_CallFrame_isProcCallFrame(framePtr), - Tcl_CallFrame_clientData(framePtr), - Tcl_CallFrame_objc(framePtr) ? ObjStr(Tcl_CallFrame_objv(framePtr)[0]) : "(null)"); - - } -} -Tcl_CallFrame * -nonXotclObjectFrame(Tcl_CallFrame *framePtr) { - for (; - framePtr && (Tcl_CallFrame_isProcCallFrame(framePtr) & FRAME_IS_XOTCL_OBJECT) ; - framePtr = Tcl_CallFrame_callerPtr(framePtr)) ; - return framePtr; -} -Tcl_Namespace * -currentNonFakeNamespace(Tcl_Interp *interp) { - CallFrame *varFramePtr = (CallFrame *)Tcl_Interp_varFramePtr(interp); - for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { - if (varFramePtr->nsPtr == RUNTIME_STATE(interp)->fakeNS) - continue; - } - return varFramePtr ? varFramePtr->nsPtr : NULL; -} -#else -Tcl_CallFrame * nonXotclObjectFrame(Tcl_CallFrame *framePtr) {return framePtr;} -Tcl_Namespace *currentNonFakeNamespace(Tcl_Interp *interp) {return Tcl_GetCurrentNamespace(interp);} -#endif /* * class method implementations */ static Tcl_Namespace * callingNameSpace(Tcl_Interp *interp) { - Tcl_Namespace *ns = NULL; + Tcl_Namespace *nsPtr = NULL; XOTclCallStack *cs = &RUNTIME_STATE(interp)->cs; XOTclCallStackContent *top = cs->top; XOTclCallStackContent *csc = XOTclCallStackFindLastInvocation(interp, 0); @@ -9526,55 +9531,56 @@ if (csc && csc->currentFramePtr) { /* use the callspace from the last invocation */ XOTclCallStackContent *called = csccurrentFramePtr) : NULL; - fprintf(stderr," csc use frame= %p\n", f); - if (f) { - ns = f->nsPtr; + Tcl_CallFrame *framePtr = called ? Tcl_CallFrame_callerPtr(called->currentFramePtr) : NULL; + fprintf(stderr," csc use frame= %p\n", framePtr); + if (framePtr) { + nsPtr = framePtr->nsPtr; } else { - Tcl_CallFrame *f = nonXotclObjectFrame(Tcl_CallFrame_callerPtr(csc->currentFramePtr)); - ns = currentNonFakeNamespace(interp); + framePtr = nonXotclObjectProcFrame((Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp)); + nsPtr = Tcl_CallFrame_nsPtr(framePtr); + /* fprintf(stderr, "nonXotclObjectProcFrame returned %p frame %p, currentNs %p %s, xot %p %s\n", + framePtr,Tcl_CallFrame_callerPtr(csc->currentFramePtr), nsPtr,nsPtr?nsPtr->fullName:NULL, + RUNTIME_STATE(interp)->XOTclNS,RUNTIME_STATE(interp)->XOTclNS->fullName); + tcl85showStack(interp);*/ - fprintf(stderr, "nonXotclObjectFrame returned %p from %p, currentNs %s\n", - f,Tcl_CallFrame_callerPtr(csc->currentFramePtr), ns? ns->fullName:NULL); - tcl85showStack(interp); - /* find last incovation outside ::xotcl (for things like relmgr) */ - while (ns == RUNTIME_STATE(interp)->XOTclNS) { - if (f) { - ns = f->nsPtr; - f = Tcl_CallFrame_callerPtr(f); + while (nsPtr == RUNTIME_STATE(interp)->XOTclNS) { + /*fprintf(stderr, "... ns %s\n",nsPtr->fullName);*/ + if (framePtr) { + nsPtr = framePtr->nsPtr; + framePtr = nonXotclObjectProcFrame(Tcl_CallFrame_callerPtr(framePtr)); } else { - ns = Tcl_GetGlobalNamespace(interp); + nsPtr = Tcl_GetGlobalNamespace(interp); } + /*fprintf(stderr, "... new ns %s\n",nsPtr->fullName);*/ } - fprintf(stderr, " found ns %p '%s'\n", ns, ns?ns->fullName:"NULL"); + fprintf(stderr, " found ns %p '%s'\n", nsPtr, nsPtr?nsPtr->fullName:nsPtr); } } - if (!ns) { + if (!nsPtr) { /* calls on xotcl toplevel */ XOTclCallStackContent *bot = cs->content + 1; - fprintf(stderr, " bot=%p diff=%d\n", bot, top-bot); + fprintf(stderr, " TOPLEVEL bot=%p diff=%d\n", bot, top-bot); if (top - bot >= 0 && bot->currentFramePtr) { /* get calling tcl environment */ - Tcl_CallFrame *f = Tcl_CallFrame_callerPtr(bot->currentFramePtr); - if (f) { - ns = f->nsPtr; + Tcl_CallFrame *framePtr = Tcl_CallFrame_callerPtr(bot->currentFramePtr); + if (framePtr) { + nsPtr = framePtr->nsPtr; /*fprintf(stderr, "top=%p, bot=%p b->c=%p f=%p ns=%p\n", - top, bot, bot->currentFramePtr, f, ns);*/ - /*fprintf(stderr,"ns from calling tcl environment %p '%s'\n", - ns, ns?ns->fullName : "" );*/ + top, bot, bot->currentFramePtr, framePtr, ns);*/ + fprintf(stderr,"ns from calling tcl environment %p '%s'\n", + nsPtr, nsPtr?nsPtr->fullName : "" ); } else { fprintf(stderr, " nothing found, use ::\n"); - ns = Tcl_GetGlobalNamespace(interp); + nsPtr = Tcl_GetGlobalNamespace(interp); } } } /*XOTclCallStackDump(interp);*/ /*XOTclStackDump(interp);*/ - fprintf(stderr," **** callingNameSpace: returns %p %s\n", ns, ns?ns->fullName:""); - return ns; + fprintf(stderr," **** callingNameSpace: returns %p %s\n", nsPtr, nsPtr?nsPtr->fullName:""); + return nsPtr; } static int Index: generic/xotclAccessInt.h =================================================================== diff -u -r04a8acdb23193c6b36b339e085dd9f6814448a8d -r8ddbf5cdc1dd1f9e0d9c429a8c3f6d279c97bd8e --- generic/xotclAccessInt.h (.../xotclAccessInt.h) (revision 04a8acdb23193c6b36b339e085dd9f6814448a8d) +++ generic/xotclAccessInt.h (.../xotclAccessInt.h) (revision 8ddbf5cdc1dd1f9e0d9c429a8c3f6d279c97bd8e) @@ -18,15 +18,14 @@ #define Tcl_CallFrame_objc(cf) ((CallFrame *)cf)->objc #define Tcl_CallFrame_objv(cf) ((CallFrame *)cf)->objv #define Tcl_CallFrame_clientData(cf) ((CallFrame *)cf)->clientData +#define Tcl_CallFrame_nsPtr(cf) ((Tcl_Namespace *)((CallFrame *)cf)->nsPtr) #define Tcl_Namespace_cmdTable(nsPtr) &((Namespace *)nsPtr)->cmdTable #define Tcl_Namespace_varTable(nsPtr) &((Namespace *)nsPtr)->varTable #define Tcl_Namespace_childTable(nsPtr) &((Namespace *)nsPtr)->childTable #define Tcl_Namespace_activationCount(nsPtr) ((Namespace *)nsPtr)->activationCount #define Tcl_Namespace_deleteProc(nsPtr) ((Namespace *)nsPtr)->deleteProc - - #define Tcl_Command_refCount(cmd) ((Command *)cmd)->refCount #define Tcl_Command_cmdEpoch(cmd) ((Command *)cmd)->cmdEpoch #define Tcl_Command_flags(cmd) ((Command *)cmd)->flags Index: generic/xotclInt.h =================================================================== diff -u -r04a8acdb23193c6b36b339e085dd9f6814448a8d -r8ddbf5cdc1dd1f9e0d9c429a8c3f6d279c97bd8e --- generic/xotclInt.h (.../xotclInt.h) (revision 04a8acdb23193c6b36b339e085dd9f6814448a8d) +++ generic/xotclInt.h (.../xotclInt.h) (revision 8ddbf5cdc1dd1f9e0d9c429a8c3f6d279c97bd8e) @@ -279,7 +279,7 @@ } else { \ CallFrame *myframePtr = (CallFrame *)framePtr; \ /*fprintf(stderr,"XOTcl_PushFrame frame %p (with fakeNS)\n",framePtr);*/ \ - Tcl_PushCallFrame(interp, (Tcl_CallFrame*)framePtr, RUNTIME_STATE(interp)->fakeNS /*Tcl_Interp_varFramePtr(interp)->nsPtr*/, 1|FRAME_IS_XOTCL_OBJECT); \ + Tcl_PushCallFrame(interp, (Tcl_CallFrame*)framePtr, /* RUNTIME_STATE(interp)->fakeNS */ Tcl_CallFrame_nsPtr(Tcl_Interp_varFramePtr(interp)), 1|FRAME_IS_XOTCL_OBJECT); \ Tcl_CallFrame_procPtr(myframePtr) = &RUNTIME_STATE(interp)->fakeProc; \ Tcl_CallFrame_varTablePtr(myframePtr) = (obj)->varTable; \ } \ Index: tests/forwardtest.xotcl =================================================================== diff -u -r04a8acdb23193c6b36b339e085dd9f6814448a8d -r8ddbf5cdc1dd1f9e0d9c429a8c3f6d279c97bd8e --- tests/forwardtest.xotcl (.../forwardtest.xotcl) (revision 04a8acdb23193c6b36b339e085dd9f6814448a8d) +++ tests/forwardtest.xotcl (.../forwardtest.xotcl) (revision 8ddbf5cdc1dd1f9e0d9c429a8c3f6d279c97bd8e) @@ -298,15 +298,21 @@ NS::Main create m m i1 -#puts ==== +puts ==== ? [list set _ [NS create n1]] ::n1 +puts FFFFFF NS filter f +puts GGGG ? [list set _ [NS create n2]] ::n2 +puts HHHH NS filter "" +puts IIII #puts ==== namespace eval test { +puts JJJJJ ? [list set _ [NS create n1]] ::test::n1 +puts KKKKK ? [list set _ [NS create n3]] ::test::n3 NS filter f ? [list set _ [NS create n4]] ::test::n4