add destructors for obj_file, obj_dylib, obj_dir & bug fix

This commit is contained in:
ValKmjolnir
2022-03-13 00:11:50 +08:00
parent 82e9e97a26
commit b79d60fab5
2 changed files with 70 additions and 49 deletions
+8 -2
View File
@@ -84,6 +84,7 @@ struct nasal_ref
double to_number();
std::string to_string();
void print();
bool objchk(uint32_t);
inline nasal_ref* addr();
inline uint32_t ret ();
inline int64_t& cnt ();
@@ -154,15 +155,16 @@ struct nasal_obj
void* ptr;
/* RAII destroyer */
/* default destroyer does nothing */
typedef void (*dest)(void*);
dest destructor;
nasal_obj():ptr(nullptr),destructor(nullptr){}
~nasal_obj(){clear();}
void clear()
{
{
if(destructor && ptr)
destructor(ptr);
{destructor(ptr);}
ptr=nullptr;
}
};
@@ -345,6 +347,10 @@ void nasal_ref::print()
case vm_obj: std::cout<<"<object>"; break;
}
}
bool nasal_ref::objchk(uint32_t objtype)
{
return type==vm_obj && obj().type==objtype && obj().ptr;
}
inline nasal_ref* nasal_ref::addr (){return value.addr; }
inline uint32_t nasal_ref::ret (){return value.ret; }
inline int64_t& nasal_ref::cnt (){return value.cnt; }