Skip to content

Commit 6d103b6

Browse files
committed
py: Move call_function_*_protected() functions to py/ for reuse.
They almost certainly needed by any C code which calls Python callbacks.
1 parent 104aa26 commit 6d103b6

8 files changed

Lines changed: 8 additions & 37 deletions

File tree

esp8266/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ SRC_C = \
7676
moduos.c \
7777
modmachine.c \
7878
modonewire.c \
79-
utils.c \
8079
ets_alt_task.c \
8180
$(BUILD)/frozen.c \
8281
fatfs_port.c \

esp8266/modesp.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "user_interface.h"
4141
#include "espconn.h"
4242
#include "spi_flash.h"
43-
#include "utils.h"
4443
#include "espneopixel.h"
4544
#include "modpyb.h"
4645

esp8266/modmachine.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "py/runtime.h"
3232
#include "extmod/machine_mem.h"
3333
#include "extmod/machine_i2c.h"
34-
#include "utils.h"
3534
#include "modpyb.h"
3635
#include "modpybrtc.h"
3736

@@ -137,7 +136,7 @@ STATIC mp_obj_t esp_timer_make_new(const mp_obj_type_t *type, mp_uint_t n_args,
137136

138137
STATIC void esp_timer_cb(void *arg) {
139138
esp_timer_obj_t *self = arg;
140-
call_function_1_protected(self->callback, self);
139+
mp_call_function_1_protected(self->callback, self);
141140
}
142141

143142
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) {

esp8266/modpybpin.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#include "py/runtime.h"
3838
#include "py/gc.h"
3939
#include "modpyb.h"
40-
#include "utils.h"
4140

4241
#define GET_TRIGGER(phys_port) \
4342
GPIO_PIN_INT_TYPE_GET(GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)))
@@ -105,7 +104,7 @@ void pin_intr_handler(uint32_t status) {
105104
if (status & 1) {
106105
mp_obj_t handler = MP_STATE_PORT(pin_irq_handler)[p];
107106
if (handler != MP_OBJ_NULL) {
108-
call_function_1_protected(handler, MP_OBJ_FROM_PTR(&pyb_pin_obj[p]));
107+
mp_call_function_1_protected(handler, MP_OBJ_FROM_PTR(&pyb_pin_obj[p]));
109108
}
110109
}
111110
}

esp8266/utils.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

py/py.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ PY_O_BASENAME = \
100100
parsenum.o \
101101
emitglue.o \
102102
runtime.o \
103+
runtime_utils.o \
103104
nativeglue.o \
104105
stackctrl.o \
105106
argcheck.o \

py/runtime.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
9595
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);
9696
mp_obj_t mp_call_method_n_kw(mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
9797
mp_obj_t mp_call_method_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const mp_obj_t *args);
98+
// Call function and catch/dump exception - for Python callbacks from C code
99+
void mp_call_function_1_protected(mp_obj_t fun, mp_obj_t arg);
100+
void mp_call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
98101

99102
typedef struct _mp_call_args_t {
100103
mp_obj_t fun;

esp8266/utils.c renamed to py/runtime_utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "py/obj.h"
3030
#include "py/nlr.h"
3131

32-
void call_function_1_protected(mp_obj_t fun, mp_obj_t arg) {
32+
void mp_call_function_1_protected(mp_obj_t fun, mp_obj_t arg) {
3333
nlr_buf_t nlr;
3434
if (nlr_push(&nlr) == 0) {
3535
mp_call_function_1(fun, arg);
@@ -39,7 +39,7 @@ void call_function_1_protected(mp_obj_t fun, mp_obj_t arg) {
3939
}
4040
}
4141

42-
void call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2) {
42+
void mp_call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2) {
4343
nlr_buf_t nlr;
4444
if (nlr_push(&nlr) == 0) {
4545
mp_call_function_2(fun, arg1, arg2);

0 commit comments

Comments
 (0)