Commit Graph

97 Commits

Author SHA1 Message Date
Damien George
4c5e1a0368 py/bc: Change mp_code_state_t.exc_sp to exc_sp_idx.
Change from a pointer to an index, to make space in mp_code_state_t.
2019-10-01 12:26:22 +10:00
Jim Mussared
f67fd95f8d unix/coverage: Add coverage tests for ringbuf. 2019-10-01 09:51:02 +10:00
Josh Lloyd
7d58a197cf py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions.
Fixes #5140.
2019-09-26 16:04:56 +10:00
Milan Rossa
310b3d1b81 py: Integrate sys.settrace feature into the VM and runtime.
This commit adds support for sys.settrace, allowing to install Python
handlers to trace execution of Python code.  The interface follows CPython
as closely as possible.  The feature is disabled by default and can be
enabled via MICROPY_PY_SYS_SETTRACE.
2019-08-30 16:44:12 +10:00
Damien George
af20c2ead3 py: Add global default_emit_opt variable to make emit kind persistent.
mp_compile no longer takes an emit_opt argument, rather this setting is now
provided by the global default_emit_opt variable.

Now, when -X emit=native is passed as a command-line option, the emitter
will be set for all compiled modules (included imports), not just the
top-level script.

In the future there could be a way to also set this variable from a script.

Fixes issue #4267.
2019-08-28 12:47:58 +10:00
Damien George
15b36aa0af unix/main: Only accept full emit cmd-line options if native enabled. 2019-08-28 12:47:58 +10:00
Damien George
7d851a27f1 extmod/modure: Make regex dump-code debugging feature optional.
Enabled via MICROPY_PY_URE_DEBUG, disabled by default (but enabled on unix
coverage build).  This is a rarely used feature that costs a lot of code
(500-800 bytes flash).  Debugging of regular expressions can be done
offline with other tools.
2019-08-19 16:43:00 +10:00
stijn
af5c998f37 py/modmath: Implement math.isclose() for non-complex numbers.
As per PEP 485, this function appeared in for Python 3.5.  Configured via
MICROPY_PY_MATH_ISCLOSE which is disabled by default, but enabled for the
ports which already have MICROPY_PY_MATH_SPECIAL_FUNCTIONS enabled.
2019-08-17 23:23:17 +10:00
Damien George
497683b315 gitignore: Put build-*/ pattern in top-level gitignore file. 2019-08-16 00:08:08 +10:00
Milan Rossa
6f0c6bd774 unix: Enable sys.atexit, triggered after the main script ends. 2019-08-15 17:31:04 +10:00
Paul m. p. P
42d30c5baf unix/unix_mphal: Include time.h for CLOCK_MONOTONIC. 2019-07-09 13:05:59 +10:00
Mikhail Zakharov
ced340d739 unix/unix_mphal: Use CLOCK_MONOTONIC for ticks_ms/us when available. 2019-06-26 11:07:45 +10:00
Damien George
9d72f07b6d unix/mpconfigport.mk: Update comment about TLS implementations.
As long as the submodule is checked out, mbedTLS is now fully integrated
into the unix build if MICROPY_SSL_MBEDTLS=1.
2019-06-05 15:28:30 +10:00
Damien George
8c9758ff2e unix/modusocket: Raise ETIMEDOUT when connect or accept has timeout. 2019-05-28 17:22:54 +10:00
Damien George
653e1756c0 various: Update early copyright years to match actual edit history. 2019-05-17 18:06:11 +10:00
Paul Sokolovsky
016d9a40fe various: Add and update my copyright line based on git history.
For modules I initially created or made substantial contributions to.
2019-05-17 18:04:15 +10:00
stijn
90fae9172a py/objarray: Add support for memoryview.itemsize attribute.
This allows figuring out the number of bytes in the memoryview object as
len(memview) * memview.itemsize.

The feature is enabled via MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE and is
disabled by default.
2019-05-14 17:15:17 +10:00
Elad Namdar
3f54462add unix/modusocket: Fix use of setsockopt in usocket.settimeout impl.
The original code called setsockopt(SO_RCVTIMEO/SO_SNDTIMEO) with NULL
timeout structure argument, which is an illegal usage of that function.
The old code also didn't validate the return value of setsockopt, missing
the bug completely.
2019-05-08 13:12:30 +10:00
Yonatan Goldschmidt
ef9843653b extmod/moducryptolib: Add AES-CTR support.
Selectable at compile time via MICROPY_PY_UCRYPTOLIB_CTR.  Disabled by
default.
2019-05-06 18:09:48 +10:00
Damien George
906fb89fd7 unix/coverage: Add test for printing literal % character. 2019-05-03 23:21:28 +10:00
stijn
34a7d7ebeb unix/gcollect: Make sure stack/regs get captured properly for GC.
When building with link time optimization enabled it is possible both
gc_collect() and gc_collect_regs_and_stack() get inlined into gc_alloc()
which can result in the regs variable being pushed on the stack earlier
than some of the registers. Depending on the calling convention, those
registers might however contain pointers to blocks which have just been
allocated in the caller of gc_alloc(). Then those pointers end up higher on
the stack than regs, aren't marked by gc_collect_root() and hence get
sweeped, even though they're still in use.

As reported in #4652 this happened for in 32-bit msvc release builds:
mp_lexer_new() does two consecutive allocations and the latter triggered a
gc_collect() which would sweep the memory of the first allocation again.
2019-05-01 15:06:21 +10:00
Damiano Mazzella
0b86ba565c unix/mpthreadport: Use named semaphores on Mac OS X.
Unnamed semaphores (via sem_init) are not supported on this OS.  See #4465.
2019-03-27 10:50:01 +11:00
Damien George
c6a9bb23cd unix/Makefile: Update coverage tests to match those in Travis. 2019-03-08 16:51:09 +11:00
Damien George
b5f33ac2cb ports: Update to work with new oofatfs version. 2019-03-05 15:56:39 +11:00
Damien George
55ff562c70 unix/modffi: Eliminate unused-argument warning when debugging disabled. 2019-02-25 14:53:17 +11:00
Yonatan Goldschmidt
bc4f8b438b extmod/moduwebsocket: Refactor websocket to uwebsocket.
As mentioned in #4450, `websocket` was experimental with a single intended
user, `webrepl`. Therefore, we'll make this change without a weak
link `websocket` -> `uwebsocket`.
2019-02-14 00:35:45 +11:00
Yonatan Goldschmidt
66f0afc91d unix/modmachine: Handle repeated /dev/mem open errors.
If opening of /dev/mem has failed an `OSError` is appropriately raised, but
the next time `mem8/16/32` is accessed the invalid file descriptor is used
and the program gets a SIGSEGV.
2019-02-12 15:29:11 +11:00
Damien George
6e30f96b0b ports: Convert legacy uppercase macro names to lowercase. 2019-02-12 14:54:51 +11:00
Paul Sokolovsky
2f5d113fad py/warning: Support categories for warnings.
Python defines warnings as belonging to categories, where category is a
warning type (descending from exception type). This is useful, as e.g.
allows to disable warnings selectively and provide user-defined warning
types.  So, implement this in MicroPython, except that categories are
represented just with strings.  However, enough hooks are left to implement
categories differently per-port (e.g. as types), without need to patch each
and every usage.
2019-01-31 16:48:30 +11:00
stijn
42863830be py: Add optional support for 2-argument version of built-in next().
Configurable via MICROPY_PY_BUILTINS_NEXT2, disabled by default.
2019-01-27 13:01:28 +11:00
Mikhail Zakharov
18723e9889 unix/mpthreadport: Remove busy wait loop in thread garbage collection.
One can't use pthread calls in a signal handler because they are not
async-signal-safe (see man signal-safety).  Instead, sem_post can be used
to post from within a signal handler and this should be more efficient than
using a busy wait loop, waiting on a volatile variable.
2019-01-27 12:40:10 +11:00
Mikhail Zakharov
1e7b422226 unix/mpthreadport: Cleanup used memory on thread exit. 2019-01-27 12:39:45 +11:00
Mikhail Zakharov
f8c1be85d1 unix/mpthreadport: Add thread deinit code to stop threads on exit.
Free unused memory for threads and cancel any outstanding threads on
interpreter exit to avoid possible segmentaiton fault.
2019-01-27 12:38:23 +11:00
Paul Sokolovsky
80aca27a40 unix/modos: Rename unlink to remove to be consistent with other ports.
We standardized to provide uos.remove() as a more obvious and user-friendly
name.  That's what written in the docs.  The Unix port implementation
predates this convention, so update it now.
2018-11-26 23:27:04 +11:00
Paul m. p. P
454cca6016 py/objmodule: Implement PEP 562's __getattr__ for modules.
Configurable via MICROPY_MODULE_GETATTR, disabled by default.  Among other
things __getattr__ for modules can help to build lazy loading / code
unloading at runtime.
2018-10-23 11:22:50 +11:00
Paul Sokolovsky
5a91fce9f8 py/objstr: Make str.count() method configurable.
Configurable via MICROPY_PY_BUILTINS_STR_COUNT.  Default is enabled.
Disabled for bare-arm, minimal, unix-minimal and zephyr ports.  Disabling
it saves 408 bytes on x86.
2018-10-22 22:49:05 +11:00
Paul Sokolovsky
6ddcfe68b8 unix/Makefile: Allow to override/omit pthread lib name.
For example, on Android, pthread functions are part of libc, so LIBPTHREAD
should be empty.
2018-10-19 17:22:37 +11:00
Paul Sokolovsky
6c5b2bded2 unix/modffi: Add support for "q"/"Q" specs (int64_t/uint64_t). 2018-10-17 15:17:05 +11:00
Paul Sokolovsky
0c18633ea9 unix/modusocket: Finish socket.settimeout() implementation.
1. Return correct error code for non-blocking vs timed out socket
(POSIX returns EAGAIN for both, we want ETIMEDOUT in case of timed
out socket). To achieve this, blocking/non-blocking flag is added
to the mp_obj_socket_t, to avoid issuing fcntl() syscall each time
EAGAIN occurs. (mp_obj_socket_t used to be 8 bytes, having some room
in a standard 16-byte alloc block.)

2. Handle socket.settimeout(0) properly - in Python, that means
non-blocking mode, but SO_RCVTIMEO/SO_SNDTIMEO of 0 is infinite
timeout.

3. Overall, make sure that socket.settimeout() call switches blocking
state as expected.
2018-10-17 14:19:06 +11:00
Danielle Madeley
80a25810f9 unix/modusocket: Initial implementation of socket.settimeout(). 2018-10-17 14:19:06 +11:00
Paul Sokolovsky
b9bad7ff92 unix/moduselect: Raise OSError(ENOENT) if obj to modify is not in poller
Previously, the function silently succeeded. The new behavior is consistent
with both baremetal uselect implementation and CPython 3.
2018-10-05 16:56:43 +10:00
Paul Sokolovsky
af2030dec6 unix/mpconfigport.h: Enable MICROPY_PY_UHASHLIB_MD5 for uhashlib.md5.
This will allow to e.g. implement HTTP Digest authentication.

Adds 540 bytes for x86_32, 332 for arm_thumb2 (for Unix port, which already
includes axTLS library).
2018-09-26 15:12:28 +10:00
Christopher Swenson
8c656754aa py/modmath: Add math.factorial, optimised and non-opt implementations.
This commit adds the math.factorial function in two variants:
- squared difference, which is faster than the naive version, relatively
  compact, and non-recursive;
- a mildly optimised recursive version, faster than the above one.

There are some more optimisations that could be done, but they tend to take
more code, and more storage space.  The recursive version seems like a
sensible compromise.

The new function is disabled by default, and uses the non-optimised version
by default if it is enabled.  The options are MICROPY_PY_MATH_FACTORIAL
and MICROPY_OPT_MATH_FACTORIAL.
2018-09-26 15:03:04 +10:00
Damien George
6623d7a88c unix/modjni: Get building under coverage and nanbox builds.
Changes made:
- make use of MP_OBJ_TO_PTR and MP_OBJ_FROM_PTR where necessary
- fix shadowing of index variable i, renamed to j
- fix type of above variable to size_t to prevent comparison warning
- fix shadowing of res variable
- use "(void)" instead of "()" for functions that take no arguments
2018-09-20 16:04:08 +10:00
Paul Sokolovsky
11573fcabd unix/modjni: Update .getiter signature to include mp_obj_iter_buf_t* .
And thus be buildable again.
2018-09-20 16:03:53 +10:00
Paul Sokolovsky
2da5d41350 py/objstr: Make % (__mod__) formatting operator configurable.
Default is enabled, disabled for minimal builds. Saves 1296 bytes on x86,
976 bytes on ARM.
2018-09-20 14:41:08 +10:00
Paul Sokolovsky
064b8e0e8d unix/modos: Include extmod/vfs.h for MP_S_IFDIR, etc.
If DTTOIF() macro is not defined, the code refers to MP_S_IFDIR, etc.
symbols defined in extmod/vfs.h, so should include it.

This fixes build for Android.
2018-09-14 13:22:50 +10:00
Damien George
e6a6ded74e unix/mpconfigport_coverage.h: Enable uhashlib.md5. 2018-09-12 16:09:41 +10:00
Paul Sokolovsky
5615273bb0 unix/Makefile: Build libffi inside $BUILD.
Avoids polluting the source tree, allows to build for different (sub)archs
without intermediate cleaning.
2018-09-10 11:34:46 +03:00
Damien George
6ad5355e43 unix/Makefile: Remove building of libaxtls.a which is no longer needed. 2018-09-08 00:07:23 +10:00