support deinit no ref object

This commit is contained in:
lyon 2022-04-26 12:23:39 +08:00
parent 4956994086
commit ba11251d6d
3 changed files with 35 additions and 31 deletions

View File

@ -342,18 +342,15 @@ void* arg_getHeapStruct(Arg* self) {
}
void arg_deinitHeap(Arg* self) {
if (arg_getType(self) == ARG_TYPE_HEAP_STRUCT) {
ArgType type = arg_getType(self);
/* deinit heap struct */
if (type == ARG_TYPE_HEAP_STRUCT) {
/* deinit heap strcut */
StructDeinitFun struct_deinit_fun =
(StructDeinitFun)arg_getHeapStructDeinitFun(self);
struct_deinit_fun(arg_getHeapStruct(self));
}
}
void arg_deinit(Arg* self) {
arg_deinitHeap(self);
/* deinit sub object */
ArgType type = arg_getType(self);
if (type == ARG_TYPE_OBJECT) {
PikaObj* subObj = arg_getPtr(self);
obj_refcntDec(subObj);
@ -362,6 +359,11 @@ void arg_deinit(Arg* self) {
obj_deinit(subObj);
}
}
}
void arg_deinit(Arg* self) {
/* deinit arg pointed heap */
arg_deinitHeap(self);
/* free the ref */
arg_freeContent(self);
}

View File

@ -721,25 +721,25 @@ TEST(pikaMain, string_no_init_arg) {
EXPECT_EQ(pikaMemNow(), 0);
}
// TEST(pikaMain, obj_no_free) {
// /* init */
// pikaMemInfo.heapUsedMax = 0;
// PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
// /* run */
// __platform_printf((char*)"BEGIN\n");
// obj_run(pikaMain, (char*)
// "s = PikaStdData.String()\n"
// "s.set('test')\n"
// "s = PikaStdData.String()\n"
// "s.set('test')\n"
// "\n"
// );
// /* collect */
// /* assert */
// /* deinit */
// obj_deinit(pikaMain);
// EXPECT_EQ(pikaMemNow(), 0);
// }
TEST(pikaMain, obj_no_free) {
/* init */
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
/* run */
__platform_printf((char*)"BEGIN\n");
obj_run(pikaMain, (char*)
"s = PikaStdData.String()\n"
"s.set('test')\n"
"s = PikaStdData.String()\n"
"s.set('test')\n"
"\n"
);
/* collect */
/* assert */
/* deinit */
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(pikaMain, list__set__) {
/* init */

View File

@ -342,18 +342,15 @@ void* arg_getHeapStruct(Arg* self) {
}
void arg_deinitHeap(Arg* self) {
if (arg_getType(self) == ARG_TYPE_HEAP_STRUCT) {
ArgType type = arg_getType(self);
/* deinit heap struct */
if (type == ARG_TYPE_HEAP_STRUCT) {
/* deinit heap strcut */
StructDeinitFun struct_deinit_fun =
(StructDeinitFun)arg_getHeapStructDeinitFun(self);
struct_deinit_fun(arg_getHeapStruct(self));
}
}
void arg_deinit(Arg* self) {
arg_deinitHeap(self);
/* deinit sub object */
ArgType type = arg_getType(self);
if (type == ARG_TYPE_OBJECT) {
PikaObj* subObj = arg_getPtr(self);
obj_refcntDec(subObj);
@ -362,6 +359,11 @@ void arg_deinit(Arg* self) {
obj_deinit(subObj);
}
}
}
void arg_deinit(Arg* self) {
/* deinit arg pointed heap */
arg_deinitHeap(self);
/* free the ref */
arg_freeContent(self);
}