summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2020-03-26py/pairheap: Add helper function to initialise a new node.Damien George
2020-03-26py/pairheap: Properly unlink node on pop and delete.Damien George
This fixes a bug in the pairing-heap implementation when nodes are deleted with mp_pairheap_delete and then reinserted later on.
2020-03-26py/mpconfig.h: Enable MICROPY_MODULE_GETATTR by default.Damien George
To enable lazy loading of submodules (among other things), which is very useful for MicroPython libraries that want to have optional subcomponents. Disabled explicitly on minimal ports.
2020-03-25py/stream.h: Include sys/types.h to get size_t and off_t for POSIX API.David Lechner
2020-03-25all: Remove spaces between nested paren and inside function arg paren.Damien George
Using new options enabled in the uncrustify configuration.
2020-03-18all: Convert exceptions to use mp_raise_XXX helpers in remaining places.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-11py/objstringio: Expose tell() on StringIO and BytesIO objects.Andrew Leech
To match file objects. Fixes issue #5581.
2020-03-11tools/codeformat.py: Eliminate need for sizeof fixup.David Lechner
This eliminates the need for the sizeof regex fixup by rearranging things a bit. All other bitfields already use the parentheses around expressions with sizeof, so one case is fixed by following this convention. VM_MAX_STATE_ON_STACK is the only remaining problem and it can be worked around by changing the order of the operands.
2020-03-11py/objstr: Remove duplicate % in error string.Tom Collins
The double-% was added in 11de8399fe5f9ef54589b14470faf8d4fcc5ccaa (Jun 2014) when such errors were formatted with printf. But then 55830dd9bf4fee87c0a6d3f38c51614fea0eb483 (Dec 2018) changed mp_obj_new_exception_msg() to not format the message, as discussed in #3004. So such error strings are no longer formatted and a % is just that.
2020-02-28py/builtinevex: Support passing in a bytearray/buffer to eval/exec.Damien George
CPython allows this and it's a simple generalisation of the existing code which just supported str/bytes. Fixes issue #5704.
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-28py/parse: Add parenthesis around calculated bit-width in struct.Damien George
To improve interaction with uncrustify formatter.
2020-02-28py: Un-nest configuration #if/#endif's for selection of complex code.Damien George
Because un-nested #if's are simpler to handle with formatting tools.
2020-02-28py/malloc: Put { on separate line for funcs that have selective sigs.Damien George
To ensure there are balanced {}'s in the file, and to help with formatting.
2020-02-28py/builtinimport: Adjust if-block order in find_file to clean up #if's.Damien George
2020-02-28py/bc0.h: Shift comment to start of line to improve format consistency.Damien George
2020-02-28py: Removing dangling "else" to improve code format consistency.Damien George
2020-02-21py/objarray: Turn on MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE for memoryview.Jim Mussared
And add corresponding tests. Fixes #5674 (comparison of memoryview against bytes).
2020-02-21py/dynruntime.h: Add implementation of mp_obj_cast_to_native_base.Damien George
2020-02-21py/objtype: Allow mp_instance_cast_to_native_base to take native obj.Damien George
And rename it to mp_obj_cast_to_native_base() to indicate this. This allows users of this function to easily support native and native-subclass objects in the same way (by just passing the object through this function).
2020-02-20py/objtuple: Remove code that handles tuple-subclass equality test.Damien George
Since commit 3aab54bf434e7f025a91ea05052f1bac439fad8c this piece of code is no longer needed because the top-level function mp_obj_equal_not_equal() now handles the case of user types, and will never call tuple's binary_op function with MP_BINARY_OP_EQUAL and a non-tuple on the RHS.
2020-02-18py/objexcept: Rename mp_obj_new_exception_msg_varg2 to ..._vlist.Damien George
Follow up to recent commit ad7213d3c31bccb26a3f54f7492ccf4b0cc920f3, the name "varg2" is misleading, vlist describes better that the argument is a va_list. This name also matches CircuitPython, which already has such helper functions.
2020-02-18py: Factor out definition of mp_float_union_t to one location.Damien George
2020-02-13py/obj.h: Remove TODO idea comment about truncated mp_map_t.David Lechner
It was suggested to move this to a GitHub issue rather than keep it in the code, which isn't really sustainable for all ideas.
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-13py: Add mp_raise_type helper macro and use it where appropriate.Damien George
This provides a more consistent C-level API to raise exceptions, ie moving away from nlr_raise towards mp_raise_XXX. It also reduces code size by a small amount on some ports.
2020-02-11py/objmodule.h: Remove obsolete mp_builtin_module_weak_links_map decl.Damien George
It was made obsolete in d2384efa809953152c57cbda4c339dfbaa64cf29
2020-02-11py: Expand type equality flags to 3 separate ones, fix bool/namedtuple.Damien George
Both bool and namedtuple will check against other types for equality; int, float and complex for bool, and tuple for namedtuple. So to make them work after the recent commit 3aab54bf434e7f025a91ea05052f1bac439fad8c they would need MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST set. But that makes all bool and namedtuple equality checks less efficient because mp_obj_equal_not_equal() could no longer short-cut x==x, and would need to try __ne__. To improve this, this commit splits the MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST flags into 3 separate flags to give types more fine-grained control over how their equality behaves. These new flags are then used to fix bool and namedtuple equality. Fixes issue #5615 and #5620.
2020-02-07py/scheduler: Move clearing of kbd traceback to mp_keyboard_interrupt.Damien George
This is a more logical place to clear the KeyboardInterrupt traceback, right before it is set as a pending exception. The clearing is also optimised from a function call to a simple store of NULL.
2020-02-07py/scheduler: Allow a port to specify attrs for mp_keyboard_interrupt.Damien George
Functions like mp_keyboard_interrupt() may need to be called from an IRQ handler and may need to be in a special memory section, so provide a generic wrapping macro for a port to do this. The macro name is chosen to be MICROPY_WRAP_<function name in uppercase> so that (in the future with more wrappers) each function could potentially be handled separately.
2020-02-07py/scheduler: Move mp_keyboard_interrupt from lib/utils to py core.Damien George
This function is tightly coupled to the state and behaviour of the scheduler, and is a core part of the runtime: to schedule a pending exception. So move it there.
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-06py/compile: Allow 'return' outside function in minimal builds.Petr Viktorin
A 'return' statement on module/class level is not correct Python, but nothing terribly bad happens when it's allowed. So remove the check unless MICROPY_CPYTHON_COMPAT is on. This is similar to MicroPython's treatment of 'import *' in functions (except 'return' has unsurprising behavior if it's allowed).
2020-01-31py/modthread: Fix spelling error in comment.David Lechner
2020-01-30py: Support non-boolean results for equality and inequality tests.Nicko van Someren
This commit implements a more complete replication of CPython's behaviour for equality and inequality testing of objects. This addresses the issues discussed in #5382 and a few other inconsistencies. Improvements over the old code include: - Support for returning non-boolean results from comparisons (as used by numpy and others). - Support for non-reflexive equality tests. - Preferential use of __ne__ methods and MP_BINARY_OP_NOT_EQUAL binary operators for inequality tests, when available. - Fallback to op2 == op1 or op2 != op1 when op1 does not implement the (in)equality operators. The scheme here makes use of a new flag, MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST, in the flags word of mp_obj_type_t to indicate if various shortcuts can or cannot be used when performing equality and inequality tests. Currently four built-in classes have the flag set: float and complex are non-reflexive (since nan != nan) while bytearray and frozenszet instances can equal other builtin class instances (bytes and set respectively). The flag is also set for any new class defined by the user. This commit also includes a more comprehensive set of tests for the behaviour of (in)equality operators implemented in special methods.
2020-01-30py/objtype: Make mp_obj_type_t.flags constants public, moved to obj.h.Damien George
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-27py/nativeglue: Fix typo about where the native fun table enum is.Jim Mussared
2020-01-27py/emitnative: Stop after finding an unwind target.Jim Mussared
The loop searches backwards for a target, but doesn't stop after finding the first result, meaning that it'll always end up at the outermost exception handler.
2020-01-27py/emitnative: Use NULL for pending exception (not None).Jim Mussared
This previously made the native emitter incompatible with the bytecode emitter, and mp_resume (and subsequently mp_obj_generator_resume) expects the bytecode emitter behavior (i.e. throw==NULL).
2020-01-26py: Release GIL during syscalls in reader and writer code.David Lechner
This releases the GIL during POSIX system calls that could block.
2020-01-24py/obj.h: Add and use mp_obj_is_bool() helper.Yonatan Goldschmidt
Commit d96cfd13e3a464862cecffb2718c6286b52c77b0 introduced a regression in testing for bool objects, that such objects were in some cases no longer recognised and bools, eg when using mp_obj_is_type(o, &mp_type_bool), or mp_obj_is_integer(o). This commit fixes that problem by adding mp_obj_is_bool(o). Builds with MICROPY_OBJ_IMMEDIATE_OBJS enabled check if the object is any of the const True or False objects. Builds without it use the old method of ->type checking, which compiles to smaller code (compared with the former mentioned method). Fixes #5538.
2020-01-23py/objexcept: Optimise mp_obj_new_exception[_arg1/_args] functions.Damien George
This reduces code size by 10-70 bytes on all ports (except cc3200 which has no change).
2020-01-23py/objgenerator: Use mp_obj_new_exception_arg1 to make StopIteration.Damien George
2020-01-23py/qstr: Don't include or init qstr_mutex when GIL is enabled.David Lechner
When threads and the GIL are enabled, then the qstr mutex is not needed. The qstr_mutex field is never used in this case because of: #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL #define QSTR_ENTER() mp_thread_mutex_lock(&MP_STATE_VM(qstr_mutex), 1) #define QSTR_EXIT() mp_thread_mutex_unlock(&MP_STATE_VM(qstr_mutex)) #else #define QSTR_ENTER() #define QSTR_EXIT() #endif So, we can completely remove qstr_mutex everywhere when MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL.
2020-01-23py/gc: Don't include or init gc_mutex when GIL is enabled.David Lechner
When threads and the GIL are enabled, then the GC mutex is not needed. The gc_mutex field is never used in this case because of: #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL #define GC_ENTER() mp_thread_mutex_lock(&MP_STATE_MEM(gc_mutex), 1) #define GC_EXIT() mp_thread_mutex_unlock(&MP_STATE_MEM(gc_mutex)) #else #define GC_ENTER() #define GC_EXIT() #endif So, we can completely remove gc_mutex everywhere when MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL.
2020-01-22py/pairheap: Add generic implementation of pairing heap data structure.Damien George
2020-01-14py/objint: Add mp_obj_int_get_uint_checked() helper.Yonatan Goldschmidt
Can be used where mp_obj_int_get_checked() will overflow due to the sign-bit solely. This returns an mp_uint_t, so it also verifies the given integer is not negative. Currently implemented only for mpz configurations.