From 5d8267977cba8881204a9930f1f5e498a67f3b2e Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 2 Jan 2024 20:36:05 +0800 Subject: [PATCH] ... --- include/pocketpy/error.h | 2 +- src/pocketpy_c.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/pocketpy/error.h b/include/pocketpy/error.h index 7af21e21..d2465ae9 100644 --- a/include/pocketpy/error.h +++ b/include/pocketpy/error.h @@ -62,7 +62,7 @@ struct Exception { stack stacktrace; Exception(StrName type): type(type), is_re(true), _ip_on_error(-1), _code_on_error(nullptr), _self(nullptr) {} - PyObject* self(){ + PyObject* self() const{ PK_ASSERT(_self != nullptr); return _self; } diff --git a/src/pocketpy_c.cpp b/src/pocketpy_c.cpp index bac5ba50..0cf96911 100644 --- a/src/pocketpy_c.cpp +++ b/src/pocketpy_c.cpp @@ -496,10 +496,13 @@ bool pkpy_py_str(pkpy_vm* vm_handle) { bool pkpy_error(pkpy_vm* vm_handle, const char* name, pkpy_CString message) { VM* vm = (VM*) vm_handle; PK_ASSERT_NO_ERROR() - PyObject* e_t = vm->builtins->attr().try_get_likely_found(name); + PyObject* e_t = vm->_main->attr().try_get_likely_found(name); if(e_t == nullptr){ - e_t = vm->_t(vm->tp_exception); - std::cerr << "[warning] pkpy_error(): " << Str(name).escape() << " not found, fallback to 'Exception'" << std::endl; + e_t = vm->builtins->attr().try_get_likely_found(name); + if(e_t == nullptr){ + e_t = vm->_t(vm->tp_exception); + std::cerr << "[warning] pkpy_error(): " << Str(name).escape() << " not found, fallback to 'Exception'" << std::endl; + } } vm->_c.error = vm->call(e_t, VAR(std::string_view(message.data, message.size))); PK_OBJ_GET(Exception, vm->_c.error)._self = vm->_c.error;