Index: TODO =================================================================== diff -u -re4500c77b2bdbb0733a1503d765be84f15509be3 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- TODO (.../TODO) (revision e4500c77b2bdbb0733a1503d765be84f15509be3) +++ TODO (.../TODO) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -5011,7 +5011,7 @@ ======================================================================== TODO: -- check autoadded asserts; complete asserts for other .c files +- check autoadded asserts - check nonnull with various compilers for tcl8.6 - check deactivated tests in tests/serialize.test Index: generic/aolstub.c =================================================================== diff -u -rcaba76f5ac2943f5a3dfd33550cb578132f40c80 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/aolstub.c (.../aolstub.c) (revision caba76f5ac2943f5a3dfd33550cb578132f40c80) +++ generic/aolstub.c (.../aolstub.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -168,11 +168,15 @@ *---------------------------------------------------------------------------- */ +int Ns_ModuleInit(char *hServer, char *hModule) nonnull(1) nonnull(2); + int -Ns_ModuleInit(char *hServer, char *hModule) -{ +Ns_ModuleInit(char *hServer, char *hModule) { int ret; - + + assert(hServer); + assert(hModule); + /*Ns_Log(Notice, "+++ ModuleInit","INIT");*/ ret = Ns_TclInitInterps(hServer, NsNsf_Init, (void*)hModule); Index: generic/nsf.h =================================================================== diff -u -r8a6eddd18d929736bd1d3fefe985c2b1f2963fc0 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsf.h (.../nsf.h) (revision 8a6eddd18d929736bd1d3fefe985c2b1f2963fc0) +++ generic/nsf.h (.../nsf.h) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -412,7 +412,7 @@ NSF_nonnull(1) NSF_nonnull(2) NSF_nonnull(3) NSF_nonnull(4); EXTERN int Nsf_PointerDelete(CONST char *key, void *valuePtr, int free) - NSF_nonnull(1) NSF_nonnull(2); + NSF_nonnull(2); EXTERN void Nsf_PointerInit(Tcl_Interp *interp) NSF_nonnull(1); Index: generic/nsfCmdDefinitions.c =================================================================== diff -u -rd29a51c38be834fe558f1c85069d8bc500d201d9 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfCmdDefinitions.c (.../nsfCmdDefinitions.c) (revision d29a51c38be834fe558f1c85069d8bc500d201d9) +++ generic/nsfCmdDefinitions.c (.../nsfCmdDefinitions.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -50,6 +50,8 @@ void Nsf_CmdDefinitionInit(Tcl_Interp *interp) { + assert(interp); + NsfMutexLock(&cmdDefinitonMutex); if (cmdDefinitonRefCount == 0) { @@ -78,6 +80,9 @@ Nsf_CmdDefinitionRegister(Tcl_Interp *interp, Nsf_methodDefinition *definitionRecords) { Nsf_methodDefinition *ePtr; + assert(interp); + assert(definitionRecords); + for (ePtr = definitionRecords; ePtr->methodName; ePtr++) { Register(interp, ePtr); } @@ -103,6 +108,8 @@ Nsf_CmdDefinitionGet(Tcl_ObjCmdProc *proc) { Tcl_HashEntry *hPtr; + assert(proc); + NsfMutexLock(&cmdDefinitonMutex); hPtr = Tcl_FindHashEntry(cmdDefinitonHashTablePtr, (char *)proc); NsfMutexUnlock(&cmdDefinitonMutex); @@ -128,11 +135,16 @@ * *---------------------------------------------------------------------- */ +static int Register(Tcl_Interp *interp, Nsf_methodDefinition *methodDefinition) nonnull(1) nonnull(2); + static int Register(Tcl_Interp *interp, Nsf_methodDefinition *methodDefinition) { Tcl_HashEntry *hPtr; int isNew; + assert(interp); + assert(methodDefinition); + NsfMutexLock(&cmdDefinitonMutex); hPtr = Tcl_CreateHashEntry(cmdDefinitonHashTablePtr, (char *)methodDefinition->proc, &isNew); NsfMutexUnlock(&cmdDefinitonMutex); Index: generic/nsfCompile.c =================================================================== diff -u -rcaba76f5ac2943f5a3dfd33550cb578132f40c80 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfCompile.c (.../nsfCompile.c) (revision caba76f5ac2943f5a3dfd33550cb578132f40c80) +++ generic/nsfCompile.c (.../nsfCompile.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -58,10 +58,17 @@ } +static int initProcNsCompile(Tcl_Interp *interp, Tcl_Parse *parsePtr, + CompileEnv *envPtr) nonnull(1) nonnull(2) nonnull(3); + static int initProcNsCompile(Tcl_Interp *interp, Tcl_Parse *parsePtr, CompileEnv *envPtr) { + assert(interp); + assert(parsePtr); + assert(envPtr); + if (parsePtr->numWords != 1) { Tcl_ResetResult(interp); Tcl_AppendToObj(Tcl_GetObjResult(interp), @@ -76,10 +83,17 @@ return TCL_OK; } +static int nextCompile(Tcl_Interp *interp, Tcl_Parse *parsePtr, + CompileEnv *envPtr) nonnull(1) nonnull(2) nonnull(3); + static int nextCompile(Tcl_Interp *interp, Tcl_Parse *parsePtr, CompileEnv *envPtr) { + assert(interp); + assert(parsePtr); + assert(envPtr); + if (parsePtr->numWords != 1) return TCL_OUT_LINE_COMPILE; @@ -88,10 +102,18 @@ return TCL_OK; } + +static int selfCompile(Tcl_Interp *interp, Tcl_Parse *parsePtr, + CompileEnv *envPtr) nonnull(1) nonnull(2) nonnull(3); + static int selfCompile(Tcl_Interp *interp, Tcl_Parse *parsePtr, CompileEnv *envPtr) { + assert(interp); + assert(parsePtr); + assert(envPtr); + if (parsePtr->numWords != 1) return TCL_OUT_LINE_COMPILE; @@ -100,12 +122,21 @@ return TCL_OK; } + +static int selfDispatchCompile(Tcl_Interp *interp, Tcl_Parse *parsePtr, + CompileEnv *envPtr) nonnull(1) nonnull(2) nonnull(3); + static int selfDispatchCompile(Tcl_Interp *interp, Tcl_Parse *parsePtr, CompileEnv *envPtr) { Tcl_Token *tokenPtr; int code, wordIdx; + + assert(interp); + assert(parsePtr); + assert(envPtr); + /* fprintf(stderr, "****** selfDispatchCompile words=%d tokens=%d, avail=%d\n", parsePtr->numWords, parsePtr->numTokens, parsePtr->tokensAvailable); @@ -158,6 +189,7 @@ void NsfBytecodeInit() { int i; + for(i=0; iframePtr, *v = iPtr->varFramePtr; Tcl_Obj *varCmdObj; + assert(interp); + varCmdObj = Tcl_NewObj(); fprintf (stderr, " TCL STACK:\n"); if (f == 0) fprintf(stderr, "- "); @@ -155,8 +161,14 @@ *---------------------------------------------------------------------- */ +void NsfPrintObjv(char *string, int objc, Tcl_Obj *CONST objv[]) nonnull(1) nonnull(3); + void NsfPrintObjv(char *string, int objc, Tcl_Obj *CONST objv[]) { + + assert(string); + assert(objv); + int j; fprintf(stderr, "%s", string); for (j = 0; j < objc; j++) { @@ -181,11 +193,15 @@ * *---------------------------------------------------------------------- */ +static Tcl_HashTable * NsfMemCountGetTable(int **initialized) nonnull(1); + static Tcl_HashTable * NsfMemCountGetTable(int **initialized) { static Tcl_ThreadDataKey memCountTableKey; static Tcl_ThreadDataKey memCountFlagKey; Tcl_HashTable *tablePtr; + + assert(initialized); tablePtr = (Tcl_HashTable *)Tcl_GetThreadData(&memCountTableKey, sizeof(Tcl_HashTable)); *initialized = (int *)Tcl_GetThreadData(&memCountFlagKey, sizeof(int)); @@ -209,13 +225,19 @@ * *---------------------------------------------------------------------- */ + +void NsfMemCountAlloc(char *id, void *p) nonnull(1) nonnull(2); + void NsfMemCountAlloc(char *id, void *p) { int new, *tableInitialized; NsfMemCounter *entry; Tcl_HashTable *tablePtr = NsfMemCountGetTable(&tableInitialized); Tcl_HashEntry *hPtr; + assert(id); + assert(p); + if (!*tableInitialized) { fprintf(stderr, "+++ alloc %s %p\n", id, p); return; @@ -256,13 +278,18 @@ *---------------------------------------------------------------------- */ +void NsfMemCountFree(char *id, void *p) nonnull(1) nonnull(2); + void NsfMemCountFree(char *id, void *p) { NsfMemCounter *entry; int *tableInitialized; Tcl_HashTable *tablePtr = NsfMemCountGetTable(&tableInitialized); Tcl_HashEntry *hPtr; + assert(id); + assert(p); + if (!*tableInitialized) { fprintf(stderr, "+++ free %s %p\n", id, p); return; Index: generic/nsfEnumerationType.c =================================================================== diff -u -rd29a51c38be834fe558f1c85069d8bc500d201d9 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfEnumerationType.c (.../nsfEnumerationType.c) (revision d29a51c38be834fe558f1c85069d8bc500d201d9) +++ generic/nsfEnumerationType.c (.../nsfEnumerationType.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -31,8 +31,7 @@ static int enumerationTypeRefCount = 0; static NsfMutex enumerationMutex = 0; -static int Register(Tcl_Interp *interp, CONST char* domain, Nsf_TypeConverter *converter); - +static int Register(Tcl_Interp *interp, CONST char* domain, Nsf_TypeConverter *converter) nonnull(1) nonnull(3); /* *---------------------------------------------------------------------- * Nsf_EnumerationTypeInit -- @@ -50,6 +49,8 @@ void Nsf_EnumerationTypeInit(Tcl_Interp *interp) { + assert(interp); + NsfMutexLock(&enumerationMutex); if (enumerationTypeRefCount == 0) { @@ -78,6 +79,9 @@ Nsf_EnumerationTypeRegister(Tcl_Interp *interp, Nsf_EnumeratorConverterEntry *typeRecords) { Nsf_EnumeratorConverterEntry *ePtr; + assert(interp); + assert(typeRecords); + for (ePtr = typeRecords; ePtr->converter; ePtr++) { Register(interp, ePtr->domain, ePtr->converter); } @@ -105,6 +109,8 @@ Tcl_HashSearch hSrch; CONST char* domain = NULL; + assert(converter); + NsfMutexLock(&enumerationMutex); for (hPtr = Tcl_FirstHashEntry(enumerationHashTablePtr, &hSrch); hPtr != NULL; @@ -134,11 +140,15 @@ * *---------------------------------------------------------------------- */ + static int Register(Tcl_Interp *interp, CONST char* domain, Nsf_TypeConverter *converter) { Tcl_HashEntry *hPtr; int isNew; + assert(interp); + assert(converter); + NsfMutexLock(&enumerationMutex); hPtr = Tcl_CreateHashEntry(enumerationHashTablePtr, domain, &isNew); NsfMutexUnlock(&enumerationMutex); Index: generic/nsfInt.h =================================================================== diff -u -r8a6eddd18d929736bd1d3fefe985c2b1f2963fc0 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfInt.h (.../nsfInt.h) (revision 8a6eddd18d929736bd1d3fefe985c2b1f2963fc0) +++ generic/nsfInt.h (.../nsfInt.h) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -917,14 +917,11 @@ nonnull(1) nonnull(2); EXTERN void NsfProfileRecordProcData(Tcl_Interp *interp, char *methodName, long startSec, long startUsec) nonnull(1) nonnull(2); -EXTERN void NsfProfileInit(Tcl_Interp *interp) - nonnull(1); -EXTERN void NsfProfileFree(Tcl_Interp *interp) - nonnull(1); -EXTERN void NsfProfileClearData(Tcl_Interp *interp) - nonnull(1); -EXTERN void NsfProfileGetData(Tcl_Interp *interp) - nonnull(1); +EXTERN void NsfProfileInit(Tcl_Interp *interp) nonnull(1); +EXTERN void NsfProfileFree(Tcl_Interp *interp) nonnull(1); +EXTERN void NsfProfileClearData(Tcl_Interp *interp) nonnull(1); +EXTERN void NsfProfileGetData(Tcl_Interp *interp) nonnull(1); + EXTERN NsfCallStackContent *NsfCallStackGetTopFrame(Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr) nonnull(1) nonnull(2); #endif Index: generic/nsfObj.c =================================================================== diff -u -rcaba76f5ac2943f5a3dfd33550cb578132f40c80 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfObj.c (.../nsfObj.c) (revision caba76f5ac2943f5a3dfd33550cb578132f40c80) +++ generic/nsfObj.c (.../nsfObj.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -478,6 +478,11 @@ int NsfMixinregGet(Tcl_Obj *obj, NsfClass **clPtr, Tcl_Obj **guardObj) { + + assert(obj); + assert(clPtr); + assert(guardObj); + if (obj->typePtr == &NsfMixinregObjType) { Mixinreg *mixinRegPtr = obj->internalRep.twoPtrValue.ptr1; *guardObj = mixinRegPtr->guardObj; @@ -555,10 +560,11 @@ static void FilterregDupInternalRep( Tcl_Obj *srcObjPtr, - Tcl_Obj *dstObjPtr) -{ + Tcl_Obj *dstObjPtr) { register Filterreg *srcPtr = (Filterreg *)srcObjPtr->internalRep.twoPtrValue.ptr1, *dstPtr; + assert(srcObjPtr); + assert(dstObjPtr); assert(srcPtr); #if defined(METHOD_OBJECT_TRACE) @@ -655,6 +661,11 @@ int NsfFilterregGet(Tcl_Obj *obj, Tcl_Obj **filterObj, Tcl_Obj **guardObj) { + + assert(obj); + assert(filterObj); + assert(guardObj); + if (obj->typePtr == &NsfFilterregObjType) { Filterreg *filterregPtr = obj->internalRep.twoPtrValue.ptr1; *filterObj = filterregPtr->filterObj; Index: generic/nsfPointer.c =================================================================== diff -u -rcaba76f5ac2943f5a3dfd33550cb578132f40c80 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfPointer.c (.../nsfPointer.c) (revision caba76f5ac2943f5a3dfd33550cb578132f40c80) +++ generic/nsfPointer.c (.../nsfPointer.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -53,6 +53,11 @@ Nsf_PointerAdd(Tcl_Interp *interp, char *buffer, CONST char *typeName, void *valuePtr) { int *counterPtr; + assert(interp); + assert(buffer); + assert(typeName); + assert(valuePtr); + counterPtr = Nsf_PointerTypeLookup(interp, typeName); if (counterPtr) { Tcl_DString ds, *dsPtr = &ds; @@ -95,10 +100,15 @@ * *---------------------------------------------------------------------- */ +static void * Nsf_PointerGet(char *key, CONST char *prefix) nonnull(1) nonnull(2); + static void * Nsf_PointerGet(char *key, CONST char *prefix) { void *valuePtr = NULL; + assert(key); + assert(prefix); + /* make sure to return the right type of hash entry */ if (strncmp(prefix, key, strlen(prefix)) == 0) { Tcl_HashEntry *hPtr; @@ -134,11 +144,15 @@ * *---------------------------------------------------------------------- */ +static Tcl_HashEntry * Nsf_PointerGetHptr(void *valuePtr) nonnull(1); + static Tcl_HashEntry * Nsf_PointerGetHptr(void *valuePtr) { Tcl_HashEntry *hPtr; Tcl_HashSearch hSrch; + assert(valuePtr); + for (hPtr = Tcl_FirstHashEntry(pointerHashTablePtr, &hSrch); hPtr; hPtr = Tcl_NextHashEntry(&hSrch)) { void *ptr = Tcl_GetHashValue(hPtr); @@ -209,11 +223,21 @@ *---------------------------------------------------------------------- */ +int Nsf_ConvertToPointer(Tcl_Interp *interp, Tcl_Obj *objPtr, Nsf_Param CONST *pPtr, + ClientData *clientData, Tcl_Obj **outObjPtr) + nonnull(1) nonnull(2) nonnull(3) nonnull(4) nonnull(5); + int Nsf_ConvertToPointer(Tcl_Interp *interp, Tcl_Obj *objPtr, Nsf_Param CONST *pPtr, ClientData *clientData, Tcl_Obj **outObjPtr) { void *valuePtr; + assert(interp); + assert(objPtr); + assert(pPtr); + assert(clientData); + assert(outObjPtr); + *outObjPtr = objPtr; valuePtr = Nsf_PointerGet(ObjStr(objPtr), pPtr->type); if (valuePtr) { @@ -243,6 +267,10 @@ Tcl_HashEntry *hPtr; int isNew; + assert(interp); + assert(typeName); + assert(counterPtr); + NsfMutexLock(&pointerMutex); hPtr = Tcl_CreateHashEntry(pointerHashTablePtr, typeName, &isNew); @@ -277,6 +305,9 @@ Nsf_PointerTypeLookup(Tcl_Interp *interp, CONST char* typeName) { Tcl_HashEntry *hPtr; + assert(interp); + assert(typeName); + NsfMutexLock(&pointerMutex); hPtr = Tcl_CreateHashEntry(pointerHashTablePtr, typeName, NULL); NsfMutexUnlock(&pointerMutex); @@ -305,15 +336,17 @@ void Nsf_PointerInit(Tcl_Interp *interp) { - NsfMutexLock(&pointerMutex); + assert(interp); - if (pointerTableRefCount == 0) { - Tcl_InitHashTable(pointerHashTablePtr, TCL_STRING_KEYS); - } - pointerTableRefCount++; + NsfMutexLock(&pointerMutex); - NsfMutexUnlock(&pointerMutex); + if (pointerTableRefCount == 0) { + Tcl_InitHashTable(pointerHashTablePtr, TCL_STRING_KEYS); + } + pointerTableRefCount++; + NsfMutexUnlock(&pointerMutex); + } /* @@ -334,31 +367,33 @@ void Nsf_PointerExit(Tcl_Interp *interp) { - NsfMutexLock(&pointerMutex); - if (--pointerTableRefCount == 0) { + assert(interp); - if (RUNTIME_STATE(interp)->debugLevel >= 2) { - Tcl_HashSearch hSrch; - Tcl_HashEntry *hPtr; + NsfMutexLock(&pointerMutex); + if (--pointerTableRefCount == 0) { - for (hPtr = Tcl_FirstHashEntry(pointerHashTablePtr, &hSrch); hPtr; - hPtr = Tcl_NextHashEntry(&hSrch)) { - char *key = Tcl_GetHashKey(pointerHashTablePtr, hPtr); - void *valuePtr = Tcl_GetHashValue(hPtr); + if (RUNTIME_STATE(interp)->debugLevel >= 2) { + Tcl_HashSearch hSrch; + Tcl_HashEntry *hPtr; - /* - * We can't use NsfLog here any more, since the Tcl procs are - * already deleted. - */ + for (hPtr = Tcl_FirstHashEntry(pointerHashTablePtr, &hSrch); hPtr; + hPtr = Tcl_NextHashEntry(&hSrch)) { + char *key = Tcl_GetHashKey(pointerHashTablePtr, hPtr); + void *valuePtr = Tcl_GetHashValue(hPtr); - fprintf(stderr, "Nsf_PointerExit: we have still an entry %s with value %p\n", key, valuePtr); - } - } + /* + * We can't use NsfLog here any more, since the Tcl procs are + * already deleted. + */ - Tcl_DeleteHashTable(pointerHashTablePtr); + fprintf(stderr, "Nsf_PointerExit: we have still an entry %s with value %p\n", key, valuePtr); + } } - NsfMutexUnlock(&pointerMutex); + Tcl_DeleteHashTable(pointerHashTablePtr); + } + + NsfMutexUnlock(&pointerMutex); } /* Index: generic/nsfProfile.c =================================================================== diff -u -rcaba76f5ac2943f5a3dfd33550cb578132f40c80 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfProfile.c (.../nsfProfile.c) (revision caba76f5ac2943f5a3dfd33550cb578132f40c80) +++ generic/nsfProfile.c (.../nsfProfile.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -49,12 +49,17 @@ * *---------------------------------------------------------------------- */ +static void NsfProfileFillTable(Tcl_HashTable *table, char *keyStr, double totalMicroSec) nonnull(1) nonnull(2); + static void NsfProfileFillTable(Tcl_HashTable *table, char *keyStr, double totalMicroSec) { NsfProfileData *value; Tcl_HashEntry *hPtr; int isNew; + assert(table); + assert(keyStr); + hPtr = Tcl_CreateHashEntry(table, keyStr, &isNew); if (isNew) { value = (NsfProfileData *)ckalloc(sizeof(NsfProfileData)); @@ -95,6 +100,9 @@ NsfProfile *profile = &RUNTIME_STATE(interp)->profile; struct timeval trt; + assert(interp); + assert(cscPtr); + gettimeofday(&trt, NULL); totalMicroSec = (trt.tv_sec - cscPtr->startSec) * 1000000 + (trt.tv_usec - cscPtr->startUsec); @@ -168,6 +176,9 @@ double totalMicroSec; struct timeval trt; + assert(interp); + assert(methodName); + gettimeofday(&trt, NULL); totalMicroSec = (trt.tv_sec - startSec) * 1000000 + (trt.tv_usec - startUsec); @@ -191,12 +202,16 @@ *---------------------------------------------------------------------- */ + +static void NsfProfileClearTable(Tcl_HashTable *table) nonnull(1); + static void NsfProfileClearTable(Tcl_HashTable *table) { Tcl_HashSearch hSrch; Tcl_HashEntry *hPtr; assert(table); + for (hPtr = Tcl_FirstHashEntry(table, &hSrch); hPtr; hPtr = Tcl_NextHashEntry(&hSrch)) { NsfProfileData *value = (NsfProfileData *) Tcl_GetHashValue(hPtr); @@ -220,11 +235,14 @@ * *---------------------------------------------------------------------- */ + void NsfProfileClearData(Tcl_Interp *interp) { NsfProfile *profilePtr = &RUNTIME_STATE(interp)->profile; struct timeval trt; + assert(interp); + NsfProfileClearTable(&profilePtr->objectData); NsfProfileClearTable(&profilePtr->methodData); NsfProfileClearTable(&profilePtr->procData); @@ -250,13 +268,17 @@ * *---------------------------------------------------------------------- */ +static Tcl_Obj* NsfProfileGetTable(Tcl_Interp *interp, Tcl_HashTable *table) nonnull(1) nonnull(2); + static Tcl_Obj* NsfProfileGetTable(Tcl_Interp *interp, Tcl_HashTable *table) { Tcl_Obj *list = Tcl_NewListObj(0, NULL); Tcl_HashSearch hSrch; Tcl_HashEntry *hPtr; + assert(interp); assert(table); + for (hPtr = Tcl_FirstHashEntry(table, &hSrch); hPtr; hPtr = Tcl_NextHashEntry(&hSrch)) { NsfProfileData *value = (NsfProfileData *) Tcl_GetHashValue(hPtr); @@ -288,13 +310,16 @@ * *---------------------------------------------------------------------- */ + void NsfProfileGetData(Tcl_Interp *interp) { Tcl_Obj *list = Tcl_NewListObj(0, NULL); NsfProfile *profilePtr = &RUNTIME_STATE(interp)->profile; long totalMicroSec; struct timeval trt; + assert(interp); + gettimeofday(&trt, NULL); totalMicroSec = (trt.tv_sec - profilePtr->startSec) * 1000000 + (trt.tv_usec - profilePtr->startUSec); @@ -328,6 +353,8 @@ NsfProfile *profilePtr = &RUNTIME_STATE(interp)->profile; struct timeval trt; + assert(interp); + Tcl_InitHashTable(&profilePtr->objectData, TCL_STRING_KEYS); Tcl_InitHashTable(&profilePtr->methodData, TCL_STRING_KEYS); Tcl_InitHashTable(&profilePtr->procData, TCL_STRING_KEYS); @@ -357,6 +384,8 @@ NsfProfileFree(Tcl_Interp *interp) { NsfProfile *profilePtr = &RUNTIME_STATE(interp)->profile; + assert(interp); + NsfProfileClearData(interp); Tcl_DeleteHashTable(&profilePtr->objectData); Tcl_DeleteHashTable(&profilePtr->methodData); Index: generic/nsfShadow.c =================================================================== diff -u -rcaba76f5ac2943f5a3dfd33550cb578132f40c80 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfShadow.c (.../nsfShadow.c) (revision caba76f5ac2943f5a3dfd33550cb578132f40c80) +++ generic/nsfShadow.c (.../nsfShadow.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -44,12 +44,16 @@ * *---------------------------------------------------------------------- */ +static int NsfReplaceCommandCleanup(Tcl_Interp *interp, NsfGlobalNames name) nonnull(1); + static int NsfReplaceCommandCleanup(Tcl_Interp *interp, NsfGlobalNames name) { Tcl_Command cmd; int result = TCL_OK; NsfShadowTclCommandInfo *ti = &RUNTIME_STATE(interp)->tclCommands[name-NSF_EXPR]; + assert(interp); + /*fprintf(stderr," cleanup for %s ti=%p in %p\n", NsfGlobalStrings[name], ti, interp);*/ cmd = Tcl_GetCommandFromObj(interp, NsfGlobalObjs[name]); if (cmd != NULL) { @@ -77,10 +81,16 @@ * *---------------------------------------------------------------------- */ +static void NsfReplaceCommandCheck(Tcl_Interp *interp, NsfGlobalNames name, Tcl_ObjCmdProc *proc) nonnull(1) nonnull(3); + static void NsfReplaceCommandCheck(Tcl_Interp *interp, NsfGlobalNames name, Tcl_ObjCmdProc *proc) { - Tcl_Command cmd; NsfShadowTclCommandInfo *ti = &RUNTIME_STATE(interp)->tclCommands[name-NSF_EXPR]; + Tcl_Command cmd; + + assert(interp); + assert(proc); + cmd = Tcl_GetCommandFromObj(interp, NsfGlobalObjs[name]); if (cmd != NULL && ti->proc && Tcl_Command_objProc(cmd) != proc) { @@ -110,13 +120,18 @@ * *---------------------------------------------------------------------- */ +static int NsfReplaceCommand(Tcl_Interp *interp, NsfGlobalNames name, + Tcl_ObjCmdProc *nsfReplacementProc, int pass) nonnull(1); + static int NsfReplaceCommand(Tcl_Interp *interp, NsfGlobalNames name, Tcl_ObjCmdProc *nsfReplacementProc, int pass) { Tcl_Command cmd; NsfShadowTclCommandInfo *ti = &RUNTIME_STATE(interp)->tclCommands[name-NSF_EXPR]; int result = TCL_OK; + assert(interp); + /*fprintf(stderr,"NsfReplaceCommand %d\n", name);*/ cmd = Tcl_GetCommandFromObj(interp, NsfGlobalObjs[name]); @@ -162,13 +177,16 @@ * *---------------------------------------------------------------------- */ -EXTERN int -NsfProcStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); +EXTERN int NsfProcStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) + nonnull(1) nonnull(2) nonnull(4); static int Nsf_InfoBodyObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { Tcl_Command cmd; + assert(interp); + assert(objv); + if (objc != 2) { /* wrong # args, let Tcl generate the error */ return NsfCallCommand(interp, NSF_INFO_BODY, objc, objv); @@ -369,8 +387,11 @@ int NsfShadowTclCommands(Tcl_Interp *interp, NsfShadowOperations load) { int rc = TCL_OK; + assert(interp); + if (load == SHADOW_LOAD) { int initialized = (RUNTIME_STATE(interp)->tclCommands != NULL); + assert(initialized == 0); RUNTIME_STATE(interp)->tclCommands = NEW_ARRAY(NsfShadowTclCommandInfo, NSF_RENAME - NSF_EXPR + 1); Index: generic/nsfStack.c =================================================================== diff -u -rcaba76f5ac2943f5a3dfd33550cb578132f40c80 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfStack.c (.../nsfStack.c) (revision caba76f5ac2943f5a3dfd33550cb578132f40c80) +++ generic/nsfStack.c (.../nsfStack.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -41,13 +41,16 @@ * *---------------------------------------------------------------------- */ +static int CscListRemove(Tcl_Interp *interp, NsfCallStackContent *cscPtr, NsfClasses **cscListPtr) + nonnull(1) nonnull(2) nonnull(3); 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); } @@ -234,6 +237,7 @@ 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));*/ @@ -246,6 +250,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); @@ -269,11 +274,13 @@ * *---------------------------------------------------------------------- */ -static Tcl_CallFrame *CallStackGetActiveProcFrame(Tcl_CallFrame *framePtr) nonnull(1); +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); @@ -342,11 +349,12 @@ # endif #endif -NSF_INLINE static NsfObject *GetSelfObj(Tcl_Interp *interp) nonnull(1); +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", @@ -416,6 +424,8 @@ return NULL; } +NSF_INLINE static NsfCallStackContent* CallStackGetTopFrame0(Tcl_Interp *interp) nonnull(1); + NSF_INLINE static NsfCallStackContent* CallStackGetTopFrame0(Tcl_Interp *interp) { register Tcl_CallFrame *varFramePtr; @@ -433,6 +443,8 @@ } #if defined(NSF_PROFILE) +NsfCallStackContent* NsfCallStackGetTopFrame(Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr) nonnull(1); + NsfCallStackContent* NsfCallStackGetTopFrame(Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr) { return CallStackGetTopFrame(interp, framePtrPtr); @@ -461,6 +473,8 @@ NsfCallStackFindLastInvocation(Tcl_Interp *interp, int offset, Tcl_CallFrame **framePtrPtr) { register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); int lvl = Tcl_CallFrame_level(varFramePtr); + + assert(interp); for (; likely(varFramePtr != NULL); varFramePtr = Tcl_CallFrame_callerVarPtr(varFramePtr)) { @@ -519,6 +533,8 @@ NsfCallStackFindActiveFrame(Tcl_Interp *interp, int offset, Tcl_CallFrame **framePtrPtr) { register Tcl_CallFrame *varFramePtr; + assert(interp); + /* skip #offset frames */ for (varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); offset>0 && varFramePtr; @@ -604,6 +620,8 @@ static void CallStackRestoreSavedFrames(Tcl_Interp *interp, callFrameContext *ctx) { + + assert(interp); assert(ctx); if (ctx->frameSaved) { @@ -627,10 +645,14 @@ * *---------------------------------------------------------------------- */ +static NsfCallStackContent * CallStackFindActiveFilter(Tcl_Interp *interp) nonnull(1); + static NsfCallStackContent * CallStackFindActiveFilter(Tcl_Interp *interp) { register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + assert(interp); + for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { if (Tcl_CallFrame_isProcCallFrame(varFramePtr) & (FRAME_IS_NSF_METHOD|FRAME_IS_NSF_CMETHOD)) { NsfCallStackContent *cscPtr = (NsfCallStackContent *)Tcl_CallFrame_clientData(varFramePtr); @@ -659,12 +681,16 @@ * *---------------------------------------------------------------------- */ +static NsfCallStackContent * CallStackFindEnsembleCsc(Tcl_CallFrame *framePtr, Tcl_CallFrame **framePtrPtr) nonnull(1) nonnull(2); + static NsfCallStackContent * CallStackFindEnsembleCsc(Tcl_CallFrame *framePtr, Tcl_CallFrame **framePtrPtr) { register Tcl_CallFrame *varFramePtr; NsfCallStackContent *cscPtr = NULL; assert(framePtr); + assert(framePtrPtr); + for (/* Skipping the starting frame, assuming a "leaf" frame in an ensemble dispatch */ varFramePtr = Tcl_CallFrame_callerPtr(framePtr); Tcl_CallFrame_isProcCallFrame(varFramePtr) & FRAME_IS_NSF_CMETHOD; @@ -687,9 +713,9 @@ if ((cscPtr->frameType & NSF_CSC_TYPE_ENSEMBLE) == 0 && (cscPtr->flags & NSF_CSC_CALL_IS_ENSEMBLE)) break; } - if (framePtrPtr) { - *framePtrPtr = varFramePtr; - } + + *framePtrPtr = varFramePtr; + return cscPtr; } @@ -708,13 +734,17 @@ * *---------------------------------------------------------------------- */ +static Tcl_Obj* CallStackMethodPath(Tcl_Interp *interp, Tcl_CallFrame *framePtr) nonnull(1) nonnull(2); + static Tcl_Obj* CallStackMethodPath(Tcl_Interp *interp, Tcl_CallFrame *framePtr) { int elements; Tcl_Obj *resultObj; Tcl_Obj *methodPathObj = Tcl_NewListObj(0, NULL); + assert(interp); assert(framePtr); + /* * Append all ensemble names to the specified list obj */ @@ -799,10 +829,15 @@ * *---------------------------------------------------------------------- */ +NSF_INLINE static int FilterActiveOnObj(Tcl_Interp *interp, NsfObject *object, Tcl_Command cmd) nonnull(1) nonnull(2); + NSF_INLINE static int FilterActiveOnObj(Tcl_Interp *interp, NsfObject *object, Tcl_Command cmd) { register Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp); + assert(interp); + assert(object); + for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { if (Tcl_CallFrame_isProcCallFrame(varFramePtr) & (FRAME_IS_NSF_METHOD|FRAME_IS_NSF_CMETHOD)) { NsfCallStackContent *cscPtr = (NsfCallStackContent *)Tcl_CallFrame_clientData(varFramePtr); @@ -831,10 +866,16 @@ * *---------------------------------------------------------------------- */ +static void CallStackReplaceVarTableReferences(Tcl_Interp *interp, TclVarHashTable *oldVarTablePtr, TclVarHashTable *newVarTablePtr) nonnull(1) nonnull(2) nonnull(3); + static void CallStackReplaceVarTableReferences(Tcl_Interp *interp, TclVarHashTable *oldVarTablePtr, TclVarHashTable *newVarTablePtr) { Tcl_CallFrame *framePtr; + assert(interp); + assert(oldVarTablePtr); + assert(newVarTablePtr); + for (framePtr = (Tcl_CallFrame *)Tcl_Interp_framePtr(interp); framePtr; framePtr = Tcl_CallFrame_callerPtr(framePtr)) { int frameFlags = Tcl_CallFrame_isProcCallFrame(framePtr); @@ -867,6 +908,8 @@ static void CallStackPopAll(Tcl_Interp *interp) { + assert(interp); + if (RUNTIME_STATE(interp)->debugLevel > 2) { NsfShowStack(interp); } @@ -935,6 +978,14 @@ * *---------------------------------------------------------------------- */ +#if defined(NRE) +static NsfCallStackContent * CscAlloc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, Tcl_Command cmd) + nonnull(1); +#else +static NsfCallStackContent * CscAlloc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, Tcl_Command cmd) + nonnull(2); +#endif + static NsfCallStackContent * CscAlloc(Tcl_Interp *interp, NsfCallStackContent *cscPtr, Tcl_Command cmd) { #if defined(NRE) @@ -947,6 +998,7 @@ cscPtr->flags = 0; } #else + assert(cscPtr); (void)interp; (void)cmd; cscPtr->flags = 0; @@ -971,6 +1023,9 @@ * *---------------------------------------------------------------------- */ +NSF_INLINE static void CscInit_(/*@notnull@*/ NsfCallStackContent *cscPtr, NsfObject *object, NsfClass *cl, + Tcl_Command cmd, int frameType, int flags) nonnull(1) nonnull(2); + NSF_INLINE static void CscInit_(/*@notnull@*/ NsfCallStackContent *cscPtr, NsfObject *object, NsfClass *cl, Tcl_Command cmd, int frameType, int flags) { @@ -979,6 +1034,7 @@ #endif assert(cscPtr); + assert(object); #if defined(NSF_PROFILE) gettimeofday(&trt, NULL); @@ -1047,10 +1103,13 @@ * *---------------------------------------------------------------------- */ +NSF_INLINE static void CscFinish_(Tcl_Interp *interp, NsfCallStackContent *cscPtr) nonnull(1) nonnull(2); + NSF_INLINE static void CscFinish_(Tcl_Interp *interp, NsfCallStackContent *cscPtr) { NsfObject *object; + assert(interp); assert(cscPtr); assert(cscPtr->self); @@ -1146,11 +1205,15 @@ *---------------------------------------------------------------------- */ #if 0 +static Tcl_CallFrame * BeginOfCallChain(Tcl_Interp *interp, NsfObject *object) nonnull(1); + static Tcl_CallFrame * BeginOfCallChain(Tcl_Interp *interp, NsfObject *object) { Tcl_CallFrame *varFramePtr = (Tcl_CallFrame *)Tcl_Interp_varFramePtr(interp), *prevFramePtr = varFramePtr; + assert(interp); + if (object) { fprintf(stderr, "BeginOfCallChain obj %s\n", ObjectName(object)); for (; varFramePtr; varFramePtr = Tcl_CallFrame_callerPtr(varFramePtr)) { Index: generic/nsfUtil.c =================================================================== diff -u -rcaba76f5ac2943f5a3dfd33550cb578132f40c80 -r92ab630ebd3c1b907e3d0fdf97cc07914245c028 --- generic/nsfUtil.c (.../nsfUtil.c) (revision caba76f5ac2943f5a3dfd33550cb578132f40c80) +++ generic/nsfUtil.c (.../nsfUtil.c) (revision 92ab630ebd3c1b907e3d0fdf97cc07914245c028) @@ -89,6 +89,8 @@ char tmp[LONG_AS_STRING], *pointer = &tmp[1], *string, *p; *tmp = 0; + assert(buf); + if (i<0) { i = -i; negative = nr_written = 1; @@ -138,6 +140,8 @@ NsfStringIncr(NsfStringIncrStruct *iss) { char newch, *currentChar; + assert(iss); + currentChar = iss->buffer + iss->bufSize - 2; newch = *(alphabet + chartable[(unsigned)*currentChar]); @@ -201,6 +205,8 @@ int i = 0; const size_t bufSize = blockIncrement>2 ? blockIncrement : 2; + assert(iss); + for (p=alphabet; *p; p++) { chartable[(int)*p] = ++i; } @@ -220,6 +226,9 @@ void NsfStringIncrFree(NsfStringIncrStruct *iss) { + + assert(iss); + ckfree(iss->buffer); }