aboutsummaryrefslogtreecommitdiff
path: root/ports/unix
AgeCommit message (Collapse)Author
2020-04-29unix: Add support for modbluetooth and BLE using btstack.Jim Mussared
This commit adds full support to the unix port for Bluetooth using the common extmod/modbluetooth Python bindings. This uses the libusb HCI transport, which supports many common USB BT adaptors.
2020-04-29unix/modmachine: Add machine.idle(), implemented using sched_yield.Jim Mussared
Also add a definition of MICROPY_EVENT_POLL_HOOK so the unix port can build against modules that require this.
2020-04-23all: Format code to add space after C++-style comment start.stijn
Note: the uncrustify configuration is explicitly set to 'add' instead of 'force' in order not to alter the comments which use extra spaces after // as a means of indenting text for clarity.
2020-04-18all: Enable extra conversion warnings where applicable.stijn
Add -Wdouble-promotion and -Wfloat-conversion for most ports to ban out implicit floating point conversions, and add extra Travis builds using MICROPY_FLOAT_IMPL_FLOAT to uncover warnings which weren't found previously. For the unix port -Wsign-comparison is added as well but only there since only clang supports this but gcc doesn't.
2020-04-18all: Fix implicit floating point to integer conversions.stijn
These are found when building with -Wfloat-conversion.
2020-04-18all: Fix implicit conversion from double to float.stijn
These are found when building with -Wfloat-conversion.
2020-04-18all: Fix implicit floating point promotion.stijn
Initially some of these were found building the unix coverage variant on MacOS because that build uses clang and has -Wdouble-promotion enabled, and clang performs more vigorous promotion checks than gcc. Additionally the codebase has been compiled with clang and msvc (the latter with warning level 3), and with MICROPY_FLOAT_IMPL_FLOAT to find the rest of the conversions. Fixes are implemented either as explicit casts, or by using the correct type, or by using one of the utility functions to handle floating point casting; these have been moved from nativeglue.c to the public API.
2020-04-18Revert "all: Fix implicit casts of float/double, and signed comparison."stijn
This reverts commit a2110bd3fca59df8b16a2b5fe4645a4af30b06ed. There's nothing inherently wrong with it, but upcoming commits will apply similar fixes in a slightly different way.
2020-04-13all: Clean up error strings to use lowercase and change cannot to can't.Damien George
Now that error string compression is supported it's more important to have consistent error string formatting (eg all lowercase English words, consistent contractions). This commit cleans up some of the strings to make them more consistent.
2020-04-13unix/Makefile: Fix regression using install on non-GNU systems.David Lechner
This was fixed previously in 31fc81d3b8bb227109777eed02d0021e564fb523 but regressed in 4af79e76943312bf71be395a71fa80ab39e7c2c2. Fixes #5885.
2020-04-13unix: Implement MICROPY_BEGIN/END_ATOMIC_SECTION protection macros.Jim Mussared
This macro is used to implement global serialisation, typically by disabling IRQs. On the unix port, if threading is enabled, use the existing thread mutex (that protects the thread list structure) for this purpose. Other places in the code (eg the scheduler) assume this macro will provide serialisation.
2020-04-13unix: Fix behaviour of COPT/NDEBUG for unix variants.Jim Mussared
Based on eg 1e6fd9f2b4072873f5d6846b19b2ef0ccc5e4e52, it's understood that the intention for unix builds is that regular builds disable assert, but the coverage build should set -O0 and enable asserts. It looks like this didn't work (even before variants were introduced, eg at v1.11) -- coverage always built with -Os and -DNDEBUG. This commit makes it possible for variants to have finer-grained control over COPT flags, and enables assert() and -O0 on coverage builds. Other variants already match the defaults so they have been updated.
2020-04-05ports: Enable error text compression for various ports, but not all.Jim Mussared
Enabled on: bare-arm, minimal, unix coverage/dev/minimal, stm32, esp32, esp8266, cc3200, teensy, qemu-arm, nrf. Not enabled on others to be able to test the code when the feature is disabled (the default case). Code size change for this commit: bare-arm: -600 -0.906% minimal x86: -308 -0.208% unix x64: +0 +0.000% unix nanbox: +0 +0.000% stm32: -3368 -0.869% PYBV10 cc3200: -1024 -0.558% esp8266: -2512 -0.368% GENERIC esp32: -2876 -0.205% GENERIC[incl -3168(data)] nrf: -1708 -1.173% pca10040 samd: +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2020-04-05all: Use MP_ERROR_TEXT for all error messages.Jim Mussared
2020-03-31unix/mpthreadport: Ensure enough thread stack to detect overflow.Damien George
Following up to 5e6cee07aba4fd73c13024f091a287171bea1f17, some systems (eg FreeBSD 12.0 64-bit) will crash if the stack-overflow margin is too small. It seems the margin of 8192 bytes (or thereabouts) is always needed. This commit adds this much margin if the requested stack size is too small. Fixes issue #5824.
2020-03-30all: Fix implicit casts of float/double, and signed comparison.David Lechner
These were found by buiding the unix coverage variant on macOS (so clang compiler). Mostly, these are fixing implicit cast of float/double to mp_float_t which is one of those two and one mp_int_t to size_t fix for good measure.
2020-03-28all: Remove spaces inside and around parenthesis.Damien George
Using new options enabled in the uncrustify configuration.
2020-03-27unix: Implement PEP 475 to retry syscalls failing with EINTR.David Lechner
https://www.python.org/dev/peps/pep-0475/ This implements something similar to PEP 475 on the unix port, and for the VfsPosix class. There are a few differences from the CPython implementation: - Since we call mp_handle_pending() between any ENITR's, additional functions could be called if MICROPY_ENABLE_SCHEDULER is enabled, not just signal handlers. - CPython only handles signal on the main thread, so other threads will raise InterruptedError instead of retrying. On MicroPython, mp_handle_pending() will currently raise exceptions on any thread. A new macro MP_HAL_RETRY_SYSCALL is introduced to reduce duplicated code and ensure that all instances behave the same. This will also allow other ports that use POSIX-like system calls (and use, eg, VfsPosix) to provide their own implementation if needed.
2020-03-27unix/mpthreadport: Fix crash when thread stack size <= 8k.David Lechner
The stack size adjustment for detecting stack overflow in threads was not taking into account that the requested stack size could be <= 8k, in which case the subtraction would overflow. This is fixed in this commit by ensuring that the adjustment can't be more than the available size. This fixes the test tests/thread/thread_stacksize1.py which sometimes crashes with a segmentation fault because of an uncaught NLR jump, which is a "maximum recursion depth exceeded" exception. Suggested-by: @dpgeorge
2020-03-26unix: Enable uasyncio C helper module on coverage build.Damien George
2020-03-26unix/coverage: Init all pairheap test nodes before using them.Damien George
2020-03-25unix,windows: Use STDIN_FILENO, STDOUT_FILENO macros where appropriate.David Lechner
This replaces 0 and 1 with STDIN_FILENO and STDOUT_FILENO to make the intention of the code clearer.
2020-03-25unix: Remove custom definition of MP_PLAT_PRINT_STRN.David Lechner
This removes the port-specific definition of MP_PLAT_PRINT_STRN on the unix port. Since fee7e5617f55b4778de74ee185fcc3950cdc7b6d this is no longer a single function call so we are not really optimising anything over using the default definition of MP_PLAT_PRINT_STRN which calls mp_hal_stdout_tx_strn_cooked().
2020-03-25windows/msvc: Fix warnings regarding function declarations.stijn
Fix missing mkdir and gettimeofday declarations, then silence msvc-specific compiler warning C4996: 'The POSIX name for this item is deprecated'.
2020-03-18unix: Remove custom file implementation to use extmod's VFS POSIX one.Damien George
The implementation in extmod/vfs_posix_file.c is now equivalent to that in ports/unix/file.c, so remove the latter and use the former instead.
2020-03-11unix/Makefile: Detect and pass thru mpy-cross flags when running tests.Damien George
2020-03-11py/modmicropython: Add heap_locked function to test state of heap.Andrew Leech
This commit adds micropython.heap_locked() which returns the current lock-depth of the heap, and can be used by Python code to check if the heap is locked or not. This new function is configured via MICROPY_PY_MICROPYTHON_HEAP_LOCKED and is disabled by default. This commit also changes the return value of micropython.heap_unlock() so it returns the current lock-depth as well.
2020-03-04unix/file: Don't raise OSError(EINVAL) on sys.stdin/out/err.flush().Damien George
sys.stdout.flush() is needed on CPython to flush the output, and the change in this commit makes such an expression also work on MicroPython (although MicroPython doesn't actual need to do any flushing).
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2020-02-28all: Add *FORMAT-OFF* in various places.Damien George
This string is recognised by uncrustify, to disable formatting in the region marked by these comments. This is necessary in the qstrdef*.h files to prevent modification of the strings within the Q(...). In other places it is used to prevent excessive reformatting that would make the code less readable.
2020-02-28unix/unix_mphal: Adjust #if in mp_hal_stdin_rx_chr to improve format.Damien George
2020-02-20unix/mphalport.h: Fix build when MICROPY_USE_READLINE=0.Damien George
If the built-in input() is enabled (which it is by default) then it needs some form of readline, so supply it with one when MICROPY_USE_READLINE=0. Fixes issue #5658.
2020-02-20unix/mpthreadport: Fix Mac build by using SIGUSR1 if SIGRTMIN not avail.David Lechner
Some platforms, like Apple, don't define SIGRTMIN, so fall back to SIGUSR1 in such a case. Fixes #5659.
2020-02-18unix/mpthreadport: Use SIGRTMIN+5 instead of SIGUSR1 for thread-GC.David Lechner
This changes the signal used to trigger garbage collection from SIGUSR1 to SIGRTMIN + 5. SIGUSR1 is quite common compared to SIGRTMIN (measured by google search results) and is more likely to conflict with libraries that may use the same signal. POSIX specifies that there are at least 8 real-time signal so 5 was chosen as a "random" number to further avoid potential conflict with libraries that may use SIGRTMIN or SIGRTMAX. Also, if we ever have a `usignal` module, it would be nice to leave SIGUSR1 and SIGUSR2 free for user programs.
2020-02-16unix/Makefile: Allow to install all variants of the executable.David Lechner
The install target is current broken when PROG is used to override the default executable name. This fixes it by removing the redundant TARGET variable and uses PROG directly instead. The install and uninstall targets are also moved to the common unix Makefile so that all variants can be installed in the same way.
2020-02-16unix/variants/standard: Fix role of PREFIX when used to install.David Lechner
Currently it is not possible to override PREFIX when installing micropython using the makefile. It is common practice to be able to run something like this: $ make install PREFIX=/usr DESTDIR=/tmp/staging This fixes such usage.
2020-02-16unix/Makefile: Remove old variant targets that are no longer needed.Damien George
To eliminate confusion about what targets to use when building.
2020-02-13py: Add mp_raise_msg_varg helper and use it where appropriate.Damien George
This commit adds mp_raise_msg_varg(type, fmt, ...) as a helper for nlr_raise(mp_obj_new_exception_msg_varg(type, fmt, ...)). It makes the C-level API for raising exceptions more consistent, and reduces code size on most ports: bare-arm: +28 +0.042% minimal x86: +100 +0.067% unix x64: -56 -0.011% unix nanbox: -300 -0.068% stm32: -204 -0.054% PYBV10 cc3200: +0 +0.000% esp8266: -64 -0.010% GENERIC esp32: -104 -0.007% GENERIC nrf: -136 -0.094% pca10040 samd: +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2020-02-11unix/main: Use OS-dependent path separator when searching path.stijn
2020-02-07unix, windows: Use mp_keyboard_interrupt instead of custom code.Damien George
The mp_keyboard_interrupt() function does exactly what is needed here, and using it gets ctrl-C working when MICROPY_ENABLE_SCHEDULER is enabled on these ports (and MICROPY_ASYNC_KBD_INTR is disabled).
2020-02-07tests/unix: Add coverage tests for kbd-intr and scheduler.Damien George
2020-02-07lib/utils/pyexec: Handle pending exceptions after disabling kbd intrs.Damien George
Pending exceptions would otherwise be handled later on where there may not be an NLR handler in place. A similar fix is also made to the unix port's REPL handler. Fixes issues #4921 and #5488.
2020-02-07py/scheduler: Add "raise_exc" argument to mp_handle_pending.Damien George
Previous behaviour is when this argument is set to "true", in which case the function will raise any pending exception. Setting it to "false" will cancel any pending exception.
2020-02-04unix/modos: Implement putenv and unsetenv to complement getenv.David Lechner
CPython also has os.environ, which should be used instead of os.getenv() due to caching in the os.environ mapping. But for MicroPython it makes sense to only implement the basic underlying methods, ie getenv/putenv/ unsetenv.
2020-02-04unix/main: Add command-line -h option for printing help text.David Lechner
This adds a -h option to print the usage help text and adds a new, shorter error message that is printed when invalid arguments are given. This behaviour follows CPython (and other tools) more closely.
2020-02-04unix/main: Add #if guard around -v option usage and document -i/-m opts.David Lechner
This commit modifies the usage() function to only print the -v option help text when MICROPY_DEBUG_PRINTERS is enabled. The -v option requires this build option to be enabled for it to have any effect. The usage text is also modified to show the -i and -m options, and also show that running a command, module or file are mutually exclusive.
2020-02-04unix/main: Add support for MICROPYINSPECT environment variable.David Lechner
This adds support for a MICROPYINSPECT environment variable that works exactly like PYTHONINSPECT; per CPython docs: If this is set to a non-empty string it is equivalent to specifying the -i option. This variable can also be modified by Python code using os.environ to force inspect mode on program termination.
2020-02-01unix/main: Print usage and NLR errors to stderr instead of stdout.David Lechner
When stdout is redirected it is useful to have errors printed to stderr instead of being redirected. mp_stderr_print() can't be used in these two instances since the MicroPython runtime is not running so we use fprintf(stderr) instead.
2020-01-29py/mpthread.h: Use strong type for mp_thread_set_state() argument.David Lechner
This modifies the signature of mp_thread_set_state() to use mp_state_thread_t* instead of void*. This matches the return type of mp_thread_get_state(), which returns the same value. `struct _mp_state_thread_t;` had to be moved before `#include <mpthreadport.h>` since the stm32 port uses it in its mpthreadport.h file.
2020-01-26unix/unix_mphal: Add compile check for incompatible GIL+ASYNC_KBD_INTR.David Lechner
It is not safe to enable MICROPY_ASYNC_KBD_INTR and MICROPY_PY_THREAD_GIL at the same time. This will trigger a compiler error to ensure that it is not possible to make this mistake.