mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
fix #371
This commit is contained in:
parent
c1e4440a9f
commit
70e824a6b6
@ -77,7 +77,7 @@ typedef struct py_Callbacks {
|
|||||||
/// Flush the output buffer of `print`.
|
/// Flush the output buffer of `print`.
|
||||||
void (*flush)();
|
void (*flush)();
|
||||||
/// Used by `input` to get a character.
|
/// Used by `input` to get a character.
|
||||||
int (*getchar)();
|
int (*getchr)();
|
||||||
/// Used by `gc.collect()` to mark extra objects for garbage collection.
|
/// Used by `gc.collect()` to mark extra objects for garbage collection.
|
||||||
void (*gc_mark)(void (*f)(py_Ref val, void* ctx), void* ctx);
|
void (*gc_mark)(void (*f)(py_Ref val, void* ctx), void* ctx);
|
||||||
} py_Callbacks;
|
} py_Callbacks;
|
||||||
|
@ -32,6 +32,8 @@ static void pk_default_print(const char* data) { printf("%s", data); }
|
|||||||
|
|
||||||
static void pk_default_flush() { fflush(stdout); }
|
static void pk_default_flush() { fflush(stdout); }
|
||||||
|
|
||||||
|
static int pk_default_getchr() { return getchar(); }
|
||||||
|
|
||||||
void LineProfiler__tracefunc(py_Frame* frame, enum py_TraceEvent event) {
|
void LineProfiler__tracefunc(py_Frame* frame, enum py_TraceEvent event) {
|
||||||
LineProfiler* self = &pk_current_vm->line_profiler;
|
LineProfiler* self = &pk_current_vm->line_profiler;
|
||||||
if(self->enabled && event == TRACE_EVENT_LINE) { LineProfiler__tracefunc_line(self, frame); }
|
if(self->enabled && event == TRACE_EVENT_LINE) { LineProfiler__tracefunc_line(self, frame); }
|
||||||
@ -75,7 +77,7 @@ void VM__ctor(VM* self) {
|
|||||||
self->callbacks.importfile = pk_default_importfile;
|
self->callbacks.importfile = pk_default_importfile;
|
||||||
self->callbacks.print = pk_default_print;
|
self->callbacks.print = pk_default_print;
|
||||||
self->callbacks.flush = pk_default_flush;
|
self->callbacks.flush = pk_default_flush;
|
||||||
self->callbacks.getchar = getchar;
|
self->callbacks.getchr = pk_default_getchr;
|
||||||
|
|
||||||
self->last_retval = *py_NIL();
|
self->last_retval = *py_NIL();
|
||||||
self->curr_exception = *py_NIL();
|
self->curr_exception = *py_NIL();
|
||||||
@ -810,7 +812,7 @@ int py_replinput(char* buf, int max_size) {
|
|||||||
printf(">>> ");
|
printf(">>> ");
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
int c = pk_current_vm->callbacks.getchar();
|
int c = pk_current_vm->callbacks.getchr();
|
||||||
if(c == EOF) return -1;
|
if(c == EOF) return -1;
|
||||||
|
|
||||||
if(c == '\n') {
|
if(c == '\n') {
|
||||||
|
@ -205,7 +205,7 @@ static bool builtins_input(int argc, py_Ref argv) {
|
|||||||
c11_sbuf buf;
|
c11_sbuf buf;
|
||||||
c11_sbuf__ctor(&buf);
|
c11_sbuf__ctor(&buf);
|
||||||
while(true) {
|
while(true) {
|
||||||
int c = py_callbacks()->getchar();
|
int c = py_callbacks()->getchr();
|
||||||
if(c == '\n' || c == '\r') break;
|
if(c == '\n' || c == '\r') break;
|
||||||
if(c == EOF) break;
|
if(c == EOF) break;
|
||||||
c11_sbuf__write_char(&buf, c);
|
c11_sbuf__write_char(&buf, c);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user