This commit is contained in:
blueloveTH 2025-06-07 02:19:55 +08:00
parent c1e4440a9f
commit 70e824a6b6
3 changed files with 6 additions and 4 deletions

View File

@ -77,7 +77,7 @@ typedef struct py_Callbacks {
/// Flush the output buffer of `print`.
void (*flush)();
/// Used by `input` to get a character.
int (*getchar)();
int (*getchr)();
/// Used by `gc.collect()` to mark extra objects for garbage collection.
void (*gc_mark)(void (*f)(py_Ref val, void* ctx), void* ctx);
} py_Callbacks;

View File

@ -32,6 +32,8 @@ static void pk_default_print(const char* data) { printf("%s", data); }
static void pk_default_flush() { fflush(stdout); }
static int pk_default_getchr() { return getchar(); }
void LineProfiler__tracefunc(py_Frame* frame, enum py_TraceEvent event) {
LineProfiler* self = &pk_current_vm->line_profiler;
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.print = pk_default_print;
self->callbacks.flush = pk_default_flush;
self->callbacks.getchar = getchar;
self->callbacks.getchr = pk_default_getchr;
self->last_retval = *py_NIL();
self->curr_exception = *py_NIL();
@ -810,7 +812,7 @@ int py_replinput(char* buf, int max_size) {
printf(">>> ");
while(true) {
int c = pk_current_vm->callbacks.getchar();
int c = pk_current_vm->callbacks.getchr();
if(c == EOF) return -1;
if(c == '\n') {

View File

@ -205,7 +205,7 @@ static bool builtins_input(int argc, py_Ref argv) {
c11_sbuf buf;
c11_sbuf__ctor(&buf);
while(true) {
int c = py_callbacks()->getchar();
int c = py_callbacks()->getchr();
if(c == '\n' || c == '\r') break;
if(c == EOF) break;
c11_sbuf__write_char(&buf, c);