Skip to content
Snippets Groups Projects
Select Git revision
  • 357dbd700fc239aae37271463c4a74a7815d3a94
  • master default protected
  • fix-warnings
  • tvbgone-fixes
  • genofire/ble-follow-py
  • schneider/ble-stability-new-phy-adv
  • schneider/ble-stability
  • msgctl/gfx_rle
  • schneider/ble-stability-new-phy
  • add_menu_vibration
  • plaetzchen/ios-workaround
  • blinkisync-as-preload
  • schneider/max30001-pycardium
  • schneider/max30001-epicaridum
  • schneider/max30001
  • schneider/stream-locks
  • schneider/fundamental-test
  • schneider/ble-buffers
  • schneider/maxim-sdk-update
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
36 results

main.c

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    objexcept.c 12.05 KiB
    #include <string.h>
    #include <stdarg.h>
    #include <assert.h>
    
    #include "nlr.h"
    #include "misc.h"
    #include "mpconfig.h"
    #include "qstr.h"
    #include "obj.h"
    #include "objtuple.h"
    #include "runtime.h"
    #include "runtime0.h"
    
    typedef struct _mp_obj_exception_t {
        mp_obj_base_t base;
        mp_obj_t traceback; // a list object, holding (file,line,block) as numbers (not Python objects); a hack for now
        mp_obj_tuple_t *args;
    } mp_obj_exception_t;
    
    // Instance of MemoryError exception - needed by mp_malloc_fail
    const mp_obj_exception_t mp_const_MemoryError_obj = {{&mp_type_MemoryError}, MP_OBJ_NULL, mp_const_empty_tuple};
    
    // Local non-heap memory for allocating an exception when we run out of RAM
    STATIC mp_obj_exception_t mp_emergency_exception_obj;
    
    // Instance of GeneratorExit exception - needed by generator.close()
    // This would belong to objgenerator.c, but to keep mp_obj_exception_t
    // definition module-private so far, have it here.
    const mp_obj_exception_t mp_const_GeneratorExit_obj = {{&mp_type_GeneratorExit}, MP_OBJ_NULL, mp_const_empty_tuple};
    
    STATIC void mp_obj_exception_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
        mp_obj_exception_t *o = o_in;
        mp_print_kind_t k = kind & ~PRINT_EXC_SUBCLASS;
        bool is_subclass = kind & PRINT_EXC_SUBCLASS;
        if (!is_subclass && (k == PRINT_REPR || k == PRINT_EXC)) {
            print(env, "%s", qstr_str(o->base.type->name));
        }
    
        if (k == PRINT_EXC) {
            print(env, ": ");
        }
    
        if (k == PRINT_STR || k == PRINT_EXC) {
            if (o->args == NULL || o->args->len == 0) {
                print(env, "");
                return;
            } else if (o->args->len == 1) {
                mp_obj_print_helper(print, env, o->args->items[0], PRINT_STR);
                return;
            }
        }
        tuple_print(print, env, o->args, kind);
    }
    
    mp_obj_t mp_obj_exception_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
        mp_obj_type_t *type = type_in;
    
        if (n_kw != 0) {
            nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "%s does not take keyword arguments", mp_obj_get_type_str(type_in)));
        }
    
        mp_obj_exception_t *o = m_new_obj_var_maybe(mp_obj_exception_t, mp_obj_t, 0);
        if (o == NULL) {
            // Couldn't allocate heap memory; use local data instead.
            o = &mp_emergency_exception_obj;
            // We can't store any args.
            n_args = 0;
            o->args = mp_const_empty_tuple;
        } else {
            o->args = mp_obj_new_tuple(n_args, args);