clean up null object

This commit is contained in:
IlyaShurupov 2024-03-25 11:36:29 +03:00 committed by Ilya Shurupov
parent 24f9d8acae
commit 88b78d907a
6 changed files with 30 additions and 50 deletions

View file

@ -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;
}

View file

@ -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"

View file

@ -49,7 +49,6 @@ static bool init(const ModuleManifest*) {
}
static void deinit(const ModuleManifest*) {
NullObject::uninit();
MethodObject::UnInitialize();
objects_api::finalize();