remove retv.

This commit is contained in:
ykiko 2024-09-22 19:38:15 +08:00
parent bf8b91b9f8
commit 5e156d9d0c
6 changed files with 11 additions and 41 deletions

View File

@ -40,7 +40,8 @@ public:
auto info = &type_info::of<T>();
int slot = ((std::is_same_v<dynamic_attr, Args> || ...) ? -1 : 0);
void* data = py_newobject(retv, steal<type>(cls).index(), slot, sizeof(instance));
void* data =
py_newobject(py_retval(), steal<type>(cls).index(), slot, sizeof(instance));
new (data) instance{instance::Flag::Own, operator new (info->size), info};
return true;
},

View File

@ -34,13 +34,9 @@ inline auto raise_call(Args&&... args) {
using type = decltype(result);
if constexpr(std::is_same_v<type, bool>) {
if(result != false) {
return result;
}
if(result != false) { return result; }
} else if constexpr(std::is_same_v<type, int>) {
if(result != -1) {
return result;
}
if(result != -1) { return result; }
} else {
static_assert(dependent_false<type>, "invalid return type");
}
@ -87,7 +83,7 @@ inline object::operator bool () const { return raise_call<py_bool>(m_ptr); }
#define PKBIND_BINARY_OPERATOR(name, lop, rop) \
inline object operator name (handle lhs, handle rhs) { \
raise_call<py_binaryop>(lhs.ptr(), rhs.ptr(), lop, rop); \
return object(retv, object::realloc_t{}); \
return object::from_ret(); \
}
PKBIND_BINARY_OPERATOR(==, __eq__, __eq__)

View File

@ -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<std::type_index, py_Type>* m_type_map = nullptr;
} // namespace pkbind

View File

@ -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<name>);
static_assert(std::is_trivially_copyable_v<handle>);

View File

@ -101,7 +101,7 @@ public:
iterator& operator++ () {
int result = raise_call<py_next>(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 <typename Dervied>
iterator interface<Dervied>::begin() const {
raise_call<py_iter>(ptr());
return iterator(retv);
return iterator(py_retval());
}
template <typename Dervied>

View File

@ -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);