Index: TODO =================================================================== diff -u -r714fdeeeeca44ee6f77d93349a0afec4c4b139cc -rb361d502bbf5fc7920797d064ec21bd111d11081 --- TODO (.../TODO) (revision 714fdeeeeca44ee6f77d93349a0afec4c4b139cc) +++ TODO (.../TODO) (revision b361d502bbf5fc7920797d064ec21bd111d11081) @@ -5004,6 +5004,9 @@ improve documentation - get rid of // comments - use nonnull variable attributes for prototpyes (nsf.h, nsfInt.h, nsf.c) +- add returns_nonnull assertion +- simplify few inner code pieces based on assertions +- add serveral more assertions based on nonnull sepcifications. ======================================================================== TODO: Index: generic/nsf.c =================================================================== diff -u -r714fdeeeeca44ee6f77d93349a0afec4c4b139cc -rb361d502bbf5fc7920797d064ec21bd111d11081 --- generic/nsf.c (.../nsf.c) (revision 714fdeeeeca44ee6f77d93349a0afec4c4b139cc) +++ generic/nsf.c (.../nsf.c) (revision b361d502bbf5fc7920797d064ec21bd111d11081) @@ -278,8 +278,8 @@ nonnull(1) nonnull(2); /* prototypes for namespace specific calls */ -static Tcl_Obj *NameInNamespaceObj(Tcl_Interp *interp, CONST char *name, Tcl_Namespace *ns) - nonnull(1) nonnull(2) nonnull(3); +static Tcl_Obj *NameInNamespaceObj(CONST char *name, Tcl_Namespace *ns) + nonnull(1) nonnull(2); static Tcl_Namespace *CallingNameSpace(Tcl_Interp *interp) nonnull(1); NSF_INLINE static Tcl_Command NSFindCommand(Tcl_Interp *interp, CONST char *name) @@ -401,10 +401,9 @@ /* prototypes for (class) list handling */ static NsfClasses ** NsfClassListAdd(NsfClasses **firstPtrPtr, NsfClass *cl, ClientData clientData) - nonnull(1); + nonnull(1) returns_nonnull; -static void NsfClassListFree(NsfClasses *firstPtr) - nonnull(1); +static void NsfClassListFree(NsfClasses *firstPtr); /* misc prototypes */ static int SetInstVar(Tcl_Interp *interp, NsfObject *object, Tcl_Obj *nameObj, Tcl_Obj *valueObj) @@ -431,7 +430,9 @@ EXTERN void NsfDStringArgv(Tcl_DString *dsPtr, int objc, Tcl_Obj *CONST objv[]) nonnull(1) nonnull(3); + static int MethodSourceMatches(int withSource, NsfClass *cl, NsfObject *object); + #ifdef DO_CLEANUP static void DeleteNsfProcs(Tcl_Interp *interp, Tcl_Namespace *nsPtr) nonnull(1); @@ -1152,9 +1153,13 @@ * *---------------------------------------------------------------------- */ +NSF_INLINE static int IsClassNsName(CONST char *string, CONST char **cont) nonnull(1); + NSF_INLINE static int IsClassNsName(CONST char *string, CONST char **cont) { + assert(string); + if (*string == ':' && strncmp((string), "::nsf::classes", 14) == 0) { if (cont) {*cont = string + 14;} return 1; @@ -1201,10 +1206,17 @@ * *---------------------------------------------------------------------- */ +NSF_INLINE static NsfObject *GetObjectFromNsName(Tcl_Interp *interp, CONST char *string, int *fromClassNS) + nonnull(1) nonnull(2) nonnull(3); + NSF_INLINE static NsfObject * GetObjectFromNsName(Tcl_Interp *interp, CONST char *string, int *fromClassNS) { CONST char *className; + assert(interp != NULL); + assert(string != NULL); + assert(fromClassNS != NULL); + if (IsClassNsName(string, &className)) { *fromClassNS = 1; return (NsfObject *)GetClassFromString(interp, className); @@ -1292,10 +1304,16 @@ * *---------------------------------------------------------------------- */ +static int TclObjIsNsfObject(Tcl_Interp *interp, Tcl_Obj *objPtr, NsfObject **objectPtr) nonnull(1) nonnull(2) nonnull(3); static int TclObjIsNsfObject(Tcl_Interp *interp, Tcl_Obj *objPtr, NsfObject **objectPtr) { Tcl_ObjType CONST86 *cmdType = objPtr->typePtr; + + assert(interp); + assert(objPtr); + assert(objectPtr); + if (cmdType == Nsf_OT_tclCmdNameType) { Tcl_Command cmd = Tcl_GetCommandFromObj(interp, objPtr); if (likely(cmd != NULL)) { @@ -1325,13 +1343,18 @@ * *---------------------------------------------------------------------- */ +static int GetObjectFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, NsfObject **objectPtr) nonnull(1) nonnull(2) nonnull(3); static int GetObjectFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, NsfObject **objectPtr) { NsfObject *object; CONST char *string; Tcl_Command cmd; + assert(interp); + assert(objPtr); + assert(objectPtr); + /*fprintf(stderr, "GetObjectFromObj obj %p %s is of type %s\n", objPtr, ObjStr(objPtr), objPtr->typePtr ? objPtr->typePtr->name : "(null)");*/ @@ -1360,7 +1383,7 @@ if (isAbsolutePath(string)) { object = NULL; } else { - Tcl_Obj *tmpName = NameInNamespaceObj(interp, string, CallingNameSpace(interp)); + Tcl_Obj *tmpName = NameInNamespaceObj(string, CallingNameSpace(interp)); CONST char *nsString = ObjStr(tmpName); INCR_REF_COUNT(tmpName); @@ -1466,6 +1489,10 @@ CONST char *objName = ObjStr(objPtr); Tcl_Command cmd; + assert(interp); + assert(objPtr); + assert(clPtr); + cmd = Tcl_GetCommandFromObj(interp, objPtr); /*fprintf(stderr, "GetClassFromObj %p %s unknown %d cmd %p\n", objPtr, objName, withUnknown, cmd);*/ @@ -1485,7 +1512,7 @@ int alias_oc = 0; if (!isAbsolutePath(objName)) { - nameObj = NameInNamespaceObj(interp, objName, CallingNameSpace(interp)); + nameObj = NameInNamespaceObj(objName, CallingNameSpace(interp)); objName = ObjStr(nameObj); INCR_REF_COUNT(nameObj); } @@ -1510,7 +1537,7 @@ } #endif if (cls) { - if (clPtr) *clPtr = cls; + *clPtr = cls; return TCL_OK; } } @@ -1519,7 +1546,7 @@ if (result == TCL_OK) { cls = NsfObjectToClass(object); if (cls) { - if (clPtr) *clPtr = cls; + *clPtr = cls; return TCL_OK; } else { /* flag, that we could not convert so far */ @@ -1529,9 +1556,7 @@ if (withUnknown) { result = NsfCallObjectUnknownHandler(interp, isAbsolutePath(objName) ? objPtr : - NameInNamespaceObj(interp, - objName, - CallingNameSpace(interp))); + NameInNamespaceObj(objName, CallingNameSpace(interp))); if (result == TCL_OK) { /* Retry, but now, the last argument (withUnknown) has to be 0 */ @@ -1571,7 +1596,7 @@ static int IsObjectOfType(Tcl_Interp *interp, NsfObject *object, CONST char *what, Tcl_Obj *objPtr, - Nsf_Param CONST *pPtr) { + Nsf_Param CONST *pPtr) { NsfClass *cl; Tcl_DString ds, *dsPtr = &ds; @@ -1621,10 +1646,11 @@ *---------------------------------------------------------------------- */ static Tcl_Obj * -NameInNamespaceObj(Tcl_Interp *interp, CONST char *name, Tcl_Namespace *nsPtr) { +NameInNamespaceObj(CONST char *name, Tcl_Namespace *nsPtr) { Tcl_Obj *objPtr; Tcl_DString ds, *dsPtr = &ds; + assert(name); assert(nsPtr); /*fprintf(stderr, "NameInNamespaceObj %s (%p, %s) ", name, nsPtr, nsPtr->fullName);*/ @@ -1643,7 +1669,7 @@ * NewTclCommand -- * * Given a provided prefix in dsPtr, make it a name of a command that does not exist. - * This function is used by the *new command, when "anonyous" objects are created + * This function is used by the *new command, when "anonymous" objects are created * * Results: * dsPtr will be complete to represent a new (unused) name of a command @@ -1687,10 +1713,15 @@ * *---------------------------------------------------------------------- */ +static NsfClasses *NsfReverseClasses(NsfClasses *sl) nonnull(1) returns_nonnull; + static NsfClasses * NsfReverseClasses(NsfClasses *sl) { NsfClasses *firstPtr = NULL; - for (; sl; sl = sl->nextPtr) { + + assert(sl != NULL); + + for (; likely(sl != NULL); sl = sl->nextPtr) { NsfClasses *element = NEW(NsfClasses); element->cl = sl->cl; @@ -1745,6 +1776,8 @@ NsfClassListAdd(NsfClasses **firstPtrPtr, NsfClass *cl, ClientData clientData) { NsfClasses *l = *firstPtrPtr, *element = NEW(NsfClasses); + assert(firstPtrPtr); + element->cl = cl; element->clientData = clientData; element->nextPtr = NULL; @@ -1819,8 +1852,13 @@ * *---------------------------------------------------------------------- */ +static NsfClasses *NsfClassListFind(NsfClasses *clPtr, NsfClass *cl) nonnull(2); + static NsfClasses * NsfClassListFind(NsfClasses *clPtr, NsfClass *cl) { + + assert(cl); + for (; clPtr; clPtr = clPtr->nextPtr) { if (clPtr->cl == cl) break; } @@ -1892,11 +1930,15 @@ * *---------------------------------------------------------------------- */ +static NsfClasses *NsfClassListUnlink(NsfClasses **firstPtrPtr, void *key) nonnull(1) nonnull(2); static NsfClasses * NsfClassListUnlink(NsfClasses **firstPtrPtr, void *key) { NsfClasses *entryPtr = NULL; + assert(firstPtrPtr != NULL); + assert(key != NULL); + if (*firstPtrPtr != NULL) { NsfClasses *prevPtr = NULL; @@ -2006,10 +2048,15 @@ * *---------------------------------------------------------------------- */ +static int MustBeBefore(NsfClass *a, NsfClass *b, NsfClasses *superClasses) nonnull(1) nonnull(2) nonnull(3); + static int MustBeBefore(NsfClass *a, NsfClass *b, NsfClasses *superClasses) { int result; + assert(a != NULL); + assert(b != NULL); + assert(superClasses != NULL); assert(b->order != NULL); /* @@ -2106,12 +2153,17 @@ * *---------------------------------------------------------------------- */ +static NsfClasses *MergeInheritanceLists(NsfClasses *pl, NsfClass *cl) nonnull(1) nonnull(2) returns_nonnull; + static NsfClasses * MergeInheritanceLists(NsfClasses *pl, NsfClass *cl) { NsfClasses *sl, *baseList, **plNext, *superClasses, *deletionList = NULL; + assert(pl != NULL); + assert(cl != NULL); + #if defined(NSF_LINEARIZER_TRACE) fprintf(stderr, "=== working on %s\n", ClassName(cl)); #endif @@ -2271,9 +2323,8 @@ /* fprintf(stderr, "delete from deletion list %p client data %p\n", sl, sl->clientData); */ NsfClassListFree(sl->clientData); } - if (deletionList) { - NsfClassListFree(deletionList); - } + + NsfClassListFree(deletionList); NsfClassListFree(superClasses); return pl; @@ -2295,10 +2346,15 @@ * *---------------------------------------------------------------------- */ +static int TopoSortSuper(NsfClass *cl, NsfClass *baseClass) nonnull(1) nonnull(2); + static int TopoSortSuper(NsfClass *cl, NsfClass *baseClass) { NsfClasses *pl, *sl; + assert(cl != NULL); + assert(baseClass != NULL); + /* * Be careful to reset the color of unreported classes to * white in the caller on all exits to WHITE. @@ -2376,12 +2432,15 @@ * *---------------------------------------------------------------------- */ +NSF_INLINE static NsfClasses *PrecedenceOrder(NsfClass *cl) nonnull(1) returns_nonnull; NSF_INLINE static NsfClasses * PrecedenceOrder(NsfClass *cl) { register NsfClasses *sl; int success; + assert(cl != NULL); + /* * Check, of the superclass order is already cached. */ @@ -2503,11 +2562,14 @@ * *---------------------------------------------------------------------- */ +static void FlushPrecedences(NsfClasses *subClasses) nonnull(1); + static void -FlushPrecedences(NsfClasses *subClasses) { - NsfClasses *clPtr; +FlushPrecedences(NsfClasses *clPtr) { - for (clPtr = subClasses; clPtr; clPtr = clPtr->nextPtr) { + assert(clPtr != NULL); + + for (; clPtr; clPtr = clPtr->nextPtr) { NsfClassListFree(clPtr->cl->order); clPtr->cl->order = NULL; } @@ -2528,12 +2590,15 @@ * *---------------------------------------------------------------------- */ +static void AddInstance(NsfObject *object, NsfClass *cl) nonnull(1) nonnull(2); static void AddInstance(NsfObject *object, NsfClass *cl) { int newItem; + assert(object); assert(cl); + object->cl = cl; (void) Tcl_CreateHashEntry(&cl->instances, (char *)object, &newItem); /*if (newItem == 0) { @@ -2558,10 +2623,12 @@ * *---------------------------------------------------------------------- */ +static void RemoveInstance(NsfObject *object, NsfClass *cl) nonnull(1) nonnull(2); static void RemoveInstance(NsfObject *object, NsfClass *cl) { + assert(object); assert(cl); /* * If we are during a delete, which should not happen under normal @@ -2585,42 +2652,43 @@ /* * superclass/subclass list maintenance */ +static void AddSuper1(NsfClass *s, NsfClasses **sl) nonnull(1) nonnull(2); +static void AddSuper(NsfClass *cl, NsfClass *super) nonnull(1); +static int RemoveSuper1(NsfClass *s, NsfClasses **sl) nonnull(1) nonnull(2); +static int RemoveSuper(NsfClass *cl, NsfClass *super) nonnull(1) nonnull(2); static void -AS(NsfClass *s, NsfClasses **sl) { -#if 0 - register NsfClasses *l = *sl; - while (l && l->cl != s) { - l = l->nextPtr; - } -#else - register NsfClasses *l = NULL; -#endif - if (!l) { - NsfClasses *sc = NEW(NsfClasses); +AddSuper1(NsfClass *s, NsfClasses **sl) { + NsfClasses *sc = NEW(NsfClasses); - sc->cl = s; - sc->nextPtr = *sl; - *sl = sc; - } + assert(s != NULL); + assert(sl != NULL); + + sc->cl = s; + sc->nextPtr = *sl; + *sl = sc; } static void AddSuper(NsfClass *cl, NsfClass *super) { - if (cl && super) { + if (super) { + assert(cl != NULL); /* * keep corresponding sub in step with super */ - AS(super, &cl->super); - AS(cl, &super->sub); + AddSuper1(super, &cl->super); + AddSuper1(cl, &super->sub); } } static int RemoveSuper1(NsfClass *s, NsfClasses **sl) { NsfClasses *l = *sl; - if (!l) return 0; + assert(s != NULL); + assert(sl != NULL); + + if (l == NULL) return 0; if (l->cl == s) { *sl = l->nextPtr; FREE(NsfClasses, l); @@ -2644,6 +2712,9 @@ int sp = RemoveSuper1(super, &cl->super); int sb = RemoveSuper1(cl, &super->sub); + assert(cl != NULL); + assert(super != NULL); + return sp && sb; } @@ -2846,7 +2917,7 @@ cmd = Tcl_GetCommandFromObj(interp, methodHandleObj); ensembleObject = cmd ? NsfGetObjectFromCmdPtr(cmd) : NULL; - if (!ensembleObject) { + if (ensembleObject == NULL) { DECR_REF_COUNT(methodHandleObj); if (methodName1) {*methodName1 = NULL;} if (regObject) {*regObject = NULL;} @@ -3009,7 +3080,9 @@ FindMethod(Tcl_Namespace *nsPtr, CONST char *methodName) { register Tcl_HashEntry *entryPtr; - assert(nsPtr); + assert(nsPtr != NULL); + assert(methodName != NULL); + if ((entryPtr = Tcl_CreateHashEntry(Tcl_Namespace_cmdTablePtr(nsPtr), methodName, NULL))) { return (Tcl_Command) Tcl_GetHashValue(entryPtr); } @@ -3225,14 +3298,14 @@ } } - if (!cmd && object->nsPtr) { + if (cmd == NULL && object->nsPtr) { int fromClassNS = 0; cmd = ResolveMethodName(interp, object->nsPtr, methodObj, NULL, NULL, NULL, NULL, &fromClassNS); } - if (!cmd && object->cl) { + if (cmd == NULL && object->cl) { *pcl = (*lookupFunction)(interp, object->cl, methodObj, &cmd); } @@ -3639,7 +3712,7 @@ static NsfObjectOpt * NsfRequireObjectOpt(NsfObject *object) { - if (!object->opt) { + if (object->opt == NULL) { object->opt = NEW(NsfObjectOpt); memset(object->opt, 0, sizeof(NsfObjectOpt)); } @@ -3649,7 +3722,7 @@ static NsfClassOpt * NsfRequireClassOpt(/*@notnull@*/ NsfClass *cl) { assert(cl); - if (!cl->opt) { + if (cl->opt == NULL) { cl->opt = NEW(NsfClassOpt); memset(cl->opt, 0, sizeof(NsfClassOpt)); if (cl->object.flags & NSF_IS_CLASS) { @@ -3666,7 +3739,7 @@ #ifdef NAMESPACE_TRACE fprintf(stderr, "+++ MakeObjNamespace for %s\n", ObjectName(object)); #endif - if (!object->nsPtr) { + if (object->nsPtr == NULL) { Tcl_Namespace *nsPtr; nsPtr = object->nsPtr = NSGetFreshNamespace(interp, object, ObjectName(object)); @@ -3764,11 +3837,14 @@ * *---------------------------------------------------------------------- */ +static CONST char *MethodName(Tcl_Obj *methodObj) nonnull(1) returns_nonnull; + static CONST char * MethodName(Tcl_Obj *methodObj) { char *methodName; assert(methodObj); + methodName = ObjStr(methodObj); if (FOR_COLON_RESOLVER(methodName)) { methodName ++; @@ -3804,7 +3880,10 @@ Tcl_Obj *resultObj = Tcl_NewListObj(0, NULL); - if (!framePtr) { + assert(interp); + assert(methodName); + + if (framePtr == NULL) { /* We default to the top frame, if not requested otherwise */ (void) CallStackGetTopFrame(interp, &framePtr); } @@ -3814,14 +3893,8 @@ CallStackMethodPath(interp, framePtr)); } - if (methodName) { - - //assert(*methodName != ':'); - - Tcl_ListObjAppendElement(interp, resultObj, - Tcl_NewStringObj(methodName,-1)); - } - + Tcl_ListObjAppendElement(interp, resultObj, + Tcl_NewStringObj(methodName,-1)); return resultObj; } @@ -4068,7 +4141,7 @@ return var; } - if (unlikely(!object)) { + if (unlikely(object == NULL)) { return NULL; } @@ -4703,7 +4776,7 @@ static Tcl_Namespace * RequireObjNamespace(Tcl_Interp *interp, NsfObject *object) { - if (!object->nsPtr) { + if (object->nsPtr == NULL) { MakeObjNamespace(interp, object); NsfNamespaceInit(object->nsPtr); } @@ -5441,7 +5514,9 @@ GetObjectFromString(Tcl_Interp *interp, CONST char *name) { register Tcl_Command cmd; + assert(interp); assert(name); + /*fprintf(stderr, "GetObjectFromString name = '%s'\n", name);*/ cmd = NSFindCommand(interp, name); @@ -5471,6 +5546,9 @@ static NsfClass * GetClassFromString(Tcl_Interp *interp, CONST char *name) { NsfObject *object = GetObjectFromString(interp, name); + + assert(interp); + assert(name); return (object && NsfObjectIsClass(object)) ? (NsfClass *)object : NULL; } @@ -6415,7 +6493,7 @@ /* * no obj->opt -> checkoption == CHECK_NONE */ - if (!object->opt) { + if (object->opt == NULL) { return TCL_OK; } /* we do not check assertion modifying methods, otherwise @@ -6450,7 +6528,7 @@ } } - if (!comment) { + if (comment == 0) { CallFrame frame, *framePtr = &frame; Nsf_PushFrameObj(interp, object, framePtr); @@ -6667,7 +6745,7 @@ /* fprintf(stderr, "find %p %s in checklist 1 %p\n", pl->cl, ClassName(pl->cl), *checkList);*/ - if (NsfClassListFind(*checkList, pl->cl)) { + if (*checkList != NULL && NsfClassListFind(*checkList, pl->cl)) { /*fprintf(stderr, "+++ never add %s\n", ClassName(pl->cl));*/ } else { if (opt && opt->classMixins) { @@ -6765,7 +6843,9 @@ MixinComputeOrder(Tcl_Interp *interp, NsfObject *object) { NsfClasses *fullList, *checkList = NULL, *mixinClasses = NULL, *clPtr; - if (object->mixinOrder) MixinResetOrder(object); + if (object->mixinOrder) { + MixinResetOrder(object); + } /* Append per-obj mixins */ if (object->opt) { @@ -6799,6 +6879,7 @@ CmdListPrint(interp, "mixinOrder", object->mixinOrder);*/ NsfClassListFree(checkList); + fullList = mixinClasses; /* @@ -6815,13 +6896,14 @@ checker = NsfClassListFind(clPtr->nextPtr, cl); /* - * if checker is set, it is a duplicate and ignored + * If checker is set, it is a duplicate and ignored. */ if (checker == NULL) { /* check object->cl hierarchy */ checker = NsfClassListFind(PrecedenceOrder(object->cl), cl); /* - * if checker is set, it was found in the class hierarchy and it is ignored + * If checker is set, it was found in the class hierarchy and it is + * ignored. */ } if (checker == NULL) { @@ -6914,7 +6996,7 @@ */ static void AppendMatchingElement(Tcl_Interp *interp, Tcl_Obj *resultObj, Tcl_Obj *nameObj, CONST char *pattern) { - if (!pattern || Tcl_StringMatch( ObjStr(nameObj), pattern)) { + if (pattern == NULL || Tcl_StringMatch( ObjStr(nameObj), pattern)) { Tcl_ListObjAppendElement(interp, resultObj, nameObj); } } @@ -7125,7 +7207,7 @@ Tcl_CreateHashEntry(destTablePtr, (char *)cl, new); if (*new) { if (appendResult) { - if (!pattern || Tcl_StringMatch(ClassName(cl), pattern)) { + if (pattern == NULL || Tcl_StringMatch(ClassName(cl), pattern)) { Tcl_Obj *listObj = Tcl_NewListObj(0, NULL); Tcl_Obj *g = (Tcl_Obj *) clientData; INCR_REF_COUNT(listObj); @@ -8009,9 +8091,9 @@ m, m->next, pattern, matchObject);*/ if (mixinClass && - (!pattern - || (matchObject && &(mixinClass->object) == matchObject) - || (!matchObject && Tcl_StringMatch(ObjStr(mixinClass->object.cmdName), pattern)))) { + (pattern == NULL + || (matchObject != NULL && &(mixinClass->object) == matchObject) + || (matchObject == NULL && Tcl_StringMatch(ObjStr(mixinClass->object.cmdName), pattern)))) { if (withGuards && m->clientData) { Tcl_Obj *l = Tcl_NewListObj(0, NULL); Tcl_Obj *g = (Tcl_Obj *) m->clientData; @@ -8114,7 +8196,7 @@ */ if (startingClass) { *cl = SearchCMethod(startingClass, name, &cmd); - if (!*cl) { + if (*cl == NULL) { /* * If no filter is found yet -> search the meta-class */ @@ -8272,7 +8354,7 @@ } if (object->flags & NSF_MIXIN_ORDER_DEFINED_AND_VALID) { NsfCmdList *ml; - for (ml = object->mixinOrder; ml && !guardAdded; ml = ml->nextPtr) { + for (ml = object->mixinOrder; ml != NULL && !guardAdded; ml = ml->nextPtr) { NsfClass *mixin = NsfGetClassFromCmdPtr(ml->cmdPtr); if (mixin && mixin->opt) { guardAdded = GuardAddFromDefinitionList(dest, filterCmd, @@ -8324,7 +8406,7 @@ if (frl) { /* try to find simple name first */ NsfCmdList *h = CmdListFindNameInList(interp, interceptorName, frl); - if (!h) { + if (h == NULL) { /* maybe it is a qualified name */ Tcl_Command cmd = NSFindCommand(interp, interceptorName); if (cmd) { @@ -8635,7 +8717,7 @@ while (f) { CONST char *simpleName = Tcl_GetCommandName(interp, f->cmdPtr); - if (!pattern || Tcl_StringMatch(simpleName, pattern)) { + if (pattern == NULL || Tcl_StringMatch(simpleName, pattern)) { if (withGuards && f->clientData) { Tcl_Obj *innerList = Tcl_NewListObj(0, NULL); Tcl_Obj *g = (Tcl_Obj *) f->clientData; @@ -11068,7 +11150,7 @@ if (rst->doFilters && !rst->guardCount) { NsfCallStackContent *cscPtr1 = CallStackGetTopFrame0(interp); - if (!cscPtr1 || + if (cscPtr1 == NULL || (object != cscPtr1->self || (cscPtr1->frameType != NSF_CSC_TYPE_ACTIVE_FILTER))) { FilterStackPush(object, methodObj); flags |= NSF_CSC_FILTER_STACK_PUSHED; @@ -13447,7 +13529,7 @@ /* * Set the namespace of the method as inside of the class. */ - if (!regObject->nsPtr) { + if (regObject->nsPtr == NULL) { MakeObjNamespace(interp, regObject); } /*fprintf(stderr, "obj %s\n", ObjectName(defObject)); @@ -13492,7 +13574,7 @@ CONST char *argsStr = ObjStr(args), *bodyStr = ObjStr(body), *nameStr = ObjStr(nameObj); int result; - if (precondition && !postcondition) { + if (precondition && postcondition == NULL) { return NsfPrintError(interp, "%s method '%s'; when specifying a precondition (%s)" " a postcondition must be specified as well", ClassName(cl), nameStr, ObjStr(precondition)); @@ -13521,13 +13603,13 @@ if (precondition || postcondition) { if (cl) { NsfClassOpt *opt = NsfRequireClassOpt(cl); - if (!opt->assertions) { + if (opt->assertions == NULL) { opt->assertions = AssertionCreateStore(); } aStore = opt->assertions; } else { NsfObjectOpt *opt = NsfRequireObjectOpt(defObject); - if (!opt->assertions) { + if (opt->assertions == NULL) { opt->assertions = AssertionCreateStore(); } aStore = opt->assertions; @@ -14278,7 +14360,7 @@ } } - if (!tcd->cmdName) { + if (tcd->cmdName == NULL) { tcd->cmdName = nameObj; } @@ -14295,7 +14377,7 @@ */ CONST char *nameString = ObjStr(tcd->cmdName); if (!isAbsolutePath(nameString)) { - tcd->cmdName = NameInNamespaceObj(interp, nameString, CallingNameSpace(interp)); + tcd->cmdName = NameInNamespaceObj(nameString, CallingNameSpace(interp)); /*fprintf(stderr, "+++ name %s not absolute, therefore qualifying %s\n", nameString, ObjStr(tcd->cmdName));*/ } @@ -14319,7 +14401,7 @@ } } - tcd->passthrough = !tcd->args && *(ObjStr(tcd->cmdName)) != '%' && tcd->objProc; + tcd->passthrough = tcd->args == NULL && *(ObjStr(tcd->cmdName)) != '%' && tcd->objProc; forward_process_options_exit: /*fprintf(stderr, "forward args = %p, name = '%s'\n", tcd->args, ObjStr(tcd->cmdName));*/ @@ -14419,7 +14501,7 @@ * Report just the already fully initialized slot objects, not the one * being right now created. */ - if (!childObject || (childObject->flags & NSF_INIT_CALLED) == 0) { + if (childObject == NULL || (childObject->flags & NSF_INIT_CALLED) == 0) { /* fprintf(stderr, "....... key %s unfinished\n", key);*/ continue; } @@ -14672,11 +14754,11 @@ /* always make sure, we only decrement when necessary */ *freeArgumentVector = 0; - if (!cscPtr) { + if (cscPtr == NULL) { return NsfPrintError(interp, "next: can't find self"); } - if (!cscPtr->cmdPtr) { + if (cscPtr->cmdPtr == NULL) { return NsfPrintError(interp, "next: no executing proc"); } @@ -15059,7 +15141,7 @@ Tcl_ResetResult(interp); methodName = (char *)Tcl_GetCommandName(interp, cscPtr->cmdPtr); - if (!methodName) { + if (methodName == NULL) { return TCL_OK; } @@ -15344,7 +15426,7 @@ object->teardown = interp; object->nsPtr = nsPtr; - if (!softrecreate && cl) { + if (!softrecreate && cl != NULL) { AddInstance(object, cl); } if (object->flags & NSF_RECREATE) { @@ -15404,7 +15486,7 @@ NsfObject *object = (NsfObject *)clientData; Tcl_Interp *interp; - if (!object || !object->teardown) return; + if (object == NULL || object->teardown == NULL) return; /*fprintf(stderr, "****** PrimitiveODestroy %p cmd %p flags %.6x\n", object, object->id, object->flags);*/ @@ -15947,7 +16029,7 @@ /* * check and latch against recurrent calls with obj->teardown */ - if (!object || !object->teardown) return; + if (object == NULL || object->teardown == NULL) return; interp = object->teardown; /* @@ -16595,7 +16677,7 @@ NsfObject *object = cd->object; if (objc > 2) return NsfObjWrongArgs(interp, "wrong # args", object->cmdName, objv[0], "?value?"); - if (!object) return NsfDispatchClientDataError(interp, clientData, "object", ObjStr(objv[0])); + if (object == NULL) return NsfDispatchClientDataError(interp, clientData, "object", ObjStr(objv[0])); if (cd->paramsPtr && objc == 2) { Tcl_Obj *outObjPtr; @@ -16967,7 +17049,7 @@ */ return CallForwarder(tcd, interp, objc, objv); - } else if (!tcd->args && *(ObjStr(tcd->cmdName)) != '%') { + } else if (tcd->args == NULL && *(ObjStr(tcd->cmdName)) != '%') { /* * We have have no args, therefore we have only to replace the method name * with the given cmd name. @@ -17390,7 +17472,7 @@ break; } - if (!framePtr) { + if (framePtr == NULL) { nsPtr = Tcl_GetGlobalNamespace(interp); } @@ -18178,7 +18260,7 @@ for (; hPtr; hPtr = Tcl_NextHashEntry(&hSrch)) { Var *val = TclVarHashGetValue(hPtr); Tcl_Obj *key = TclVarHashGetKey(val); - if (!pattern || Tcl_StringMatch(ObjStr(key), pattern)) { + if (pattern == NULL || Tcl_StringMatch(ObjStr(key), pattern)) { Tcl_ListObjAppendElement(interp, list, key); } } @@ -18493,7 +18575,7 @@ Tcl_ResetResult(interp); - if (!cmd) { + if (cmd == NULL) { if (subcmd == InfomethodsubcmdExistsIdx) { Tcl_SetObjResult(interp, Tcl_NewIntObj(0)); } @@ -19174,9 +19256,11 @@ int classesOnly, NsfClass *type) { NsfObject *childObject; - if (!object->nsPtr) return TCL_OK; + if (object->nsPtr == NULL) { + return TCL_OK; + } - if (pattern && NoMetaChars(pattern)) { + if (pattern != NULL && NoMetaChars(pattern)) { Tcl_DString ds, *dsPtr = &ds; Tcl_DStringInit(dsPtr); @@ -19208,7 +19292,7 @@ hPtr = Tcl_NextHashEntry(&hSrch)) { char *key = Tcl_GetHashKey(cmdTablePtr, hPtr); - if (!pattern || Tcl_StringMatch(key, pattern)) { + if (pattern == NULL || Tcl_StringMatch(key, pattern)) { Tcl_Command cmd = (Tcl_Command)Tcl_GetHashValue(hPtr); /*fprintf(stderr, "... check %s child key %s child object %p %p\n", @@ -19337,7 +19421,13 @@ ClientData clientData; int rc; - if (pattern && + assert(cl != NULL); + + if (cl->super == NULL) { + return TCL_OK; + } + + if (pattern != NULL && ConvertToObjpattern(interp, pattern, NULL, &clientData, &outObjPtr) == TCL_OK) { patternObj = (Tcl_Obj *)clientData; if (GetMatchObject(interp, patternObj, pattern, &matchObject, &patternString) == -1) { @@ -20318,7 +20408,7 @@ slaveCmdObj = Tcl_GetObjResult(interp); slavePtr = Tcl_GetSlave(interp, ObjStr(slaveCmdObj)); - if (!slavePtr) { + if (slavePtr == NULL) { return NsfPrintError(interp, "creation of slave interpreter failed"); } if (Nsf_Init(slavePtr) == TCL_ERROR) { @@ -21109,7 +21199,7 @@ case ObjectpropertyClassIdx: flags = NSF_IS_CLASS; break; case ObjectpropertyRootmetaclassIdx: flags = NSF_IS_ROOT_META_CLASS; break; case ObjectpropertyVolatileIdx: - if (!valueObj) { + if (valueObj == NULL) { Tcl_SetObjResult(interp, NsfGlobalObjs[object->opt && object->opt->volatileVarName ? NSF_ONE : NSF_ZERO]); return TCL_OK; @@ -21172,7 +21262,7 @@ if (isAbsolutePath(nameString)) { Tcl_SetObjResult(interp, nameObj); } else { - Tcl_SetObjResult(interp, NameInNamespaceObj(interp, nameString, CallingNameSpace(interp))); + Tcl_SetObjResult(interp, NameInNamespaceObj(nameString, CallingNameSpace(interp))); } return TCL_OK; } @@ -21195,9 +21285,9 @@ memset(osPtr, 0, sizeof(NsfObjectSystem)); object = isAbsolutePath(objectName) ? Object : - NameInNamespaceObj(interp, objectName, CallingNameSpace(interp)); + NameInNamespaceObj(objectName, CallingNameSpace(interp)); class = isAbsolutePath(className) ? Class : - NameInNamespaceObj(interp, className, CallingNameSpace(interp)); + NameInNamespaceObj(className, CallingNameSpace(interp)); GetClassFromObj(interp, object, &theobj, 0); GetClassFromObj(interp, class, &thecls, 0); @@ -21262,7 +21352,7 @@ /* fprintf(stderr, "CreateObjectSystem created base classes \n"); */ /* check whether Object and Class creation was successful */ - if (!theobj || !thecls) { + if (theobj == NULL || thecls == NULL) { if (thecls) PrimitiveCDestroy(thecls); if (theobj) PrimitiveCDestroy(theobj); @@ -21323,7 +21413,7 @@ #if 0 /* TODO attempt to make "my" NRE-enabled, failed so far (crash in mixinInheritanceTest) */ NsfCallStackContent *cscPtr = CallStackGetTopFrame0(interp); - if (!cscPtr || self != cscPtr->self) { + if (cscPtr == NULL || self != cscPtr->self) { flags = NSF_CSC_IMMEDIATE; } else { flags = NsfImmediateFromCallerFlags(cscPtr->flags); @@ -21731,7 +21821,7 @@ int configure = 0; Tcl_Obj *configureObj = Nsf_ObjGetVar2((Nsf_Object *)slotObject, interp, NsfGlobalObjs[NSF_CONFIGURABLE], NULL, 0); - if (!configureObj) continue; + if (configureObj == NULL) continue; Tcl_GetBooleanFromObj(interp, configureObj, &configure); if (!configure) continue; } @@ -21926,7 +22016,7 @@ return TCL_OK; } GetClassFromObj(interp, valueObj, &cl, 1); - if (!cl) return NsfObjErrType(interp, "class", valueObj, "a class", NULL); + if (cl == NULL) return NsfObjErrType(interp, "class", valueObj, "a class", NULL); i = ChangeClass(interp, object, cl); if (i == TCL_OK) { Tcl_SetObjResult(interp, object->cl->object.cmdName); @@ -21946,7 +22036,7 @@ return NsfPrintError(interp, "metaclass must be specified as third argument"); } GetClassFromObj(interp, valueObj, &metaClass, 0); - if (!metaClass) return NsfObjErrType(interp, "rootclass", valueObj, "class", NULL); + if (metaClass == NULL) return NsfObjErrType(interp, "rootclass", valueObj, "class", NULL); cl->object.flags |= NSF_IS_ROOT_CLASS; metaClass->object.flags |= NSF_IS_ROOT_META_CLASS; @@ -22148,7 +22238,7 @@ } } - if (unlikely(!object && selfoption != CurrentoptionCallinglevelIdx)) { + if (unlikely(object == NULL && selfoption != CurrentoptionCallinglevelIdx)) { return NsfNoCurrentObjectError(interp, NULL); } @@ -22249,7 +22339,7 @@ break; case CurrentoptionCallinglevelIdx: - if (!object) { + if (object == NULL) { Tcl_SetIntObj(Tcl_GetObjResult(interp), 1); } else { Tcl_SetObjResult(interp, ComputeLevelObj(interp, CALLING_LEVEL)); @@ -22860,7 +22950,7 @@ /* Get the object parameter definition */ result = GetObjectParameterDefinition(interp, objv[0], object, &parsedParam); - if (result != TCL_OK || !parsedParam.paramDefs) { + if (result != TCL_OK || parsedParam.paramDefs == NULL) { /*fprintf(stderr, "... nothing to do for method %s\n", ObjStr(objv[0]));*/ return result; } @@ -23107,7 +23197,7 @@ * Set the instance variable unless the last argument of the * definition is varArgs. */ - if (i < paramDefs->nrParams || !pc.varArgs) { + if (i < paramDefs->nrParams || pc.varArgs == 0) { #if defined(CONFIGURE_ARGS_TRACE) fprintf(stderr, "*** %s SET %s '%s' // %p\n", @@ -23606,11 +23696,11 @@ objc -= i; objv += i; - if (!framePtr) { + if (framePtr == NULL) { NsfCallStackFindLastInvocation(interp, 1, &framePtr); - if (!framePtr) { + if (framePtr == NULL) { framePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp)->callerVarPtr; - if (!framePtr) { + if (framePtr == NULL) { framePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); } } @@ -23811,7 +23901,7 @@ parentNsPtr = NULL; } else { parentNsPtr = CallingNameSpace(interp); - nameObj = tmpName = NameInNamespaceObj(interp, nameString, parentNsPtr); + nameObj = tmpName = NameInNamespaceObj(nameString, parentNsPtr); if (strchr(nameString, ':')) { parentNsPtr = NULL; } @@ -23856,7 +23946,7 @@ */ if (!isAbsolutePath(nameString)) { parentNsPtr = CallingNameSpace(interp); - tmpObj = NameInNamespaceObj(interp, nameString, parentNsPtr); + tmpObj = NameInNamespaceObj(nameString, parentNsPtr); /* * If the name contains colons, the parentNsPtr is not appropriate * for determining the parent. @@ -24126,7 +24216,7 @@ Tcl_DStringAppend(dsPtr, parentName, -1); } } else { - Tcl_Obj *tmpName = NameInNamespaceObj(interp, parentName, CallingNameSpace(interp)); + Tcl_Obj *tmpName = NameInNamespaceObj(parentName, CallingNameSpace(interp)); CONST char *completedParentName; INCR_REF_COUNT(tmpName); @@ -24451,7 +24541,7 @@ } } - if (!cmdList) { + if (cmdList == NULL) { return TCL_OK; } fcl = cmdList->clorobj; @@ -24745,7 +24835,7 @@ result = GetObjectParameterDefinition(interp, NsfGlobalObjs[NSF_EMPTY], object, &parsedParam); - if (result != TCL_OK || !parsedParam.paramDefs) { + if (result != TCL_OK || parsedParam.paramDefs == NULL) { return result; } Index: generic/nsfAccessInt.h =================================================================== diff -u -r880487204ff2da18d2d25ebd727b9b4bbda86c8e -rb361d502bbf5fc7920797d064ec21bd111d11081 --- generic/nsfAccessInt.h (.../nsfAccessInt.h) (revision 880487204ff2da18d2d25ebd727b9b4bbda86c8e) +++ generic/nsfAccessInt.h (.../nsfAccessInt.h) (revision b361d502bbf5fc7920797d064ec21bd111d11081) @@ -90,11 +90,19 @@ # define Tcl_HashSize(tablePtr) ((tablePtr)->numEntries) #endif +static NSF_INLINE NsfObject*NsfGetObjectFromCmdPtr(Tcl_Command cmd) nonnull(1); +static NSF_INLINE NsfClass*NsfGetClassFromCmdPtr(Tcl_Command cmd) nonnull(1); +static NSF_INLINE ClientData NsfGetClientDataFromCmdPtr(Tcl_Command cmd) nonnull(1); +static NSF_INLINE Var *VarHashCreateVar(TclVarHashTable *tablePtr, Tcl_Obj *key, int *newPtr) nonnull(1) nonnull(2); + static NSF_INLINE Var * VarHashCreateVar(TclVarHashTable *tablePtr, Tcl_Obj *key, int *newPtr) { Var *varPtr = NULL; Tcl_HashEntry *hPtr; + assert(tablePtr); + assert(key); + hPtr = Tcl_CreateHashEntry((Tcl_HashTable *) tablePtr, (char *) key, newPtr); if (likely(hPtr != NULL)) { @@ -133,6 +141,7 @@ static NSF_INLINE NsfClass* NsfGetClassFromCmdPtr(Tcl_Command cmd) { ClientData cd = NsfGetClientDataFromCmdPtr(cmd); + assert(cmd); /*fprintf(stderr, "cd=%p\n",cd);*/ if (likely(cd != NULL)) { return NsfObjectToClass(cd); @@ -143,6 +152,7 @@ static NSF_INLINE NsfObject* NsfGetObjectFromCmdPtr(Tcl_Command cmd) { + assert(cmd); return (NsfObject*) NsfGetClientDataFromCmdPtr(cmd); } Index: generic/nsfInt.h =================================================================== diff -u -r3c7047087688c6072761e4f1141e4bfe644daa1a -rb361d502bbf5fc7920797d064ec21bd111d11081 --- generic/nsfInt.h (.../nsfInt.h) (revision 3c7047087688c6072761e4f1141e4bfe644daa1a) +++ generic/nsfInt.h (.../nsfInt.h) (revision b361d502bbf5fc7920797d064ec21bd111d11081) @@ -80,8 +80,15 @@ # define nonnull(ARGS) __attribute__((__nonnull__(ARGS))) #else # define nonnull(ARGS) +# define returns_nonnull #endif +#if __GNUC_PREREQ(4, 9) +# define returns_nonnull __attribute__((returns_nonnull)) +#else +# define returns_nonnull +#endif + /* * Tries to use gcc __attribute__ unused and mangles the name, so the * attribute could not be used, if declared as unused. @@ -986,7 +993,8 @@ nonnull(1) nonnull(2) nonnull(3) nonnull(5); EXTERN CONST char *NsfMethodName(Tcl_Obj *methodObj) - nonnull(1); + nonnull(1) returns_nonnull; + EXTERN void NsfReportVars(Tcl_Interp *interp) nonnull(1); EXTERN void NsfDStringArgv(Tcl_DString *dsPtr, int objc, Tcl_Obj *CONST objv[]) @@ -995,7 +1003,7 @@ EXTERN Tcl_Obj *NsfMethodNamePath(Tcl_Interp *interp, Tcl_CallFrame *framePtr, CONST char *methodName) - nonnull(1) nonnull(3); + nonnull(1) nonnull(3) returns_nonnull; /* * Definition of methodEpoch macros Index: generic/nsfStack.c =================================================================== diff -u -r134e9484601ec4c2fb68787c129d85ce3c1f5ed2 -rb361d502bbf5fc7920797d064ec21bd111d11081 --- generic/nsfStack.c (.../nsfStack.c) (revision 134e9484601ec4c2fb68787c129d85ce3c1f5ed2) +++ generic/nsfStack.c (.../nsfStack.c) (revision b361d502bbf5fc7920797d064ec21bd111d11081) @@ -41,8 +41,13 @@ * *---------------------------------------------------------------------- */ +static void CscListAdd(Tcl_Interp *interp, NsfCallStackContent *cscPtr) nonnull(1) nonnull(2); +static int CscListRemove(Tcl_Interp *interp, NsfCallStackContent *cscPtr, NsfClasses **cscListPtr) nonnull(1) nonnull(2) nonnull(3); + static void CscListAdd(Tcl_Interp *interp, NsfCallStackContent *cscPtr) { + assert(interp); + assert(cscPtr); NsfClassListAdd(&RUNTIME_STATE(interp)->cscList, (NsfClass *)cscPtr, NULL); } @@ -65,6 +70,11 @@ static int CscListRemove(Tcl_Interp *interp, NsfCallStackContent *cscPtr, NsfClasses **cscListPtr) { NsfClasses *entryPtr, **cscList = &RUNTIME_STATE(interp)->cscList; + + assert(interp); + assert(cscPtr); + assert(cscListPtr); + entryPtr = NsfClassListUnlink(cscList, cscPtr); if (entryPtr) { FREE(NsfClasses, entryPtr); @@ -160,8 +170,14 @@ * *---------------------------------------------------------------------- */ +static void Nsf_PushFrameObj(Tcl_Interp *interp, NsfObject *object, CallFrame *framePtr) nonnull(1) nonnull(2) nonnull(3); +static void Nsf_PopFrameObj(Tcl_Interp *interp, CallFrame *framePtr) nonnull(1) nonnull(2); static void Nsf_PushFrameObj(Tcl_Interp *interp, NsfObject *object, CallFrame *framePtr) { + assert(interp); + assert(object); + assert(framePtr); + /*fprintf(stderr,"PUSH OBJECT_FRAME (Nsf_PushFrameObj) frame %p\n", framePtr);*/ if (object->nsPtr) { Tcl_PushCallFrame(interp, (Tcl_CallFrame *)framePtr, object->nsPtr, @@ -180,7 +196,10 @@ Tcl_CallFrame_clientData(framePtr) = (ClientData)object; } + static void Nsf_PopFrameObj(Tcl_Interp *interp, CallFrame *framePtr) { + assert(interp); + assert(framePtr); /*fprintf(stderr,"POP OBJECT_FRAME (Nsf_PopFrameObj) frame %p, varTable %p set to NULL, already %d\n", framePtr, Tcl_CallFrame_varTablePtr(framePtr), Tcl_CallFrame_varTablePtr(framePtr) == NULL);*/ @@ -204,10 +223,17 @@ * *---------------------------------------------------------------------- */ +NSF_INLINE static void Nsf_PushFrameCsc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, CallFrame *framePtr) + nonnull(1) nonnull(2) nonnull(3); +static void Nsf_PopFrameCsc(Tcl_Interp *interp, CallFrame *UNUSED(framePtr)) nonnull(1); NSF_INLINE static void Nsf_PushFrameCsc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, CallFrame *framePtr) { CallFrame *varFramePtr = Tcl_Interp_varFramePtr(interp); + + assert(interp); + assert(cscPtr); + assert(framePtr); /*fprintf(stderr,"PUSH CMETHOD_FRAME (Nsf_PushFrameCsc) frame %p cscPtr %p methodName %s\n", framePtr, cscPtr, Tcl_GetCommandName(interp, cscPtr->cmdPtr));*/ @@ -219,6 +245,7 @@ NSF_INLINE static void Nsf_PopFrameCsc(Tcl_Interp *interp, CallFrame *UNUSED(framePtr)) { + assert(interp); /*fprintf(stderr,"POP CMETHOD_FRAME (Nsf_PopFrameCsc) frame %p, varTablePtr = %p\n", framePtr, Tcl_CallFrame_varTablePtr(framePtr));*/ Tcl_PopCallFrame(interp); @@ -242,9 +269,11 @@ * *---------------------------------------------------------------------- */ +static Tcl_CallFrame *CallStackGetActiveProcFrame(Tcl_CallFrame *framePtr) nonnull(1); static Tcl_CallFrame * CallStackGetActiveProcFrame(Tcl_CallFrame *framePtr) { + assert(framePtr); for (; framePtr; framePtr = Tcl_CallFrame_callerPtr(framePtr)) { register int flag = Tcl_CallFrame_isProcCallFrame(framePtr); @@ -276,9 +305,12 @@ * *---------------------------------------------------------------------- */ +static Tcl_CallFrame * CallStackNextFrameOfType(Tcl_CallFrame *framePtr, int flags) nonnull(1); static Tcl_CallFrame * CallStackNextFrameOfType(Tcl_CallFrame *framePtr, int flags) { + assert(framePtr); + for (; framePtr; framePtr = Tcl_CallFrame_callerPtr(framePtr)) { if (Tcl_CallFrame_isProcCallFrame(framePtr) & flags) return framePtr; @@ -310,21 +342,24 @@ # endif #endif +NSF_INLINE static NsfObject *GetSelfObj(Tcl_Interp *interp) nonnull(1); + NSF_INLINE static NsfObject* GetSelfObj(Tcl_Interp *interp) { register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + assert(interp); /*fprintf(stderr, "GetSelfObj interp has frame %p and var-frame %p\n", Tcl_Interp_framePtr(interp), Tcl_Interp_varFramePtr(interp));*/ for (; varFramePtr; varFramePtr = #if defined(SKIP_LEVELS) - Tcl_CallFrame_callerPtr(varFramePtr) + Tcl_CallFrame_callerPtr(varFramePtr) #else - NULL + NULL #endif - ) { + ) { register int flags = Tcl_CallFrame_isProcCallFrame(varFramePtr); if (likely(flags & (FRAME_IS_NSF_METHOD|FRAME_IS_NSF_CMETHOD))) { @@ -359,13 +394,19 @@ * *---------------------------------------------------------------------- */ +static NsfCallStackContent*CallStackGetTopFrame(Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr) nonnull(1); +NSF_INLINE static NsfCallStackContent* CallStackGetTopFrame0(Tcl_Interp *interp) nonnull(1); static NsfCallStackContent* CallStackGetTopFrame(Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr) { - register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + register Tcl_CallFrame *varFramePtr; - for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { + assert(interp); + for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + varFramePtr; + varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { + if (Tcl_CallFrame_isProcCallFrame(varFramePtr) & (FRAME_IS_NSF_METHOD|FRAME_IS_NSF_CMETHOD)) { if (framePtrPtr) *framePtrPtr = varFramePtr; return (NsfCallStackContent *)Tcl_CallFrame_clientData(varFramePtr); @@ -377,8 +418,13 @@ NSF_INLINE static NsfCallStackContent* CallStackGetTopFrame0(Tcl_Interp *interp) { - register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); - for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { + register Tcl_CallFrame *varFramePtr; + + assert(interp); + + for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + varFramePtr; + varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { if (likely(Tcl_CallFrame_isProcCallFrame(varFramePtr) & (FRAME_IS_NSF_METHOD|FRAME_IS_NSF_CMETHOD))) { return (NsfCallStackContent *)Tcl_CallFrame_clientData(varFramePtr); } @@ -408,6 +454,9 @@ * *---------------------------------------------------------------------- */ +static NsfCallStackContent *NsfCallStackFindLastInvocation(Tcl_Interp *interp, int offset, Tcl_CallFrame **framePtrPtr) + nonnull(1); + static NsfCallStackContent * NsfCallStackFindLastInvocation(Tcl_Interp *interp, int offset, Tcl_CallFrame **framePtrPtr) { register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); @@ -464,13 +513,16 @@ * *---------------------------------------------------------------------- */ +static NsfCallStackContent *NsfCallStackFindActiveFrame(Tcl_Interp *interp, int offset, Tcl_CallFrame **framePtrPtr) nonnull(1); static NsfCallStackContent * NsfCallStackFindActiveFrame(Tcl_Interp *interp, int offset, Tcl_CallFrame **framePtrPtr) { - register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + register Tcl_CallFrame *varFramePtr; /* skip #offset frames */ - for (; offset>0 && varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr), offset--); + for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + offset>0 && varFramePtr; + varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr), offset--); /* search for first active frame and set tcl frame pointers */ for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { @@ -505,11 +557,15 @@ * *---------------------------------------------------------------------- */ +static void CallStackUseActiveFrame(Tcl_Interp *interp, callFrameContext *ctx) nonnull(1) nonnull(2); static void CallStackUseActiveFrame(Tcl_Interp *interp, callFrameContext *ctx) { Tcl_CallFrame *framePtr, *inFramePtr; + assert(interp); + assert(ctx); + inFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); /* Get the first active non object frame */ @@ -544,9 +600,12 @@ * *---------------------------------------------------------------------- */ +static void CallStackRestoreSavedFrames(Tcl_Interp *interp, callFrameContext *ctx) nonnull(1) nonnull(2); static void CallStackRestoreSavedFrames(Tcl_Interp *interp, callFrameContext *ctx) { + assert(ctx); + if (ctx->frameSaved) { /*fprintf(stderr, "CallStackRestoreSavedFrames drops %p restores %p\n", Tcl_Interp_varFramePtr(interp), ctx->varFramePtr);*/