With this commit, if file open fails, the object will have fd = -1 (closed)
and the finaliser will not attempt to close anything.
Fixes issue #13672.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This combines the argument parsing and checking for the machine.SPI.init()
and machine.SPI() interfaces.
The only real difference was unspecified arguments in init() mean to keep
the same value, while in new they get default values.
Behavior has changed for passing the "id" argument to init(). On other
ports this isn't allowed. But on esp32 it would change the SPI controller
of the static SPI instance to the new id. This results in multiple static
spi objects for the same controller and they would fight over which one has
inconsistent mpy vs esp-idf state. This has been changed to not allow "id"
with init(), like other ports.
In a few causes, a loop is used over arguments that are handled the same
way instead of cut & pasting the same stanza of code for each argument.
The init_internal function had a lot of arguments, which is not efficient
to pass. Pass the args mp_arg_val_t array instead as a single argument.
This reduced both the number of C lines and the compiled code size.
Summary of code size change: Two argument lists of 72 bytes are replaced
by a single shared 72 byte list. New shared argument parsing code is small
enough to be inlined, but is still efficient enough to shrink the overall
code size by 349 bytes of the three argument handlering functions.
add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-349 (-349)
Function old new delta
machine_hw_spi_make_new 255 203 -52
machine_hw_spi_init 122 67 -55
machine_hw_spi_init_internal 698 456 -242
Total: Before=1227667, After=1227318, chg -0.03%
add/remove: 2/0 grow/shrink: 0/2 up/down: 92/-144 (-52)
Data old new delta
spi_allowed_args - 72 +72
defaults$0 - 20 +20
allowed_args$1 240 168 -72
allowed_args$0 1080 1008 -72
Total: Before=165430, After=165378, chg -0.03%
add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0)
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
The size of the flash varies among MCU variants. Instead of requiring a
build-time variable to configure this, compute it at runtime using the
special device information word accessible through the FLASH_SIZE macro.
This feature is currently only implemented for H5 MCUs, but can be extended
to others.
Signed-off-by: Damien George <damien@micropython.org>
This is now easy to support, since the first machine-word of a native
function tells how to find the prelude, from which the function name can be
extracted in the same way as for bytecode.
Signed-off-by: Damien George <damien@micropython.org>
Now native functions and native generators have similar behaviour: the
first machine-word of their code is an index to get to the prelude. This
simplifies the handling of these types of functions, and also reduces the
size of the emitted native machine code by no longer requiring special code
at the start of the function to load a pointer to the prelude.
Signed-off-by: Damien George <damien@micropython.org>
Viper functions are quite different to native functions and benefit from
being a separate type. For example, viper functions don't have a bytecode-
style prelude, and don't support generators or default arguments.
Signed-off-by: Damien George <damien@micropython.org>
They are no longer used. The new `mp_obj_malloc_with_finaliser()` macros
should be used instead, which force the setting of the `base.type` field.
And there's always `m_malloc_with_finaliser()` if needed.
Signed-off-by: Damien George <damien@micropython.org>
Following 709e8328d9.
Using this helps to reduce code size. And it ensure that the type is
always set as soon as the object is allocated, which is important for the
GC to function correctly.
Signed-off-by: Damien George <damien@micropython.org>
MICROPY_GIT_HASH was removed in 69e34b6b6b
but it is useful for, and used by, third-party code to tell which hash of
MicroPython is used.
Signed-off-by: Damien George <damien@micropython.org>
Follow up to 35dd959133, allows explicitly
adding the unix-ffi library path from the command line.
This option is needed when building unix-ffi manifests in micropython-lib
CI.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Allows bytecode itself to be used instead of an mp_raw_code_t in the simple
and common cases of a bytecode function without any children.
This can be used to further reduce frozen code size, and has the potential
to optimise other areas like importing.
Signed-off-by: Damien George <damien@micropython.org>
To simplify their access and reduce code size.
The `scope_flags` member is only ever used to determine if a function is a
generator or not, so make it reflect that fact as a bool type.
Signed-off-by: Damien George <damien@micropython.org>
The `asm_n_pos_args` and `asm_type_sig` members of `mp_raw_code_t` are only
used for raw codes of type MP_CODE_NATIVE_ASM, which are rare, for example
in frozen code. So using a truncated `mp_raw_code_t` in these cases helps
to reduce frozen code size on targets that have MICROPY_EMIT_INLINE_ASM
enabled.
With this, change in firmware size of RPI_PICO builds is -648.
Signed-off-by: Damien George <damien@micropython.org>
The mp_raw_code_t struct has been reordered and some members resized. The
`n_pos_args` member is renamed to `asm_n_pos_args`, and `type_sig` renamed
to `asm_type_sig` to indicate that these are used only for the inline-asm
emitters. These two members are also grouped together in the struct.
The justifications for resizing the members are:
- `fun_data_len` can be 32-bits without issue
- `n_children` is already limited to 16-bits by
`mp_emit_common_t::ct_cur_child`
- `scope_flags` is already limited to 16-bits by `scope_t::scope_flags`
- `prelude_offset` is already limited to 16-bits by the argument to
`mp_emit_glue_assign_native()`
- it's reasonable to limit the maximim number of inline-asm arguments to 12
(24 bits for `asm_type_sig` divided by 2)
This change helps to reduce frozen code size (and in some cases RAM usage)
in the following cases:
- 64-bit targets
- builds with MICROPY_PY_SYS_SETTRACE enabled
- builds with MICROPY_EMIT_MACHINE_CODE enabled but MICROPY_EMIT_INLINE_ASM
disabled
With this change, unix 64-bit builds are -4080 bytes in size. Bare-metal
ports like rp2 are unchanged (because mp_raw_code_t is still 32 bytes on
those 32-bit targets).
Signed-off-by: Damien George <damien@micropython.org>
With these changes IPv6 works on the rp2 port (and possibly others that use
the lwIP socket implementation).
Things that have been tested and work:
- Neighbour solicitation for v6 link local address.
- Ping of v6 link-local address.
- Receiving a SLAAC address via router advertisement.
- Ping a v6 address allocated via SLAAC.
- Perform an outgoing connection to a routed v6-address (via default
gateway).
- Create a listening IPv6 wildcard socked bound to ::, and trying to access
it via link-local, SLAAC, and IPv4 (to ensure the dual-stack binding
works).
Things that could be improved:
- socket.socket().getaddrinfo only returns the v4 address. It could also
return v6 addresses (getaddrinfo is actively programmed to only return a
single address, and this is the v4-address by default, with fallback to
the v6 address if both are enabled).
Signed-off-by: Felix Dörre <felix@dogcraft.de>
The Python BLE IRQ handler will most likely run on the NimBLE task, so its
C stack must be large enough to accommodate reasonably complicated Python
code (eg a few call depths). So increase this stack size.
Also increase the headroom from 1024 to 2048 bytes. This is needed because
(1) the esp32 architecture uses a fair amount of stack in general; and (2)
by the time execution gets to setting the Python stack top via
`mp_stack_set_top()` in this interlock code, about 600 bytes of stack are
already used, which reduces the amount available for Python.
Fixes issue #12349.
Signed-off-by: Damien George <damien@micropython.org>
In case callbacks must run (eg a disconnect event happens during the
deinit) and the GIL must be obtained to run the callback.
Fixes part of issue #12349.
Signed-off-by: Damien George <damien@micropython.org>
PPP is not that commonly used, let it be turned off in the board config to
save space. It is still on by default.
On an basic ESP32-S3 build, turning off PPP with LWIP still on saves ~35 kB
of codend 4 kB of data.
text data bss dec hex filename
1321257 304296 2941433 4566986 45afca before-ppp-off.elf
1285101 299920 2810305 4395326 43113e after-ppp-off.elf
-------------------------------
-36156 -4376 -56
Note that the BSS segment size includes all NOBITS sections in ELF file.
Some of these are aligned to 64kB chunk sized dummy blocks, I think for
alignment to MMU boundaries, and these went down by 1 block each, so 128
kiB of BSS is not really part of the binary size reduction.
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
For mimxrt, nrf, renesas-ra, rp2 and samd ports, this commit implements
similar behaviour to the stm32 port, where USB is only brought up after
boot.py completes execution.
Currently this doesn't add any useful functionality (and may break
workflows that depend on USB-CDC being live in boot.py), however it's a
precondition for more usable workflows with USB devices defined in
Python (allows setting up USB interfaces in boot.py before the device
enumerates for the first time).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The C99 standard states:
6.8.6.4 The return statement Constraints
A return statement with an expression shall not appear in a function
whose return type is void. A return statement without an expression
shall only appear in a function whose return type is void.
And when `-pedantic` is enabled the compiler gives an error.
Signed-off-by: Yoctopuce <dev@yoctopuce.com>
Obtaining the stack-top via a few function calls may yield a pointer which
is too deep within the stack. So require the user to obtain it from a
higher level (or via some other means).
Fixes issue #11781.
Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
It's rare to freeze .mpy files without specifying a qstr header from a
firmware build, but it can be useful for testing, eg
`mpy-tool.py -f test.mpy`. Fix this case so static qstrs are properly
excluded from the frozen qstr list.
Signed-off-by: Damien George <damien@micropython.org>
Similar to the previous commit but for MP_BLUETOOTH_IRQ_GATTC_READ_DONE:
the pending_value_handle needs to be reset before calling
mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ
handler, which may in turn call back into BTstack to perform an action like
a write. In that case the pending_value_handle will need to be available
for the write/read/etc to proceed.
Fixes issue #13634.
Signed-off-by: Damien George <damien@micropython.org>
The pending_value_handle needs to be freed and reset before calling
mp_bluetooth_gattc_on_read_write_status(), which will call the Python IRQ
handler, which may in turn call back into BTstack to perform an action like
a write. In that case the pending_value_handle will need to be available
for the write/read/etc to proceed.
Fixes issue #13611.
Signed-off-by: Damien George <damien@micropython.org>
This commit changes how library packages are searched for when a manifest
file is loaded: there is now simply a list of library paths that is
searched in order for the given package. This list defaults to the
main directories in micropython-lib, but can be added to -- either appended
or prepended -- by using `add_library()`.
In particular the way unix-ffi library packages are searched has changed,
because the `unix_ffi` argument to `require()` is now removed. Instead, if
a build wants to include packages from micropython-lib/unix-ffi, then it
must explicitly add this to the list of paths to search using:
add_library("unix-ffi", "$(MPY_LIB_DIR)/unix-ffi")
Work done in collaboration with Jim Mussared.
Signed-off-by: Damien George <damien@micropython.org>
All the other workflow YAML files use vertical whitespace around top-level
items.
Also remove spurious comment, the features in the linked doc aren't
actually used in this workflow (any more?).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>