mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
free obj auto when arg is updated
This commit is contained in:
parent
6d8bba2dcc
commit
8833e606ab
@ -697,4 +697,24 @@ TEST(pikaMain, for_in_string) {
|
|||||||
/* deinit */
|
/* deinit */
|
||||||
obj_deinit(pikaMain);
|
obj_deinit(pikaMain);
|
||||||
EXPECT_EQ(pikaMemNow(), 0);
|
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);
|
||||||
}
|
}
|
@ -26,6 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "dataArgs.h"
|
#include "dataArgs.h"
|
||||||
|
#include "PikaObj.h"
|
||||||
#include "PikaPlatform.h"
|
#include "PikaPlatform.h"
|
||||||
#include "dataLink.h"
|
#include "dataLink.h"
|
||||||
#include "dataMemory.h"
|
#include "dataMemory.h"
|
||||||
@ -194,7 +195,7 @@ int32_t args_isArgExist(Args* self, char* name) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t updateArg(Args* self, Arg* argNew) {
|
int32_t __updateArg(Args* self, Arg* argNew) {
|
||||||
LinkNode* nodeToUpdate = NULL;
|
LinkNode* nodeToUpdate = NULL;
|
||||||
LinkNode* nodeNow = self->firstNode;
|
LinkNode* nodeNow = self->firstNode;
|
||||||
LinkNode* priorNode = NULL;
|
LinkNode* priorNode = NULL;
|
||||||
@ -211,7 +212,11 @@ int32_t updateArg(Args* self, Arg* argNew) {
|
|||||||
priorNode = nodeNow;
|
priorNode = nodeNow;
|
||||||
nodeNow = content_getNext(nodeNow);
|
nodeNow = content_getNext(nodeNow);
|
||||||
}
|
}
|
||||||
|
/* free the object */
|
||||||
|
if (TYPE_OBJECT == arg_getType(nodeToUpdate)) {
|
||||||
|
PikaObj* obj = arg_getPtr(nodeToUpdate);
|
||||||
|
obj_deinit(obj);
|
||||||
|
}
|
||||||
nodeToUpdate = arg_setContent(nodeToUpdate, arg_getContent(argNew),
|
nodeToUpdate = arg_setContent(nodeToUpdate, arg_getContent(argNew),
|
||||||
arg_getContentSize(argNew));
|
arg_getContentSize(argNew));
|
||||||
|
|
||||||
@ -235,7 +240,7 @@ int32_t args_setArg(Args* self, Arg* arg) {
|
|||||||
args_pushArg(self, arg);
|
args_pushArg(self, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
updateArg(self, arg);
|
__updateArg(self, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user