Update Angelscript from 2.32.0 to 2.35.1

Didn't require any changes except dos2unix.
This commit is contained in:
Bryan Quigley
2021-11-04 13:43:10 -07:00
parent 0d8b01b08b
commit 73c94f571d
37 changed files with 5585 additions and 2550 deletions

View File

@@ -1,6 +1,6 @@
/*
AngelCode Scripting Library
Copyright (c) 2003-2016 Andreas Jonsson
Copyright (c) 2003-2019 Andreas Jonsson
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
@@ -121,6 +121,94 @@ asIScriptObject *ScriptObjectFactory(const asCObjectType *objType, asCScriptEngi
return ptr;
}
// This helper function will call the copy factory, that is a script function
// TODO: Clean up: This function is almost identical to ScriptObjectFactory. Should make better use of the identical code.
asIScriptObject *ScriptObjectCopyFactory(const asCObjectType *objType, void *origObj, asCScriptEngine *engine)
{
asIScriptContext *ctx = 0;
int r = 0;
bool isNested = false;
// Use nested call in the context if there is an active context
ctx = asGetActiveContext();
if (ctx)
{
// It may not always be possible to reuse the current context,
// in which case we'll have to create a new one any way.
if (ctx->GetEngine() == objType->GetEngine() && ctx->PushState() == asSUCCESS)
isNested = true;
else
ctx = 0;
}
if (ctx == 0)
{
// Request a context from the engine
ctx = engine->RequestContext();
if (ctx == 0)
{
// TODO: How to best report this failure?
return 0;
}
}
r = ctx->Prepare(engine->scriptFunctions[objType->beh.copyfactory]);
if (r < 0)
{
if (isNested)
ctx->PopState();
else
engine->ReturnContext(ctx);
return 0;
}
// Let the context handle the case for argument by ref (&) or by handle (@)
ctx->SetArgObject(0, origObj);
for (;;)
{
r = ctx->Execute();
// We can't allow this execution to be suspended
// so resume the execution immediately
if (r != asEXECUTION_SUSPENDED)
break;
}
if (r != asEXECUTION_FINISHED)
{
if (isNested)
{
ctx->PopState();
// If the execution was aborted or an exception occurred,
// then we should forward that to the outer execution.
if (r == asEXECUTION_EXCEPTION)
{
// TODO: How to improve this exception
ctx->SetException(TXT_EXCEPTION_IN_NESTED_CALL);
}
else if (r == asEXECUTION_ABORTED)
ctx->Abort();
}
else
engine->ReturnContext(ctx);
return 0;
}
asIScriptObject *ptr = (asIScriptObject*)ctx->GetReturnAddress();
// Increase the reference, because the context will release its pointer
ptr->AddRef();
if (isNested)
ctx->PopState();
else
engine->ReturnContext(ctx);
return ptr;
}
#ifdef AS_MAX_PORTABILITY
static void ScriptObject_AddRef_Generic(asIScriptGeneric *gen)
@@ -726,14 +814,19 @@ void asCScriptObject::EnumReferences(asIScriptEngine *engine)
{
asCObjectProperty *prop = objType->properties[n];
void *ptr = 0;
if( prop->type.IsObject() )
if (prop->type.IsObject())
{
// TODO: gc: The members of the value type needs to be enumerated
// too, since the value type may be holding a reference.
if( prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF) )
if (prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF))
ptr = *(void**)(((char*)this) + prop->byteOffset);
else
ptr = (void*)(((char*)this) + prop->byteOffset);
// The members of the value type needs to be enumerated
// too, since the value type may be holding a reference.
if ((prop->type.GetTypeInfo()->flags & asOBJ_VALUE) && (prop->type.GetTypeInfo()->flags & asOBJ_GC))
{
reinterpret_cast<asCScriptEngine*>(engine)->CallObjectMethod(ptr, engine, CastToObjectType(prop->type.GetTypeInfo())->beh.gcEnumReferences);
}
}
else if (prop->type.IsFuncdef())
ptr = *(void**)(((char*)this) + prop->byteOffset);
@@ -749,18 +842,31 @@ void asCScriptObject::ReleaseAllHandles(asIScriptEngine *engine)
{
asCObjectProperty *prop = objType->properties[n];
// TODO: gc: The members of the members needs to be released
// too, since they may be holding a reference. Even
// if the member is a value type.
if( prop->type.IsObject() && prop->type.IsObjectHandle() )
if (prop->type.IsObject())
{
void **ptr = (void**)(((char*)this) + prop->byteOffset);
if( *ptr )
if (prop->type.IsObjectHandle())
{
asASSERT( (prop->type.GetTypeInfo()->flags & asOBJ_NOCOUNT) || prop->type.GetBehaviour()->release );
if( prop->type.GetBehaviour()->release )
((asCScriptEngine*)engine)->CallObjectMethod(*ptr, prop->type.GetBehaviour()->release);
*ptr = 0;
void **ptr = (void**)(((char*)this) + prop->byteOffset);
if (*ptr)
{
asASSERT((prop->type.GetTypeInfo()->flags & asOBJ_NOCOUNT) || prop->type.GetBehaviour()->release);
if (prop->type.GetBehaviour()->release)
((asCScriptEngine*)engine)->CallObjectMethod(*ptr, prop->type.GetBehaviour()->release);
*ptr = 0;
}
}
else if ((prop->type.GetTypeInfo()->flags & asOBJ_VALUE) && (prop->type.GetTypeInfo()->flags & asOBJ_GC))
{
// The members of the members needs to be released
// too, since they may be holding a reference. Even
// if the member is a value type.
void *ptr = 0;
if (prop->type.IsReference())
ptr = *(void**)(((char*)this) + prop->byteOffset);
else
ptr = (void*)(((char*)this) + prop->byteOffset);
reinterpret_cast<asCScriptEngine*>(engine)->CallObjectMethod(ptr, engine, CastToObjectType(prop->type.GetTypeInfo())->beh.gcReleaseAllReferences);
}
}
else if (prop->type.IsFuncdef())
@@ -782,30 +888,43 @@ asCScriptObject &ScriptObject_Assignment(asCScriptObject *other, asCScriptObject
asCScriptObject &asCScriptObject::operator=(const asCScriptObject &other)
{
if( &other != this )
CopyFromAs(&other, objType);
return *this;
}
// internal
int asCScriptObject::CopyFromAs(const asCScriptObject *other, asCObjectType *in_objType)
{
if( other != this )
{
if( !other.objType->DerivesFrom(objType) )
if( !other->objType->DerivesFrom(in_objType) )
{
// We cannot allow a value assignment from a type that isn't the same or
// derives from this type as the member properties may not have the same layout
asIScriptContext *ctx = asGetActiveContext();
ctx->SetException(TXT_MISMATCH_IN_VALUE_ASSIGN);
return *this;
return asERROR;
}
// If the script class implements the opAssign method, it should be called
asCScriptEngine *engine = objType->engine;
asCScriptFunction *func = engine->scriptFunctions[objType->beh.copy];
asCScriptEngine *engine = in_objType->engine;
asCScriptFunction *func = engine->scriptFunctions[in_objType->beh.copy];
if( func->funcType == asFUNC_SYSTEM )
{
// Copy all properties
for( asUINT n = 0; n < objType->properties.GetLength(); n++ )
// If derived, use the base class' assignment operator to copy the inherited
// properties. Then only copy new properties for the derived class
if( in_objType->derivedFrom )
CopyFromAs(other, in_objType->derivedFrom);
for( asUINT n = in_objType->derivedFrom ? in_objType->derivedFrom->properties.GetLength() : 0;
n < in_objType->properties.GetLength();
n++ )
{
asCObjectProperty *prop = objType->properties[n];
asCObjectProperty *prop = in_objType->properties[n];
if( prop->type.IsObject() )
{
void **dst = (void**)(((char*)this) + prop->byteOffset);
void **src = (void**)(((char*)&other) + prop->byteOffset);
void **src = (void**)(((char*)other) + prop->byteOffset);
if( !prop->type.IsObjectHandle() )
{
if( prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF) )
@@ -819,7 +938,7 @@ asCScriptObject &asCScriptObject::operator=(const asCScriptObject &other)
else if (prop->type.IsFuncdef())
{
asCScriptFunction **dst = (asCScriptFunction**)(((char*)this) + prop->byteOffset);
asCScriptFunction **src = (asCScriptFunction**)(((char*)&other) + prop->byteOffset);
asCScriptFunction **src = (asCScriptFunction**)(((char*)other) + prop->byteOffset);
if (*dst)
(*dst)->Release();
*dst = *src;
@@ -829,7 +948,7 @@ asCScriptObject &asCScriptObject::operator=(const asCScriptObject &other)
else
{
void *dst = ((char*)this) + prop->byteOffset;
void *src = ((char*)&other) + prop->byteOffset;
void *src = ((char*)other) + prop->byteOffset;
memcpy(dst, src, prop->type.GetSizeInMemoryBytes());
}
}
@@ -855,24 +974,20 @@ asCScriptObject &asCScriptObject::operator=(const asCScriptObject &other)
// Request a context from the engine
ctx = engine->RequestContext();
if( ctx == 0 )
{
// TODO: How to best report this failure?
return *this;
}
return asERROR;
}
r = ctx->Prepare(engine->scriptFunctions[objType->beh.copy]);
r = ctx->Prepare(engine->scriptFunctions[in_objType->beh.copy]);
if( r < 0 )
{
if( isNested )
ctx->PopState();
else
engine->ReturnContext(ctx);
// TODO: How to best report this failure?
return *this;
return r;
}
r = ctx->SetArgAddress(0, const_cast<asCScriptObject*>(&other));
r = ctx->SetArgAddress(0, const_cast<asCScriptObject*>(other));
asASSERT( r >= 0 );
r = ctx->SetObject(this);
asASSERT( r >= 0 );
@@ -908,7 +1023,7 @@ asCScriptObject &asCScriptObject::operator=(const asCScriptObject &other)
// Return the context to the engine
engine->ReturnContext(ctx);
}
return *this;
return asERROR;
}
if( isNested )
@@ -921,10 +1036,10 @@ asCScriptObject &asCScriptObject::operator=(const asCScriptObject &other)
}
}
return *this;
return asSUCCESS;
}
int asCScriptObject::CopyFrom(asIScriptObject *other)
int asCScriptObject::CopyFrom(const asIScriptObject *other)
{
if( other == 0 ) return asINVALID_ARG;
@@ -933,7 +1048,7 @@ int asCScriptObject::CopyFrom(asIScriptObject *other)
*this = *(asCScriptObject*)other;
return 0;
return asSUCCESS;
}
void *asCScriptObject::AllocateUninitializedObject(asCObjectType *in_objType, asCScriptEngine *engine)
@@ -983,19 +1098,19 @@ void asCScriptObject::FreeObject(void *ptr, asCObjectType *in_objType, asCScript
}
}
void asCScriptObject::CopyObject(void *src, void *dst, asCObjectType *in_objType, asCScriptEngine *engine)
void asCScriptObject::CopyObject(const void *src, void *dst, asCObjectType *in_objType, asCScriptEngine *engine)
{
int funcIndex = in_objType->beh.copy;
if( funcIndex )
{
asCScriptFunction *func = engine->scriptFunctions[in_objType->beh.copy];
if( func->funcType == asFUNC_SYSTEM )
engine->CallObjectMethod(dst, src, funcIndex);
engine->CallObjectMethod(dst, const_cast<void*>(src), funcIndex);
else
{
// Call the script class' opAssign method
asASSERT(in_objType->flags & asOBJ_SCRIPT_OBJECT );
reinterpret_cast<asCScriptObject*>(dst)->CopyFrom(reinterpret_cast<asCScriptObject*>(src));
reinterpret_cast<asCScriptObject*>(dst)->CopyFrom(reinterpret_cast<const asCScriptObject*>(src));
}
}
else if( in_objType->size && (in_objType->flags & asOBJ_POD) )