-
Notifications
You must be signed in to change notification settings - Fork 953
Closed
Description
Related to #220, #407
cc: @konstin @joar @davidhewitt
So as I said now I'm investigating safer layout than our current pyclass, which is constructed (roughly) by
let ptr = alloc(...); // *mut PyObject
let align = std::mem::align_of::<Self>(); // Self = pyclass
// Suppose
// struct PyClassLayout { |\
// base: Self::BASE, | offset
// self_: PyClass |/
// }
let offset = (self::BASE::SIZE + align - 1) / align * align;
let self_ptr = (ptr as *mut u8).offset(Self::OFFSET) as *mut T;And what I found problematic is <Py~ as PyTypeInfo>::SIZE is std::mem::size_of::<ffi::PyObject> for all Py~ types, which is not true.
Actually, PyDictObject is defined as (roughly)
typedef struct {
PyObject ob_base;
Py_ssize_t ma_used;
uint64_t ma_version_tag;
PyDictKeysObject *ma_keys;
PyObject **ma_values;
} PyDictObject;So it's size 64bit * 4 = 32bytes larger than PyObject.
Is it the cause of segfault?
Reactions are currently unavailable