blueloveTH 2 mēneši atpakaļ
vecāks
revīzija
9d2cb89b24
2 mainītis faili ar 6 papildinājumiem un 3 dzēšanām
  1. 4 2
      3rd/periphery/src/periphery.c
  2. 2 1
      ffigen/ffigen/struct.py

+ 4 - 2
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);

+ 2 - 1
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__);')