clean up null object
This commit is contained in:
parent
24f9d8acae
commit
88b78d907a
6 changed files with 30 additions and 50 deletions
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include "core/Object.hpp"
|
||||
|
||||
#include "primitives/NullObject.hpp"
|
||||
#include "primitives/ClassObject.hpp"
|
||||
#include "primitives/MethodObject.hpp"
|
||||
|
||||
|
|
@ -11,9 +12,18 @@ using namespace obj;
|
|||
|
||||
ObjectsContext* obj::gObjectsContext = nullptr;
|
||||
|
||||
ObjectsContext::ObjectsContext() {
|
||||
memSetVal(sl_callbacks, SAVE_LOAD_MAX_CALLBACK_SLOTS * sizeof(save_load_callbacks*), 0);
|
||||
interp = new Interpreter();
|
||||
}
|
||||
|
||||
ObjectsContext::~ObjectsContext() { delete interp; }
|
||||
|
||||
void objects_api::initialize() {
|
||||
ASSERT(!gObjectsContext)
|
||||
gObjectsContext = new ObjectsContext();
|
||||
|
||||
gObjectsContext->nullObject = create<NullObject>();
|
||||
}
|
||||
|
||||
void objects_api::finalize() {
|
||||
|
|
@ -44,13 +54,6 @@ void obj::load_string(ArchiverIn& file, std::string& out) {
|
|||
Object* ObjectMemAllocate(const ObjectType* type);
|
||||
void ObjectMemDeallocate(Object* object);
|
||||
|
||||
ObjectsContext::ObjectsContext() {
|
||||
memSetVal(sl_callbacks, SAVE_LOAD_MAX_CALLBACK_SLOTS * sizeof(save_load_callbacks*), 0);
|
||||
interp = new Interpreter();
|
||||
}
|
||||
|
||||
ObjectsContext::~ObjectsContext() { delete interp; }
|
||||
|
||||
void hierarchy_copy(Object* self, const Object* in, const ObjectType* type);
|
||||
void hierarchy_construct(Object* self, const ObjectType* type);
|
||||
|
||||
|
|
@ -226,4 +229,11 @@ void objects_api::addTypeToGroup(ObjectType* type, InitialierList<const char*> p
|
|||
|
||||
bool objects_api::isType(const char* name) { return gObjectsContext->types.presents(name).isValid(); }
|
||||
|
||||
const ObjectType* objects_api::getType(const char* name) { return gObjectsContext->types.get(name); }
|
||||
const ObjectType* objects_api::getType(const char* name) { return gObjectsContext->types.get(name); }
|
||||
|
||||
NullObject* objects_api::getNull() { return gObjectsContext->nullObject; }
|
||||
|
||||
NullObject* objects_api::getNullReferenced() {
|
||||
increaseReferenceCount(gObjectsContext->nullObject);
|
||||
return gObjectsContext->nullObject;
|
||||
}
|
||||
|
|
@ -296,7 +296,7 @@ Object* objects_api::load(ArchiverIn& ndf, alni file_adress) {
|
|||
// check for null object
|
||||
if (out->type == &NullObject::TypeData) {
|
||||
ObjectMemDeallocate(out);
|
||||
out = NdoNull_globalInstance;
|
||||
out = getNull();
|
||||
}
|
||||
|
||||
// save heap adress in "loaded_file"
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ static bool init(const ModuleManifest*) {
|
|||
}
|
||||
|
||||
static void deinit(const ModuleManifest*) {
|
||||
NullObject::uninit();
|
||||
MethodObject::UnInitialize();
|
||||
|
||||
objects_api::finalize();
|
||||
|
|
|
|||
|
|
@ -5,31 +5,12 @@
|
|||
using namespace tp;
|
||||
using namespace obj;
|
||||
|
||||
obj::NullObject* obj::NdoNull_globalInstance = nullptr;
|
||||
bool uninit_flag = false;
|
||||
|
||||
void NullObject::uninit() {
|
||||
uninit_flag = true;
|
||||
objects_api::destroy(NdoNull_globalInstance);
|
||||
NdoNull_globalInstance = nullptr;
|
||||
}
|
||||
|
||||
void NullObject::destructor(Object* self) {
|
||||
DEBUG_ASSERT(uninit_flag && "Only one the instance of NullObject exists and thus it can't be destroyed");
|
||||
}
|
||||
|
||||
std::string to_string(NullObject* self) { return "nullptr"; }
|
||||
|
||||
alni to_int(NullObject* self) { return 0; }
|
||||
|
||||
alnf to_float(NullObject* self) { return 0; }
|
||||
|
||||
obj::TypeMethods* tm_construct() {
|
||||
auto out = new obj::TypeMethods();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
struct ObjectTypeConversions NullObjectTypeConversions = {
|
||||
.from_int = nullptr,
|
||||
.from_float = nullptr,
|
||||
|
|
@ -42,7 +23,7 @@ struct ObjectTypeConversions NullObjectTypeConversions = {
|
|||
struct ObjectType NullObject::TypeData = {
|
||||
.base = nullptr,
|
||||
.constructor = nullptr,
|
||||
.destructor = NullObject::destructor,
|
||||
.destructor = nullptr,
|
||||
.copy = nullptr,
|
||||
.size = sizeof(NullObject),
|
||||
.name = "null",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue