示例#1
0
// interface
int asCModule::ResetGlobalVars()
{
	if( isGlobalVarInitialized ) 
		CallExit();

	CallInit();

	return 0;
}
示例#2
0
// interface
int asCModule::ResetGlobalVars()
{
	if( isGlobalVarInitialized ) 
		CallExit();

	// TODO: The application really should do this manually through a context
	//       otherwise it cannot properly handle script exceptions that may be
	//       thrown by object initializations.
	return CallInit();
}
示例#3
0
int asCModule::ResetGlobalVars()
{
	if( !isGlobalVarInitialized ) return asERROR;

	CallExit();

	CallInit();

	return 0;
}
示例#4
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);
}
void
TestInterruptShutdownRaceParent::StartShuttingDown()
{
    // NB: we sleep here to try and avoid receiving the Orphan message
    // while waiting for the CallExit() reply.  if we fail at that, it
    // will cause the test to pass spuriously, because there won't be
    // an OnMaybeDequeueOne task for Orphan
    PR_Sleep(2000);

    if (CallExit())
        fail("connection was supposed to be interrupted");

    Close();

    delete static_cast<TestInterruptShutdownRaceParent*>(gParentActor);
    gParentActor = nullptr;

    XRE_GetIOMessageLoop()->PostTask(NewRunnableFunction(DeleteSubprocess));

    // this is ordered after the OnMaybeDequeueOne event in the queue
    MessageLoop::current()->PostTask(NewRunnableFunction(Done));

    // |this| has been deleted, be mindful
}
示例#6
0
void asCModule::Reset()
{
	assert( !IsUsed() );

	CallExit();

	initFunction.byteCode.SetLength(0);

	// Free global variables
	globalMem.SetLength(0);
	globalVarPointers.SetLength(0);

	isBuildWithoutErrors = true;
	isDiscarded = false;

	asUINT n;
	for( n = 0; n < scriptFunctions.GetLength(); n++ )
		delete scriptFunctions[n];
	scriptFunctions.SetLength(0);

	for( n = 0; n < importedFunctions.GetLength(); n++ )
		delete importedFunctions[n];
	importedFunctions.SetLength(0);

	// Release bound functions
	for( n = 0; n < bindInformations.GetLength(); n++ )
	{
		int oldFuncID = bindInformations[n].importedFunction;
		if( oldFuncID != -1 )
		{
			asCModule *oldModule = engine->GetModule(oldFuncID);
			if( oldModule != 0 ) 
			{
				// Release reference to the module
				oldModule->ReleaseModuleRef();
			}
		}
	}
	bindInformations.SetLength(0);

	for( n = 0; n < stringConstants.GetLength(); n++ )
		delete stringConstants[n];
	stringConstants.SetLength(0);

	for( n = 0; n < scriptGlobals.GetLength(); n++ )
		delete scriptGlobals[n];
	scriptGlobals.SetLength(0);

	for( n = 0; n < scriptSections.GetLength(); n++ )
		delete scriptSections[n];
	scriptSections.SetLength(0);

	for( n = 0; n < structTypes.GetLength(); n++ )
		structTypes[n]->refCount--;
	structTypes.SetLength(0);

	for( n = 0; n < scriptArrayTypes.GetLength(); n++ )
		scriptArrayTypes[n]->refCount--;
	scriptArrayTypes.SetLength(0);

	// Release all used object types
	for( n = 0; n < usedTypes.GetLength(); n++ )
		usedTypes[n]->refCount--;
	usedTypes.SetLength(0);

	// Release all config groups
	for( n = 0; n < configGroups.GetLength(); n++ )
		configGroups[n]->Release();
	configGroups.SetLength(0);
}
// internal
void asCModule::InternalReset()
{
	asASSERT( !IsUsed() );

	CallExit();

	size_t n;

	// TODO: This is incorrect. If there are still live objects, the methods shouldn't be destroyed yet.
	//       It should still be possible to discard the module, but the methods should only be destroyed
	//       when all objects have been destroyed. However, we can't just check if there are live objects
	//       when determining if functions can or cannot be destroyed, because then we could create situations
	//       of memory that is never freed, e.g. a global variable in the module, being referenced by one
	//       of it's own class methods. To fix this, we need a full garbage collector that can resolve 
	//       circular references. 

	// Since we're going to delete the script functions, we must 
	// not allow any straying objects call them afterwards. If this is not done
	// the object types' function id will either point to non-existing functions,
	// or possibly to new functions that re-use the old function id. Needless to
	// say, it could be disastrous if the function is called like this.
	for( n = 0; n < classTypes.GetLength(); n++ )
	{
		if( classTypes[n] == 0 ) continue;

		// Skip interfaces that the module doesn't own, as it's methods won't be deleted
		if( classTypes[n]->IsInterface() && classTypes[n]->GetRefCount() > 1 )
			continue;

		// Just set the function id's to 0
		classTypes[n]->beh.factory   = 0;
		classTypes[n]->beh.construct = 0;
		classTypes[n]->beh.destruct  = 0;
		classTypes[n]->beh.factories.SetLength(0);
		classTypes[n]->beh.constructors.SetLength(0);
		classTypes[n]->beh.operators.SetLength(0);
		classTypes[n]->methods.SetLength(0);
	}

	// First free the functions
	for( n = 0; n < scriptFunctions.GetLength(); n++ )
	{
		if( scriptFunctions[n] == 0 )
			continue;

		// Don't delete interface methods, if the module isn't the only owner of the interface
		if( scriptFunctions[n]->objectType && scriptFunctions[n]->objectType->IsInterface() && scriptFunctions[n]->objectType->GetRefCount() > 1 )
			continue;

		engine->DeleteScriptFunction(scriptFunctions[n]->id);
	}
	scriptFunctions.SetLength(0);
	globalFunctions.SetLength(0);

	if( initFunction )
	{
		engine->DeleteScriptFunction(initFunction->id);
		initFunction = 0;
	}

	// Release bound functions
	for( n = 0; n < bindInformations.GetLength(); n++ )
	{
		int oldFuncID = bindInformations[n].importedFunction;
		if( oldFuncID != -1 )
		{
			asCModule *oldModule = engine->GetModuleFromFuncId(oldFuncID);
			if( oldModule != 0 ) 
			{
				// Release reference to the module
				oldModule->ReleaseModuleRef();
			}
		}
	}
	bindInformations.SetLength(0);

	for( n = 0; n < importedFunctions.GetLength(); n++ )
	{
		asDELETE(importedFunctions[n],asCScriptFunction);
	}
	importedFunctions.SetLength(0);

	// Free global variables
	// TODO: global: Release references
	globalVarPointers.SetLength(0);

	isBuildWithoutErrors = true;
	isDiscarded = false;

	for( n = 0; n < stringConstants.GetLength(); n++ )
	{
		asDELETE(stringConstants[n],asCString);
	}
	stringConstants.SetLength(0);

	// Release the global properties declared in the module
	for( n = 0; n < scriptGlobals.GetLength(); n++ )
	{
		engine->ReleaseGlobalProperty(scriptGlobals[n]);
	}
	scriptGlobals.SetLength(0);

	for( n = 0; n < scriptSections.GetLength(); n++ )
	{
		asDELETE(scriptSections[n],asCString);
	}
	scriptSections.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);
}
示例#8
0
void asCModule::Reset()
{
	assert( !IsUsed() );

	CallExit();

	// First free the functions
	size_t n;
	for( n = 0; n < scriptFunctions.GetLength(); n++ )
		engine->DeleteScriptFunction(scriptFunctions[n]->id);
	scriptFunctions.SetLength(0);

	if( initFunction )
	{
		engine->DeleteScriptFunction(initFunction->id);
		initFunction = 0;
	}

	// Release bound functions
	for( n = 0; n < bindInformations.GetLength(); n++ )
	{
		int oldFuncID = bindInformations[n].importedFunction;
		if( oldFuncID != -1 )
		{
			asCModule *oldModule = engine->GetModuleFromFuncId(oldFuncID);
			if( oldModule != 0 ) 
			{
				// Release reference to the module
				oldModule->ReleaseModuleRef();
			}
		}
	}
	bindInformations.SetLength(0);

	for( n = 0; n < importedFunctions.GetLength(); n++ )
	{
		DELETE(importedFunctions[n],asCScriptFunction);
	}
	importedFunctions.SetLength(0);

	// Free global variables
	globalMem.SetLength(0);
	globalVarPointers.SetLength(0);

	isBuildWithoutErrors = true;
	isDiscarded = false;

	for( n = 0; n < stringConstants.GetLength(); n++ )
	{
		DELETE(stringConstants[n],asCString);
	}
	stringConstants.SetLength(0);

	for( n = 0; n < scriptGlobals.GetLength(); n++ )
	{
		DELETE(scriptGlobals[n],asCProperty);
	}
	scriptGlobals.SetLength(0);

	for( n = 0; n < scriptSections.GetLength(); n++ )
	{
		DELETE(scriptSections[n],asCString);
	}
	scriptSections.SetLength(0);

	for( n = 0; n < classTypes.GetLength(); n++ )
		classTypes[n]->refCount--;
	classTypes.SetLength(0);
}
示例#9
0
// internal
void asCModule::InternalReset()
{
	asASSERT( !IsUsed() );

	CallExit();

	// First free the functions
	size_t n;
	for( n = 0; n < scriptFunctions.GetLength(); n++ )
	{
		if( scriptFunctions[n] == 0 )
			continue;

		// Don't delete interface methods, if the module isn't the only owner of the interface
		if( scriptFunctions[n]->objectType && scriptFunctions[n]->objectType->IsInterface() && scriptFunctions[n]->objectType->GetRefCount() > 1 )
			continue;

		engine->DeleteScriptFunction(scriptFunctions[n]->id);
	}
	scriptFunctions.SetLength(0);
	globalFunctions.SetLength(0);

	if( initFunction )
	{
		engine->DeleteScriptFunction(initFunction->id);
		initFunction = 0;
	}

	// Release bound functions
	for( n = 0; n < bindInformations.GetLength(); n++ )
	{
		int oldFuncID = bindInformations[n].importedFunction;
		if( oldFuncID != -1 )
		{
			asCModule *oldModule = engine->GetModuleFromFuncId(oldFuncID);
			if( oldModule != 0 ) 
			{
				// Release reference to the module
				oldModule->ReleaseModuleRef();
			}
		}
	}
	bindInformations.SetLength(0);

	for( n = 0; n < importedFunctions.GetLength(); n++ )
	{
		asDELETE(importedFunctions[n],asCScriptFunction);
	}
	importedFunctions.SetLength(0);

	// Free global variables
	globalVarPointers.SetLength(0);

	isBuildWithoutErrors = true;
	isDiscarded = false;

	for( n = 0; n < stringConstants.GetLength(); n++ )
	{
		asDELETE(stringConstants[n],asCString);
	}
	stringConstants.SetLength(0);

	for( n = 0; n < scriptGlobals.GetLength(); n++ )
	{
		asDELETE(scriptGlobals[n],asCGlobalProperty);
	}
	scriptGlobals.SetLength(0);

	for( n = 0; n < scriptSections.GetLength(); n++ )
	{
		asDELETE(scriptSections[n],asCString);
	}
	scriptSections.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);
}