From 3082645733e4a6861be70b3c5dc2e131ec768a81 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 2 May 2024 17:22:56 +0800 Subject: [PATCH] remove unnecessary `_()` --- docs/bindings.md | 7 ++----- include/pocketpy/bindings.h | 15 +++++++-------- include/pocketpy/linalg.h | 4 ---- src/array2d.cpp | 2 -- src/modules.cpp | 2 -- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/docs/bindings.md b/docs/bindings.md index c6063fa6..9cf3618e 100644 --- a/docs/bindings.md +++ b/docs/bindings.md @@ -122,9 +122,6 @@ struct wrapped__Point{ // wrapped value Point value; - // special method _ returns a pointer of the wrapped value - Point* _() { return &value; } - // define default constructors wrapped__Point() = default; wrapped__Point(const wrapped__Point&) = default; @@ -136,9 +133,9 @@ struct wrapped__Point{ static void _register(VM* vm, PyObject* mod, PyObject* type){ // wrap field x - PY_FIELD(wrapped__Point, "x", x) + PY_FIELD(wrapped__Point, "x", value.x) // wrap field y - PY_FIELD(wrapped__Point, "y", y) + PY_FIELD(wrapped__Point, "y", value.y) // __init__ method vm->bind(type, "__init__(self, x, y)", [](VM* vm, ArgsView args){ diff --git a/include/pocketpy/bindings.h b/include/pocketpy/bindings.h index 92cef6de..9881f54a 100644 --- a/include/pocketpy/bindings.h +++ b/include/pocketpy/bindings.h @@ -154,30 +154,29 @@ void _bind(VM* vm, PyObject* obj, const char* sig, Ret(T::*func)(Params...)){ /*****************************************************************/ #define PY_STRUCT_LIKE(wT) \ - using vT = std::remove_pointer_t()._())>; \ - static_assert(std::is_trivially_copyable::value); \ + static_assert(std::is_trivially_copyable::value); \ type->attr().set("__struct__", vm->True); \ vm->bind_func<1>(type, "from_struct", [](VM* vm, ArgsView args){ \ C99Struct& s = CAST(C99Struct&, args[0]); \ - if(s.size != sizeof(vT)) vm->ValueError("size mismatch"); \ + if(s.size != sizeof(wT)) vm->ValueError("size mismatch"); \ PyObject* obj = vm->new_user_object(); \ - memcpy(_CAST(wT&, obj)._(), s.p, sizeof(vT)); \ + memcpy(&_CAST(wT&, obj), s.p, sizeof(wT)); \ return obj; \ }, {}, BindType::STATICMETHOD); \ vm->bind_method<0>(type, "to_struct", [](VM* vm, ArgsView args){ \ wT& self = _CAST(wT&, args[0]); \ - return vm->new_user_object(self._(), sizeof(vT)); \ + return vm->new_user_object(&self, sizeof(wT)); \ }); \ vm->bind_method<0>(type, "addr", [](VM* vm, ArgsView args){ \ wT& self = _CAST(wT&, args[0]); \ - return vm->new_user_object(self._()); \ + return vm->new_user_object(&self); \ }); \ vm->bind_method<0>(type, "copy", [](VM* vm, ArgsView args){ \ wT& self = _CAST(wT&, args[0]); \ - return vm->new_user_object(*self._()); \ + return vm->new_user_object(self); \ }); \ vm->bind_method<0>(type, "sizeof", [](VM* vm, ArgsView args){ \ - return VAR(sizeof(vT)); \ + return VAR(sizeof(wT)); \ }); \ vm->bind__eq__(PK_OBJ_GET(Type, type), [](VM* vm, PyObject* _0, PyObject* _1){ \ wT& self = _CAST(wT&, _0); \ diff --git a/include/pocketpy/linalg.h b/include/pocketpy/linalg.h index 55df1586..6e067529 100644 --- a/include/pocketpy/linalg.h +++ b/include/pocketpy/linalg.h @@ -7,7 +7,6 @@ namespace pkpy{ inline bool isclose(float a, float b){ return std::fabs(a - b) < 1e-4; } struct Vec2{ - Vec2* _() { return this; } static void _register(VM* vm, PyObject* mod, PyObject* type); float x, y; @@ -33,7 +32,6 @@ struct Vec2{ }; struct Vec3{ - Vec3* _() { return this; } static void _register(VM* vm, PyObject* mod, PyObject* type); float x, y, z; @@ -58,7 +56,6 @@ struct Vec3{ }; struct Vec4{ - Vec4* _() { return this; } static void _register(VM* vm, PyObject* mod, PyObject* type); float x, y, z, w; @@ -82,7 +79,6 @@ struct Vec4{ }; struct Mat3x3{ - Mat3x3* _(){ return this; } static void _register(VM* vm, PyObject* mod, PyObject* type); union { diff --git a/src/array2d.cpp b/src/array2d.cpp index 4bd489f3..d6d03b53 100644 --- a/src/array2d.cpp +++ b/src/array2d.cpp @@ -17,8 +17,6 @@ struct Array2d{ numel = 0; } - Array2d* _() { return this; } - void init(int n_cols, int n_rows){ this->n_cols = n_cols; this->n_rows = n_rows; diff --git a/src/modules.cpp b/src/modules.cpp index 24606576..c05ec448 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -36,8 +36,6 @@ struct PyStructTime{ tm_isdst = tm->tm_isdst; } - PyStructTime* _() { return this; } - static void _register(VM* vm, PyObject* mod, PyObject* type){ vm->bind_notimplemented_constructor(type); PY_READONLY_FIELD(PyStructTime, "tm_year", tm_year);