debug connot find object when run method of locals.obj

This commit is contained in:
lyon1998 2021-11-03 21:28:37 +08:00
parent c63493050d
commit ce3df083b6
2 changed files with 34 additions and 12 deletions

View File

@ -1,12 +1,31 @@
// #include "gtest/gtest.h"
// extern "C" {
// #include "dataMemory.h"
// #include "pikaScript.h"
// }
// extern PikaMemInfo pikaMemInfo;
// TEST(pikaMain, init) {
// pikaMemInfo.heapUsedMax = 0;
// PikaObj* pikaMain = pikaScriptInit();
// obj_deinit(pikaMain);
// EXPECT_EQ(pikaMemNow(), 0);
// }
#include "gtest/gtest.h"
extern "C" {
#include "PikaMain.h"
#include "PikaStdLib_MemChecker.h"
#include "dataArgs.h"
#include "dataMemory.h"
#include "pikaScript.h"
}
extern PikaMemInfo pikaMemInfo;
TEST(pikaMain, init) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = pikaScriptInit();
obj_deinit(pikaMain);
EXPECT_EQ(pikaMemNow(), 0);
}
TEST(pikaMain, new_mem) {
pikaMemInfo.heapUsedMax = 0;
PikaObj* pikaMain = newRootObj((char*)"pikaMain", New_PikaMain);
Parameters* globals =
obj_runDirect(pikaMain, (char*)
"mem = PikaStdLib.MemChecker()\n"
"mem.max()\n"
);
PikaObj* mem = (PikaObj*)args_getPtr(globals->attributeList, (char*)"mem");
PikaObj* memClassPtr = (PikaObj*)obj_getPtr(mem, (char*)"_clsptr");
EXPECT_EQ((void*)memClassPtr, (void*)New_PikaStdLib_MemChecker);
obj_deinit(pikaMain);
obj_deinit(globals);
EXPECT_EQ(pikaMemNow(), 0);
}

View File

@ -335,6 +335,9 @@ Arg* pikaVM_runInstruct(PikaObj* self,
}
/* get method host obj */
PikaObj* methodHostObj = obj_getObj(self, methodPath, 1);
if (NULL == methodHostObj) {
methodHostObj = obj_getObj(locals, methodPath, 1);
}
if (NULL == methodHostObj) {
/* error, not found object */
args_setErrorCode(locals->attributeList, 1);