fix mem_lack for StdData_List

This commit is contained in:
pikastech 2022-06-16 01:18:11 +08:00
parent d72bd7cacc
commit f30dd75da1
7 changed files with 19 additions and 56 deletions

View File

@ -17,8 +17,10 @@ Arg* PikaStdData_List_get(PikaObj* self, int i) {
}
void PikaStdData_List___init__(PikaObj* self) {
PikaList* list = New_list();
obj_setPtr(self, "list", list);
if (!obj_isArgExist(self, "list")) {
PikaList* list = New_list();
obj_setPtr(self, "list", list);
}
}
void PikaStdData_List_set(PikaObj* self, Arg* arg, int i) {

View File

@ -68,7 +68,7 @@ void PikaStdTask_Task_call_period_ms(PikaObj* self,
calls.append(period_ms)
calls.append(fun_todo)
calls.append(0)
is_period = 1
is_period = 1
)
/* clang-format on */
const uint8_t bytes[] =
@ -204,21 +204,7 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
void __Task_update_tick(PikaObj* self) {
if (obj_getInt(self, "is_perod")) {
PIKA_PYTHON_BEGIN
/* clang-format off */
PIKA_PYTHON(
platformGetTick()
)
/* clang-format on */
const uint8_t bytes[] = {
0x04, 0x00, /* instruct array size */
0x00, 0x82, 0x01, 0x00, /* instruct array */
0x11, 0x00, /* const pool size */
0x00, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d,
0x47, 0x65, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x00, /* const pool */
};
PIKA_PYTHON_END
pikaVM_runByteCode(self, (uint8_t*)bytes);
obj_runNativeMethod(self, "platformGetTick", NULL);
}
}

View File

@ -204,21 +204,7 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
void __Task_update_tick(PikaObj* self) {
if (obj_getInt(self, "is_perod")) {
PIKA_PYTHON_BEGIN
/* clang-format off */
PIKA_PYTHON(
platformGetTick()
)
/* clang-format on */
const uint8_t bytes[] = {
0x04, 0x00, /* instruct array size */
0x00, 0x82, 0x01, 0x00, /* instruct array */
0x11, 0x00, /* const pool size */
0x00, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d,
0x47, 0x65, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x00, /* const pool */
};
PIKA_PYTHON_END
pikaVM_runByteCode(self, (uint8_t*)bytes);
obj_runNativeMethod(self, "platformGetTick", NULL);
}
}

View File

@ -984,9 +984,9 @@ TEST(pikaMain, task_run_period_until) {
" if mem_now == 0:\n"
" mem_now = mem.getNow()\n"
" else:\n"
" if mem.getNow() > mem_now:\n"
" if mem.getNow() > mem_now + 0.05:\n"
" mem_lack = True\n"
" print(cformat('%0.2f', mem.getNow()))\n"
" print(cformat('%0.8f', mem.getNow()))\n"
"def todo2():\n"
" print('task 2 running...')\n"
"def todo3():\n"
@ -996,7 +996,7 @@ TEST(pikaMain, task_run_period_until) {
"task = GTestTask.Task()\n"
"task.call_period_ms(todo1, 200)\n"
"task.call_period_ms(todo2, 500)\n"
"# task.call_when(todo3, when3)\n"
"# task.call_always(todo3)\n"
"task.run_until_ms(1000)\n"
"\n");
/* collect */

View File

@ -532,8 +532,9 @@ PIKA_RES list_setArg(PikaList* self, int index, Arg* arg) {
if (index > top) {
return PIKA_RES_ERR_OUT_OF_RANGE;
}
arg_setName(arg, i_str);
args_setArg(&self->super, arg_copy(arg));
Arg* new_arg = arg_copy(arg);
new_arg = arg_setName(new_arg, i_str);
args_setArg(&self->super, new_arg);
return PIKA_RES_OK;
}

View File

@ -17,8 +17,10 @@ Arg* PikaStdData_List_get(PikaObj* self, int i) {
}
void PikaStdData_List___init__(PikaObj* self) {
PikaList* list = New_list();
obj_setPtr(self, "list", list);
if (!obj_isArgExist(self, "list")) {
PikaList* list = New_list();
obj_setPtr(self, "list", list);
}
}
void PikaStdData_List_set(PikaObj* self, Arg* arg, int i) {

View File

@ -68,7 +68,7 @@ void PikaStdTask_Task_call_period_ms(PikaObj* self,
calls.append(period_ms)
calls.append(fun_todo)
calls.append(0)
is_period = 1
is_period = 1
)
/* clang-format on */
const uint8_t bytes[] =
@ -204,21 +204,7 @@ void PikaStdTask_Task_run_once(PikaObj* self) {
void __Task_update_tick(PikaObj* self) {
if (obj_getInt(self, "is_perod")) {
PIKA_PYTHON_BEGIN
/* clang-format off */
PIKA_PYTHON(
platformGetTick()
)
/* clang-format on */
const uint8_t bytes[] = {
0x04, 0x00, /* instruct array size */
0x00, 0x82, 0x01, 0x00, /* instruct array */
0x11, 0x00, /* const pool size */
0x00, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d,
0x47, 0x65, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x00, /* const pool */
};
PIKA_PYTHON_END
pikaVM_runByteCode(self, (uint8_t*)bytes);
obj_runNativeMethod(self, "platformGetTick", NULL);
}
}