From f397917ff590c63f5c39a5b3e5468eae08f73427 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 9 May 2023 14:05:05 +0800 Subject: [PATCH] ... --- src/base64.h | 4 ++-- src/cffi.h | 9 +++++---- src/io.h | 4 ++-- src/str.h | 1 - 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/base64.h b/src/base64.h index de5b3331..e7e577d1 100644 --- a/src/base64.h +++ b/src/base64.h @@ -172,7 +172,7 @@ void add_module_base64(VM* vm){ PyObject* mod = vm->new_module("base64"); // b64encode - vm->bind_static_method<1>(mod, "b64encode", [](VM* vm, ArgsView args){ + vm->bind_func<1>(mod, "b64encode", [](VM* vm, ArgsView args){ Bytes& b = CAST(Bytes&, args[0]); std::vector out(b.size() * 2); int size = base64_encode((const unsigned char*)b.data(), b.size(), out.data()); @@ -181,7 +181,7 @@ void add_module_base64(VM* vm){ }); // b64decode - vm->bind_static_method<1>(mod, "b64decode", [](VM* vm, ArgsView args){ + vm->bind_func<1>(mod, "b64decode", [](VM* vm, ArgsView args){ Bytes& b = CAST(Bytes&, args[0]); std::vector out(b.size()); int size = base64_decode(b.data(), b.size(), (unsigned char*)out.data()); diff --git a/src/cffi.h b/src/cffi.h index 6f97688b..2d219a15 100644 --- a/src/cffi.h +++ b/src/cffi.h @@ -12,11 +12,11 @@ namespace pkpy { return OBJ_GET(Type, vm->_modules[__x0]->attr(__x1)); \ } \ static PyObject* register_class(VM* vm, PyObject* mod) { \ - PyObject* type = vm->new_type_object(mod, #name, vm->tp_object); \ if(OBJ_NAME(mod) != #mod) { \ auto msg = fmt("register_class() failed: ", OBJ_NAME(mod), " != ", #mod); \ throw std::runtime_error(msg); \ } \ + PyObject* type = vm->new_type_object(mod, #name, vm->tp_object); \ T::_register(vm, mod, type); \ type->attr()._try_perfect_rehash(); \ return type; \ @@ -30,12 +30,13 @@ struct VoidP{ void* ptr; VoidP(void* ptr): ptr(ptr){} + VoidP(): ptr(nullptr){} static void _register(VM* vm, PyObject* mod, PyObject* type){ - vm->bind_static_method<1>(type, "__new__", CPP_NOT_IMPLEMENTED()); + vm->bind_default_constructor(type); - vm->bind_static_method<1>(type, "__repr__", [](VM* vm, ArgsView args){ - VoidP& self = CAST(VoidP&, args[0]); + vm->bind_method<0>(type, "__repr__", [](VM* vm, ArgsView args){ + VoidP& self = _CAST(VoidP&, args[0]); std::stringstream ss; ss << ""; return VAR(ss.str()); diff --git a/src/io.h b/src/io.h index 2e1dfe30..3806412a 100644 --- a/src/io.h +++ b/src/io.h @@ -47,9 +47,9 @@ struct FileIO { } static void _register(VM* vm, PyObject* mod, PyObject* type){ - vm->bind_static_method<2>(type, "__new__", [](VM* vm, ArgsView args){ + vm->bind_constructor<3>(type, [](VM* vm, ArgsView args){ return VAR_T(FileIO, - vm, CAST(Str&, args[0]).str(), CAST(Str&, args[1]).str() + vm, CAST(Str&, args[1]).str(), CAST(Str&, args[2]).str() ); }); diff --git a/src/str.h b/src/str.h index 0f458e27..3e2507e1 100644 --- a/src/str.h +++ b/src/str.h @@ -381,7 +381,6 @@ inline std::vector StrName::_r_interned; const StrName __class__ = StrName::get("__class__"); const StrName __base__ = StrName::get("__base__"); -const StrName __new__ = StrName::get("__new__"); const StrName __iter__ = StrName::get("__iter__"); const StrName __next__ = StrName::get("__next__"); const StrName __str__ = StrName::get("__str__");