py: Move call_function_*_protected() functions to py/ for reuse.
They almost certainly needed by any C code which calls Python callbacks.
This commit is contained in:
parent
104aa26271
commit
6d103b6548
@ -76,7 +76,6 @@ SRC_C = \
|
|||||||
moduos.c \
|
moduos.c \
|
||||||
modmachine.c \
|
modmachine.c \
|
||||||
modonewire.c \
|
modonewire.c \
|
||||||
utils.c \
|
|
||||||
ets_alt_task.c \
|
ets_alt_task.c \
|
||||||
$(BUILD)/frozen.c \
|
$(BUILD)/frozen.c \
|
||||||
fatfs_port.c \
|
fatfs_port.c \
|
||||||
|
@ -40,7 +40,6 @@
|
|||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
#include "espconn.h"
|
#include "espconn.h"
|
||||||
#include "spi_flash.h"
|
#include "spi_flash.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "espneopixel.h"
|
#include "espneopixel.h"
|
||||||
#include "modpyb.h"
|
#include "modpyb.h"
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "extmod/machine_mem.h"
|
#include "extmod/machine_mem.h"
|
||||||
#include "extmod/machine_i2c.h"
|
#include "extmod/machine_i2c.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "modpyb.h"
|
#include "modpyb.h"
|
||||||
#include "modpybrtc.h"
|
#include "modpybrtc.h"
|
||||||
|
|
||||||
@ -137,7 +136,7 @@ STATIC mp_obj_t esp_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args,
|
|||||||
|
|
||||||
STATIC void esp_timer_cb(void *arg) {
|
STATIC void esp_timer_cb(void *arg) {
|
||||||
esp_timer_obj_t *self = arg;
|
esp_timer_obj_t *self = arg;
|
||||||
call_function_1_protected(self->callback, self);
|
mp_call_function_1_protected(self->callback, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
STATIC mp_obj_t esp_timer_init_helper(esp_timer_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
|
@ -37,7 +37,6 @@
|
|||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/gc.h"
|
#include "py/gc.h"
|
||||||
#include "modpyb.h"
|
#include "modpyb.h"
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#define GET_TRIGGER(phys_port) \
|
#define GET_TRIGGER(phys_port) \
|
||||||
GPIO_PIN_INT_TYPE_GET(GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)))
|
GPIO_PIN_INT_TYPE_GET(GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)))
|
||||||
@ -105,7 +104,7 @@ void pin_intr_handler(uint32_t status) {
|
|||||||
if (status & 1) {
|
if (status & 1) {
|
||||||
mp_obj_t handler = MP_STATE_PORT(pin_irq_handler)[p];
|
mp_obj_t handler = MP_STATE_PORT(pin_irq_handler)[p];
|
||||||
if (handler != MP_OBJ_NULL) {
|
if (handler != MP_OBJ_NULL) {
|
||||||
call_function_1_protected(handler, MP_OBJ_FROM_PTR(&pyb_pin_obj[p]));
|
mp_call_function_1_protected(handler, MP_OBJ_FROM_PTR(&pyb_pin_obj[p]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the Micro Python project, http://micropython.org/
|
|
||||||
*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015 Josef Gajdusek
|
|
||||||
* Copyright (c) 2015 Paul Sokolovsky
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void call_function_1_protected(mp_obj_t fun, mp_obj_t arg);
|
|
||||||
void call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
|
|
1
py/py.mk
1
py/py.mk
@ -100,6 +100,7 @@ PY_O_BASENAME = \
|
|||||||
parsenum.o \
|
parsenum.o \
|
||||||
emitglue.o \
|
emitglue.o \
|
||||||
runtime.o \
|
runtime.o \
|
||||||
|
runtime_utils.o \
|
||||||
nativeglue.o \
|
nativeglue.o \
|
||||||
stackctrl.o \
|
stackctrl.o \
|
||||||
argcheck.o \
|
argcheck.o \
|
||||||
|
@ -95,6 +95,9 @@ mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
|
|||||||
mp_obj_t mp_call_function_n_kw(mp_obj_t fun, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
mp_obj_t mp_call_function_n_kw(mp_obj_t fun, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
||||||
mp_obj_t mp_call_method_n_kw(mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
mp_obj_t mp_call_method_n_kw(mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
||||||
mp_obj_t mp_call_method_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const mp_obj_t *args);
|
mp_obj_t mp_call_method_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const mp_obj_t *args);
|
||||||
|
// Call function and catch/dump exception - for Python callbacks from C code
|
||||||
|
void mp_call_function_1_protected(mp_obj_t fun, mp_obj_t arg);
|
||||||
|
void mp_call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
|
||||||
|
|
||||||
typedef struct _mp_call_args_t {
|
typedef struct _mp_call_args_t {
|
||||||
mp_obj_t fun;
|
mp_obj_t fun;
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "py/nlr.h"
|
#include "py/nlr.h"
|
||||||
|
|
||||||
void call_function_1_protected(mp_obj_t fun, mp_obj_t arg) {
|
void mp_call_function_1_protected(mp_obj_t fun, mp_obj_t arg) {
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
mp_call_function_1(fun, arg);
|
mp_call_function_1(fun, arg);
|
||||||
@ -39,7 +39,7 @@ void call_function_1_protected(mp_obj_t fun, mp_obj_t arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2) {
|
void mp_call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2) {
|
||||||
nlr_buf_t nlr;
|
nlr_buf_t nlr;
|
||||||
if (nlr_push(&nlr) == 0) {
|
if (nlr_push(&nlr) == 0) {
|
||||||
mp_call_function_2(fun, arg1, arg2);
|
mp_call_function_2(fun, arg1, arg2);
|
Loading…
x
Reference in New Issue
Block a user