diff --git a/include/pybind11/internal/class.h b/include/pybind11/internal/class.h index 5cf5ea52..edd72924 100644 --- a/include/pybind11/internal/class.h +++ b/include/pybind11/internal/class.h @@ -40,7 +40,8 @@ public: auto info = &type_info::of(); int slot = ((std::is_same_v || ...) ? -1 : 0); - void* data = py_newobject(retv, steal(cls).index(), slot, sizeof(instance)); + void* data = + py_newobject(py_retval(), steal(cls).index(), slot, sizeof(instance)); new (data) instance{instance::Flag::Own, operator new (info->size), info}; return true; }, diff --git a/include/pybind11/internal/error.h b/include/pybind11/internal/error.h index 763d29f0..fbacb453 100644 --- a/include/pybind11/internal/error.h +++ b/include/pybind11/internal/error.h @@ -34,13 +34,9 @@ inline auto raise_call(Args&&... args) { using type = decltype(result); if constexpr(std::is_same_v) { - if(result != false) { - return result; - } + if(result != false) { return result; } } else if constexpr(std::is_same_v) { - if(result != -1) { - return result; - } + if(result != -1) { return result; } } else { static_assert(dependent_false, "invalid return type"); } @@ -84,10 +80,10 @@ class attribute_error : public std::runtime_error { inline object::operator bool () const { return raise_call(m_ptr); } -#define PKBIND_BINARY_OPERATOR(name, lop, rop) \ - inline object operator name (handle lhs, handle rhs) { \ - raise_call(lhs.ptr(), rhs.ptr(), lop, rop); \ - return object(retv, object::realloc_t{}); \ +#define PKBIND_BINARY_OPERATOR(name, lop, rop) \ + inline object operator name (handle lhs, handle rhs) { \ + raise_call(lhs.ptr(), rhs.ptr(), lop, rop); \ + return object::from_ret(); \ } PKBIND_BINARY_OPERATOR(==, __eq__, __eq__) diff --git a/include/pybind11/internal/kernel.h b/include/pybind11/internal/kernel.h index f9b1d92c..03dde561 100644 --- a/include/pybind11/internal/kernel.h +++ b/include/pybind11/internal/kernel.h @@ -18,21 +18,6 @@ namespace pkbind { class handle; -struct retv_t { - py_Ref value; - - void operator= (py_Ref ref) & { py_assign(value, ref); } - - operator py_Ref () & { - assert(value && "return value is not initialized"); - return value; - } - - void operator= (handle value) &; - - operator handle () &; -}; - /// hold the object long time. struct object_pool { inline static int cache = -1; @@ -143,8 +128,6 @@ private: void (*init)(T&) = nullptr; }; -inline retv_t retv; - inline std::unordered_map* m_type_map = nullptr; } // namespace pkbind diff --git a/include/pybind11/internal/object.h b/include/pybind11/internal/object.h index dd1b6502..1d52f03a 100644 --- a/include/pybind11/internal/object.h +++ b/include/pybind11/internal/object.h @@ -261,7 +261,7 @@ public: object(handle h, ref_t) : handle(h) {} - static object from_ret() { return object(retv, realloc_t{}); } + static object from_ret() { return object(py_retval(), realloc_t{}); } operator object_pool::object_ref () const { return {m_ptr, m_index}; } @@ -281,13 +281,6 @@ T borrow(handle h) { return T(h, object::realloc_t{}); } -inline void retv_t::operator= (handle h) & { py_assign(value, h.ptr()); } - -inline retv_t::operator handle () & { - assert(value && "return value is not initialized"); - return value; -} - static_assert(std::is_trivially_copyable_v); static_assert(std::is_trivially_copyable_v); diff --git a/include/pybind11/internal/types.h b/include/pybind11/internal/types.h index 38e2de7e..d37a5ebc 100644 --- a/include/pybind11/internal/types.h +++ b/include/pybind11/internal/types.h @@ -101,7 +101,7 @@ public: iterator& operator++ () { int result = raise_call(m_ptr); if(result == 1) { - m_value = object(retv, realloc_t{}); + m_value = object::from_ret(); } else if(result == 0) { m_value = object(); } @@ -125,7 +125,7 @@ private: template iterator interface::begin() const { raise_call(ptr()); - return iterator(retv); + return iterator(py_retval()); } template diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 40ca61b9..fe5565de 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -16,9 +16,6 @@ inline bool initialized = false; inline void initialize(int object_pool_size = 1024) { if(!initialized) { py_initialize(); } - // initialize ret. - retv.value = py_retval(); - // initialize object pool. object_pool::initialize(object_pool_size);