An attempt to build the coverage module into the nanbox binary failed, but
pointed out that these sites needed explicit conversion from pointer to
object.
Signed-off-by: Jeff Epler <jepler@gmail.com>
When `MICROPY_PY_SYS_SETTRACE` was enabled, a crash was seen in the
qemu_mips build. It seems likely that this was due to these added fields
not being initialized.
Signed-off-by: Jeff Epler <jepler@gmail.com>
The unix coverage variant should have all features enabled, so they can be
tested for coverage. Therefore, enabled `MICROPY_PY_SYS_SETTRACE`.
Signed-off-by: Jeff Epler <jepler@gmail.com>
In the case where an mpz number is zero, its `len` is 0 and its `dig` is
NULL. In that case, decrementing NULL via `d--` is undefined behavior
according to the C specification.
Restructuring the loops in this way avoids undefined behavior.
Also, ensure that these cases are tested in the coverage test. This
doesn't make much difference now, but would otherwise cause errors later
when the undefined behavior sanitizer is employed in CI.
Signed-off-by: Jeff Epler <jepler@gmail.com>
This commit fixes CI test runs for the `nanbox` target, which were
broken by the unconditional native emitter code output changes in the
test runner.
The `nanbox` configuration does not enable native emitters of any kind,
and with a full test run that includes executing emitted native code
things would break when doing CI runs.
This is worked around by introducing a common subset of tests that do
not involve the native emitter, and a more comprehensive set of tests
that include both non-emitter and emitter tests. The `nanbox` CI test
run will stop at the first subset, whilst other configurations will run
that and execute further tests.
Function names have been kept the same for steps that involve native
code, with the `nanbox` subset having another one. This should not
trigger any breakage in existing CI configurations or external scripts.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Test modified to reschedule itself based on a flag setting. Without the
change in the parent commit, this test executes the callback indefinitely
and hangs but with the change it runs only once each time
mp_handle_pending() is called.
Modified-by: Angus Gratton <angus@redyak.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
If the BLE radio stops responding before deinit is called the function can
get stuck waiting for an event that is never received, particularly if the
radio is external or on a separate core.
This commit adds a timeout, similar to the timeout already used in the init
function. Updated for nimble, btstack, esp32 and zephyr bindings.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This commit fixes thread-related compilation issues under Android using
Termux as its runtime environment.
On Android's libc (Bionic) thread cancellation is not implemented, but
the Unix port uses that mechanism to provide asynchronous thread
termination. In this commit there is a workaround for that, by adding a
new signal handler to each newly created thread, whose callback simply
exits the thread. Threads are then sent the new signal rather than
being explicitly cancelled, which in turn trigger the signal handler to
stop the thread execution at the next possible occasion.
This makes the cancellation behaviour differ slightly on Android, as
threads are probably going to linger a little bit more since the method
introduced in this commit is equivalent to setting
PTHREAD_CANCEL_DEFERRED as the thread cancellation type. On the other
hand there are no guarantees of immediate cancellation using
PTHREAD_CANCEL_ASYNCHRONOUS either.
This fixes the pthread-related issues reported in #16259.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
POSIX.1-2008 ensures realpath() give a dynamically allocated buffer if
NULL is passed (which is also true for ports/windows/realpath.c),
avoiding an explicit call to malloc() and use of PATH_MAX, which may be
undefined on some systems.
Signed-off-by: David Yang <mmyangfl@gmail.com>
In order to provide test coverage for the previous commit, `os.uname()`
support is added to the unix coverage build.
Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
This is a generic interface to allow querying and modifying the read-only
memory area of a device, if it has such an area.
Signed-off-by: Damien George <damien@micropython.org>
Allows refactoring the existing thread_mutex atomic section support to use
the new recursive mutex type.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This allows coverage to test MicroPython-specific features such as
the tracked alloc cleanups added in the parent commit.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
On 64-bit systems this should have no effect.
On 32-bit systems it will force 64-bit file sizes and fixes directory
listing on certain 32-bit ports. This option should work on pretty much
all 32-bit systems these days.
Signed-off-by: Damien George <damien@micropython.org>
The `MICROPY_FORCE_PLAT_ALLOC_EXEC` config option was made obsolete by
commit 9796625457, so remove it.
Signed-off-by: Damien George <damien@micropython.org>
This tracing was originally needed for three reasons:
1. To trace object/raw-code pointers embedded in native code, eg from
@micropython.native functions.
2. To trace pointers to BSS/rodata from relocated viper code.
3. For libffi tracing.
The tracing in point 1 was made unnecessary long ago in commit
7d4b6cc868 (see also commit
bbccb0f630 which removed scanning of native
code on the esp8266 port).
Since the previous commit, point 2 is no longer needed.
For point 3, this was made unnecessary in the recent commit
9796625457.
Signed-off-by: Damien George <damien@micropython.org>
This commit clears the upper 32 bits of returned `uint32_t` values,
which are handled as `unsigned int`s by the MicroPython runtime and
thus could be extended to 64 bits on some platforms.
RV64 holds 32-bit values as signed integers when held in registers, but
the code handling the FFI unsigned int case did not take this into
account. That introduced test failures when a 32-bit value had its most
significant bit set, as when performing the value extension from 32 to
64 bits, the upper half of the value would be filled with ones.
On 32 bit platforms this change should be converted to a no-op, and
on other 64 bit platforms that aren't RISC-V it shouldn't hurt as the
value being manipulated is expected to only hold valid bits in its lower
half.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit removes custom FFI closures alloc/free functions, in favour
of using the tracked allocation facility to allocate memory for FFI
callback objects.
This stems from linking issues in the Arm port when updating LibFFI to
the latest stable version, as the overridden alloc/free functions didn't
replace LibFFI's (unlike in other ports). The original code did no
effective cleanup for allocated callback objects, so there is no real
impact when switching allocation strategy.
The tracked allocation feature used to be enabled only if the Bluetooth
stack integration was enabled. This commit also enables tracked
allocation support if FFI support is enabled.
Co-authored-by: Damien George <damien@micropython.org>
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Libffi is updated to the latest stable version (v3.4.6) as the version
of libffi that was linked by the repository predates the introduction of
RISC-V processors (both 32 and 64 bits).
This is necessary as the packaged version of libffi used by the CI for
RISC-V 64 turned out to simply not work correctly, whilst a source-built
version of libffi worked just fine.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit adds a new `RingIO` type which exposes the internal ring-buffer
code for general use in Python programs. It has the stream interface
making it similar to `StringIO` and `BytesIO`, except `RingIO` has a fixed
buffer size and is automatically safe when reads and writes are in
different threads or an IRQ.
This new type is enabled at the "extra features" ROM level.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Casting an ffi_arg to a signed int may truncate the value. E.g., when the
ffi_arg is 64-bit and the signed int is 32-bit. Also, casting an ffi_arg
to a larger signed type will not sign extend the value. E.g., when the
ffi_arg is 32-bit and the larger signed type is int64_t. If the value is
signed, it should be cast to ffi_sarg, which is the same size as ffi_arg.
Signed-off-by: Michael Sawyer <mjfsawyer@gmail.com>
- Present the default build dependencies in one place at the top, and make
a separate section about building standalone.
- Add steps for the "minimal" variant as well.
- Document that building standalone requires autoconf and libtool.
- Allow MICROPY_STANDALONE to be set as an environment variable.
Fixes issue #11313.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Necessary to pass CI when testing the V2 preview APIs.
Also adds an extra coverage test for the legacy stackctrl API, to maintain
coverage and check for any regression.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Add native gchelper support for 64 bits RISC-V RV64I targets.
Now that RV64 is under CI, this also enables platform-specific ghelper
in the Unix port.
Also changes the data type holding the register contents to something more
appropriate, so in the remote eventuality somebody wants to use this with
RV128 all they have to do is update the `__riscv_xlen` check.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This contains a workaround to silence a possibly incorrect warning when
building the Unix port with GCC targeting RISC-V 64 bits.
Fixes issue #12838.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This simplifies configuration by removing the `MICROPY_PY_OS_SEP` option
and instead including `os.sep` if `MICROPY_VFS` is enabled. That matches
the configuration of all existing ports that enabled `os.sep` (they also
had `MICROPY_VFS` enabled), and brings consistency to other ports.
Fixes issue #15116.
Signed-off-by: Damien George <damien@micropython.org>
The current situation with SystemExit and soft reset is the following:
- `sys.exit()` follows CPython and just raises `SystemExit`.
- On the unix port, raising `SystemExit` quits the application/MicroPython,
whether at the REPL or in code (this follows CPython behaviour).
- On bare-metal ports, raising `SystemExit` at the REPL does nothing,
raising it in code will stop the code and drop into the REPL.
- `machine.soft_reset()` raises `SystemExit` but with a special flag set,
and bare-metal targets check this flag when it propagates to the
top-level and do a soft reset when they receive it.
The original idea here was that a bare-metal target can't "quit" like the
unix port can, and so dropping to the REPL was considered the same as
"quit". But this bare-metal behaviour is arguably inconsistent with unix,
and "quit" should mean terminate everything, including REPL access.
This commit changes the behaviour to the following, which is more
consistent:
- Raising `SystemExit` on a bare-metal port will do a soft reset (unless
the exception is caught by the application).
- `machine.soft_reset()` is now equivalent to `sys.exit()`.
- unix port behaviour remains unchanged.
Tested running the test suite on an stm32 board and everything still
passes, in particular tests that skip by raising `SystemExit` still
correctly skip.
Signed-off-by: Damien George <damien@micropython.org>
This adds some more baudrate option as they are available in the termios.h
header - up to a point that seems reasonable in an embedded context.
Signed-off-by: Lennart Schierling <Lennart@binarylabs.dev>
Use new function mp_obj_new_str_from_cstr() where appropriate. It
simplifies the code, and makes it smaller too.
Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
Before this change, long/mpz ints propagated into all future calculations,
even if their value could fit in a small-int object. With this change, the
result of a big-int binary op will now be converted to a small-int object
if the value fits in a small-int.
For example, a relatively common operation like `x = a * b // c` where
a,b,c all small ints would always result in a long/mpz int, even if it
didn't need to, and then this would impact all future calculations with
x.
This adds +24 bytes on PYBV11 but avoids heap allocations and potential
surprises (e.g. `big-big` is now a small `0`, and can safely be accessed
with MP_OBJ_SMALL_INT_VALUE).
Performance tests are unchanged on PYBV10, except for `bm_pidigits.py`
which makes heavy use of big-ints and gains about 8% in speed.
Unix coverage tests have been updated to cover mpz code that is now
unreachable by normal Python code (removing the unreachable code would lead
to some surprising gaps in the internal C functions and the functionality
may be needed in the future, so it is kept because it has minimal
overhead).
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The current `ssl` module has quite a few differences to the CPython
implementation. This change moves the MicroPython variant to a new `tls`
module and provides a wrapper module for `ssl` (in micropython-lib).
Users who only rely on implemented comparible behavior can continue to use
`ssl`, while users that rely on non-compatible behavior should switch to
`tls`. Then we can make the facade in `ssl` more strictly adhere to
CPython.
Signed-off-by: Felix Dörre <felix@dogcraft.de>