summaryrefslogtreecommitdiffstatshomepage
path: root/py/objexcept.c
Commit message (Collapse)AuthorAge
* all: Use the name MicroPython consistently in commentsAlexander Steffen2017-07-31
| | | | | There were several different spellings of MicroPython present in comments, when there should be only one.
* py: Optimise types for common case where type has a single parent type.Damien George2017-04-12
| | | | | | | | | | | | | | | | | | | | | | | | The common cases for inheritance are 0 or 1 parent types, for both built-in types (eg built-in exceptions) as well as user defined types. So it makes sense to optimise the case of 1 parent type by storing just the type and not a tuple of 1 value (that value being the single parent type). This patch makes such an optimisation. Even though there is a bit more code to handle the two cases (either a single type or a tuple with 2 or more values) it helps reduce overall code size because it eliminates the need to create a static tuple to hold single parents (eg for the built-in exceptions). It also helps reduce RAM usage for user defined types that only derive from a single parent. Changes in code size (in bytes) due to this patch: bare-arm: -16 minimal (x86): -176 unix (x86-64): -320 unix nanbox: -384 stmhal: -64 cc3200: -32 esp8266: -108
* py: Make sure that static emg-exc-buffer is aligned to size of mp_obj_t.Damien George2017-04-10
| | | | | | | | | | | | This buffer is used to allocate objects temporarily, and such objects require that their underlying memory be correctly aligned for their data type. Aligning for mp_obj_t should be sufficient for emergency exceptions, but in general the memory buffer should aligned to the maximum alignment of the machine (eg on a 32-bit machine with mp_obj_t being 4 bytes, a double may not be correctly aligned). This patch fixes a bug for certain nan-boxing builds, where mp_obj_t is 8 bytes and must be aligned to 8 bytes (even though the machine is 32 bit).
* py/objexcept: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objexcept: Replace if-cond and assert(0) with simple assert.Damien George2017-01-17
|
* py/objexcept: Allow clearing traceback with 'exc.__traceback__ = None'.Paul Sokolovsky2016-11-14
| | | | | | | | | | | | | We allow 'exc.__traceback__ = None' assignment as a low-level optimization of pre-allocating exception instance and raising it repeatedly - this avoids memory allocation during raise. However, uPy will keep adding traceback entries to such exception instance, so before throwing it, traceback should be cleared like above. 'exc.__traceback__ = None' syntax is CPython compatible. However, unlike it, reading that attribute or setting it to any other value is not supported (and not intended to be supported, again, the only reason for adding this feature is to allow zero-memalloc exception raising).
* py/objexcept: Don't convert errno to str in constructor, do it in print.Damien George2016-05-12
| | | | | | | | OSError's are now printed like: OSError: [Errno 1] EPERM but only if the string corresponding to the errno is found.
* py: Add mp_errno_to_str() and use it to provide nicer OSError msgs.Damien George2016-05-12
| | | | | | | If an OSError is raised with an integer argument, and that integer corresponds to an errno, then the string for the errno is used as the argument to the exception, instead of the integer. Only works if the uerrno module is enabled.
* py: add async/await/async for/async with syntaxpohmelie2016-04-13
| | | | | | | | They are sugar for marking function as generator, "yield from" and pep492 python "semantically equivalents" respectively. @dpgeorge was the original author of this patch, but @pohmelie made changes to implement `async for` and `async with`.
* py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.Damien George2016-01-11
| | | | | | | | The first argument to the type.make_new method is naturally a uPy type, and all uses of this argument cast it directly to a pointer to a type structure. So it makes sense to just have it a pointer to a type from the very beginning (and a const pointer at that). This patch makes such a change, and removes all unnecessary casting to/from mp_obj_t.
* py: Change type signature of builtin funs that take variable or kw args.Damien George2016-01-11
| | | | | With this patch the n_args parameter is changed type from mp_uint_t to size_t.
* py: Change type of .make_new and .call args: mp_uint_t becomes size_t.Damien George2016-01-11
| | | | | | | This patch changes the type signature of .make_new and .call object method slots to use size_t for n_args and n_kw (was mp_uint_t. Makes code more efficient when mp_uint_t is larger than a machine word. Doesn't affect ports when size_t and mp_uint_t have the same size.
* py: Change exception traceback data to use size_t instead of mp_uint_t.Damien George2016-01-02
| | | | | The traceback array stores qstrs and line numbers. qstrs are typed as size_t, and line numbers should safely fit in size_t as well.
* py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George2015-11-29
| | | | | | | | | This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
* py: Add MP_ROM_* macros and mp_rom_* types and use them.Damien George2015-11-29
|
* py: Improve allocation policy of qstr data.Damien George2015-07-14
| | | | | | | | | | | | | | | | | | | | Previous to this patch all interned strings lived in their own malloc'd chunk. On average this wastes N/2 bytes per interned string, where N is the number-of-bytes for a quanta of the memory allocator (16 bytes on 32 bit archs). With this patch interned strings are concatenated into the same malloc'd chunk when possible. Such chunks are enlarged inplace when possible, and shrunk to fit when a new chunk is needed. RAM savings with this patch are highly varied, but should always show an improvement (unless only 3 or 4 strings are interned). New version typically uses about 70% of previous memory for the qstr data, and can lead to savings of around 10% of total memory footprint of a running script. Costs about 120 bytes code size on Thumb2 archs (depends on how many calls to gc_realloc are made).
* py: Add TimeoutError exception subclassed from OSError.Daniel Campora2015-07-02
| | | | | | | The TimeoutError is useful for some modules, specially the the socket module. TimeoutError can then be alised to socket.timeout and then Python code can differentiate between socket.error and socket.timeout.
* py: Make viper codegen raise proper exception (ViperTypeError) on error.Damien George2015-04-20
| | | | | | | | | | | This fixes a long standing problem that viper code generation gave terrible error messages, and actually no errors on pyboard where assertions are disabled. Now all compile-time errors are raised as proper Python exceptions, and are of type ViperTypeError. Addresses issue #940.
* py: Add %q format support to mp_[v]printf, and use it.Damien George2015-04-16
|
* py: Overhaul and simplify printf/pfenv mechanism.Damien George2015-04-16
| | | | | | | | | | | | | | | | | | | | | | Previous to this patch the printing mechanism was a bit of a tangled mess. This patch attempts to consolidate printing into one interface. All (non-debug) printing now uses the mp_print* family of functions, mainly mp_printf. All these functions take an mp_print_t structure as their first argument, and this structure defines the printing backend through the "print_strn" function of said structure. Printing from the uPy core can reach the platform-defined print code via two paths: either through mp_sys_stdout_obj (defined pert port) in conjunction with mp_stream_write; or through the mp_plat_print structure which uses the MP_PLAT_PRINT_STRN macro to define how string are printed on the platform. The former is only used when MICROPY_PY_IO is defined. With this new scheme printing is generally more efficient (less layers to go through, less arguments to pass), and, given an mp_print_t* structure, one can call mp_print_str for efficiency instead of mp_printf("%s", ...). Code size is also reduced by around 200 bytes on Thumb2 archs.
* py: Combine load_attr and store_attr type methods into one (attr).Damien George2015-04-11
| | | | | | This simplifies the API for objects and reduces code size (by around 400 bytes on Thumb2, and around 2k on x86). Performance impact was measured with Pystone score, but change was barely noticeable.
* py: Use m_{new,renew,del} consistently.Damien George2015-02-27
| | | | This is so all memory requests go through the same interface.
* py: Fix adding of traceback so that it appends to existing info.Damien George2015-02-27
| | | | | | | | This makes exception traceback info self contained (ie doesn't rely on list object, which was a bit of a hack), reduces code size, and reduces RAM footprint of exception by eliminating the list object. Addresses part of issue #1126.
* py: Implement UnicodeError.Paul Sokolovsky2015-02-23
| | | | | Still too shy to implement UnicodeEncodeError which was really needed for micropython-lib case.
* objexcept: Optimize traceback allocation for exception.Paul Sokolovsky2015-02-15
| | | | | | Traceback allocation for exception will now never lead to recursive MemoryError exception - if there's no memory for traceback, it simply won't be created.
* objexcept: Optimize using messages without formatting substitutions.Paul Sokolovsky2015-02-15
| | | | | They are directly cast to str object, skipping allocation of formatting buffer.
* py: Add mp_obj_new_str_from_vstr, and use it where relevant.Damien George2015-01-21
| | | | | | | | This patch allows to reuse vstr memory when creating str/bytes object. This improves memory usage. Also saves code ROM: 128 bytes on stmhal, 92 bytes on bare-arm, and 88 bytes on unix x64.
* py: Use mp_arg_check_num in some _make_new functions.Damien George2015-01-20
| | | | Reduces stmhal code size by about 250 bytes.
* py: Put all global state together in state structures.Damien George2015-01-07
| | | | | | This patch consolidates all global variables in py/ core into one place, in a global structure. Root pointers are all located together to make GC tracing easier and more efficient.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* py: Make gc.enable/disable just control auto-GC; alloc is still allowed.Damien George2014-10-31
| | | | | | gc.enable/disable are now the same as CPython: they just control whether automatic garbage collection is enabled or not. If disabled, you can still allocate heap memory, and initiate a manual collection.
* py: Add mp_pending_exception global variable, for VM soft interrupt.Damien George2014-10-25
| | | | | | | | | | | This allows to implement KeyboardInterrupt on unix, and a much safer ctrl-C in stmhal port. First ctrl-C is a soft one, with hope that VM will notice it; second ctrl-C is a hard one that kills anything (for both unix and stmhal). One needs to check for a pending exception in the VM only for jump opcodes. Others can't produce an infinite loop (infinite recursion is caught by stack check).
* py: Remove unused and unneeded SystemError exception.Damien George2014-10-22
| | | | | It's purpose is for internal errors that are not catastrophic (ie not as bad as RuntimeError). Since we don't use it, we don't need it.
* py: Fix dummy definition of BEGIN/END_ATOMIC_SECTION.Damien George2014-10-15
|
* py: Remove IOError since it's deprecated; use OSError instead.Damien George2014-09-30
| | | | | | | | | | | In CPython IOError (and EnvironmentError) is deprecated and aliased to OSError. All modules that used to raise IOError now raise OSError (or a derived exception). In Micro Python we never used IOError (except 1 place, incorrectly) and so don't need to keep it. See http://legacy.python.org/dev/peps/pep-3151/ for background.
* py: Tidy up exception matching; allow matching of tuple of exceptions.Damien George2014-09-25
| | | | Addresses issue #864.
* py: Change all uint to mp_uint_t in obj.h.Damien George2014-08-30
| | | | Part of code cleanup, working towards resolving issue #50.
* py: Make tuple and list use mp_int_t/mp_uint_t.Damien George2014-08-30
| | | | Part of code cleanup, to resolve issue #50.
* Change some parts of the core API to use mp_uint_t instead of uint/int.Damien George2014-08-30
| | | | Addressing issue #50, still some way to go yet.
* stmhal: Make enable_irq and disable_irq inline functions.Damien George2014-08-25
| | | | | | | | | | | | These functions are generally 1 machine instruction, and are used in critical code, so makes sense to have them inline. Also leave these functions uninverted (ie 0 means enable, 1 means disable) and provide macro constants if you really need to distinguish the states. This makes for smaller code as well (combined with inlining). Applied to teensy port as well.
* Add save/restore_irqDave Hylands2014-08-25
| | | | Factored irq functions into a separate file.
* Add support for storing args during an exception raised by an irq.Dave Hylands2014-07-25
| | | | | | | | | | | | | | | | | The user code should call micropython.alloc_emergency_exception_buf(size) where size is the size of the buffer used to print the argument passed to the exception. With the test code from #732, and a call to micropython.alloc_emergenncy_exception_buf(100) the following error is now printed: ```python >>> import heartbeat_irq Uncaught exception in Timer(4) interrupt handler Traceback (most recent call last): File "0://heartbeat_irq.py", line 14, in heartbeat_cb NameError: name 'led' is not defined ```
* Rename machine_(u)int_t to mp_(u)int_t.Damien George2014-07-03
| | | | See discussion in issue #50.
* py, objexcept: Only check for locked gc if gc is enabled.Damien George2014-07-01
|
* Try not to cause a MemoryError when raising an exception during nterrupt ↵Dave Hylands2014-06-30
| | | | | | handling. Step 1 fixes #732
* Change comments (mainly URLs) to no longer specifically say Python 3.3Chris Angelico2014-06-06
|
* Change const byte* to const char* where sensible.Damien George2014-05-25
| | | | | This removes need for some casts (at least, more than it adds need for new casts!).
* Add SystemExit exception and use it in unix/ and stmhal/ ports.Damien George2014-05-24
| | | | Addresses issue #598.
* Merge pull request #607 from Anton-2/osx-clangDamien George2014-05-21
|\ | | | | Allow compilation of unix port under clang on OS X
| * Fix some unused variables, and silence a clang warning about initialization ↵Antonin ENFRUN2014-05-12
| | | | | | | | override in vmentrytable.h