/*************************************************** NAME : ClearBloadObjectPatterns DESCRIPTION : Releases all emmory associated with binary image object patterns INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Memory released and global network pointers set to NULL NOTES : None ***************************************************/ static void ClearBloadObjectPatterns() { UNLN space; register long i; /* ================================================ All instances have been deleted by this point so we don't need to worry about clearing partial matches ================================================ */ for (i = 0L ; i < AlphaNodeCount ; i++) { DecrementBitMapCount(AlphaArray[i].classbmp); if (AlphaArray[i].slotbmp != NULL) DecrementBitMapCount(AlphaArray[i].slotbmp); } if (AlphaNodeCount != 0L) { space = (UNLN) (AlphaNodeCount * sizeof(OBJECT_ALPHA_NODE)); genlongfree((void *) AlphaArray,space); AlphaArray = NULL; space = (UNLN) (PatternNodeCount * sizeof(OBJECT_PATTERN_NODE)); genlongfree((void *) PatternArray,space); PatternArray = NULL; } SetObjectNetworkTerminalPointer(NULL); SetObjectNetworkPointer(NULL); #if BLOAD_ONLY ResetObjectMatchTimeTags(); #endif }
static void ClearBload() { long i; unsigned long space; /*=======================================================*/ /* Decrement in use counters for atomic values contained */ /* in the construct headers. Also decrement data */ /* structures used to store the defglobal's value. */ /*=======================================================*/ for (i = 0; i < NumberOfDefglobals; i++) { UnmarkConstructHeader(&DefglobalArray[i].header); ValueDeinstall(&(DefglobalArray[i].current)); if (DefglobalArray[i].current.type == MULTIFIELD) { ReturnMultifield((struct multifield *) DefglobalArray[i].current.value); } } /*==============================================================*/ /* Deallocate the space used for the defglobal data structures. */ /*==============================================================*/ space = NumberOfDefglobals * sizeof(struct defglobal); if (space != 0) genlongfree((void *) DefglobalArray,space); /*=====================================================================*/ /* Deallocate the space used for the defglobal module data structures. */ /*=====================================================================*/ space = NumberOfDefglobalModules * sizeof(struct defglobalModule); if (space != 0) genlongfree((void *) ModuleArray,space); }
static void ClearBload() { long i; unsigned long space; struct portItem *theList; /*===========================*/ /* Decrement in use counters */ /* used by the binary image. */ /*===========================*/ for (i = 0; i < NumberOfDefmodules; i++) { DecrementSymbolCount(DefmoduleArray[i].name); for (theList = DefmoduleArray[i].importList; theList != NULL; theList = theList->next) { if (theList->moduleName != NULL) DecrementSymbolCount(theList->moduleName); if (theList->constructType != NULL) DecrementSymbolCount(theList->constructType); if (theList->constructName != NULL) DecrementSymbolCount(theList->constructName); } for (theList = DefmoduleArray[i].exportList; theList != NULL; theList = theList->next) { if (theList->moduleName != NULL) DecrementSymbolCount(theList->moduleName); if (theList->constructType != NULL) DecrementSymbolCount(theList->constructType); if (theList->constructName != NULL) DecrementSymbolCount(theList->constructName); } rm(DefmoduleArray[i].itemsArray,(int) sizeof(void *) * GetNumberOfModuleItems()); } /*================================*/ /* Deallocate the space used for */ /* the defmodule data structures. */ /*================================*/ space = NumberOfDefmodules * sizeof(struct defmodule); if (space != 0) genlongfree((void *) DefmoduleArray,space); /*================================*/ /* Deallocate the space used for */ /* the port item data structures. */ /*================================*/ space = NumberOfPortItems * sizeof(struct portItem); if (space != 0) genlongfree((void *) PortItemArray,space); /*===========================*/ /* Reset module information. */ /*===========================*/ SetListOfDefmodules(NULL); CreateMainModule(); MainModuleRedefinable = TRUE; }
static void ClearBload( void *theEnv) { unsigned long int space; int i; /*=============================================*/ /* Decrement in use counters for atomic values */ /* contained in the construct headers. */ /*=============================================*/ for (i = 0; i < DeftemplateBinaryData(theEnv)->NumberOfDeftemplates; i++) { UnmarkConstructHeader(theEnv,&DeftemplateBinaryData(theEnv)->DeftemplateArray[i].header); } /*=======================================*/ /* Decrement in use counters for symbols */ /* used as slot names. */ /*=======================================*/ for (i = 0; i < DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots; i++) { DecrementSymbolCount(theEnv,DeftemplateBinaryData(theEnv)->SlotArray[i].slotName); } /*======================================================================*/ /* Deallocate the space used for the deftemplateModule data structures. */ /*======================================================================*/ space = DeftemplateBinaryData(theEnv)->NumberOfTemplateModules * sizeof(struct deftemplateModule); if (space != 0) genlongfree(theEnv,(void *) DeftemplateBinaryData(theEnv)->ModuleArray,space); DeftemplateBinaryData(theEnv)->NumberOfTemplateModules = 0; /*================================================================*/ /* Deallocate the space used for the deftemplate data structures. */ /*================================================================*/ space = DeftemplateBinaryData(theEnv)->NumberOfDeftemplates * sizeof(struct deftemplate); if (space != 0) genlongfree(theEnv,(void *) DeftemplateBinaryData(theEnv)->DeftemplateArray,space); DeftemplateBinaryData(theEnv)->NumberOfDeftemplates = 0; /*=================================================================*/ /* Deallocate the space used for the templateSlot data structures. */ /*=================================================================*/ space = DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots * sizeof(struct templateSlot); if (space != 0) genlongfree(theEnv,(void *) DeftemplateBinaryData(theEnv)->SlotArray,space); DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots = 0; /*======================================*/ /* Create the initial-fact deftemplate. */ /*======================================*/ #if (! BLOAD_ONLY) CreateImpliedDeftemplate(theEnv,(SYMBOL_HN *) EnvAddSymbol(theEnv,"initial-fact"),FALSE); #endif }
static void DeallocateDeffunctionBloadData( void *theEnv) { unsigned long space; #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) space = DeffunctionBinaryData(theEnv)->DeffunctionCount * sizeof(struct deffunctionStruct); if (space != 0) genlongfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->DeffunctionArray,space); space = DeffunctionBinaryData(theEnv)->ModuleCount * sizeof(struct deffunctionModule); if (space != 0) genlongfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->ModuleArray,space); #endif }
static void DeallocateDeftemplateBloadData( void *theEnv) { unsigned long space; space = DeftemplateBinaryData(theEnv)->NumberOfTemplateModules * sizeof(struct deftemplateModule); if (space != 0) genlongfree(theEnv,(void *) DeftemplateBinaryData(theEnv)->ModuleArray,space); space = DeftemplateBinaryData(theEnv)->NumberOfDeftemplates * sizeof(struct deftemplate); if (space != 0) genlongfree(theEnv,(void *) DeftemplateBinaryData(theEnv)->DeftemplateArray,space); space = DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots * sizeof(struct templateSlot); if (space != 0) genlongfree(theEnv,(void *) DeftemplateBinaryData(theEnv)->SlotArray,space); }
/*************************************************************** NAME : ClearBloadGenerics DESCRIPTION : Release all binary-loaded generic function structure arrays Resets generic function list to NULL INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Memory cleared NOTES : Generic function name symbol counts decremented ***************************************************************/ static void ClearBloadGenerics( void *theEnv) { register long i; unsigned long space; space = (unsigned long) (sizeof(DEFGENERIC_MODULE) * DefgenericBinaryData(theEnv)->ModuleCount); if (space == 0L) return; genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->ModuleArray,space); DefgenericBinaryData(theEnv)->ModuleArray = NULL; DefgenericBinaryData(theEnv)->ModuleCount = 0L; for (i = 0 ; i < DefgenericBinaryData(theEnv)->GenericCount ; i++) UnmarkConstructHeader(theEnv,&DefgenericBinaryData(theEnv)->DefgenericArray[i].header); space = (unsigned long) (sizeof(DEFGENERIC) * DefgenericBinaryData(theEnv)->GenericCount); if (space == 0L) return; genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->DefgenericArray,space); DefgenericBinaryData(theEnv)->DefgenericArray = NULL; DefgenericBinaryData(theEnv)->GenericCount = 0L; space = (unsigned long) (sizeof(DEFMETHOD) * DefgenericBinaryData(theEnv)->MethodCount); if (space == 0L) return; genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->MethodArray,space); DefgenericBinaryData(theEnv)->MethodArray = NULL; DefgenericBinaryData(theEnv)->MethodCount = 0L; space = (unsigned long) (sizeof(RESTRICTION) * DefgenericBinaryData(theEnv)->RestrictionCount); if (space == 0L) return; genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->RestrictionArray,space); DefgenericBinaryData(theEnv)->RestrictionArray = NULL; DefgenericBinaryData(theEnv)->RestrictionCount = 0L; #if ! OBJECT_SYSTEM for (i = 0 ; i < DefgenericBinaryData(theEnv)->TypeCount ; i++) DecrementIntegerCount(theEnv,(INTEGER_HN *) DefgenericBinaryData(theEnv)->TypeArray[i]); #endif space = (unsigned long) (sizeof(void *) * DefgenericBinaryData(theEnv)->TypeCount); if (space == 0L) return; genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->TypeArray,space); DefgenericBinaryData(theEnv)->TypeArray = NULL; DefgenericBinaryData(theEnv)->TypeCount = 0L; }
globle void ReturnAllBlocks( void *theEnv) { struct blockInfo *theBlock, *nextBlock; struct longMemoryPtr *theLongMemory, *nextLongMemory; /*======================================*/ /* Free up int based memory allocation. */ /*======================================*/ theBlock = MemoryData(theEnv)->TopMemoryBlock; while (theBlock != NULL) { nextBlock = theBlock->nextBlock; free((char *) theBlock); theBlock = nextBlock; } MemoryData(theEnv)->TopMemoryBlock = NULL; /*=======================================*/ /* Free up long based memory allocation. */ /*=======================================*/ theLongMemory = MemoryData(theEnv)->TopLongMemoryPtr; while (theLongMemory != NULL) { nextLongMemory = theLongMemory->next; genlongfree(theEnv,theLongMemory,(unsigned long) theLongMemory->size); theLongMemory = nextLongMemory; } MemoryData(theEnv)->TopLongMemoryPtr = NULL; }
/*************************************************************** NAME : ClearBloadGenerics DESCRIPTION : Release all binary-loaded generic function structure arrays Resets generic function list to NULL INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Memory cleared NOTES : Generic function name symbol counts decremented ***************************************************************/ static void ClearBloadGenerics() { register long i; unsigned long space; space = (unsigned long) (sizeof(DEFGENERIC_MODULE) * ModuleCount); if (space == 0L) return; genlongfree((void *) ModuleArray,space); ModuleArray = NULL; ModuleCount = 0L; for (i = 0 ; i < GenericCount ; i++) UnmarkConstructHeader(&defgenericArray[i].header); space = (unsigned long) (sizeof(DEFGENERIC) * GenericCount); if (space == 0L) return; genlongfree((void *) defgenericArray,space); defgenericArray = NULL; GenericCount = 0L; space = (unsigned long) (sizeof(DEFMETHOD) * MethodCount); if (space == 0L) return; genlongfree((void *) methodArray,space); methodArray = NULL; MethodCount = 0L; space = (unsigned long) (sizeof(RESTRICTION) * RestrictionCount); if (space == 0L) return; genlongfree((void *) restrictionArray,space); restrictionArray = NULL; RestrictionCount = 0L; #if ! OBJECT_SYSTEM for (i = 0 ; i < TypeCount ; i++) DecrementIntegerCount((INTEGER_HN *) typeArray[i]); #endif space = (unsigned long) (sizeof(void *) * TypeCount); if (space == 0L) return; genlongfree((void *) typeArray,space); typeArray = NULL; TypeCount = 0L; }
static void DeallocateObjectReteBinaryData( void *theEnv) { #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) unsigned long space; long i; for (i = 0; i < ObjectReteBinaryData(theEnv)->AlphaNodeCount; i++) { DestroyAlphaBetaMemory(theEnv,ObjectReteBinaryData(theEnv)->AlphaArray[i].header.alphaMemory); } space = ObjectReteBinaryData(theEnv)->AlphaNodeCount * sizeof(struct objectAlphaNode); if (space != 0) genlongfree(theEnv,(void *) ObjectReteBinaryData(theEnv)->AlphaArray,space); space = ObjectReteBinaryData(theEnv)->PatternNodeCount * sizeof(struct objectPatternNode); if (space != 0) genlongfree(theEnv,(void *) ObjectReteBinaryData(theEnv)->PatternArray,space); #endif }
globle void ClearBloadedConstraints( void *theEnv) { if (ConstraintData(theEnv)->NumberOfConstraints != 0) { genlongfree(theEnv,(void *) ConstraintData(theEnv)->ConstraintArray, (unsigned long) (sizeof(CONSTRAINT_RECORD) * ConstraintData(theEnv)->NumberOfConstraints)); ConstraintData(theEnv)->NumberOfConstraints = 0; } }
/*************************************************************** NAME : ClearDeffunctionBload DESCRIPTION : Release all binary-loaded deffunction structure arrays Resets deffunction list to NULL INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Memory cleared NOTES : Deffunction name symbol counts decremented ***************************************************************/ static void ClearDeffunctionBload() { register long i; unsigned long space; space = (unsigned long) (sizeof(DEFFUNCTION_MODULE) * ModuleCount); if (space == 0L) return; genlongfree((void *) ModuleArray,space); ModuleArray = NULL; ModuleCount = 0L; for (i = 0L ; i < DeffunctionCount ; i++) UnmarkConstructHeader(&deffunctionArray[i].header); space = (unsigned long) (sizeof(DEFFUNCTION) * DeffunctionCount); if (space == 0L) return; genlongfree((void *) deffunctionArray,space); deffunctionArray = NULL; DeffunctionCount = 0L; }
static void DeallocateDefruleBloadData( void *theEnv) { #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) unsigned long space; long i; struct defruleModule *theModuleItem; struct activation *theActivation, *tmpActivation; for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfJoins; i++) { DestroyAlphaBetaMemory(theEnv,DefruleBinaryData(theEnv)->JoinArray[i].beta); } for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfDefruleModules; i++) { theModuleItem = &DefruleBinaryData(theEnv)->ModuleArray[i]; theActivation = theModuleItem->agenda; while (theActivation != NULL) { tmpActivation = theActivation->next; if (theActivation->sortedBasis != NULL) { DestroyPartialMatch(theEnv,theActivation->sortedBasis); } rtn_struct(theEnv,activation,theActivation); theActivation = tmpActivation; } } space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->ModuleArray,space); space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->DefruleArray,space); space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->JoinArray,space); #endif }
static void DeallocateDefgenericBinaryData( void *theEnv) { #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) unsigned long space; space = DefgenericBinaryData(theEnv)->GenericCount * sizeof(struct defgeneric); if (space != 0) genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->DefgenericArray,space); space = DefgenericBinaryData(theEnv)->MethodCount * sizeof(struct method); if (space != 0) genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->MethodArray,space); space = DefgenericBinaryData(theEnv)->RestrictionCount * sizeof(struct restriction); if (space != 0) genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->RestrictionArray,space); space = DefgenericBinaryData(theEnv)->TypeCount * sizeof(void *); if (space != 0) genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->TypeArray,space); space = DefgenericBinaryData(theEnv)->ModuleCount * sizeof(struct defgenericModule); if (space != 0) genlongfree(theEnv,(void *) DefgenericBinaryData(theEnv)->ModuleArray,space); #endif }
/*************************************************************** NAME : ClearDeffunctionBload DESCRIPTION : Release all binary-loaded deffunction structure arrays Resets deffunction list to NULL INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Memory cleared NOTES : Deffunction name symbol counts decremented ***************************************************************/ static void ClearDeffunctionBload( void *theEnv) { register long i; unsigned long space; space = (unsigned long) (sizeof(DEFFUNCTION_MODULE) * DeffunctionBinaryData(theEnv)->ModuleCount); if (space == 0L) return; genlongfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->ModuleArray,space); DeffunctionBinaryData(theEnv)->ModuleArray = NULL; DeffunctionBinaryData(theEnv)->ModuleCount = 0L; for (i = 0L ; i < DeffunctionBinaryData(theEnv)->DeffunctionCount ; i++) UnmarkConstructHeader(theEnv,&DeffunctionBinaryData(theEnv)->DeffunctionArray[i].header); space = (unsigned long) (sizeof(DEFFUNCTION) * DeffunctionBinaryData(theEnv)->DeffunctionCount); if (space == 0L) return; genlongfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->DeffunctionArray,space); DeffunctionBinaryData(theEnv)->DeffunctionArray = NULL; DeffunctionBinaryData(theEnv)->DeffunctionCount = 0L; }
/************************************************************ NAME : BloadandRefresh DESCRIPTION : Loads and refreshes objects - will bload all objects at once, if possible, but will aslo work in increments if memory is restricted INPUTS : 1) the number of objects to bload and update 2) the size of one object 3) An update function which takes a bloaded object buffer and the index of the object to refresh as arguments RETURNS : Nothing useful SIDE EFFECTS : Objects bloaded and updated NOTES : Assumes binary file pointer is positioned for bloads of the objects ************************************************************/ globle void BloadandRefresh( void *theEnv, long objcnt, unsigned objsz, void (*objupdate)(void *,void *,long)) { register long i,bi; char *buf; long objsmaxread,objsread; unsigned long space; int (*oldOutOfMemoryFunction)(void *,unsigned long); if (objcnt == 0L) return; oldOutOfMemoryFunction = EnvSetOutOfMemoryFunction(theEnv,BloadOutOfMemoryFunction); objsmaxread = objcnt; do { space = objsmaxread * objsz; buf = (char *) genlongalloc(theEnv,space); if (buf == NULL) { if ((objsmaxread / 2) == 0) { if ((*oldOutOfMemoryFunction)(theEnv,space) == TRUE) { EnvSetOutOfMemoryFunction(theEnv,oldOutOfMemoryFunction); return; } } else objsmaxread /= 2; } } while (buf == NULL); EnvSetOutOfMemoryFunction(theEnv,oldOutOfMemoryFunction); i = 0L; do { objsread = (objsmaxread > (objcnt - i)) ? (objcnt - i) : objsmaxread; GenReadBinary(theEnv,(void *) buf,objsread * objsz); for (bi = 0L ; bi < objsread ; bi++ , i++) (*objupdate)(theEnv,buf + objsz * bi,i); } while (i < objcnt); genlongfree(theEnv,(void *) buf,space); }
globle int PrintNRouter( void *theEnv, char *logicalName, char *str, unsigned long length) { char *tempStr; int rv; tempStr = (char *) genlongalloc(theEnv,length+1); strncpy(tempStr,str,length); tempStr[length] = 0; rv = EnvPrintRouter(theEnv,logicalName,tempStr); genlongfree(theEnv,tempStr,length+1); return(rv); }
static void DeallocateExpressionData( void *theEnv) { #if ! RUN_TIME int i; EXPRESSION_HN *tmpPtr, *nextPtr; #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) if (! Bloaded(theEnv)) #endif { for (i = 0; i < EXPRESSION_HASH_SIZE; i++) { tmpPtr = ExpressionData(theEnv)->ExpressionHashTable[i]; while (tmpPtr != NULL) { nextPtr = tmpPtr->next; ReturnPackedExpression(theEnv,tmpPtr->exp); rtn_struct(theEnv,exprHashNode,tmpPtr); tmpPtr = nextPtr; } } } rm(theEnv,ExpressionData(theEnv)->ExpressionHashTable, (int) (sizeof(EXPRESSION_HN *) * EXPRESSION_HASH_SIZE)); #else #if MAC_MCW || IBM_MCW || MAC_XCD #pragma unused(theEnv) #endif #endif #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) if ((ExpressionData(theEnv)->NumberOfExpressions != 0) && Bloaded(theEnv)) { genlongfree(theEnv,(void *) ExpressionData(theEnv)->ExpressionArray, ExpressionData(theEnv)->NumberOfExpressions * sizeof(struct expr)); } #endif }
globle int rm3( void *theEnv, void *str, long size) { struct memoryPtr *memPtr; if (size == 0) { SystemError(theEnv,"MEMORY",1); EnvExitRouter(theEnv,EXIT_FAILURE); } if (size < sizeof(char *)) size = sizeof(char *); if (size >= MEM_TABLE_SIZE) return(genlongfree(theEnv,(void *) str,(unsigned long) size)); memPtr = (struct memoryPtr *) str; memPtr->next = MemoryData(theEnv)->MemoryTable[(int) size]; MemoryData(theEnv)->MemoryTable[(int) size] = memPtr; return(1); }
globle int EnvBload( void *theEnv, char *fileName) { long numberOfFunctions; unsigned long space; int error; char IDbuffer[20]; char constructBuffer[CONSTRUCT_HEADER_SIZE]; struct BinaryItem *biPtr; struct callFunctionItem *bfPtr; /*================*/ /* Open the file. */ /*================*/ if (GenOpenReadBinary(theEnv,"bload",fileName) == 0) return(FALSE); /*=====================================*/ /* Determine if this is a binary file. */ /*=====================================*/ GenReadBinary(theEnv,IDbuffer,(unsigned long) strlen(BloadData(theEnv)->BinaryPrefixID) + 1); if (strcmp(IDbuffer,BloadData(theEnv)->BinaryPrefixID) != 0) { PrintErrorID(theEnv,"BLOAD",2,FALSE); EnvPrintRouter(theEnv,WERROR,"File "); EnvPrintRouter(theEnv,WERROR,fileName); EnvPrintRouter(theEnv,WERROR," is not a binary construct file.\n"); GenCloseBinary(theEnv); return(FALSE); } /*=======================================*/ /* Determine if it's a binary file using */ /* a format from a different version. */ /*=======================================*/ GenReadBinary(theEnv,IDbuffer,(unsigned long) strlen(BloadData(theEnv)->BinaryVersionID) + 1); if (strcmp(IDbuffer,BloadData(theEnv)->BinaryVersionID) != 0) { PrintErrorID(theEnv,"BLOAD",3,FALSE); EnvPrintRouter(theEnv,WERROR,"File "); EnvPrintRouter(theEnv,WERROR,fileName); EnvPrintRouter(theEnv,WERROR," is an incompatible binary construct file.\n"); GenCloseBinary(theEnv); return(FALSE); } /*====================*/ /* Clear environment. */ /*====================*/ if (BloadData(theEnv)->BloadActive) { if (ClearBload(theEnv) == FALSE) { GenCloseBinary(theEnv); return(FALSE); } } /*=================================*/ /* Determine if the KB environment */ /* was successfully cleared. */ /*=================================*/ if (ClearReady(theEnv) == FALSE) { GenCloseBinary(theEnv); EnvPrintRouter(theEnv,WERROR,"The "); EnvPrintRouter(theEnv,WERROR,APPLICATION_NAME); EnvPrintRouter(theEnv,WERROR," environment could not be cleared.\n"); EnvPrintRouter(theEnv,WERROR,"Binary load cannot continue.\n"); return(FALSE); } /*==================================*/ /* Call the list of functions to be */ /* executed before a bload occurs. */ /*==================================*/ for (bfPtr = BloadData(theEnv)->BeforeBloadFunctions; bfPtr != NULL; bfPtr = bfPtr->next) { if (bfPtr->environmentAware) { (*bfPtr->func)(theEnv); } else { (* (void (*)(void)) bfPtr->func)(); } } /*====================================================*/ /* Read in the functions needed by this binary image. */ /*====================================================*/ BloadData(theEnv)->FunctionArray = ReadNeededFunctions(theEnv,&numberOfFunctions,&error); if (error) { GenCloseBinary(theEnv); AbortBload(theEnv); return(FALSE); } /*================================================*/ /* Read in the atoms needed by this binary image. */ /*================================================*/ ReadNeededAtomicValues(theEnv); /*===========================================*/ /* Determine the number of expressions to be */ /* read and allocate the appropriate space */ /*===========================================*/ AllocateExpressions(theEnv); /*==========================================================*/ /* Read in the memory requirements of the constructs stored */ /* in this binary image and allocate the necessary space */ /*==========================================================*/ for (GenReadBinary(theEnv,constructBuffer,(unsigned long) CONSTRUCT_HEADER_SIZE); strncmp(constructBuffer,BloadData(theEnv)->BinaryPrefixID,CONSTRUCT_HEADER_SIZE) != 0; GenReadBinary(theEnv,constructBuffer,(unsigned long) CONSTRUCT_HEADER_SIZE)) { intBool found; /*================================================*/ /* Search for the construct type in the list of */ /* binary items. If found, allocate the storage */ /* needed by the construct for this binary image. */ /*================================================*/ found = FALSE; for (biPtr = BsaveData(theEnv)->ListOfBinaryItems; biPtr != NULL; biPtr = biPtr->next) { if (strncmp(biPtr->name,constructBuffer,CONSTRUCT_HEADER_SIZE) == 0) { if (biPtr->bloadStorageFunction != NULL) { (*biPtr->bloadStorageFunction)(theEnv); found = TRUE; } break; } } /*==========================================*/ /* If the construct type wasn't found, skip */ /* the storage binary load information for */ /* this construct. */ /*==========================================*/ if (! found) { GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long)); GetSeekCurBinary(theEnv,(long) space); if (space != 0) { EnvPrintRouter(theEnv,WDIALOG,"\nSkipping "); EnvPrintRouter(theEnv,WDIALOG,constructBuffer); EnvPrintRouter(theEnv,WDIALOG," constructs because of unavailibility\n"); } } } /*======================================*/ /* Refresh the pointers in expressions. */ /*======================================*/ RefreshExpressions(theEnv); /*==========================*/ /* Read in the constraints. */ /*==========================*/ ReadNeededConstraints(theEnv); /*======================================================*/ /* Read in the constructs stored in this binary image. */ /*======================================================*/ for (GenReadBinary(theEnv,constructBuffer,(unsigned long) CONSTRUCT_HEADER_SIZE); strncmp(constructBuffer,BloadData(theEnv)->BinaryPrefixID,CONSTRUCT_HEADER_SIZE) != 0; GenReadBinary(theEnv,constructBuffer,(unsigned long) CONSTRUCT_HEADER_SIZE)) { intBool found; /*==================================================*/ /* Search for the function to load the construct */ /* into the previously allocated storage. If found, */ /* call the function to load the construct. */ /*==================================================*/ found = FALSE; for (biPtr = BsaveData(theEnv)->ListOfBinaryItems; biPtr != NULL; biPtr = biPtr->next) { if (strncmp(biPtr->name,constructBuffer,CONSTRUCT_HEADER_SIZE) == 0) { if (biPtr->bloadFunction != NULL) { (*biPtr->bloadFunction)(theEnv); found = TRUE; } break; } } /*==========================================*/ /* If the construct type wasn't found, skip */ /* the binary data for this construct. */ /*==========================================*/ if (! found) { GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long)); GetSeekCurBinary(theEnv,(long) space); } } /*=================*/ /* Close the file. */ /*=================*/ GenCloseBinary(theEnv); /*========================================*/ /* Free up temporary storage used for the */ /* function and atomic value information. */ /*========================================*/ if (BloadData(theEnv)->FunctionArray != NULL) { genlongfree(theEnv,(void *) BloadData(theEnv)->FunctionArray, (unsigned long) sizeof(struct FunctionDefinition *) * numberOfFunctions); } FreeAtomicValueStorage(theEnv); /*==================================*/ /* Call the list of functions to be */ /* executed after a bload occurs. */ /*==================================*/ for (bfPtr = BloadData(theEnv)->AfterBloadFunctions; bfPtr != NULL; bfPtr = bfPtr->next) { if (bfPtr->environmentAware) { (*bfPtr->func)(theEnv); } else { (* (void (*)(void)) bfPtr->func)(); } } /*=======================================*/ /* Add a clear function to remove binary */ /* load when a clear command is issued. */ /*=======================================*/ BloadData(theEnv)->BloadActive = TRUE; EnvAddClearFunction(theEnv,"bload",(void (*)(void *)) ClearBload,10000); /*=============================*/ /* Return TRUE to indicate the */ /* binary load was successful. */ /*=============================*/ return(TRUE); }
static void ClearBload() { unsigned long int space; long i; struct patternParser *theParser = NULL; struct patternEntity *theEntity = NULL; void *theModule; /*===========================================*/ /* Delete all known entities before removing */ /* the defrule data structures. */ /*===========================================*/ GetNextPatternEntity(&theParser,&theEntity); while (theEntity != NULL) { (*theEntity->theInfo->base.deleteFunction)(theEntity); theEntity = NULL; GetNextPatternEntity(&theParser,&theEntity); } /*=========================================*/ /* Remove all activations from the agenda. */ /*=========================================*/ SaveCurrentModule(); for (theModule = GetNextDefmodule(NULL); theModule != NULL; theModule = GetNextDefmodule(theModule)) { SetCurrentModule(theModule); RemoveAllActivations(); } RestoreCurrentModule(); ClearFocusStack(); /*==========================================================*/ /* Remove all partial matches from the beta memories in the */ /* join network. Alpha memories do not need to be examined */ /* since all pattern entities have been deleted by now. */ /*==========================================================*/ for (i = 0; i < NumberOfJoins; i++) { FlushAlphaBetaMemory(JoinArray[i].beta); } /*================================================*/ /* Decrement the symbol count for each rule name. */ /*================================================*/ for (i = 0; i < NumberOfDefrules; i++) { UnmarkConstructHeader(&DefruleArray[i].header); } /*==================================================*/ /* Return the space allocated for the bload arrays. */ /*==================================================*/ space = NumberOfDefruleModules * sizeof(struct defruleModule); if (space != 0) genlongfree((void *) ModuleArray,space); space = NumberOfDefrules * sizeof(struct defrule); if (space != 0) genlongfree((void *) DefruleArray,space); #if FUZZY_DEFTEMPLATES space = NumberOfPatternFuzzyValues * sizeof(struct fzSlotLocator); if (space != 0) genlongfree((void *) PatternFuzzyValueArray,space); #endif space = NumberOfJoins * sizeof(struct joinNode); if (space != 0) genlongfree((void *) JoinArray,space); }
/*************************************************************** NAME : ClearBloadObjects DESCRIPTION : Release all binary-loaded class and handler structure arrays (and others) INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Memory cleared NOTES : None ***************************************************************/ static void ClearBloadObjects() { register long i; UNLN space; space = (unsigned long) (sizeof(DEFCLASS_MODULE) * ModuleCount); if (space == 0L) return; genlongfree((void *) ModuleArray,space); ModuleArray = NULL; ModuleCount = 0L; if (ClassCount != 0L) { rm((void *) ClassIDMap,(int) (sizeof(DEFCLASS *) * MaxClassID)); ClassIDMap = NULL; MaxClassID = 0; for (i = 0L ; i < ClassCount ; i++) { UnmarkConstructHeader(&defclassArray[i].header); #if DEFMODULE_CONSTRUCT DecrementBitMapCount(defclassArray[i].scopeMap); #endif RemoveClassFromTable((DEFCLASS *) &defclassArray[i]); } for (i = 0L ; i < SlotCount ; i++) { DecrementSymbolCount(slotArray[i].overrideMessage); if ((slotArray[i].defaultValue != NULL) && (slotArray[i].dynamicDefault == 0)) { ValueDeinstall((DATA_OBJECT *) slotArray[i].defaultValue); rtn_struct(dataObject,slotArray[i].defaultValue); } } for (i = 0L ; i < SlotNameCount ; i++) { SlotNameTable[slotNameArray[i].hashTableIndex] = NULL; DecrementSymbolCount(slotNameArray[i].name); DecrementSymbolCount(slotNameArray[i].putHandlerName); } space = (UNLN) (sizeof(DEFCLASS) * ClassCount); if (space != 0L) { genlongfree((void *) defclassArray,space); defclassArray = NULL; ClassCount = 0L; } space = (UNLN) (sizeof(DEFCLASS *) * LinkCount); if (space != 0L) { genlongfree((void *) linkArray,space); linkArray = NULL; LinkCount = 0L; } space = (UNLN) (sizeof(SLOT_DESC) * SlotCount); if (space != 0L) { genlongfree((void *) slotArray,space); slotArray = NULL; SlotCount = 0L; } space = (UNLN) (sizeof(SLOT_NAME) * SlotNameCount); if (space != 0L) { genlongfree((void *) slotNameArray,space); slotNameArray = NULL; SlotNameCount = 0L; } space = (UNLN) (sizeof(SLOT_DESC *) * TemplateSlotCount); if (space != 0L) { genlongfree((void *) tmpslotArray,space); tmpslotArray = NULL; TemplateSlotCount = 0L; } space = (UNLN) (sizeof(unsigned) * SlotNameMapCount); if (space != 0L) { genlongfree((void *) mapslotArray,space); mapslotArray = NULL; SlotNameMapCount = 0L; } } if (HandlerCount != 0L) { for (i = 0L ; i < HandlerCount ; i++) DecrementSymbolCount(handlerArray[i].name); space = (UNLN) (sizeof(HANDLER) * HandlerCount); if (space != 0L) { genlongfree((void *) handlerArray,space); handlerArray = NULL; space = (UNLN) (sizeof(unsigned) * HandlerCount); genlongfree((void *) maphandlerArray,space); maphandlerArray = NULL; HandlerCount = 0L; } } }
static void DeallocateDefmoduleData( void *theEnv) { struct moduleStackItem *tmpMSPtr, *nextMSPtr; struct moduleItem *tmpMIPtr, *nextMIPtr; #if (! RUN_TIME) struct defmodule *tmpDMPtr, *nextDMPtr; struct portConstructItem *tmpPCPtr, *nextPCPtr; #endif #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) int i; unsigned long space; #endif #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) for (i = 0; i < DefmoduleData(theEnv)->BNumberOfDefmodules; i++) { if (DefmoduleData(theEnv)->DefmoduleArray[i].itemsArray != NULL) { rm(theEnv,DefmoduleData(theEnv)->DefmoduleArray[i].itemsArray, sizeof(void *) * GetNumberOfModuleItems(theEnv)); } } space = DefmoduleData(theEnv)->BNumberOfDefmodules * sizeof(struct defmodule); if (space != 0) { genlongfree(theEnv,(void *) DefmoduleData(theEnv)->DefmoduleArray,space); DefmoduleData(theEnv)->ListOfDefmodules = NULL; } space = DefmoduleData(theEnv)->NumberOfPortItems * sizeof(struct portItem); if (space != 0) genlongfree(theEnv,(void *) DefmoduleData(theEnv)->PortItemArray,space); #endif #if (! RUN_TIME) && (! BLOAD_ONLY) tmpDMPtr = DefmoduleData(theEnv)->ListOfDefmodules; while (tmpDMPtr != NULL) { nextDMPtr = tmpDMPtr->next; ReturnDefmodule(theEnv,tmpDMPtr,TRUE); tmpDMPtr = nextDMPtr; } tmpPCPtr = DefmoduleData(theEnv)->ListOfPortConstructItems; while (tmpPCPtr != NULL) { nextPCPtr = tmpPCPtr->next; rtn_struct(theEnv,portConstructItem,tmpPCPtr); tmpPCPtr = nextPCPtr; } #endif tmpMSPtr = DefmoduleData(theEnv)->ModuleStack; while (tmpMSPtr != NULL) { nextMSPtr = tmpMSPtr->next; rtn_struct(theEnv,moduleStackItem,tmpMSPtr); tmpMSPtr = nextMSPtr; } tmpMIPtr = DefmoduleData(theEnv)->ListOfModuleItems; while (tmpMIPtr != NULL) { nextMIPtr = tmpMIPtr->next; rtn_struct(theEnv,moduleItem,tmpMIPtr); tmpMIPtr = nextMIPtr; } #if (! RUN_TIME) && (! BLOAD_ONLY) DeallocateCallList(theEnv,DefmoduleData(theEnv)->AfterModuleDefinedFunctions); #endif DeallocateCallList(theEnv,DefmoduleData(theEnv)->AfterModuleChangeFunctions); }
static void ClearBload( void *theEnv) { unsigned long int space; long i; struct patternParser *theParser = NULL; struct patternEntity *theEntity = NULL; void *theModule; /*===========================================*/ /* Delete all known entities before removing */ /* the defrule data structures. */ /*===========================================*/ GetNextPatternEntity(theEnv,&theParser,&theEntity); while (theEntity != NULL) { (*theEntity->theInfo->base.deleteFunction)(theEnv,theEntity); theEntity = NULL; GetNextPatternEntity(theEnv,&theParser,&theEntity); } /*=========================================*/ /* Remove all activations from the agenda. */ /*=========================================*/ SaveCurrentModule(theEnv); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,theModule); RemoveAllActivations(theEnv); } RestoreCurrentModule(theEnv); EnvClearFocusStack(theEnv); /*==========================================================*/ /* Remove all partial matches from the beta memories in the */ /* join network. Alpha memories do not need to be examined */ /* since all pattern entities have been deleted by now. */ /*==========================================================*/ for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfJoins; i++) { FlushAlphaBetaMemory(theEnv,DefruleBinaryData(theEnv)->JoinArray[i].beta); } /*================================================*/ /* Decrement the symbol count for each rule name. */ /*================================================*/ for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfDefrules; i++) { UnmarkConstructHeader(theEnv,&DefruleBinaryData(theEnv)->DefruleArray[i].header); } /*==================================================*/ /* Return the space allocated for the bload arrays. */ /*==================================================*/ space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->ModuleArray,space); DefruleBinaryData(theEnv)->NumberOfDefruleModules = 0; space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->DefruleArray,space); DefruleBinaryData(theEnv)->NumberOfDefrules = 0; space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode); if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->JoinArray,space); DefruleBinaryData(theEnv)->NumberOfJoins = 0; }