From 6caae0bcb183fabd2bcf65c2ae2346b4e2d5cbe7 Mon Sep 17 00:00:00 2001 From: Antonin ENFRUN Date: Sun, 11 May 2014 21:28:26 +0200 Subject: [PATCH 1/4] unix: Create __bss_start and _end symbols for Mach-O targets. It's a hack, but can't find a cleaner way to do it. --- py/nlrx64.S | 4 ++++ unix/Makefile | 9 +++++++-- unix/order.def | 1 + unix/seg_helpers.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 unix/order.def create mode 100644 unix/seg_helpers.c diff --git a/py/nlrx64.S b/py/nlrx64.S index 55cb4d7960..baed6cabd6 100644 --- a/py/nlrx64.S +++ b/py/nlrx64.S @@ -32,6 +32,10 @@ #if !defined(__CYGWIN__) +#if (defined(__APPLE__) && defined(__MACH__)) +#define nlr_jump_fail _nlr_jump_fail +#endif // (defined(__APPLE__) && defined(__MACH__)) + /* uint nlr_push(rdi=nlr_buf_t *nlr) */ #if !(defined(__APPLE__) && defined(__MACH__)) .globl nlr_push diff --git a/unix/Makefile b/unix/Makefile index 05cdfb5b39..ba2180fe58 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -19,8 +19,8 @@ CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) - LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-map,$@.map -else + LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-map,$@.map,-order_file,order.def + else LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-Map=$@.map,--cref endif @@ -70,6 +70,11 @@ SRC_C = \ modsocket.c \ $(SRC_MOD) +# Must be the last file +ifeq ($(UNAME_S),Darwin) +SRC_C += seg_helpers.c +endif + OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) include ../py/mkrules.mk diff --git a/unix/order.def b/unix/order.def new file mode 100644 index 0000000000..34a4fea3e6 --- /dev/null +++ b/unix/order.def @@ -0,0 +1 @@ +seg_helpers.o: ___bss_start diff --git a/unix/seg_helpers.c b/unix/seg_helpers.c new file mode 100644 index 0000000000..1684f7a8f8 --- /dev/null +++ b/unix/seg_helpers.c @@ -0,0 +1,38 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * + * 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. + */ + +/* + This is a stub used to create the symbols __bss_start and _end in a Mach-O object file. + Thoses are needed by the GC, and should point to the start and end of the bss section. + We reach this goal by linking this file last (putting _end at the end...), and using an + order file (order.def) to move __bss_start at the start of bss. + + TODO: Some pragma to do it inline ? +*/ + +char __bss_start = 0; +char _end = 0; + From 1b901c320b28b85ea83972570675f2e701a06b4e Mon Sep 17 00:00:00 2001 From: Antonin ENFRUN Date: Sun, 11 May 2014 21:29:54 +0200 Subject: [PATCH 2/4] tests: create result file for test/basics/memoryerror.py . On Mac OS "python3 test/basics/memoryerror.py" never runs out of memory, the process is frozen by the os before. --- tests/basics/memoryerror.py.exp | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/basics/memoryerror.py.exp diff --git a/tests/basics/memoryerror.py.exp b/tests/basics/memoryerror.py.exp new file mode 100644 index 0000000000..930dbe98d6 --- /dev/null +++ b/tests/basics/memoryerror.py.exp @@ -0,0 +1,2 @@ +MemoryError +10000 0 9999 From ceac71f1f54220d64c87a0c2ebfd583ea49ca037 Mon Sep 17 00:00:00 2001 From: Antonin ENFRUN Date: Mon, 12 May 2014 00:24:41 +0200 Subject: [PATCH 3/4] unix: Add asm statements needed to read registers with clang. Code generated by gcc 4.9.0 is unchanged (same statements, different order). Both are inefficient, saving unmodified registers on the stack. --- unix/gccollect.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/unix/gccollect.c b/unix/gccollect.c index 647a1214de..1b5a38ffc6 100644 --- a/unix/gccollect.c +++ b/unix/gccollect.c @@ -43,11 +43,17 @@ typedef machine_uint_t regs_t[6]; void gc_helper_get_regs(regs_t arr) { register long rbx asm ("rbx"); + asm("" : "=r"(rbx)); register long rbp asm ("rbp"); + asm("" : "=r"(rbp)); register long r12 asm ("r12"); + asm("" : "=r"(r12)); register long r13 asm ("r13"); + asm("" : "=r"(r13)); register long r14 asm ("r14"); + asm("" : "=r"(r14)); register long r15 asm ("r15"); + asm("" : "=r"(r15)); arr[0] = rbx; arr[1] = rbp; arr[2] = r12; From da1fffaa093d2541f7374a7aaf16d2f00ed29ddc Mon Sep 17 00:00:00 2001 From: Antonin ENFRUN Date: Mon, 12 May 2014 00:21:50 +0200 Subject: [PATCH 4/4] Fix some unused variables, and silence a clang warning about initialization override in vmentrytable.h --- py/modmath.c | 1 + py/objexcept.c | 10 ++++++---- py/vmentrytable.h | 9 +++++++++ unix/modsocket.c | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/py/modmath.c b/py/modmath.c index f2253ab41e..485d9462a9 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -151,6 +151,7 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_copysign), (mp_obj_t)&mp_math_copysign_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_fabs), (mp_obj_t)&mp_math_fabs_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_floor), (mp_obj_t)&mp_math_floor_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_fmod), (mp_obj_t)&mp_math_fmod_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_frexp), (mp_obj_t)&mp_math_frexp_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_ldexp), (mp_obj_t)&mp_math_ldexp_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_modf), (mp_obj_t)&mp_math_modf_obj }, diff --git a/py/objexcept.c b/py/objexcept.c index 60b3565f6d..7f5f9c73d2 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -168,11 +168,13 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION(KeyError, LookupError) MP_DEFINE_EXCEPTION(MemoryError, Exception) MP_DEFINE_EXCEPTION(NameError, Exception) - MP_DEFINE_EXCEPTION_BASE(NameError) - //MP_DEFINE_EXCEPTION(UnboundLocalError, NameError) - MP_DEFINE_EXCEPTION(OSError, Exception) - MP_DEFINE_EXCEPTION_BASE(OSError) /* + MP_DEFINE_EXCEPTION_BASE(NameError) + MP_DEFINE_EXCEPTION(UnboundLocalError, NameError) + */ + MP_DEFINE_EXCEPTION(OSError, Exception) + /* + MP_DEFINE_EXCEPTION_BASE(OSError) MP_DEFINE_EXCEPTION(BlockingIOError, OSError) MP_DEFINE_EXCEPTION(ChildProcessError, OSError) MP_DEFINE_EXCEPTION(ConnectionError, OSError) diff --git a/py/vmentrytable.h b/py/vmentrytable.h index 217d84d3fd..598b5b8726 100644 --- a/py/vmentrytable.h +++ b/py/vmentrytable.h @@ -24,6 +24,11 @@ * THE SOFTWARE. */ +#if __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Winitializer-overrides" +#endif // __clang__ + static void* entry_table[256] = { [0 ... 255] = &&entry_default, [MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE, @@ -110,3 +115,7 @@ static void* entry_table[256] = { [MP_BC_IMPORT_FROM] = &&entry_MP_BC_IMPORT_FROM, [MP_BC_IMPORT_STAR] = &&entry_MP_BC_IMPORT_STAR, }; + +#if __clang__ +#pragma clang diagnostic pop +#endif // __clang__ diff --git a/unix/modsocket.c b/unix/modsocket.c index 72aee95eab..131d9285e4 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -291,6 +291,7 @@ STATIC const mp_obj_type_t microsocket_type = { .locals_dict = (mp_obj_t)µsocket_locals_dict, }; +#if MICROPY_SOCKET_EXTRA STATIC mp_obj_t mod_socket_htons(mp_obj_t arg) { return MP_OBJ_NEW_SMALL_INT((machine_int_t)htons(MP_OBJ_SMALL_INT_VALUE(arg))); } @@ -308,7 +309,6 @@ STATIC mp_obj_t mod_socket_inet_aton(mp_obj_t arg) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_inet_aton_obj, mod_socket_inet_aton); -#if MICROPY_SOCKET_EXTRA STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { assert(MP_OBJ_IS_TYPE(arg, &mp_type_str)); const char *s = mp_obj_str_get_str(arg); @@ -321,7 +321,7 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) { return mp_obj_new_int(*(int*)*h->h_addr_list); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_gethostbyname_obj, mod_socket_gethostbyname); -#endif +#endif // MICROPY_SOCKET_EXTRA STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { // TODO: Implement all args