Skip to content

Commit 4d7a176

Browse files
committed
fix ports/unix
1 parent ea77228 commit 4d7a176

File tree

9 files changed

+91
-37
lines changed

9 files changed

+91
-37
lines changed

ports/unix/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ INC += -I$(BUILD)
5050
# compiler settings
5151
CWARN = -Wall -Werror
5252
// CIRCUITPY-CHANGE: add -Wno-missing-field-initializers
53-
CWARN += -Wextra -Wno-unused-parameter -Wpointer-arith -Wdouble-promotion -Wfloat-conversion
53+
CWARN += -Wextra -Wno-unused-parameter -Wpointer-arith -Wdouble-promotion -Wfloat-conversion -Wno-missing-field-initializers
5454
CFLAGS += $(INC) $(CWARN) -std=gnu99 -DUNIX $(COPT) -I$(VARIANT_DIR) $(CFLAGS_EXTRA)
5555

5656
# Force the use of 64-bits for file sizes in C library functions on 32-bit platforms.

ports/unix/coverage.c

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ static void pairheap_test(size_t nops, int *ops) {
185185
mp_printf(&mp_plat_print, "\n");
186186
}
187187

188+
// CIRCUITPY-CHANGE: not turned on in CircuitPython
189+
#if MICROPY_SCHEDULER_STATIC_NODES
188190
static mp_sched_node_t mp_coverage_sched_node;
189191
static bool coverage_sched_function_continue;
190192

@@ -196,6 +198,7 @@ static void coverage_sched_function(mp_sched_node_t *node) {
196198
mp_sched_schedule_node(&mp_coverage_sched_node, coverage_sched_function);
197199
}
198200
}
201+
#endif
199202

200203
// function to run extra tests for things that can't be checked by scripts
201204
static mp_obj_t extra_coverage(void) {
@@ -589,6 +592,22 @@ static mp_obj_t extra_coverage(void) {
589592
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
590593
}
591594

595+
// mp_obj_get_uint from a non-int object (should raise exception)
596+
if (nlr_push(&nlr) == 0) {
597+
mp_obj_get_uint(mp_const_none);
598+
nlr_pop();
599+
} else {
600+
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
601+
}
602+
603+
// mp_obj_int_get_ll from a non-int object (should raise exception)
604+
if (nlr_push(&nlr) == 0) {
605+
mp_obj_get_ll(mp_const_none);
606+
nlr_pop();
607+
} else {
608+
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
609+
}
610+
592611
// call mp_obj_new_exception_args (it's a part of the public C API and not used in the core)
593612
mp_obj_print_exception(&mp_plat_print, mp_obj_new_exception_args(&mp_type_ValueError, 0, NULL));
594613
}
@@ -598,26 +617,6 @@ static mp_obj_t extra_coverage(void) {
598617
mp_emitter_warning(MP_PASS_CODE_SIZE, "test");
599618
}
600619

601-
// format float
602-
{
603-
mp_printf(&mp_plat_print, "# format float\n");
604-
605-
// format with inadequate buffer size
606-
char buf[5];
607-
mp_format_float(1, buf, sizeof(buf), 'g', 0, '+');
608-
mp_printf(&mp_plat_print, "%s\n", buf);
609-
610-
// format with just enough buffer so that precision must be
611-
// set from 0 to 1 twice
612-
char buf2[8];
613-
mp_format_float(1, buf2, sizeof(buf2), 'g', 0, '+');
614-
mp_printf(&mp_plat_print, "%s\n", buf2);
615-
616-
// format where precision is trimmed to avoid buffer overflow
617-
mp_format_float(1, buf2, sizeof(buf2), 'e', 0, '+');
618-
mp_printf(&mp_plat_print, "%s\n", buf2);
619-
}
620-
621620
// binary
622621
{
623622
mp_printf(&mp_plat_print, "# binary\n");
@@ -641,14 +640,26 @@ static mp_obj_t extra_coverage(void) {
641640
fun_bc.context = &context;
642641
fun_bc.child_table = NULL;
643642
fun_bc.bytecode = (const byte *)"\x01"; // just needed for n_state
643+
#if MICROPY_PY_SYS_SETTRACE
644+
struct _mp_raw_code_t rc = {};
645+
fun_bc.rc = &rc;
646+
#endif
644647
mp_code_state_t *code_state = m_new_obj_var(mp_code_state_t, state, mp_obj_t, 1);
645648
code_state->fun_bc = &fun_bc;
646649
code_state->ip = (const byte *)"\x00"; // just needed for an invalid opcode
647650
code_state->sp = &code_state->state[0];
648651
code_state->exc_sp_idx = 0;
649652
code_state->old_globals = NULL;
653+
#if MICROPY_STACKLESS
654+
code_state->prev = NULL;
655+
#endif
656+
#if MICROPY_PY_SYS_SETTRACE
657+
code_state->prev_state = NULL;
658+
code_state->frame = NULL;
659+
#endif
660+
650661
mp_vm_return_kind_t ret = mp_execute_bytecode(code_state, MP_OBJ_NULL);
651-
mp_printf(&mp_plat_print, "%d %d\n", ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError);
662+
mp_printf(&mp_plat_print, "%d %d\n", (int)ret, mp_obj_get_type(code_state->state[0]) == &mp_type_NotImplementedError);
652663
}
653664

654665
// scheduler
@@ -705,9 +716,25 @@ static mp_obj_t extra_coverage(void) {
705716
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
706717
}
707718
mp_handle_pending(true);
719+
720+
// CIRCUITPY-CHANGE: not turned on in CircuitPython
721+
#if MICROPY_SCHEDULER_STATIC_NODES
722+
coverage_sched_function_continue = true;
723+
mp_sched_schedule_node(&mp_coverage_sched_node, coverage_sched_function);
724+
for (int i = 0; i < 3; ++i) {
725+
mp_printf(&mp_plat_print, "loop\n");
726+
mp_handle_pending(true);
727+
}
728+
// Clear this flag to prevent the function scheduling itself again
729+
coverage_sched_function_continue = false;
730+
// Will only run the first time through this loop, then not scheduled again
731+
for (int i = 0; i < 3; ++i) {
732+
mp_handle_pending(true);
733+
}
734+
#endif
708735
}
709736

710-
// CIRCUITPY-CHANGE: ringbuf is different
737+
// CIRCUITPY-CHANGE: ringbuf is quite different
711738
// ringbuf
712739
{
713740
#define RINGBUF_SIZE 99
@@ -719,7 +746,7 @@ static mp_obj_t extra_coverage(void) {
719746
mp_printf(&mp_plat_print, "# ringbuf\n");
720747

721748
// Single-byte put/get with empty ringbuf.
722-
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_free(&ringbuf), (int)ringbuf_num_filled(&ringbuf));
749+
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_num_empty(&ringbuf), (int)ringbuf_num_filled(&ringbuf));
723750
ringbuf_put(&ringbuf, 22);
724751
mp_printf(&mp_plat_print, "%d %d\n", (int)ringbuf_num_empty(&ringbuf), (int)ringbuf_num_filled(&ringbuf));
725752
mp_printf(&mp_plat_print, "%d\n", ringbuf_get(&ringbuf));

ports/unix/coveragecpp.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
extern "C" {
2-
// CIRCUITPY-CHANGE: do not include everything: it causes compilation warnings
3-
#include "py/obj.h"
2+
// Include the complete public API to verify everything compiles as C++.
3+
#include <py/gc.h>
4+
#include <py/obj.h>
5+
#include <py/objarray.h>
6+
#include <py/objexcept.h>
7+
#include <py/objfun.h>
8+
#include <py/objgenerator.h>
9+
#include <py/objint.h>
10+
#include <py/objlist.h>
11+
#include <py/objmodule.h>
12+
#include <py/objnamedtuple.h>
13+
#include <py/objstr.h>
14+
#include <py/objstringio.h>
15+
#include <py/objtuple.h>
16+
#include <py/objtype.h>
17+
#include <py/runtime.h>
418
}
519

620
// Invoke all (except one, see below) public API macros which initialize structs to make sure

ports/unix/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,18 @@ static inline int convert_pyexec_result(int ret) {
269269
}
270270

271271
static int do_file(const char *file) {
272-
return convert_pyexec_result(pyexec_file(file));
272+
// CIRCUITPY-CHANGE: pyexec_file result arg
273+
pyexec_result_t pyexec_result;
274+
return convert_pyexec_result(pyexec_file(file, &pyexec_result));
273275
}
274276

275277
static int do_str(const char *str) {
276278
vstr_t vstr;
277279
vstr.buf = (char *)str;
278280
vstr.len = strlen(str);
279-
int ret = pyexec_vstr(&vstr, true);
281+
// CIRCUITPY-CHANGE: pyexec_vstr result arg
282+
pyexec_result_t pyexec_result;
283+
int ret = pyexec_vstr(&vstr, true, &pyexec_result);
280284
return convert_pyexec_result(ret);
281285
}
282286

ports/unix/mphalport.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626
#include <errno.h>
2727
#include <unistd.h>
28-
// CIRCUITPY-CHANGE: extra include
2928
#include <stdbool.h>
3029

3130
#ifndef CHAR_CTRL_C
@@ -38,6 +37,20 @@
3837
#define MICROPY_END_ATOMIC_SECTION(x) (void)x; mp_thread_unix_end_atomic_section()
3938
#endif
4039

40+
// In lieu of a WFI(), slow down polling from being a tight loop.
41+
//
42+
// Note that we don't delay for the full TIMEOUT_MS, as execution
43+
// can't be woken from the delay.
44+
#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) \
45+
do { \
46+
MP_THREAD_GIL_EXIT(); \
47+
mp_hal_delay_us(500); \
48+
MP_THREAD_GIL_ENTER(); \
49+
} while (0)
50+
51+
// The port provides `mp_hal_stdio_mode_raw()` and `mp_hal_stdio_mode_orig()`.
52+
#define MICROPY_HAL_HAS_STDIO_MODE_SWITCH (1)
53+
4154
// CIRCUITPY-CHANGE: mp_hal_set_interrupt_char(int) instead of char
4255
void mp_hal_set_interrupt_char(int c);
4356
bool mp_hal_is_interrupted(void);

py/bc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static inline void mp_module_context_alloc_tables(mp_module_context_t *context,
304304
size_t nq = (n_qstr * sizeof(qstr_short_t) + sizeof(mp_uint_t) - 1) / sizeof(mp_uint_t);
305305
size_t no = n_obj;
306306
// CIRCUITPY-CHANGE
307-
mp_uint_t *mem = m_malloc_items(nq + no);
307+
mp_uint_t *mem = (mp_uint_t *)m_malloc_items(nq + no);
308308
context->constants.qstr_table = (qstr_short_t *)mem;
309309
context->constants.obj_table = (mp_obj_t *)(mem + nq);
310310
#else

py/mpconfig.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,11 +2434,6 @@ typedef time_t mp_timestamp_t;
24342434
#define MP_COLD __attribute__((cold))
24352435
#endif
24362436

2437-
// CIRCUITPY-CHANGE: avoid undefined warnings
2438-
#ifndef MICROPY_HAL_HAS_STDIO_MODE_SWITCH
2439-
#define MICROPY_HAL_HAS_STDIO_MODE_SWITCH (0)
2440-
#endif
2441-
24422437
// To annotate that code is unreachable
24432438
#ifndef MP_UNREACHABLE
24442439
#if defined(__GNUC__)

py/obj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
408408
{.base = {.type = &mp_type_fun_builtin_var}, .sig = MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, false), .fun = {.var = fun_name}}
409409
#define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) \
410410
const mp_obj_fun_builtin_var_t obj_name = \
411-
{{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, MP_OBJ_FUN_ARGS_MAX, true), .fun.kw = fun_name}
411+
{.base = {.type = &mp_type_fun_builtin_var}, .sig = MP_OBJ_FUN_MAKE_SIG(n_args_min, MP_OBJ_FUN_ARGS_MAX, true), .fun = {.kw = fun_name}}
412412

413413
// CIRCUITPY-CHANGE
414414
#define MP_DEFINE_CONST_PROP_GET(obj_name, fun_name) \

shared/runtime/pyexec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ MP_REGISTER_ROOT_POINTER(vstr_t * repl_line);
570570

571571
#else // MICROPY_REPL_EVENT_DRIVEN
572572

573-
#if !MICROPY_HAL_HAS_STDIO_MODE_SWITCH
573+
// CIRCUITPY-CHANGE: avoid warnings
574+
#if defined(MICROPY_HAL_HAS_STDIO_MODE_SWITCH) && !MICROPY_HAL_HAS_STDIO_MODE_SWITCH
574575
// If the port doesn't need any stdio mode switching calls then provide trivial ones.
575576
static inline void mp_hal_stdio_mode_raw(void) {
576577
}

0 commit comments

Comments
 (0)