Updated Build Troubleshooting (markdown)

master
Jim Mussared 2022-09-19 21:45:53 +10:00
rodzic a65433826d
commit d026052dd4
1 zmienionych plików z 29 dodań i 3 usunięć

@ -4,7 +4,9 @@
## DEFINE_CONST_OBJ_TYPE
If you see errors involving the `DEFINE_CONST_OBJ_TYPE` macro, or anything to do with the definition of `mp_obj_type_t` then see #8813. You will need to update any definition of types in your custom modules from:
If you see errors involving the `DEFINE_CONST_OBJ_TYPE` macro, or anything to do with the definition of `mp_obj_type_t` then see [#8813](https://github.com/micropython/micropython/pull/8813). This PR changed the way object types are defined, in order to save significant amounts of ROM. The `mp_obj_type_t` struct previously always stored 12 pointers to various functions that customise the type's behavior. However this meant that all types, even very simple ones, always used 12 words of ROM. Now the type only uses as much ROM as it has slots defined. Unfortunately the way this is represented can't be easily done using plain C initialisers, so the implementation of this is hidden in a new macro.
You will need to update any definition of types in your custom modules from:
```c
const mp_obj_type_t mp_type_foo = {
@ -21,8 +23,8 @@ to
```c
MP_DEFINE_CONST_OBJ_TYPE(
mp_type_array,
MP_QSTR_array,
mp_type_foo,
MP_QSTR_foo,
MP_TYPE_FLAG_NONE,
print, array_print,
make_new, array_make_new,
@ -35,6 +37,30 @@ Note that a trailing comma after the last argument is not allowed.
The first three arguments (symbol name, type name QSTR, flags) are required, and then a variable number of "slots" can be specified. If you don't have any flags (most types), then use `MP_TYPE_FLAG_NONE`.
If your type was previously static, i.e.
```c
STATIC const mp_obj_type_t mp_type_foo = {
```
then you can add `STATIC` in front of the `MP_DEFINE_CONST_OBJ_TYPE`.
```c
MP_DEFINE_CONST_OBJ_TYPE(
mp_type_foo,
...
```
In most cases this change should be mechanical, pass the type, name, and flags as the first three arguments, then just replace all remaining `.a = b,` with `a, b,`. The one exception is `getiter` & `iternext`, see the next section.
If your code need to access properties on a give type, e.g. `mp_type_foo.make_new` then it needs to be updated to use the accessor macros.
```c
MP_OBJ_TYPE_HAS_SLOT(type, slot) # True if type->slot is non-NULL
MP_OBJ_TYPE_GET_SLOT(type, slot) # equivalent to type->slot (but you must know that the slot is set)
MP_OBJ_TYPE_GET_SLOT_OR_NULL(type, slot) # marginally less efficient but will return NULL if the slot is not set
```
## getiter/iternext
If you see errors about `getiter` and/or `iternext` then also see #8813.