diff --git a/include/pocketpy/cffi.h b/include/pocketpy/cffi.h index dd5c098e..802b8bb9 100644 --- a/include/pocketpy/cffi.h +++ b/include/pocketpy/cffi.h @@ -37,7 +37,6 @@ struct VoidP{ void* ptr; VoidP(void* ptr): ptr(ptr){} - VoidP(): ptr(nullptr){} bool operator==(const VoidP& other) const { return ptr == other.ptr; diff --git a/include/pocketpy/linalg.h b/include/pocketpy/linalg.h index 57710b98..c3bdc77b 100644 --- a/include/pocketpy/linalg.h +++ b/include/pocketpy/linalg.h @@ -234,7 +234,7 @@ struct Mat3x3{ bool is_affine() const{ float det = _11 * _22 - _12 * _21; - if(!isclose(det, 0)) return false; + if(isclose(det, 0)) return false; return _31 == 0.0f && _32 == 0.0f && _33 == 1.0f; } diff --git a/include/typings/c.pyi b/include/typings/c.pyi index d3365adc..3a0348fe 100644 --- a/include/typings/c.pyi +++ b/include/typings/c.pyi @@ -7,14 +7,13 @@ def memset(ptr: 'void_p', value: int, size: int) -> None: ... def memcpy(dst: 'void_p', src: 'void_p', size: int) -> None: ... class void_p: + def __init__(self, addr: int): ... def __add__(self, i: int) -> 'void_p': ... def __sub__(self, i: int) -> 'void_p': ... def __eq__(self, other: 'void_p') -> bool: ... def __ne__(self, other: 'void_p') -> bool: ... def hex(self) -> str: ... - @staticmethod - def from_hex(s: str) -> 'void_p': ... def read_char(self) -> int: ... def read_uchar(self) -> int: ... diff --git a/src/cffi.cpp b/src/cffi.cpp index 5369a44f..27e98605 100644 --- a/src/cffi.cpp +++ b/src/cffi.cpp @@ -3,15 +3,12 @@ namespace pkpy{ void VoidP::_register(VM* vm, PyObject* mod, PyObject* type){ - vm->bind_default_constructor(type); - - vm->bind_func<1>(type, "from_hex", [](VM* vm, ArgsView args){ - std::string s = CAST(Str&, args[0]).str(); - size_t size; - intptr_t ptr = std::stoll(s, &size, 16); - if(size != s.size()) vm->ValueError("invalid literal for void_p(): " + s); - return VAR_T(VoidP, (void*)ptr); + vm->bind_constructor<2>(type, [](VM* vm, ArgsView args){ + Type cls = PK_OBJ_GET(Type, args[0]); + i64 addr = CAST(i64, args[1]); + return vm->heap.gcnew(cls, reinterpret_cast(addr)); }); + vm->bind_method<0>(type, "hex", [](VM* vm, ArgsView args){ VoidP& self = _CAST(VoidP&, args[0]); return VAR(self.hex()); diff --git a/tests/40_class.py b/tests/40_class.py index 320c0bb4..3c167f37 100644 --- a/tests/40_class.py +++ b/tests/40_class.py @@ -109,11 +109,3 @@ class B(A): # assert B.a == 1 ...bug here assert B.b == 3 assert B.c == 4 - -import c - -class A(c.void_p): - pass - -a = A() -assert repr(a).startswith('