blueloveTH 2 лет назад
Родитель
Сommit
5d8267977c
2 измененных файлов с 7 добавлено и 4 удалено
  1. 1 1
      include/pocketpy/error.h
  2. 6 3
      src/pocketpy_c.cpp

+ 1 - 1
include/pocketpy/error.h

@@ -62,7 +62,7 @@ struct Exception {
     stack<ExceptionLine> 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;
     }

+ 6 - 3
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;