globle int UndefineFunction( void *theEnv, const char *functionName) { SYMBOL_HN *findValue; struct FunctionDefinition *fPtr, *lastPtr = NULL; findValue = (SYMBOL_HN *) FindSymbolHN(theEnv,functionName); for (fPtr = ExternalFunctionData(theEnv)->ListOfFunctions; fPtr != NULL; fPtr = fPtr->next) { if (fPtr->callFunctionName == findValue) { DecrementSymbolCount(theEnv,fPtr->callFunctionName); RemoveHashFunction(theEnv,fPtr); if (lastPtr == NULL) { ExternalFunctionData(theEnv)->ListOfFunctions = fPtr->next; } else { lastPtr->next = fPtr->next; } ClearUserDataList(theEnv,fPtr->usrData); rtn_struct(theEnv,FunctionDefinition,fPtr); return(TRUE); } lastPtr = fPtr; } return(FALSE); }
globle void DestroyMethodInfo( void *theEnv, EXEC_STATUS, DEFGENERIC *gfunc, DEFMETHOD *meth) { register int j; register RESTRICTION *rptr; #if MAC_MCW || WIN_MCW || MAC_XCD #pragma unused(gfunc) #endif ReturnPackedExpression(theEnv,execStatus,meth->actions); ClearUserDataList(theEnv,execStatus,meth->usrData); if (meth->ppForm != NULL) rm(theEnv,execStatus,(void *) meth->ppForm,(sizeof(char) * (strlen(meth->ppForm)+1))); for (j = 0 ; j < meth->restrictionCount ; j++) { rptr = &meth->restrictions[j]; if (rptr->types != NULL) rm(theEnv,execStatus,(void *) rptr->types,(sizeof(void *) * rptr->tcnt)); ReturnPackedExpression(theEnv,execStatus,rptr->query); } if (meth->restrictions != NULL) rm(theEnv,execStatus,(void *) meth->restrictions, (sizeof(RESTRICTION) * meth->restrictionCount)); }
/*************************************************** NAME : DeleteMethodInfo DESCRIPTION : Deallocates all the data associated w/ a method but does not release the method structure itself INPUTS : 1) The generic function address 2) The method address RETURNS : Nothing useful SIDE EFFECTS : Nodes deallocated NOTES : None ***************************************************/ globle void DeleteMethodInfo( void *theEnv, DEFGENERIC *gfunc, DEFMETHOD *meth) { short j,k; RESTRICTION *rptr; SaveBusyCount(gfunc); ExpressionDeinstall(theEnv,meth->actions); ReturnPackedExpression(theEnv,meth->actions); ClearUserDataList(theEnv,meth->usrData); if (meth->ppForm != NULL) rm(theEnv,(void *) meth->ppForm,(sizeof(char) * (strlen(meth->ppForm)+1))); for (j = 0 ; j < meth->restrictionCount ; j++) { rptr = &meth->restrictions[j]; for (k = 0 ; k < rptr->tcnt ; k++) #if OBJECT_SYSTEM DecrementDefclassBusyCount(theEnv,rptr->types[k]); #else DecrementIntegerCount(theEnv,(INTEGER_HN *) rptr->types[k]); #endif if (rptr->types != NULL) rm(theEnv,(void *) rptr->types,(sizeof(void *) * rptr->tcnt)); ExpressionDeinstall(theEnv,rptr->query); ReturnPackedExpression(theEnv,rptr->query); } if (meth->restrictions != NULL) rm(theEnv,(void *) meth->restrictions, (sizeof(RESTRICTION) * meth->restrictionCount)); RestoreBusyCount(gfunc); }
/*************************************************** NAME : DestroyMethodInfo DESCRIPTION : Deallocates all the data associated w/ a method but does not release the method structure itself INPUTS : 1) The generic function address 2) The method address RETURNS : Nothing useful SIDE EFFECTS : Nodes deallocated NOTES : None ***************************************************/ globle void DestroyMethodInfo( void *theEnv, DEFGENERIC *gfunc, DEFMETHOD *meth) { register int j; register RESTRICTION *rptr; ReturnPackedExpression(theEnv,meth->actions); ClearUserDataList(theEnv,meth->usrData); if (meth->ppForm != NULL) rm(theEnv,(void *) meth->ppForm,(sizeof(char) * (strlen(meth->ppForm)+1))); for (j = 0 ; j < meth->restrictionCount ; j++) { rptr = &meth->restrictions[j]; if (rptr->types != NULL) rm(theEnv,(void *) rptr->types,(sizeof(void *) * rptr->tcnt)); ReturnPackedExpression(theEnv,rptr->query); } if (meth->restrictions != NULL) rm(theEnv,(void *) meth->restrictions, (sizeof(RESTRICTION) * meth->restrictionCount)); }
void DestroyDefrule( void *theEnv, void *vTheDefrule) { struct defrule *theDefrule = (struct defrule *) vTheDefrule; struct defrule *nextDisjunct; bool first = true; if (theDefrule == NULL) return; while (theDefrule != NULL) { DetachJoinsDriver(theEnv,theDefrule,true); if (first) { #if (! BLOAD_ONLY) && (! RUN_TIME) if (theDefrule->dynamicSalience != NULL) { ReturnPackedExpression(theEnv,theDefrule->dynamicSalience); } if (theDefrule->header.ppForm != NULL) { struct defrule *tmpPtr; rm(theEnv,(void *) theDefrule->header.ppForm,strlen(theDefrule->header.ppForm) + 1); /*=======================================================*/ /* All of the rule disjuncts share the same pretty print */ /* form, so we want to avoid deleting it again. */ /*=======================================================*/ for (tmpPtr = theDefrule->disjunct; tmpPtr != NULL; tmpPtr = tmpPtr->disjunct) { tmpPtr->header.ppForm = NULL; } } #endif first = false; } if (theDefrule->header.usrData != NULL) { ClearUserDataList(theEnv,theDefrule->header.usrData); } #if (! BLOAD_ONLY) && (! RUN_TIME) if (theDefrule->actions != NULL) { ReturnPackedExpression(theEnv,theDefrule->actions); } #endif nextDisjunct = theDefrule->disjunct; #if (! BLOAD_ONLY) && (! RUN_TIME) rtn_struct(theEnv,defrule,theDefrule); #endif theDefrule = nextDisjunct; } }
/************************************************************** NAME : RemoveDefinstances DESCRIPTION : Deallocates and removes a definstance construct INPUTS : The definstance address RETURNS : Nothing useful SIDE EFFECTS : Existing definstance construct deleted NOTES : Assumes busy count of definstance is 0 **************************************************************/ static void RemoveDefinstances( void *theEnv, void *vdptr) { DEFINSTANCES *dptr = (DEFINSTANCES *) vdptr; DecrementSymbolCount(theEnv,GetDefinstancesNamePointer((void *) dptr)); ExpressionDeinstall(theEnv,dptr->mkinstance); ReturnPackedExpression(theEnv,dptr->mkinstance); SetDefinstancesPPForm((void *) dptr,NULL); ClearUserDataList(theEnv,dptr->header.usrData); rtn_struct(theEnv,definstances,dptr); }
/*************************************************** NAME : RemoveDeffunction DESCRIPTION : Removes a deffunction INPUTS : Deffunction pointer RETURNS : Nothing useful SIDE EFFECTS : Deffunction deallocated NOTES : Assumes deffunction is not in use!! ***************************************************/ globle void RemoveDeffunction( void *theEnv, void *vdptr) { DEFFUNCTION *dptr = (DEFFUNCTION *) vdptr; if (dptr == NULL) return; DecrementSymbolCount(theEnv,GetDeffunctionNamePointer((void *) dptr)); ExpressionDeinstall(theEnv,dptr->code); ReturnPackedExpression(theEnv,dptr->code); SetDeffunctionPPForm((void *) dptr,NULL); ClearUserDataList(theEnv,dptr->header.usrData); rtn_struct(theEnv,deffunctionStruct,dptr); }
/************************************************** NAME : RemoveDefgeneric DESCRIPTION : Removes a generic function node from the generic list along with all its methods INPUTS : The generic function RETURNS : Nothing useful SIDE EFFECTS : List adjusted Nodes deallocated NOTES : Assumes generic is not in use!!! **************************************************/ globle void RemoveDefgeneric( void *vgfunc) { DEFGENERIC *gfunc = (DEFGENERIC *) vgfunc; register int i; for (i = 0 ; i < gfunc->mcnt ; i++) DeleteMethodInfo(gfunc,&gfunc->methods[i]); if (gfunc->mcnt != 0) rm((void *) gfunc->methods,(int) (sizeof(DEFMETHOD) * gfunc->mcnt)); DecrementSymbolCount(GetDefgenericNamePointer((void *) gfunc)); SetDefgenericPPForm((void *) gfunc,NULL); ClearUserDataList(gfunc->header.usrData); rtn_struct(defgeneric,gfunc); }
globle void DeinstallConstructHeader( struct constructHeader *theHeader) { DecrementSymbolCount(theHeader->name); if (theHeader->ppForm != NULL) { rm(theHeader->ppForm, (int) sizeof(char) * ((int) strlen(theHeader->ppForm) + 1)); theHeader->ppForm = NULL; } if (theHeader->usrData != NULL) { ClearUserDataList(theHeader->usrData); theHeader->usrData = NULL; } }
globle void DestroyConstructHeader( void *theEnv, struct constructHeader *theHeader) { if (theHeader->ppForm != NULL) { rm(theEnv,(void *) theHeader->ppForm, sizeof(char) * (strlen(theHeader->ppForm) + 1)); theHeader->ppForm = NULL; } if (theHeader->usrData != NULL) { ClearUserDataList(theEnv,theHeader->usrData); theHeader->usrData = NULL; } }
globle void DestroyDefrule( void *theEnv, void *vTheDefrule) { struct defrule *theDefrule = (struct defrule *) vTheDefrule; struct defrule *nextDisjunct; int first = TRUE; if (theDefrule == NULL) return; while (theDefrule != NULL) { DetachJoins(theEnv,theDefrule,TRUE); if (first) { #if (! BLOAD_ONLY) && (! RUN_TIME) #if DYNAMIC_SALIENCE if (theDefrule->dynamicSalience != NULL) { ReturnPackedExpression(theEnv,theDefrule->dynamicSalience); } #endif if (theDefrule->header.ppForm != NULL) { rm(theEnv,theDefrule->header.ppForm,strlen(theDefrule->header.ppForm) + 1); } #endif first = FALSE; } if (theDefrule->header.usrData != NULL) { ClearUserDataList(theEnv,theDefrule->header.usrData); } #if (! BLOAD_ONLY) && (! RUN_TIME) if (theDefrule->actions != NULL) { ReturnPackedExpression(theEnv,theDefrule->actions); } #endif nextDisjunct = theDefrule->disjunct; #if (! BLOAD_ONLY) && (! RUN_TIME) rtn_struct(theEnv,defrule,theDefrule); #endif theDefrule = nextDisjunct; } }
void DeinstallConstructHeader( Environment *theEnv, ConstructHeader *theHeader) { ReleaseLexeme(theEnv,theHeader->name); if (theHeader->ppForm != NULL) { rm(theEnv,(void *) theHeader->ppForm, sizeof(char) * (strlen(theHeader->ppForm) + 1)); theHeader->ppForm = NULL; } if (theHeader->usrData != NULL) { ClearUserDataList(theEnv,theHeader->usrData); theHeader->usrData = NULL; } }
/************************************************** NAME : RemoveDefgeneric DESCRIPTION : Removes a generic function node from the generic list along with all its methods INPUTS : The generic function RETURNS : Nothing useful SIDE EFFECTS : List adjusted Nodes deallocated NOTES : Assumes generic is not in use!!! **************************************************/ globle void RemoveDefgeneric( void *theEnv, EXEC_STATUS, void *vgfunc) { DEFGENERIC *gfunc = (DEFGENERIC *) vgfunc; long i; for (i = 0 ; i < gfunc->mcnt ; i++) DeleteMethodInfo(theEnv,execStatus,gfunc,&gfunc->methods[i]); if (gfunc->mcnt != 0) rm(theEnv,execStatus,(void *) gfunc->methods,(sizeof(DEFMETHOD) * gfunc->mcnt)); DecrementSymbolCount(theEnv,execStatus,GetDefgenericNamePointer((void *) gfunc)); SetDefgenericPPForm((void *) gfunc,NULL); ClearUserDataList(theEnv,execStatus,gfunc->header.usrData); rtn_struct(theEnv,execStatus,defgeneric,gfunc); }
globle void DeinstallConstructHeader( void *theEnv, EXEC_STATUS, struct constructHeader *theHeader) { DecrementSymbolCount(theEnv,execStatus,theHeader->name); if (theHeader->ppForm != NULL) { rm(theEnv,execStatus,theHeader->ppForm, sizeof(char) * (strlen(theHeader->ppForm) + 1)); theHeader->ppForm = NULL; } if (theHeader->usrData != NULL) { ClearUserDataList(theEnv,execStatus,theHeader->usrData); theHeader->usrData = NULL; } }
globle void ReturnDefrule( void *theEnv, void *vWaste) { #if (! RUN_TIME) && (! BLOAD_ONLY) struct defrule *waste = (struct defrule *) vWaste; int first = TRUE; struct defrule *nextPtr, *tmpPtr; if (waste == NULL) return; /*======================================*/ /* If a rule is redefined, then we want */ /* to save its breakpoint status. */ /*======================================*/ #if DEBUGGING_FUNCTIONS DefruleData(theEnv)->DeletedRuleDebugFlags = 0; if (waste->afterBreakpoint) BitwiseSet(DefruleData(theEnv)->DeletedRuleDebugFlags,0); if (waste->watchActivation) BitwiseSet(DefruleData(theEnv)->DeletedRuleDebugFlags,1); if (waste->watchFiring) BitwiseSet(DefruleData(theEnv)->DeletedRuleDebugFlags,2); #endif /*================================*/ /* Clear the agenda of all the */ /* activations added by the rule. */ /*================================*/ ClearRuleFromAgenda(theEnv,waste); /*======================*/ /* Get rid of the rule. */ /*======================*/ while (waste != NULL) { /*================================================*/ /* Remove the rule's joins from the join network. */ /*================================================*/ DetachJoinsDriver(theEnv,waste,FALSE); /*=============================================*/ /* If this is the first disjunct, get rid of */ /* the dynamic salience and pretty print form. */ /*=============================================*/ if (first) { if (waste->dynamicSalience != NULL) { ExpressionDeinstall(theEnv,waste->dynamicSalience); ReturnPackedExpression(theEnv,waste->dynamicSalience); waste->dynamicSalience = NULL; } #if CERTAINTY_FACTORS /* changed 03-12-96 */ if (waste->dynamicCF != NULL) { ExpressionDeinstall(theEnv,waste->dynamicCF); ReturnPackedExpression(theEnv,waste->dynamicCF); waste->dynamicCF = NULL; } #endif if (waste->header.ppForm != NULL) { rm(theEnv,(void *) waste->header.ppForm,strlen(waste->header.ppForm) + 1); waste->header.ppForm = NULL; /*=======================================================*/ /* All of the rule disjuncts share the same pretty print */ /* form, so we want to avoid deleting it again. */ /*=======================================================*/ for (tmpPtr = waste->disjunct; tmpPtr != NULL; tmpPtr = tmpPtr->disjunct) { tmpPtr->header.ppForm = NULL; } } first = FALSE; } /*===========================*/ /* Get rid of any user data. */ /*===========================*/ if (waste->header.usrData != NULL) { ClearUserDataList(theEnv,waste->header.usrData); } /*===========================================*/ /* Decrement the count for the defrule name. */ /*===========================================*/ DecrementSymbolCount(theEnv,waste->header.name); /*========================================*/ /* Get rid of the the rule's RHS actions. */ /*========================================*/ if (waste->actions != NULL) { ExpressionDeinstall(theEnv,waste->actions); ReturnPackedExpression(theEnv,waste->actions); } /*===============================*/ /* Move on to the next disjunct. */ /*===============================*/ nextPtr = waste->disjunct; #if FUZZY_DEFTEMPLATES if (waste != EngineData(theEnv)->ExecutingRule) { if (waste->numberOfFuzzySlots > 0) rm(theEnv,waste->pattern_fv_arrayPtr, sizeof(struct fzSlotLocator) * waste->numberOfFuzzySlots); } #endif rtn_struct(theEnv,defrule,waste); waste = nextPtr; } /*==========================*/ /* Free up partial matches. */ /*==========================*/ if (EngineData(theEnv)->ExecutingRule == NULL) FlushGarbagePartialMatches(theEnv); #endif }
globle void DestroyDefrule( void *theEnv, void *vTheDefrule) { struct defrule *theDefrule = (struct defrule *) vTheDefrule; struct defrule *nextDisjunct; int first = TRUE; if (theDefrule == NULL) return; while (theDefrule != NULL) { DetachJoinsDriver(theEnv,theDefrule,TRUE); if (first) { #if (! BLOAD_ONLY) && (! RUN_TIME) if (theDefrule->dynamicSalience != NULL) { ReturnPackedExpression(theEnv,theDefrule->dynamicSalience); } if (theDefrule->header.ppForm != NULL) { struct defrule *tmpPtr; rm(theEnv,(void *) theDefrule->header.ppForm,strlen(theDefrule->header.ppForm) + 1); /*=======================================================*/ /* All of the rule disjuncts share the same pretty print */ /* form, so we want to avoid deleting it again. */ /*=======================================================*/ for (tmpPtr = theDefrule->disjunct; tmpPtr != NULL; tmpPtr = tmpPtr->disjunct) { tmpPtr->header.ppForm = NULL; } } #if CERTAINTY_FACTORS if (theDefrule->dynamicCF != NULL) { ReturnPackedExpression(theEnv,theDefrule->dynamicCF); } #endif #endif first = FALSE; } if (theDefrule->header.usrData != NULL) { ClearUserDataList(theEnv,theDefrule->header.usrData); } #if (! BLOAD_ONLY) && (! RUN_TIME) if (theDefrule->actions != NULL) { ReturnPackedExpression(theEnv,theDefrule->actions); } #if FUZZY_DEFTEMPLATES if (theDefrule->numberOfFuzzySlots > 0) { rm(theEnv,theDefrule->pattern_fv_arrayPtr, sizeof(struct fzSlotLocator) * theDefrule->numberOfFuzzySlots); } #endif #endif nextDisjunct = theDefrule->disjunct; #if (! BLOAD_ONLY) && (! RUN_TIME) rtn_struct(theEnv,defrule,theDefrule); #endif theDefrule = nextDisjunct; } }
globle void ReturnDefrule( void *theEnv, void *vWaste) { #if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY) #pragma unused(theEnv,vWaste) #endif #if (! RUN_TIME) && (! BLOAD_ONLY) struct defrule *waste = (struct defrule *) vWaste; int first = TRUE; struct defrule *nextPtr; if (waste == NULL) return; /*======================================*/ /* If a rule is redefined, then we want */ /* to save its breakpoint status. */ /*======================================*/ #if DEBUGGING_FUNCTIONS DefruleData(theEnv)->DeletedRuleDebugFlags = 0; if (waste->afterBreakpoint) BitwiseSet(DefruleData(theEnv)->DeletedRuleDebugFlags,0); if (waste->watchActivation) BitwiseSet(DefruleData(theEnv)->DeletedRuleDebugFlags,1); if (waste->watchFiring) BitwiseSet(DefruleData(theEnv)->DeletedRuleDebugFlags,2); #endif /*================================*/ /* Clear the agenda of all the */ /* activations added by the rule. */ /*================================*/ ClearRuleFromAgenda(theEnv,waste); /*======================*/ /* Get rid of the rule. */ /*======================*/ while (waste != NULL) { /*================================================*/ /* Remove the rule's joins from the join network. */ /*================================================*/ DetachJoins(theEnv,waste,FALSE); /*=============================================*/ /* If this is the first disjunct, get rid of */ /* the dynamic salience and pretty print form. */ /*=============================================*/ if (first) { #if DYNAMIC_SALIENCE if (waste->dynamicSalience != NULL) { ExpressionDeinstall(theEnv,waste->dynamicSalience); ReturnPackedExpression(theEnv,waste->dynamicSalience); waste->dynamicSalience = NULL; } #endif if (waste->header.ppForm != NULL) { rm(theEnv,waste->header.ppForm,strlen(waste->header.ppForm) + 1); waste->header.ppForm = NULL; } first = FALSE; } /*===========================*/ /* Get rid of any user data. */ /*===========================*/ if (waste->header.usrData != NULL) { ClearUserDataList(theEnv,waste->header.usrData); } /*===========================================*/ /* Decrement the count for the defrule name. */ /*===========================================*/ DecrementSymbolCount(theEnv,waste->header.name); /*========================================*/ /* Get rid of the the rule's RHS actions. */ /*========================================*/ if (waste->actions != NULL) { ExpressionDeinstall(theEnv,waste->actions); ReturnPackedExpression(theEnv,waste->actions); } /*===============================*/ /* Move on to the next disjunct. */ /*===============================*/ nextPtr = waste->disjunct; rtn_struct(theEnv,defrule,waste); waste = nextPtr; } /*==========================*/ /* Free up partial matches. */ /*==========================*/ if (EngineData(theEnv)->ExecutingRule == NULL) FlushGarbagePartialMatches(theEnv); #endif }
static void ReturnDefmodule( void *theEnv, struct defmodule *theDefmodule, intBool environmentClear) { int i; struct moduleItem *theItem; struct portItem *theSpec, *nextSpec; /*=====================================================*/ /* Set the current module to the module being deleted. */ /*=====================================================*/ if (theDefmodule == NULL) return; if (! environmentClear) { EnvSetCurrentModule(theEnv,(void *) theDefmodule); } /*============================================*/ /* Call the free functions for the constructs */ /* belonging to this module. */ /*============================================*/ if (theDefmodule->itemsArray != NULL) { if (! environmentClear) { for (i = 0, theItem = DefmoduleData(theEnv)->ListOfModuleItems; (i < DefmoduleData(theEnv)->NumberOfModuleItems) && (theItem != NULL); i++, theItem = theItem->next) { if (theItem->freeFunction != NULL) { (*theItem->freeFunction)(theEnv,theDefmodule->itemsArray[i]); } } } rm(theEnv,theDefmodule->itemsArray,sizeof(void *) * DefmoduleData(theEnv)->NumberOfModuleItems); } /*======================================================*/ /* Decrement the symbol count for the defmodule's name. */ /*======================================================*/ if (! environmentClear) { DecrementSymbolCount(theEnv,theDefmodule->name); } /*====================================*/ /* Free the items in the import list. */ /*====================================*/ theSpec = theDefmodule->importList; while (theSpec != NULL) { nextSpec = theSpec->next; if (! environmentClear) { if (theSpec->moduleName != NULL) DecrementSymbolCount(theEnv,theSpec->moduleName); if (theSpec->constructType != NULL) DecrementSymbolCount(theEnv,theSpec->constructType); if (theSpec->constructName != NULL) DecrementSymbolCount(theEnv,theSpec->constructName); } rtn_struct(theEnv,portItem,theSpec); theSpec = nextSpec; } /*====================================*/ /* Free the items in the export list. */ /*====================================*/ theSpec = theDefmodule->exportList; while (theSpec != NULL) { nextSpec = theSpec->next; if (! environmentClear) { if (theSpec->moduleName != NULL) DecrementSymbolCount(theEnv,theSpec->moduleName); if (theSpec->constructType != NULL) DecrementSymbolCount(theEnv,theSpec->constructType); if (theSpec->constructName != NULL) DecrementSymbolCount(theEnv,theSpec->constructName); } rtn_struct(theEnv,portItem,theSpec); theSpec = nextSpec; } /*=========================================*/ /* Free the defmodule pretty print string. */ /*=========================================*/ if (theDefmodule->ppForm != NULL) { rm(theEnv,theDefmodule->ppForm, (int) sizeof(char) * (strlen(theDefmodule->ppForm) + 1)); } /*=======================*/ /* Return the user data. */ /*=======================*/ ClearUserDataList(theEnv,theDefmodule->usrData); /*======================================*/ /* Return the defmodule data structure. */ /*======================================*/ rtn_struct(theEnv,defmodule,theDefmodule); }
/*************************************************** NAME : DeallocateMarkedHandlers DESCRIPTION : Removes any handlers from a class that have been previously marked for deletion. INPUTS : The class RETURNS : Nothing useful SIDE EFFECTS : Marked handlers are deleted NOTES : Assumes none of the handlers are currently executing or have a busy count != 0 for any reason ***************************************************/ globle void DeallocateMarkedHandlers( void *theEnv, EXEC_STATUS, DEFCLASS *cls) { short count; HANDLER *hnd,*nhnd; unsigned *arr,*narr; long i,j; for (i = 0 , count = 0 ; i < cls->handlerCount ; i++) { hnd = &cls->handlers[i]; if (hnd->mark == 1) { count++; DecrementSymbolCount(theEnv,execStatus,hnd->name); ExpressionDeinstall(theEnv,execStatus,hnd->actions); ReturnPackedExpression(theEnv,execStatus,hnd->actions); ClearUserDataList(theEnv,execStatus,hnd->usrData); if (hnd->ppForm != NULL) rm(theEnv,execStatus,(void *) hnd->ppForm, (sizeof(char) * (strlen(hnd->ppForm)+1))); } else /* ============================================ Use the busy field to count how many message-handlers are removed before this one ============================================ */ hnd->busy = count; } if (count == 0) return; if (count == cls->handlerCount) { rm(theEnv,execStatus,(void *) cls->handlers,(sizeof(HANDLER) * cls->handlerCount)); rm(theEnv,execStatus,(void *) cls->handlerOrderMap,(sizeof(unsigned) * cls->handlerCount)); cls->handlers = NULL; cls->handlerOrderMap = NULL; cls->handlerCount = 0; } else { count = (short) (cls->handlerCount - count); hnd = cls->handlers; arr = cls->handlerOrderMap; nhnd = (HANDLER *) gm2(theEnv,execStatus,(sizeof(HANDLER) * count)); narr = (unsigned *) gm2(theEnv,execStatus,(sizeof(unsigned) * count)); for (i = 0 , j = 0 ; j < count ; i++) { if (hnd[arr[i]].mark == 0) { /* ============================================================== The offsets in the map need to be decremented by the number of preceding nodes which were deleted. Use the value of the busy field set in the first loop. ============================================================== */ narr[j] = arr[i] - hnd[arr[i]].busy; j++; } } for (i = 0 , j = 0 ; j < count ; i++) { if (hnd[i].mark == 0) { hnd[i].busy = 0; GenCopyMemory(HANDLER,1,&nhnd[j],&hnd[i]); j++; } } rm(theEnv,execStatus,(void *) hnd,(sizeof(HANDLER) * cls->handlerCount)); rm(theEnv,execStatus,(void *) arr,(sizeof(unsigned) * cls->handlerCount)); cls->handlers = nhnd; cls->handlerOrderMap = narr; cls->handlerCount = count; } }