summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2017-09-04py/obj: Fix comparison of float/complex NaN with itself.Damien George
IEEE floating point is specified such that a comparison of NaN with itself returns false, and Python respects these semantics. This patch makes uPy also have these semantics. The fix has a minor impact on the speed of the object-equality fast-path, but that seems to be unavoidable and it's much more important to have correct behaviour (especially in this case where the wrong answer for nan==nan is silently returned).
2017-09-02py/objfloat: Fix binary ops with incompatible objects.Paul Sokolovsky
These are now returned as "operation not supported" instead of raising TypeError. In particular, this fixes equality for float vs incompatible types, which now properly results in False instead of exception. This also paves the road to support reverse operation (e.g. __radd__) with float objects. This is achieved by introducing mp_obj_get_float_maybe(), similar to existing mp_obj_get_int_maybe().
2017-09-01py/nlrthumb: Get working again on standard Thumb arch (ie not Thumb2).Damien George
"b" on Thumb might not be long enough for the jump to nlr_push_tail so it must be done indirectly.
2017-09-01py/qstrdefs: Remove unused qstrs.Damien George
They are not used by any component and take up valuable flash space.
2017-09-01py/modstruct: Check and prevent buffer-write overflow in struct packing.Damien George
Prior to this patch, the size of the buffer given to pack_into() was checked for being too small by using the count of the arguments, not their actual size. For example, a format spec of '4I' would only check that there was 4 bytes available, not 16; and 'I' would check for 1 byte, not 4. The pack() function is ok because its buffer is created to be exactly the correct size. The fix in this patch calculates the total size of the format spec at the start of pack_into() and verifies that the buffer is large enough. This adds some computational overhead, to iterate through the whole format spec. The alternative is to check during the packing, but that requires extra code to handle alignment, and the check is anyway not needed for pack(). So to maintain minimal code size the check is done using struct_calcsize.
2017-09-01py/modstruct: Check and prevent buffer-read overflow in struct unpackingDamien George
Prior to this patch, the size of the buffer given to unpack/unpack_from was checked for being too small by using the count of the arguments, not their actual size. For example, a format spec of '4I' would only check that there was 4 bytes available, not 16; and 'I' would check for 1 byte, not 4. This bug is fixed in this patch by calculating the total size of the format spec at the start of the unpacking function. This function anyway needs to calculate the number of items at the start, so calculating the total size can be done at the same time.
2017-09-01py/modstruct: In struct.pack, stop converting if there are no args left.Damien George
This patch makes a repeat counter behave the same as repeating the typecode, when there are not enough args. For example: struct.pack('2I', 1) now behave the same as struct.pack('II', 1).
2017-08-31py: Make m_malloc_fail() have void return type, since it doesn't return.Damien George
2017-08-31py/map: Remove unused new/free functions.Damien George
Maps are always allocated "statically" and (de)initialised via mp_map_init and mp_map_deinit.
2017-08-31py/map: Replace always-false condition with assertion.Damien George
2017-08-31py/objtype: mp_obj_class_lookup: Improve debug logging.Paul Sokolovsky
Now traces more explicitly thru the lookup process.
2017-08-30py/objtype: mp_obj_instance_make_new: Fix typos in comment.Paul Sokolovsky
2017-08-30py: Change obsolete "///" comment formatting to normal comments.Damien George
This comment style is no longer used because the docs are written by hand, not generated.
2017-08-30py/objtype: Handle NotImplemented return from binary special methods.Paul Sokolovsky
NotImplemented means "try other fallbacks (like calling __rop__ instead of __op__) and if nothing works, raise TypeError". As MicroPython doesn't implement any fallbacks, signal to raise TypeError right away.
2017-08-29all: Convert mp_uint_t to mp_unary_op_t/mp_binary_op_t where appropriateDamien George
The unary-op/binary-op enums are already defined, and there are no arithmetic tricks used with these types, so it makes sense to use the correct enum type for arguments that take these values. It also reduces code size quite a bit for nan-boxing builds.
2017-08-29py/nlrx86,x64: Replace #define of defined() with portable macro usage.Damien George
Using gcc -Wpedantic will warn that #define of defined() is non-portable and this patch fixes this.
2017-08-29py/objstr: startswith, endswith: Check arg to be a string.Paul Sokolovsky
Otherwise, it will silently get incorrect result on other values types, including CPython tuple form like "foo.png".endswith(("png", "jpg")) (which MicroPython doesn't support for unbloatedness).
2017-08-23py/asmthumb: Use existing macro to properly clear the D-cache.Damien George
This macro is provided by stmhal/mphalport.h and makes sure the addr and size arguments are correctly aligned.
2017-08-21py/formatfloat: Don't post-increment variable that won't be used again.Damien George
2017-08-21py/objcomplex: Remove unnecessary assignment of variable.Damien George
2017-08-21py/compile: Remove unused pn_colon code when compiling func params.Damien George
2017-08-21py/mkrules.mk: Use "find -path" when searching for frozen obj files.Damien George
This allows the command to succeed without error even if there is no $(BUILD)/build directory, which is the case for mpy-cross.
2017-08-20py/stream: seek: Consistently handle negative offset for SEEK_SET.Paul Sokolovsky
Per POSIX, this is EINVAL, so raises OSError(EINVAL).
2017-08-20py/objstringio: Fix regression with handling SEEK_SET.Paul Sokolovsky
For SEEK_SET, offset should be treated as unsigned, to allow full-width stream sizes (e.g. 32-bit instead of 31-bit). This is now fully documented in stream.h. Also, seek symbolic constants are added.
2017-08-20py/objstringio: Prevent offset wraparound for io.BytesIO objects.Tom Collins
Too big positive, or too big negative offset values could lead to overflow and address space wraparound and thus access to unrelated areas of memory (a security issue).
2017-08-17py/binary: Change internal bytearray typecode from 0 to 1.Damien George
The value of 0 can't be used because otherwise mp_binary_get_size will let a null byte through as the type code (intepreted as byterray). This can lead to invalid type-specifier strings being let through without an error in the struct module, and even buffer overruns.
2017-08-15py: Add verbose debug compile-time flag MICROPY_DEBUG_VERBOSE.Stefan Naumann
It enables all the DEBUG_printf outputs in the py/ source code.
2017-08-15py/binary.c: Fix bug when packing big-endian 'Q' values.Bas van Sisseren
Without bugfix: struct.pack('>Q', 16) b'\x00\x00\x00\x10\x00\x00\x00\x00' With bugfix: struct.pack('>Q', 16) b'\x00\x00\x00\x00\x00\x00\x00\x10'
2017-08-13all: Raise exceptions via mp_raise_XXXJavier Candeira
- Changed: ValueError, TypeError, NotImplementedError - OSError invocations unchanged, because the corresponding utility function takes ints, not strings like the long form invocation. - OverflowError, IndexError and RuntimeError etc. not changed for now until we decide whether to add new utility functions.
2017-08-11py/modsys: Initial implementation of sys.getsizeof().Paul Sokolovsky
Implemented as a new MP_UNARY_OP. This patch adds support lists, dicts and instances.
2017-08-11all: Make use of $(TOP) variable in Makefiles, instead of "..".Damien George
$(TOP) is defined in py/mkenv.mk and should be used to refer to the top level of this repository.
2017-08-09py/objstr: Raise an exception for wrong type on RHS of str binary op.Damien George
The main case to catch is invalid types for the containment operator, of the form str.__contains__(non-str).
2017-08-09py/objtuple: Allow to use inplace-multiplication operator on tuples.Damien George
2017-08-06py/mkrules.mk: Show frozen modules sizes together with executable size.Paul Sokolovsky
This works for Unix and similar ports so far.
2017-08-02py,extmod,stmhal: Use "static inline" for funcs that should be inline.Damien George
"STATIC inline" can expand to "inline" if STATIC is defined to nothing, and this case can lead to link errors.
2017-07-31all: Use the name MicroPython consistently in commentsAlexander Steffen
There were several different spellings of MicroPython present in comments, when there should be only one.
2017-07-31py/modsys: Use MP_ROM_INT for int values in an mp_rom_map_elem_t.Damien George
2017-07-28py/modio: BufferedWriter: Convert to mp_rom_map_elem_t.Paul Sokolovsky
2017-07-25py: Implement raising a big-int to a negative power.Damien George
Before this patch raising a big-int to a negative power would just return 0. Now it returns a floating-point number with the correct value.
2017-07-25py/mpz: Make mpz_is_zero() an inline function.Damien George
It's more efficient as an inline function, and saves code size.
2017-07-24all: Don't include system errno.h when it's not needed.Damien George
2017-07-24py/mperrno: Allow mperrno.h to be correctly included before other hdrs.Damien George
Before this patch the mperrno.h file could be included and would silently succeed with incorrect config settings, because mpconfig.h was not yet included.
2017-07-24py/py.mk: Make berkeley-db C-defs apply only to relevant source files.Damien George
Otherwise they can interfere (eg redefinition of "abort") with other source files in a given uPy port.
2017-07-21py/builtinevex: Add typechecking of globals/locals args to eval/exec.Tom Collins
2017-07-19all: Remove trailing spaces, per coding conventions.Damien George
2017-07-18py/modmicropython: Cast stack_limit value so it prints correctly.Damien George
Without this cast the print will give a wrong result on nan-boxing builds.
2017-07-18py/asmx64: Support moving a 64-bit immediate to one of top 8 registers.Damien George
If constants (eg mp_const_none_obj) are placed in very high memory locations that require 64-bits for the pointer then the assembler must be able to emit instructions to move such pointers to one of the top 8 registers (ie r8-r15).
2017-07-18py/vm: Make n_state variable local to just set-up part of VM.Damien George
It's not used anywhere else in the VM loop, and clashes with (is shadowed by) the n_state variable that's redeclared towards the end of the mp_execute_bytecode function. Code size is unchanged.
2017-07-18all: Unify header guard usage.Alexander Steffen
The code conventions suggest using header guards, but do not define how those should look like and instead point to existing files. However, not all existing files follow the same scheme, sometimes omitting header guards altogether, sometimes using non-standard names, making it easy to accidentally pick a "wrong" example. This commit ensures that all header files of the MicroPython project (that were not simply copied from somewhere else) follow the same pattern, that was already present in the majority of files, especially in the py folder. The rules are as follows. Naming convention: * start with the words MICROPY_INCLUDED * contain the full path to the file * replace special characters with _ In addition, there are no empty lines before #ifndef, between #ifndef and one empty line before #endif. #endif is followed by a comment containing the name of the guard macro. py/grammar.h cannot use header guards by design, since it has to be included multiple times in a single C file. Several other files also do not need header guards as they are only used internally and guaranteed to be included only once: * MICROPY_MPHALPORT_H * mpconfigboard.h * mpconfigport.h * mpthreadport.h * pin_defs_*.h * qstrdefs*.h
2017-07-12py/gc: Refactor assertions in gc_free function.Damien George
gc_free() expects either NULL or a valid pointer into the heap, so the checks for a valid pointer can be turned into assertions.