summaryrefslogtreecommitdiffstats
path: root/generic/tclOOCall.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclOOCall.c')
-rw-r--r--generic/tclOOCall.c116
1 files changed, 60 insertions, 56 deletions
diff --git a/generic/tclOOCall.c b/generic/tclOOCall.c
index 57f8860..39fd020 100644
--- a/generic/tclOOCall.c
+++ b/generic/tclOOCall.c
@@ -25,7 +25,7 @@
struct ChainBuilder {
CallChain *callChainPtr; /* The call chain being built. */
- int filterLength; /* Number of entries in the call chain that
+ size_t filterLength; /* Number of entries in the call chain that
* are due to processing filters and not the
* main call chain. */
Object *oPtr; /* The object that we are building the chain
@@ -139,7 +139,7 @@ static inline int IsStillValid(CallChain *callPtr, Object *oPtr,
int flags, int reuseMask);
static Tcl_NRPostProc ResetFilterFlags;
static Tcl_NRPostProc SetFilterFlags;
-static int SortMethodNames(Tcl_HashTable *namesPtr, int flags,
+static size_t SortMethodNames(Tcl_HashTable *namesPtr, int flags,
const char ***stringsPtr);
static inline void StashCallChain(Tcl_Obj *objPtr, CallChain *callPtr);
@@ -152,7 +152,8 @@ static const Tcl_ObjType methodNameType = {
FreeMethodNameRep,
DupMethodNameRep,
NULL,
- NULL
+ NULL,
+ TCL_OBJTYPE_V0
};
@@ -207,7 +208,7 @@ TclOODeleteChainCache(
}
}
Tcl_DeleteHashTable(tablePtr);
- ckfree(tablePtr);
+ Tcl_Free(tablePtr);
}
/*
@@ -228,9 +229,9 @@ TclOODeleteChain(
return;
}
if (callPtr->chain != callPtr->staticChain) {
- ckfree(callPtr->chain);
+ Tcl_Free(callPtr->chain);
}
- ckfree(callPtr);
+ Tcl_Free(callPtr);
}
/*
@@ -328,7 +329,7 @@ TclOOInvokeContext(
*/
if (contextPtr->index == 0) {
- int i;
+ Tcl_Size i;
for (i = 0 ; i < contextPtr->callPtr->numChain ; i++) {
AddRef(contextPtr->callPtr->chain[i].mPtr);
@@ -410,7 +411,7 @@ FinalizeMethodRefs(
int result)
{
CallContext *contextPtr = (CallContext *)data[0];
- int i;
+ Tcl_Size i;
for (i = 0 ; i < contextPtr->callPtr->numChain ; i++) {
TclOODelMethodRef(contextPtr->callPtr->chain[i].mPtr);
@@ -451,7 +452,7 @@ TclOOGetSortedMethodList(
* at. Is set-like in nature and keyed by
* pointer to class. */
FOREACH_HASH_DECLS;
- int i, numStrings;
+ Tcl_Size i, numStrings;
Class *mixinPtr;
Tcl_Obj *namePtr;
Method *mPtr;
@@ -527,7 +528,7 @@ TclOOGetSortedMethodList(
return numStrings;
}
-int
+size_t
TclOOGetSortedClassMethodList(
Class *clsPtr, /* The class to get the method names for. */
int flags, /* Whether we just want the public method
@@ -541,7 +542,7 @@ TclOOGetSortedClassMethodList(
/* Used to track what classes have been looked
* at. Is set-like in nature and keyed by
* pointer to class. */
- int numStrings;
+ size_t numStrings;
Tcl_InitObjHashTable(&names);
Tcl_InitHashTable(&examinedClasses, TCL_ONE_WORD_KEYS);
@@ -586,7 +587,7 @@ TclOOGetSortedClassMethodList(
* ----------------------------------------------------------------------
*/
-static int
+static size_t
SortMethodNames(
Tcl_HashTable *namesPtr, /* The table of names; unsorted, but contains
* whether the names are wanted and under what
@@ -595,13 +596,13 @@ SortMethodNames(
* methods. Full private methods are handled
* on insertion to the table. */
const char ***stringsPtr) /* Where to store the sorted list of strings
- * that we produce. ckalloced() */
+ * that we produce. Tcl_Alloced() */
{
const char **strings;
FOREACH_HASH_DECLS;
Tcl_Obj *namePtr;
void *isWanted;
- int i = 0;
+ size_t i = 0;
/*
* See how many (visible) method names there are. If none, we do not (and
@@ -619,7 +620,7 @@ SortMethodNames(
* sorted when it is long enough to matter.
*/
- strings = (const char **)ckalloc(sizeof(char *) * namesPtr->numEntries);
+ strings = (const char **)Tcl_Alloc(sizeof(char *) * namesPtr->numEntries);
FOREACH_HASH(namePtr, isWanted, namesPtr) {
if (!WANT_PUBLIC(flags) || (PTR2INT(isWanted) & IN_LIST)) {
if (PTR2INT(isWanted) & NO_IMPLEMENTATION) {
@@ -641,7 +642,7 @@ SortMethodNames(
}
*stringsPtr = strings;
} else {
- ckfree(strings);
+ Tcl_Free((void *)strings);
*stringsPtr = NULL;
}
return i;
@@ -692,14 +693,14 @@ AddClassMethodNames(
* pointers to the classes, and the values are
* immaterial. */
{
- int i;
+ Tcl_Size i;
/*
* If we've already started looking at this class, stop working on it now
* to prevent repeated work.
*/
- if (Tcl_FindHashEntry(examinedClassesPtr, (char *) clsPtr)) {
+ if (Tcl_FindHashEntry(examinedClassesPtr, clsPtr)) {
return;
}
@@ -716,7 +717,7 @@ AddClassMethodNames(
Method *mPtr;
int isNew;
- (void) Tcl_CreateHashEntry(examinedClassesPtr, (char *) clsPtr,
+ (void) Tcl_CreateHashEntry(examinedClassesPtr, clsPtr,
&isNew);
if (!isNew) {
break;
@@ -775,7 +776,7 @@ AddPrivateMethodNames(
if (IS_PRIVATE(mPtr)) {
int isNew;
- hPtr = Tcl_CreateHashEntry(namesPtr, (char *) namePtr, &isNew);
+ hPtr = Tcl_CreateHashEntry(namesPtr, namePtr, &isNew);
Tcl_SetHashValue(hPtr, INT2PTR(IN_LIST));
}
}
@@ -791,7 +792,7 @@ AddStandardMethodName(
if (!IS_PRIVATE(mPtr)) {
int isNew;
Tcl_HashEntry *hPtr =
- Tcl_CreateHashEntry(namesPtr, (char *) namePtr, &isNew);
+ Tcl_CreateHashEntry(namesPtr, namePtr, &isNew);
if (isNew) {
int isWanted = (!WANT_PUBLIC(flags) || IS_PUBLIC(mPtr))
@@ -839,7 +840,7 @@ AddInstancePrivateToCallContext(
int donePrivate = 0;
if (oPtr->methodsPtr) {
- hPtr = Tcl_FindHashEntry(oPtr->methodsPtr, (char *) methodName);
+ hPtr = Tcl_FindHashEntry(oPtr->methodsPtr, methodName);
if (hPtr != NULL) {
mPtr = (Method *)Tcl_GetHashValue(hPtr);
if (IS_PRIVATE(mPtr)) {
@@ -883,12 +884,13 @@ AddSimpleChainToCallContext(
* NULL, either the filter was declared by the
* object or this isn't a filter. */
{
- int i, foundPrivate = 0, blockedUnexported = 0;
+ Tcl_Size i;
+ int foundPrivate = 0, blockedUnexported = 0;
Tcl_HashEntry *hPtr;
Method *mPtr;
if (!(flags & (KNOWN_STATE | SPECIAL)) && oPtr->methodsPtr) {
- hPtr = Tcl_FindHashEntry(oPtr->methodsPtr, (char *) methodNameObj);
+ hPtr = Tcl_FindHashEntry(oPtr->methodsPtr, methodNameObj);
if (hPtr != NULL) {
mPtr = (Method *)Tcl_GetHashValue(hPtr);
@@ -919,7 +921,7 @@ AddSimpleChainToCallContext(
flags | TRAVERSED_MIXIN, filterDecl);
}
if (oPtr->methodsPtr && !blockedUnexported) {
- hPtr = Tcl_FindHashEntry(oPtr->methodsPtr, (char*) methodNameObj);
+ hPtr = Tcl_FindHashEntry(oPtr->methodsPtr, methodNameObj);
if (hPtr != NULL) {
mPtr = (Method *)Tcl_GetHashValue(hPtr);
if (!IS_PRIVATE(mPtr)) {
@@ -975,7 +977,7 @@ AddMethodToCallChain(
* not passed a mixin. */
{
CallChain *callPtr = cbPtr->callChainPtr;
- int i;
+ Tcl_Size i;
/*
* Return if this is just an entry used to record whether this is a public
@@ -1043,11 +1045,11 @@ AddMethodToCallChain(
if (callPtr->numChain == CALL_CHAIN_STATIC_SIZE) {
callPtr->chain =
- (struct MInvoke *)ckalloc(sizeof(struct MInvoke) * (callPtr->numChain + 1));
+ (struct MInvoke *)Tcl_Alloc(sizeof(struct MInvoke) * (callPtr->numChain + 1));
memcpy(callPtr->chain, callPtr->staticChain,
sizeof(struct MInvoke) * callPtr->numChain);
} else if (callPtr->numChain > CALL_CHAIN_STATIC_SIZE) {
- callPtr->chain = (struct MInvoke *)ckrealloc(callPtr->chain,
+ callPtr->chain = (struct MInvoke *)Tcl_Realloc(callPtr->chain,
sizeof(struct MInvoke) * (callPtr->numChain + 1));
}
callPtr->chain[i].mPtr = mPtr;
@@ -1155,7 +1157,7 @@ TclOOGetCallContext(
CallContext *contextPtr;
CallChain *callPtr;
struct ChainBuilder cb;
- int i, count;
+ Tcl_Size i, count;
int doFilters, donePrivate = 0;
Tcl_HashEntry *hPtr;
Tcl_HashTable doneFilters;
@@ -1211,14 +1213,14 @@ TclOOGetCallContext(
if (oPtr->flags & USE_CLASS_CACHE) {
if (oPtr->selfCls->classChainCache != NULL) {
hPtr = Tcl_FindHashEntry(oPtr->selfCls->classChainCache,
- (char *) methodNameObj);
+ methodNameObj);
} else {
hPtr = NULL;
}
} else {
if (oPtr->chainCache != NULL) {
hPtr = Tcl_FindHashEntry(oPtr->chainCache,
- (char *) methodNameObj);
+ methodNameObj);
} else {
hPtr = NULL;
}
@@ -1237,7 +1239,7 @@ TclOOGetCallContext(
doFilters = 1;
}
- callPtr = (CallChain *)ckalloc(sizeof(CallChain));
+ callPtr = (CallChain *)Tcl_Alloc(sizeof(CallChain));
InitCallChain(callPtr, oPtr, flags);
cb.callChainPtr = callPtr;
@@ -1255,7 +1257,7 @@ TclOOGetCallContext(
AddSimpleChainToCallContext(oPtr, NULL,
oPtr->fPtr->unknownMethodNameObj, &cb, NULL, 0, NULL);
callPtr->flags |= OO_UNKNOWN_METHOD;
- callPtr->epoch = -1;
+ callPtr->epoch = 0;
if (callPtr->numChain == 0) {
TclOODeleteChain(callPtr);
return NULL;
@@ -1332,30 +1334,31 @@ TclOOGetCallContext(
AddSimpleChainToCallContext(oPtr, NULL,
oPtr->fPtr->unknownMethodNameObj, &cb, NULL, 0, NULL);
callPtr->flags |= OO_UNKNOWN_METHOD;
- callPtr->epoch = -1;
+ callPtr->epoch = 0;
if (count == callPtr->numChain) {
TclOODeleteChain(callPtr);
return NULL;
}
} else if (doFilters && !donePrivate) {
if (hPtr == NULL) {
+ int isNew;
if (oPtr->flags & USE_CLASS_CACHE) {
if (oPtr->selfCls->classChainCache == NULL) {
oPtr->selfCls->classChainCache =
- (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
+ (Tcl_HashTable *)Tcl_Alloc(sizeof(Tcl_HashTable));
Tcl_InitObjHashTable(oPtr->selfCls->classChainCache);
}
hPtr = Tcl_CreateHashEntry(oPtr->selfCls->classChainCache,
- (char *) methodNameObj, &i);
+ methodNameObj, &isNew);
} else {
if (oPtr->chainCache == NULL) {
- oPtr->chainCache = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
+ oPtr->chainCache = (Tcl_HashTable *)Tcl_Alloc(sizeof(Tcl_HashTable));
Tcl_InitObjHashTable(oPtr->chainCache);
}
hPtr = Tcl_CreateHashEntry(oPtr->chainCache,
- (char *) methodNameObj, &i);
+ methodNameObj, &isNew);
}
}
callPtr->refCount++;
@@ -1415,7 +1418,7 @@ TclOOGetStereotypeCallChain(
{
CallChain *callPtr;
struct ChainBuilder cb;
- int i, count;
+ Tcl_Size count;
Foundation *fPtr = clsPtr->thisPtr->fPtr;
Tcl_HashEntry *hPtr;
Tcl_HashTable doneFilters;
@@ -1441,7 +1444,7 @@ TclOOGetStereotypeCallChain(
if (clsPtr->classChainCache != NULL) {
hPtr = Tcl_FindHashEntry(clsPtr->classChainCache,
- (char *) methodNameObj);
+ methodNameObj);
if (hPtr != NULL && Tcl_GetHashValue(hPtr) != NULL) {
const int reuseMask = (WANT_PUBLIC(flags) ? ~0 : ~PUBLIC_METHOD);
@@ -1457,7 +1460,7 @@ TclOOGetStereotypeCallChain(
hPtr = NULL;
}
- callPtr = (CallChain *)ckalloc(sizeof(CallChain));
+ callPtr = (CallChain *)Tcl_Alloc(sizeof(CallChain));
memset(callPtr, 0, sizeof(CallChain));
callPtr->flags = flags & (PUBLIC_METHOD|PRIVATE_METHOD|FILTER_HANDLING);
callPtr->epoch = fPtr->epoch;
@@ -1504,19 +1507,20 @@ TclOOGetStereotypeCallChain(
AddSimpleChainToCallContext(&obj, NULL, fPtr->unknownMethodNameObj,
&cb, NULL, 0, NULL);
callPtr->flags |= OO_UNKNOWN_METHOD;
- callPtr->epoch = -1;
+ callPtr->epoch = 0;
if (count == callPtr->numChain) {
TclOODeleteChain(callPtr);
return NULL;
}
} else {
if (hPtr == NULL) {
+ int isNew;
if (clsPtr->classChainCache == NULL) {
- clsPtr->classChainCache = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
+ clsPtr->classChainCache = (Tcl_HashTable *)Tcl_Alloc(sizeof(Tcl_HashTable));
Tcl_InitObjHashTable(clsPtr->classChainCache);
}
hPtr = Tcl_CreateHashEntry(clsPtr->classChainCache,
- (char *) methodNameObj, &i);
+ methodNameObj, &isNew);
}
callPtr->refCount++;
Tcl_SetHashValue(hPtr, callPtr);
@@ -1549,7 +1553,7 @@ AddClassFiltersToCallContext(
int flags) /* Whether we've gone along a mixin link
* yet. */
{
- int i;
+ Tcl_Size i;
int clearedFlags =
flags & ~(TRAVERSED_MIXIN|OBJECT_MIXIN|BUILDING_MIXINS);
Class *superPtr, *mixinPtr;
@@ -1580,8 +1584,7 @@ AddClassFiltersToCallContext(
FOREACH(filterObj, clsPtr->filters) {
int isNew;
- (void) Tcl_CreateHashEntry(doneFilters, (char *) filterObj,
- &isNew);
+ (void) Tcl_CreateHashEntry(doneFilters, filterObj, &isNew);
if (isNew) {
AddSimpleChainToCallContext(oPtr, NULL, filterObj, cbPtr,
doneFilters, clearedFlags|BUILDING_MIXINS, clsPtr);
@@ -1639,7 +1642,7 @@ AddPrivatesFromClassChainToCallContext(
* NULL, either the filter was declared by the
* object or this isn't a filter. */
{
- int i;
+ Tcl_Size i;
Class *superPtr;
/*
@@ -1717,7 +1720,8 @@ AddSimpleClassChainToCallContext(
* NULL, either the filter was declared by the
* object or this isn't a filter. */
{
- int i, privateDanger = 0;
+ Tcl_Size i;
+ int privateDanger = 0;
Class *superPtr;
/*
@@ -1743,7 +1747,7 @@ AddSimpleClassChainToCallContext(
filterDecl, flags);
} else {
Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&classPtr->classMethods,
- (char *) methodNameObj);
+ methodNameObj);
if (classPtr->flags & HAS_PRIVATE_METHODS) {
privateDanger |= 1;
@@ -1802,7 +1806,7 @@ TclOORenderCallChain(
Tcl_Obj *filterLiteral, *methodLiteral, *objectLiteral, *privateLiteral;
Tcl_Obj *resultObj, *descObjs[4], **objv;
Foundation *fPtr = TclOOGetFoundation(interp);
- int i;
+ Tcl_Size i;
/*
* Allocate the literals (potentially) used in our description.
@@ -1932,7 +1936,7 @@ TclOOGetDefineContextNamespace(
Tcl_ResetResult(interp);
}
if (define.list != staticSpace) {
- ckfree(define.list);
+ Tcl_Free(define.list);
}
return nsPtr;
}
@@ -1958,7 +1962,7 @@ AddSimpleDefineNamespaces(
* building. */
{
Class *mixinPtr;
- int i;
+ Tcl_Size i;
FOREACH(mixinPtr, oPtr->mixins) {
AddSimpleClassDefineNamespaces(mixinPtr, definePtr,
@@ -1987,7 +1991,7 @@ AddSimpleClassDefineNamespaces(
int flags) /* What sort of define chain are we
* building. */
{
- int i;
+ Tcl_Size i;
Class *superPtr;
/*
@@ -2097,11 +2101,11 @@ AddDefinitionNamespaceToChain(
DefineEntry *staticList = definePtr->list;
definePtr->list =
- (DefineEntry *)ckalloc(sizeof(DefineEntry) * definePtr->size);
+ (DefineEntry *)Tcl_Alloc(sizeof(DefineEntry) * definePtr->size);
memcpy(definePtr->list, staticList,
sizeof(DefineEntry) * definePtr->num);
} else {
- definePtr->list = (DefineEntry *)ckrealloc(definePtr->list,
+ definePtr->list = (DefineEntry *)Tcl_Realloc(definePtr->list,
sizeof(DefineEntry) * definePtr->size);
}
}