Skip to content

Commit 5cb104a

Browse files
committed
fix pya load
1 parent 87176db commit 5cb104a

File tree

8 files changed

+29
-12
lines changed

8 files changed

+29
-12
lines changed

package/time/_time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void _do_sleep_ms_tick(uint32_t ms) {
1616
while (1) {
1717
pika_platform_thread_yield();
1818
#if PIKA_EVENT_ENABLE
19-
if (!g_PikaVMSignal.event_thread) {
19+
if (!pika_GIL_isInit()) {
2020
_VMEvent_pickupEvent();
2121
}
2222
#endif

port/linux/package/pikascript/pikascript-lib/time/_time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void _do_sleep_ms_tick(uint32_t ms) {
1616
while (1) {
1717
pika_platform_thread_yield();
1818
#if PIKA_EVENT_ENABLE
19-
if (!g_PikaVMSignal.event_thread) {
19+
if (!pika_GIL_isInit()) {
2020
_VMEvent_pickupEvent();
2121
}
2222
#endif

port/linux/test/module-test.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,6 @@ TEST(module, REPL_runbytecode) {
517517
EXPECT_EQ(pikaMemNow(), 0);
518518
}
519519

520-
#if 0
521-
//! TODO: fix this test
522520
TEST(module, REPL_pya) {
523521
/* init */
524522
g_PikaMemInfo.heapUsedMax = 0;
@@ -539,7 +537,6 @@ TEST(module, REPL_pya) {
539537
obj_deinit(pikaMain);
540538
EXPECT_EQ(pikaMemNow(), 0);
541539
}
542-
#endif
543540

544541
TEST(module, REPL_script) {
545542
/* init */

src/PikaObj.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,9 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
19411941
uint8_t* size_byte = (uint8_t*)&size;
19421942
size_byte[i] = cfg->fn_getchar();
19431943
}
1944-
size += sizeof(uint32_t) * 2;
1944+
if (magic_code[3] == 'o') {
1945+
size += sizeof(uint32_t) * 2;
1946+
}
19451947
uint8_t* buff = pikaMalloc(size);
19461948
/* save magic code and size */
19471949
memcpy(buff, magic_code, sizeof(magic_code));
@@ -1969,6 +1971,8 @@ void _do_pikaScriptShell(PikaObj* self, ShellConfig* cfg) {
19691971
pika_platform_printf(
19701972
"=============== [REBOOT] ===============\r\n");
19711973
pika_platform_reboot();
1974+
pikaFree(buff, size);
1975+
return;
19721976
}
19731977
}
19741978
#endif
@@ -2740,15 +2744,17 @@ static void _thread_event(void* arg) {
27402744
pika_assert(_VM_is_first_lock());
27412745
while (1) {
27422746
pika_GIL_ENTER();
2743-
_VMEvent_pickupEvent();
2744-
pika_GIL_EXIT();
2745-
pika_platform_thread_yield();
27462747
#if PIKA_EVENT_ENABLE
27472748
if (g_PikaVMSignal.event_thread_exit) {
2749+
g_PikaVMSignal.event_thread_exit_done = 1;
27482750
break;
27492751
}
27502752
#endif
2753+
_VMEvent_pickupEvent();
2754+
pika_GIL_EXIT();
2755+
pika_platform_thread_yield();
27512756
}
2757+
pika_GIL_EXIT();
27522758
}
27532759

27542760
void _do_pika_eventListener_send(PikaEventListener* self,

src/PikaObj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ uint32_t pikaGC_printFreeList(void);
739739

740740
int pika_GIL_EXIT(void);
741741
int pika_GIL_ENTER(void);
742+
pika_bool pika_GIL_isInit(void);
742743

743744
/* builtins */
744745
PikaObj* New_builtins(Args* args);

src/PikaPlatform.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ PIKA_WEAK int pika_platform_fclose(FILE* stream) {
340340
}
341341

342342
/* fwrite */
343-
PIKA_WEAK size_t
344-
pika_platform_fwrite(const void* ptr,
343+
PIKA_WEAK size_t pika_platform_fwrite(const void* ptr,
345344
size_t size,
346345
size_t n,
347346
FILE* stream) {
@@ -716,7 +715,11 @@ PIKA_WEAK void pika_platform_thread_timer_usleep(unsigned long usec) {
716715
}
717716

718717
PIKA_WEAK void pika_platform_reboot(void) {
718+
#if __linux
719+
pika_platform_printf("reboot\n");
720+
#else
719721
WEAK_FUNCTION_NEED_OVERRIDE_ERROR();
722+
#endif
720723
}
721724

722725
PIKA_WEAK void pika_platform_clear(void) {

src/PikaVM.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ static uint8_t _getLRegIndex(char* data);
6262
static PikaObj* New_Locals(Args* args);
6363
char* string_slice(Args* outBuffs, char* str, int start, int end);
6464

65+
pika_bool pika_GIL_isInit(void) {
66+
return g_pikaGIL.is_init;
67+
}
68+
6569
int pika_GIL_ENTER(void) {
6670
if (!g_pikaGIL.is_init) {
6771
return 0;
@@ -208,6 +212,11 @@ void _VMEvent_deinit(void) {
208212
g_PikaVMSignal.event_thread_exit = 1;
209213
pika_platform_thread_destroy(g_PikaVMSignal.event_thread);
210214
g_PikaVMSignal.event_thread = NULL;
215+
pika_GIL_EXIT();
216+
while (!g_PikaVMSignal.event_thread_exit_done) {
217+
pika_platform_thread_yield();
218+
}
219+
pika_GIL_ENTER();
211220
}
212221
#endif
213222
}
@@ -4295,7 +4304,7 @@ PikaObj* pikaVM_runFile(PikaObj* self, char* file_name) {
42954304

42964305
void _pikaVM_yield(void) {
42974306
#if PIKA_EVENT_ENABLE
4298-
if (!g_PikaVMSignal.event_thread) {
4307+
if (!pika_GIL_isInit()) {
42994308
_VMEvent_pickupEvent();
43004309
}
43014310
#endif

src/PikaVM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ struct VMSignal {
156156
int event_pickup_cnt;
157157
pika_platform_thread_t* event_thread;
158158
pika_bool event_thread_exit;
159+
pika_bool event_thread_exit_done;
159160
#endif
160161
};
161162

0 commit comments

Comments
 (0)