diff --git a/3rd/periphery/src/periphery.c b/3rd/periphery/src/periphery.c index 76cbe028..c79ed2d7 100644 --- a/3rd/periphery/src/periphery.c +++ b/3rd/periphery/src/periphery.c @@ -142,7 +142,8 @@ static bool gpio_config__get_label(int argc, py_Ref argv) { return true; } static py_Type register__gpio_config(py_GlobalRef mod) { - py_Type type = py_newtype("gpio_config", tp_object, mod, NULL); + py_Type type = py_newtype("gpio_config", tp_stdc_Memory, mod, NULL); + py_newint(py_emplacedict(py_tpobject(type), py_name("size")), sizeof(gpio_config_t)); py_bindmethod(type, "__new__", gpio_config__new__); py_bindmethod(type, "__init__", gpio_config__init__); py_bindproperty(type, "direction", gpio_config__get_direction, gpio_config__set_direction); @@ -228,7 +229,8 @@ static bool periphery_version__get_commit_id(int argc, py_Ref argv) { return true; } static py_Type register__periphery_version(py_GlobalRef mod) { - py_Type type = py_newtype("periphery_version", tp_object, mod, NULL); + py_Type type = py_newtype("periphery_version", tp_stdc_Memory, mod, NULL); + py_newint(py_emplacedict(py_tpobject(type), py_name("size")), sizeof(periphery_version_t)); py_bindmethod(type, "__new__", periphery_version__new__); py_bindmethod(type, "__init__", periphery_version__init__); py_bindproperty(type, "major", periphery_version__get_major, periphery_version__set_major); diff --git a/ffigen/ffigen/struct.py b/ffigen/ffigen/struct.py index 7ab476cd..9ba76540 100644 --- a/ffigen/ffigen/struct.py +++ b/ffigen/ffigen/struct.py @@ -71,7 +71,8 @@ def gen_struct(w: Writer, pyi_w: Writer, struct: Struct): w.write(f'static py_Type register__{identifier}(py_GlobalRef mod) {{') w.indent() - w.write(f'py_Type type = py_newtype("{identifier}", tp_object, mod, NULL);') + w.write(f'py_Type type = py_newtype("{identifier}", tp_stdc_Memory, mod, NULL);') + w.write(f'py_newint(py_emplacedict(py_tpobject(type), py_name("size")), sizeof({name}));') w.write(f'py_bindmethod(type, "__new__", {identifier}__new__);') w.write(f'py_bindmethod(type, "__init__", {identifier}__init__);')