asCObjectType::~asCObjectType() { // Release the object type held by the templateSubType if( templateSubType.GetObjectType() ) templateSubType.GetObjectType()->Release(); if( derivedFrom ) derivedFrom->Release(); asUINT n; for( n = 0; n < properties.GetLength(); n++ ) if( properties[n] ) { if( flags & asOBJ_SCRIPT_OBJECT ) { // Release the config group for script classes that are being destroyed asCConfigGroup *group = engine->FindConfigGroupForObjectType(properties[n]->type.GetObjectType()); if( group != 0 ) group->Release(); } asDELETE(properties[n],asCObjectProperty); } properties.SetLength(0); methods.SetLength(0); for( n = 0; n < enumValues.GetLength(); n++ ) { if( enumValues[n] ) asDELETE(enumValues[n],asSEnumValue); } enumValues.SetLength(0); }
// internal void asCScriptFunction::DestroyInternal() { // Clean up user data if( userData && engine->cleanFunctionFunc ) engine->cleanFunctionFunc(this); userData = 0; // Release all references the function holds to other objects ReleaseReferences(); parameterTypes.SetLength(0); returnType = asCDataType::CreatePrimitive(ttVoid, false); byteCode.SetLength(0); for( asUINT n = 0; n < variables.GetLength(); n++ ) asDELETE(variables[n],asSScriptVariable); variables.SetLength(0); for( asUINT p = 0; p < defaultArgs.GetLength(); p++ ) if( defaultArgs[p] ) asDELETE(defaultArgs[p], asCString); defaultArgs.SetLength(0); if( sysFuncIntf ) asDELETE(sysFuncIntf,asSSystemFunctionInterface); sysFuncIntf = 0; }
// internal asCScriptFunction::~asCScriptFunction() { // Clean user data if( userData && engine->cleanFunctionFunc ) engine->cleanFunctionFunc(this); // Imported functions are not reference counted, nor are dummy // functions that are allocated on the stack asASSERT( funcType == asFUNC_DUMMY || funcType == asFUNC_IMPORTED || refCount.get() == 0 ); ReleaseReferences(); // Tell engine to free the function id if( funcType != -1 && funcType != asFUNC_IMPORTED && id ) engine->FreeScriptFunctionId(id); for( asUINT n = 0; n < variables.GetLength(); n++ ) { asDELETE(variables[n],asSScriptVariable); } if( sysFuncIntf ) { asDELETE(sysFuncIntf,asSSystemFunctionInterface); } for( asUINT p = 0; p < defaultArgs.GetLength(); p++ ) { if( defaultArgs[p] ) asDELETE(defaultArgs[p], asCString); } }
// internal void asCScriptFunction::DestroyInternal() { // Clean up user data if( userData && engine->cleanFunctionFunc ) engine->cleanFunctionFunc(this); userData = 0; // Release all references the function holds to other objects ReleaseReferences(); parameterTypes.SetLength(0); returnType = asCDataType::CreatePrimitive(ttVoid, false); for( asUINT p = 0; p < defaultArgs.GetLength(); p++ ) if( defaultArgs[p] ) asDELETE(defaultArgs[p], asCString); defaultArgs.SetLength(0); if( sysFuncIntf ) asDELETE(sysFuncIntf,asSSystemFunctionInterface); sysFuncIntf = 0; DeallocateScriptFunctionData(); // Deallocate list pattern data while( listPattern ) { asSListPatternNode *n = listPattern->next; asDELETE(listPattern, asSListPatternNode); listPattern = n; } }
void asCScriptFunction::DeallocateScriptFunctionData() { if( !scriptData ) return; for( asUINT n = 0; n < scriptData->variables.GetLength(); n++ ) asDELETE(scriptData->variables[n],asSScriptVariable); scriptData->variables.SetLength(0); asDELETE(scriptData, ScriptFunctionData); scriptData = 0; }
// internal void asCModule::InternalReset() { CallExit(); size_t n; // Release all global functions for( n = 0; n < globalFunctions.GetLength(); n++ ) { if( globalFunctions[n] ) globalFunctions[n]->Release(); } globalFunctions.SetLength(0); // First release all compiled functions for( n = 0; n < scriptFunctions.GetLength(); n++ ) { if( scriptFunctions[n] ) { // Remove the module reference in the functions scriptFunctions[n]->module = 0; scriptFunctions[n]->Release(); } } scriptFunctions.SetLength(0); // Release the global properties declared in the module for( n = 0; n < scriptGlobals.GetLength(); n++ ) scriptGlobals[n]->Release(); scriptGlobals.SetLength(0); UnbindAllImportedFunctions(); // Free bind information for( n = 0; n < bindInformations.GetLength(); n++ ) { engine->importedFunctions[bindInformations[n]->importedFunctionSignature->id & 0xFFFF] = 0 ; asDELETE(bindInformations[n]->importedFunctionSignature, asCScriptFunction); asDELETE(bindInformations[n], sBindInfo); } bindInformations.SetLength(0); // Free declared types, including classes, typedefs, and enums for( n = 0; n < classTypes.GetLength(); n++ ) classTypes[n]->Release(); classTypes.SetLength(0); for( n = 0; n < enumTypes.GetLength(); n++ ) enumTypes[n]->Release(); enumTypes.SetLength(0); for( n = 0; n < typeDefs.GetLength(); n++ ) typeDefs[n]->Release(); typeDefs.SetLength(0); }
int asCThreadManager::CleanupLocalData() { if( threadManager == 0 ) return 0; #ifndef AS_NO_THREADS #if defined AS_POSIX_THREADS asCThreadLocalData *tld = (asCThreadLocalData*)pthread_getspecific((pthread_key_t)threadManager->tlsKey); #elif defined AS_WINDOWS_THREADS #if !defined(_MSC_VER) || !(WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) asCThreadLocalData *tld = (asCThreadLocalData*)TlsGetValue((DWORD)threadManager->tlsKey); #endif #endif if( tld == 0 ) return 0; if( tld->activeContexts.GetLength() == 0 ) { asDELETE(tld,asCThreadLocalData); #if defined AS_POSIX_THREADS pthread_setspecific((pthread_key_t)threadManager->tlsKey, 0); #elif defined AS_WINDOWS_THREADS #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) tld = 0; #else TlsSetValue((DWORD)threadManager->tlsKey, 0); #endif #endif return 0; } else return asCONTEXT_ACTIVE; #else if( threadManager->tld ) { if( threadManager->tld->activeContexts.GetLength() == 0 ) { asDELETE(threadManager->tld,asCThreadLocalData); threadManager->tld = 0; } else return asCONTEXT_ACTIVE; } return 0; #endif }
int asCThreadManager::CleanupLocalData() { if( threadManager == 0 ) return 0; #ifndef AS_NO_THREADS int r = 0; #if defined AS_POSIX_THREADS asPWORD id = (asPWORD)pthread_self(); #elif defined AS_WINDOWS_THREADS asPWORD id = (asPWORD)GetCurrentThreadId(); #endif ENTERCRITICALSECTION(threadManager->criticalSection); asSMapNode<asPWORD,asCThreadLocalData*> *cursor = 0; if( threadManager->tldMap.MoveTo(&cursor, id) ) { asCThreadLocalData *tld = threadManager->tldMap.GetValue(cursor); // Can we really remove it at this time? if( tld->activeContexts.GetLength() == 0 ) { asDELETE(tld,asCThreadLocalData); threadManager->tldMap.Erase(cursor); r = 0; } else r = asCONTEXT_ACTIVE; } LEAVECRITICALSECTION(threadManager->criticalSection); return r; #else if( threadManager->tld ) { if( threadManager->tld->activeContexts.GetLength() == 0 ) { asDELETE(threadManager->tld,asCThreadLocalData); threadManager->tld = 0; } else return asCONTEXT_ACTIVE; } return 0; #endif }
int asCLockableSharedBool::Release() const { int r = refCount.atomicDec(); if( r == 0 ) asDELETE(const_cast<asCLockableSharedBool*>(this), asCLockableSharedBool); return r; }
// interface int asCModule::Build() { asASSERT( contextCount.get() == 0 ); // Only one thread may build at one time int r = engine->RequestBuild(); if( r < 0 ) return r; engine->PrepareEngine(); if( engine->configFailed ) { engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_INVALID_CONFIGURATION); engine->BuildCompleted(); return asINVALID_CONFIGURATION; } InternalReset(); if( !builder ) { engine->BuildCompleted(); return asSUCCESS; } // Store the section names for( size_t n = 0; n < builder->scripts.GetLength(); n++ ) { asCString *sectionName = asNEW(asCString)(builder->scripts[n]->name); scriptSections.PushLast(sectionName); } // Compile the script r = builder->Build(); asDELETE(builder,asCBuilder); builder = 0; if( r < 0 ) { // Reset module again InternalReset(); isBuildWithoutErrors = false; engine->BuildCompleted(); return r; } isBuildWithoutErrors = true; JITCompile(); engine->PrepareEngine(); engine->BuildCompleted(); // Initialize global variables if( r >= 0 && engine->ep.initGlobalVarsAfterBuild ) r = ResetGlobalVars(); return r; }
void asCThreadManager::Unprepare() { asASSERT(threadManager); if( threadManager == 0 ) return; // It's necessary to protect this section so no // other thread attempts to call AddRef or Release // while clean up is in progress. ENTERCRITICALSECTION(threadManager->criticalSection); if( --threadManager->refCount == 0 ) { // Make sure the local data is destroyed, at least for the current thread CleanupLocalData(); // As the critical section will be destroyed together // with the thread manager we must first clear the global // variable in case a new thread manager needs to be created; asCThreadManager *mgr = threadManager; threadManager = 0; // Leave the critical section before it is destroyed LEAVECRITICALSECTION(mgr->criticalSection); asDELETE(mgr,asCThreadManager); } else LEAVECRITICALSECTION(threadManager->criticalSection); }
asCObjectType::~asCObjectType() { // Release the object type held by the templateSubType if( templateSubType.GetObjectType() ) templateSubType.GetObjectType()->Release(); if( derivedFrom ) derivedFrom->Release(); asUINT n; ReleaseAllProperties(); ReleaseAllFunctions(); for( n = 0; n < enumValues.GetLength(); n++ ) { if( enumValues[n] ) asDELETE(enumValues[n],asSEnumValue); } enumValues.SetLength(0); // Clean the user data for( n = 0; n < userData.GetLength(); n += 2 ) { if( userData[n+1] ) { for( asUINT c = 0; c < engine->cleanObjectTypeFuncs.GetLength(); c++ ) if( engine->cleanObjectTypeFuncs[c].type == userData[n] ) engine->cleanObjectTypeFuncs[c].cleanFunc(this); } } }
// internal void asCObjectType::ReleaseAllProperties() { for( asUINT n = 0; n < properties.GetLength(); n++ ) { if( properties[n] ) { if( flags & asOBJ_SCRIPT_OBJECT ) { // Release the config group for script classes that are being destroyed asCConfigGroup *group = engine->FindConfigGroupForObjectType(properties[n]->type.GetObjectType()); if( group != 0 ) group->Release(); // Release references to objects types asCObjectType *type = properties[n]->type.GetObjectType(); if( type ) type->Release(); } else { // Release template instance types (ref increased by RegisterObjectProperty) asCObjectType *type = properties[n]->type.GetObjectType(); if( type ) type->Release(); } asDELETE(properties[n],asCObjectProperty); } } properties.SetLength(0); }
void asCObjectType::DropFromEngine() { DestroyInternal(); // If the ref counter reached zero while doing the above clean-up then we must delete the object now if( refCount.get() == 0 ) asDELETE(this, asCObjectType); }
asCObjectType::~asCObjectType() { // Release the object type held by the templateSubType if( templateSubType.GetObjectType() ) templateSubType.GetObjectType()->Release(); if( derivedFrom ) derivedFrom->Release(); asUINT n; for( n = 0; n < properties.GetLength(); n++ ) if( properties[n] ) { if( flags & asOBJ_SCRIPT_OBJECT ) { // Release the config group for script classes that are being destroyed asCConfigGroup *group = engine->FindConfigGroupForObjectType(properties[n]->type.GetObjectType()); if( group != 0 ) group->Release(); } asDELETE(properties[n],asCObjectProperty); } properties.SetLength(0); ReleaseAllFunctions(); for( n = 0; n < enumValues.GetLength(); n++ ) { if( enumValues[n] ) asDELETE(enumValues[n],asSEnumValue); } enumValues.SetLength(0); // Clean the user data for( n = 0; n < userData.GetLength(); n += 2 ) { if( userData[n+1] ) { for( asUINT c = 0; c < engine->cleanObjectTypeFuncs.GetLength(); c++ ) if( engine->cleanObjectTypeFuncs[c].type == userData[n] ) engine->cleanObjectTypeFuncs[c].cleanFunc(this); } } }
asCGarbageCollector::~asCGarbageCollector() { // This local typedef is done to workaround a compiler error on // MSVC6 when using the typedef declared in the class definition typedef asSMapNode_t node_t; for( asUINT n = 0; n < freeNodes.GetLength(); n++ ) asDELETE(freeNodes[n], node_t); freeNodes.SetLength(0); }
// internal void asCScriptFunction::DestroyInternal() { // Clean up user data for( asUINT n = 0; n < userData.GetLength(); n += 2 ) { if( userData[n+1] ) { for( asUINT c = 0; c < engine->cleanFunctionFuncs.GetLength(); c++ ) if( engine->cleanFunctionFuncs[c].type == userData[n] ) engine->cleanFunctionFuncs[c].cleanFunc(this); } } userData.SetLength(0); // Release all references the function holds to other objects ReleaseReferences(); parameterTypes.SetLength(0); returnType = asCDataType::CreatePrimitive(ttVoid, false); for( asUINT p = 0; p < defaultArgs.GetLength(); p++ ) if( defaultArgs[p] ) asDELETE(defaultArgs[p], asCString); defaultArgs.SetLength(0); if( sysFuncIntf ) asDELETE(sysFuncIntf,asSSystemFunctionInterface); sysFuncIntf = 0; if( objectType ) { objectType->ReleaseInternal(); objectType = 0; } DeallocateScriptFunctionData(); // Deallocate list pattern data while( listPattern ) { asSListPatternNode *n = listPattern->next; asDELETE(listPattern, asSListPatternNode); listPattern = n; } }
asCEnumType::~asCEnumType() { asUINT n; for (n = 0; n < enumValues.GetLength(); n++) { if (enumValues[n]) asDELETE(enumValues[n], asSEnumValue); } enumValues.SetLength(0); }
// interface int asCScriptFunction::Release() const { gcFlag = false; asASSERT( funcType != asFUNC_IMPORTED ); int r = refCount.atomicDec(); if( r == 0 && funcType != -1 ) // Dummy functions are allocated on the stack and cannot be deleted asDELETE(const_cast<asCScriptFunction*>(this),asCScriptFunction); return r; }
void asCObjectType::DestroyInternal() { if( engine == 0 ) return; // Skip this for list patterns as they do not increase the references if( flags & asOBJ_LIST_PATTERN ) { // Clear the engine pointer to mark the object type as invalid engine = 0; return; } // Release the object types held by the templateSubTypes for( asUINT subtypeIndex = 0; subtypeIndex < templateSubTypes.GetLength(); subtypeIndex++ ) { if( templateSubTypes[subtypeIndex].GetObjectType() ) templateSubTypes[subtypeIndex].GetObjectType()->ReleaseInternal(); } templateSubTypes.SetLength(0); if( derivedFrom ) derivedFrom->ReleaseInternal(); derivedFrom = 0; ReleaseAllProperties(); ReleaseAllFunctions(); asUINT n; for( n = 0; n < enumValues.GetLength(); n++ ) { if( enumValues[n] ) asDELETE(enumValues[n],asSEnumValue); } enumValues.SetLength(0); // Clean the user data for( n = 0; n < userData.GetLength(); n += 2 ) { if( userData[n+1] ) { for( asUINT c = 0; c < engine->cleanObjectTypeFuncs.GetLength(); c++ ) if( engine->cleanObjectTypeFuncs[c].type == userData[n] ) engine->cleanObjectTypeFuncs[c].cleanFunc(this); } } userData.SetLength(0); // Remove the type from the engine engine->RemoveFromTypeIdMap(this); // Clear the engine pointer to mark the object type as invalid engine = 0; }
void asCOutputBuffer::Clear() { for( asUINT n = 0; n < messages.GetLength(); n++ ) { if( messages[n] ) { asDELETE(messages[n],message_t); } } messages.SetLength(0); }
// interface int asCScriptFunction::Release() const { gcFlag = false; int r = refCount.atomicDec(); if( r == 0 && funcType != asFUNC_FUNCDEF && // Funcdefs are treated as object types and will be deleted by ClearUnusedTypes() funcType != asFUNC_DUMMY ) // Dummy functions are allocated on the stack and cannot be deleted asDELETE(const_cast<asCScriptFunction*>(this),asCScriptFunction); return r; }
void asCVariableScope::Reset() { isBreakScope = false; isContinueScope = false; for( asUINT n = 0; n < variables.GetLength(); n++ ) if( variables[n] ) { asDELETE(variables[n],sVariable); } variables.SetLength(0); }
asCThreadManager::~asCThreadManager() { #ifndef AS_NO_THREADS // Delete all thread local datas asSMapNode<asPWORD,asCThreadLocalData*> *cursor = 0; if( tldMap.MoveFirst(&cursor) ) { do { if( tldMap.GetValue(cursor) ) { asDELETE(tldMap.GetValue(cursor),asCThreadLocalData); } } while( tldMap.MoveNext(&cursor, cursor) ); } #else if( tld ) { asDELETE(tld,asCThreadLocalData); } tld = 0; #endif }
int asCObjectType::Release() const { gcFlag = false; int r = refCount.atomicDec(); if( r == 0 && engine == 0 ) { // If the engine is no longer set, then it has already been // released and we must take care of the deletion ourselves asDELETE(const_cast<asCObjectType*>(this), asCObjectType); } return r; }
// interface int asCModule::Build() { // Only one thread may build at one time // TODO: It should be possible to have multiple threads perform compilations int r = engine->RequestBuild(); if( r < 0 ) return r; engine->PrepareEngine(); if( engine->configFailed ) { engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_INVALID_CONFIGURATION); engine->BuildCompleted(); return asINVALID_CONFIGURATION; } InternalReset(); if( !builder ) { engine->BuildCompleted(); return asSUCCESS; } // Compile the script r = builder->Build(); asDELETE(builder,asCBuilder); builder = 0; if( r < 0 ) { // Reset module again InternalReset(); engine->BuildCompleted(); return r; } JITCompile(); engine->PrepareEngine(); engine->BuildCompleted(); // Initialize global variables if( r >= 0 && engine->ep.initGlobalVarsAfterBuild ) r = ResetGlobalVars(); return r; }
// internal void asCScriptFunction::DestroyHalfCreated() { asASSERT( externalRefCount.get() == 0 && internalRefCount.get() == 1 ); // Set the funcType to dummy so the destructor won't complain funcType = asFUNC_DUMMY; // If the bytecode exist remove it before destroying, otherwise it // will fail when the destructor releases the references as the bytecode // is not fully constructed. if( scriptData ) scriptData->byteCode.SetLength(0); asDELETE(this, asCScriptFunction); }
// internal int asCScriptFunction::ReleaseInternal() { int r = internalRefCount.atomicDec(); if( r == 0 && funcType != asFUNC_DUMMY ) { // There are no more internal references, if there are also no // external references then it is time to delete the function if( externalRefCount.get() == 0 ) { asDELETE(const_cast<asCScriptFunction*>(this),asCScriptFunction); } } return r; }
// interface int asCTypeInfo::Release() const { int r = externalRefCount.atomicDec(); if (r == 0) { // There are no more external references, if there are also no // internal references then it is time to delete the object type if (internalRefCount.get() == 0) { // If the engine is no longer set, then it has already been // released and we must take care of the deletion ourselves asDELETE(const_cast<asCTypeInfo*>(this), asCTypeInfo); } } return r; }
// internal asCModule::~asCModule() { InternalReset(); if( builder ) { asDELETE(builder,asCBuilder); builder = 0; } // Remove the module from the engine if( engine ) { if( engine->lastModule == this ) engine->lastModule = 0; engine->scriptModules.RemoveValue(this); } }