1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-02-07 13:27:13 +01:00

Miscellaneous.

This commit is contained in:
Sandu Liviu Catalin 2020-04-28 00:04:24 +03:00
parent 02dc14f26a
commit e7e266314e
3 changed files with 24 additions and 28 deletions

View File

@ -39,7 +39,7 @@ endif ()
target_include_directories(MaxmindDB PRIVATE ${CMAKE_CURRENT_LIST_DIR}) target_include_directories(MaxmindDB PRIVATE ${CMAKE_CURRENT_LIST_DIR})
target_include_directories(MaxmindDB PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(MaxmindDB PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
# Configure macro options # Configure macro options
target_compile_definitions(MaxmindDB PRIVATE ) #target_compile_definitions(MaxmindDB PRIVATE )
# Configure build options # Configure build options
if(GCC OR MINGW) if(GCC OR MINGW)
target_compile_options(MaxmindDB PRIVATE -Wno-unused -Wno-incompatible-pointer-types) target_compile_options(MaxmindDB PRIVATE -Wno-unused -Wno-incompatible-pointer-types)

View File

@ -55,14 +55,14 @@ struct Function {
sq_resetobject(&mObj); sq_resetobject(&mObj);
} }
// Copy constructor // Copy constructor
Function(const Function& sf) : mEnv(sf.mEnv), mObj(sf.mObj) { Function(const Function& o) : mEnv(o.mEnv), mObj(o.mObj) {
sq_addref(SqVM(), &mEnv); sq_addref(SqVM(), &mEnv);
sq_addref(SqVM(), &mObj); sq_addref(SqVM(), &mObj);
} }
// Move constructor // Move constructor
Function(Function&& sf) noexcept : mEnv(sf.mEnv), mObj(sf.mObj) { Function(Function&& o) noexcept : mEnv(o.mEnv), mObj(o.mObj) {
sq_resetobject(&sf.mEnv); sq_resetobject(&o.mEnv);
sq_resetobject(&sf.mObj); sq_resetobject(&o.mObj);
} }
// Constructs a Function from a slot in an Object // Constructs a Function from a slot in an Object
Function(const Object& e, const SQChar* slot) : mEnv(e.GetObj()) { Function(const Object& e, const SQChar* slot) : mEnv(e.GetObj()) {
@ -110,22 +110,24 @@ struct Function {
Release(); Release();
} }
// Copy Assignment operator // Copy Assignment operator
Function& operator=(const Function& sf) { Function& operator=(const Function& o) {
Release(); if (this != &o) {
mEnv = sf.mEnv; Release();
mObj = sf.mObj; mEnv = o.mEnv;
sq_addref(SqVM(), &mEnv); mObj = o.mObj;
sq_addref(SqVM(), &mObj); sq_addref(SqVM(), &mEnv);
sq_addref(SqVM(), &mObj);
}
return *this; return *this;
} }
// Move Assignment operator // Move Assignment operator
Function& operator=(Function&& sf) noexcept { Function& operator=(Function&& o) noexcept {
if (this != &sf) { if (this != &o) {
Release(); Release();
mEnv = sf.mEnv; mEnv = o.mEnv;
mObj = sf.mObj; mObj = o.mObj;
sq_resetobject(&sf.mEnv); sq_resetobject(&o.mEnv);
sq_resetobject(&sf.mObj); sq_resetobject(&o.mObj);
} }
return *this; return *this;
} }
@ -172,7 +174,6 @@ struct Function {
bool Assign(HSQUIRRELVM vm, SQInteger idx1, SQInteger idx2, bool bind_null=false) { bool Assign(HSQUIRRELVM vm, SQInteger idx1, SQInteger idx2, bool bind_null=false) {
// Release current callback, if any // Release current callback, if any
Release(); Release();
printf("assigning ty1 %lld ty2 %lld top %lld\n", idx1, idx2, sq_gettop(vm));
// Tells if the current environment was used // Tells if the current environment was used
bool cenv = false; bool cenv = false;
// Retrieve the environment type // Retrieve the environment type
@ -182,17 +183,14 @@ struct Function {
sq_pushroottable(vm); // Push it on the stack sq_pushroottable(vm); // Push it on the stack
sq_getstackobj(vm, -1, &mEnv); // Grab it sq_getstackobj(vm, -1, &mEnv); // Grab it
sq_poptop(vm); // Clean up the stack sq_poptop(vm); // Clean up the stack
printf("assigning ty1 null\n");
// Should we use current environment? // Should we use current environment?
} else if (ty1 & (_RT_CLOSURE | _RT_NATIVECLOSURE)) { } else if (ty1 & (_RT_CLOSURE | _RT_NATIVECLOSURE)) {
sq_getstackobj(vm, 1, &mEnv); // `this` as environment sq_getstackobj(vm, 1, &mEnv); // `this` as environment
idx2 = idx1; // There is no explicit environment given idx2 = idx1; // There is no explicit environment given
cenv = true; cenv = true;
printf("assigning ty1 closure\n");
// Is there a specific environment? // Is there a specific environment?
} else if (ty1 & (_RT_TABLE | _RT_CLASS | _RT_INSTANCE)) { } else if (ty1 & (_RT_TABLE | _RT_CLASS | _RT_INSTANCE)) {
sq_getstackobj(vm, idx1, &mEnv); // Grab the given environment sq_getstackobj(vm, idx1, &mEnv); // Grab the given environment
printf("assigning ty1 table\n");
} else { } else {
#if !defined (SCRAT_NO_ERROR_CHECKING) #if !defined (SCRAT_NO_ERROR_CHECKING)
SQTHROW(vm, FormatTypeError(vm, idx1, _SC("object"))); SQTHROW(vm, FormatTypeError(vm, idx1, _SC("object")));
@ -205,23 +203,18 @@ struct Function {
// Can we bind null? // Can we bind null?
if (bind_null && ty2 == OT_NULL) { if (bind_null && ty2 == OT_NULL) {
sq_resetobject(&mEnv); // Drop the environment, if any sq_resetobject(&mEnv); // Drop the environment, if any
printf("assigning ty2 null\n");
return cenv; // Just stop knowing this is what we want return cenv; // Just stop knowing this is what we want
// Is the callback is valid? // Is the callback is valid?
} else if (ty2 & (_RT_CLOSURE | _RT_NATIVECLOSURE)) { } else if (ty2 & (_RT_CLOSURE | _RT_NATIVECLOSURE)) {
printf("assigning ty2 closure\n");
sq_getstackobj(vm, idx2, &mObj);
// Reference the environment and function // Reference the environment and function
sq_addref(vm, &mEnv); sq_addref(vm, &mEnv);
sq_addref(vm, &mObj); sq_addref(vm, &mObj);
} else { } else {
printf("assigning ty2 null\n");
sq_resetobject(&mEnv); // Discard obtained environment sq_resetobject(&mEnv); // Discard obtained environment
#if !defined (SCRAT_NO_ERROR_CHECKING) #if !defined (SCRAT_NO_ERROR_CHECKING)
SQTHROW(vm, FormatTypeError(vm, idx2, _SC("closure"))); SQTHROW(vm, FormatTypeError(vm, idx2, _SC("closure")));
#endif #endif
} }
puts("");
// Return whether current environment was used // Return whether current environment was used
return cenv; return cenv;
} }

View File

@ -357,8 +357,11 @@ public:
/// ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Release() { void Release() {
sq_release(vm, &obj); if (!is_null(obj))
sq_resetobject(&obj); {
sq_release(vm, &obj);
sq_resetobject(&obj);
}
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////