From 2dae9de0c39e0f7838c1b1c491b09546d24a67fc Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 15 Aug 2024 15:49:01 +0800 Subject: [PATCH] fix a bug --- include/pocketpy/interpreter/vm.h | 1 + src/interpreter/vm.c | 2 +- src/public/py_object.c | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/pocketpy/interpreter/vm.h b/include/pocketpy/interpreter/vm.h index 163594d8..be8287f5 100644 --- a/include/pocketpy/interpreter/vm.h +++ b/include/pocketpy/interpreter/vm.h @@ -71,6 +71,7 @@ bool pk__normalize_index(int* index, int length); void pk__mark_value(py_TValue*); void pk__mark_namedict(NameDict*); void pk__tp_set_marker(py_Type type, void (*gc_mark)(void*)); +bool pk__object_new(int argc, py_Ref argv); bool pk_wrapper__self(int argc, py_Ref argv); bool pk_wrapper__NotImplementedError(int argc, py_Ref argv); diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index 4eb376d4..bc6ed1d7 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -486,7 +486,7 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall } if(p0->type == tp_nativefunc) { - if(kwargc) { + if(kwargc && p0->_cfunc != pk__object_new) { TypeError("nativefunc does not accept keyword arguments"); return RES_ERROR; } diff --git a/src/public/py_object.c b/src/public/py_object.c index 1cc97e55..168800c8 100644 --- a/src/public/py_object.c +++ b/src/public/py_object.c @@ -2,7 +2,7 @@ #include "pocketpy/common/sstream.h" #include "pocketpy/pocketpy.h" -static bool object__new__(int argc, py_Ref argv) { +bool pk__object_new(int argc, py_Ref argv) { if(argc == 0) return TypeError("object.__new__(): not enough arguments"); py_Type cls = py_totype(py_arg(0)); py_TypeInfo* ti = c11__at(py_TypeInfo, &pk_current_vm->types, cls); @@ -110,7 +110,7 @@ static bool type__module__(int argc, py_Ref argv) { void pk_object__register() { // TODO: use staticmethod - py_bindmagic(tp_object, __new__, object__new__); + py_bindmagic(tp_object, __new__, pk__object_new); py_bindmagic(tp_object, __hash__, object__hash__); py_bindmagic(tp_object, __eq__, object__eq__);