diff options
Diffstat (limited to 'unix')
-rw-r--r-- | unix/Makefile | 32 | ||||
-rw-r--r-- | unix/gccollect.c | 10 | ||||
-rw-r--r-- | unix/main.c | 20 | ||||
-rw-r--r-- | unix/modffi.c | 4 | ||||
-rw-r--r-- | unix/modos.c | 4 | ||||
-rw-r--r-- | unix/modsocket.c | 31 | ||||
-rw-r--r-- | unix/modtime.c | 4 | ||||
-rw-r--r-- | unix/mpconfigport.h | 2 |
8 files changed, 64 insertions, 43 deletions
diff --git a/unix/Makefile b/unix/Makefile index 485009135f..afe268ae45 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -7,6 +7,9 @@ PROG = micropython # qstr definitions (must come before including py.mk) QSTR_DEFS = qstrdefsport.h +# OS name, for simple autoconfig +UNAME_S := $(shell uname -s) + # include py core make definitions include ../py/py.mk @@ -15,14 +18,18 @@ INC += -I$(PY_SRC) INC += -I$(BUILD) # compiler settings -CFLAGS = $(INC) -Wall -Werror -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) +CWARN = -Wall -Werror -Wno-error=cpp +CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) -UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Darwin) - LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-map,$@.map,-order_file,$(BUILD)/order.def - else - LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-Map=$@.map,--cref - endif +# Debugging/Optimization +ifdef DEBUG +CFLAGS += -g +COPT = -O0 +else +COPT = -Os #-DNDEBUG +endif + +LDFLAGS = $(LDFLAGS_MOD) -lm -Wl,-Map=$@.map,--cref $(LDFLAGS_EXTRA) ifeq ($(MICROPY_FORCE_32BIT),1) CFLAGS += -m32 @@ -56,14 +63,6 @@ SRC_MOD += modffi.c endif -# Debugging/Optimization -ifdef DEBUG -CFLAGS += -g -COPT = -O0 -else -COPT = -Os #-DNDEBUG -endif - # source files SRC_C = \ main.c \ @@ -75,6 +74,9 @@ SRC_C = \ $(SRC_MOD) ifeq ($(UNAME_S),Darwin) + +LDFLAGS+ = -Wl,-order_file,$(BUILD)/order.def + # Must be the last file in list of sources SRC_C += seg_helpers.c diff --git a/unix/gccollect.c b/unix/gccollect.c index 4f3b786e72..f24cc52495 100644 --- a/unix/gccollect.c +++ b/unix/gccollect.c @@ -97,7 +97,7 @@ void gc_helper_get_regs(regs_t arr) { } #endif -#ifdef __thumb2__ +#if defined(__thumb2__) || defined(__thumb__) || defined(__arm__) typedef machine_uint_t regs_t[10]; void gc_helper_get_regs(regs_t arr) { @@ -130,8 +130,11 @@ void gc_collect(void) { gc_collect_start(); // this traces the .bss section -#ifdef __CYGWIN__ +#if defined( __CYGWIN__ ) #define BSS_START __bss_start__ +#elif defined( _MSC_VER ) || defined( __MINGW32__ ) +#define BSS_START *bss_start +#define _end *bss_end #else #define BSS_START __bss_start #endif @@ -141,7 +144,8 @@ void gc_collect(void) { regs_t regs; gc_helper_get_regs(regs); // GC stack (and regs because we captured them) - gc_collect_root((void**)®s, ((machine_uint_t)stack_top - (machine_uint_t)®s) / sizeof(machine_uint_t)); + void **regs_ptr = (void**)(void*)®s; + gc_collect_root(regs_ptr, ((machine_uint_t)stack_top - (machine_uint_t)®s) / sizeof(machine_uint_t)); gc_collect_end(); //printf("-----\n"); diff --git a/unix/main.c b/unix/main.c index 26736e4318..a08661339c 100644 --- a/unix/main.c +++ b/unix/main.c @@ -51,6 +51,7 @@ #include "gc.h" #include "genhdr/py-version.h" #include "input.h" +#include "stackctrl.h" // Command line options, with their defaults bool compile_only = false; @@ -63,9 +64,6 @@ uint mp_verbose_flag; long heap_size = 128*1024 * (sizeof(machine_uint_t) / 4); #endif -// Stack top at the start of program -char *stack_top; - void microsocket_init(); void time_init(); void ffi_init(); @@ -201,8 +199,8 @@ int usage(char **argv) { impl_opts_cnt++; #if MICROPY_ENABLE_GC printf( -" heapsize=<n> -- set the heap size for the GC\n" -); +" heapsize=<n> -- set the heap size for the GC (default %ld)\n" +, heap_size); impl_opts_cnt++; #endif @@ -214,10 +212,9 @@ int usage(char **argv) { } mp_obj_t mem_info(void) { - volatile int stack_dummy; printf("mem: total=%d, current=%d, peak=%d\n", m_get_total_bytes_allocated(), m_get_current_bytes_allocated(), m_get_peak_bytes_allocated()); - printf("stack: " INT_FMT "\n", stack_top - (char*)&stack_dummy); + printf("stack: %u\n", stack_usage()); #if MICROPY_ENABLE_GC gc_dump_info(); #endif @@ -268,8 +265,8 @@ void pre_process_options(int argc, char **argv) { #endif int main(int argc, char **argv) { - volatile int stack_dummy; - stack_top = (char*)&stack_dummy; + stack_ctrl_init(); + stack_set_limit(32768); pre_process_options(argc, argv); @@ -365,7 +362,8 @@ int main(int argc, char **argv) { return usage(argv); } } else { - char *basedir = realpath(argv[a], NULL); + char *pathbuf = malloc(PATH_MAX); + char *basedir = realpath(argv[a], pathbuf); if (basedir == NULL) { fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[a], errno); perror(""); @@ -377,7 +375,7 @@ int main(int argc, char **argv) { // Set base dir of the script as first entry in sys.path char *p = strrchr(basedir, '/'); path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir)); - free(basedir); + free(pathbuf); for (int i = a; i < argc; i++) { mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); diff --git a/unix/modffi.c b/unix/modffi.c index bfc840ceff..f1b219987b 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -421,8 +421,8 @@ STATIC const mp_obj_dict_t mp_module_ffi_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(mp_module_ffi_globals_table), - .alloc = ARRAY_SIZE(mp_module_ffi_globals_table), + .used = MP_ARRAY_SIZE(mp_module_ffi_globals_table), + .alloc = MP_ARRAY_SIZE(mp_module_ffi_globals_table), .table = (mp_map_elem_t*)mp_module_ffi_globals_table, }, }; diff --git a/unix/modos.c b/unix/modos.c index 657958d04c..2e02ef0aa7 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -75,8 +75,8 @@ STATIC const mp_obj_dict_t mp_module_os_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(mp_module_os_globals_table), - .alloc = ARRAY_SIZE(mp_module_os_globals_table), + .used = MP_ARRAY_SIZE(mp_module_os_globals_table), + .alloc = MP_ARRAY_SIZE(mp_module_os_globals_table), .table = (mp_map_elem_t*)mp_module_os_globals_table, }, }; diff --git a/unix/modsocket.c b/unix/modsocket.c index b1a34a39b8..5b3fb01877 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -356,6 +356,8 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { const char *host = mp_obj_str_get_str(args[0]); const char *serv = NULL; + struct addrinfo hints; + memset(&hints, 0, sizeof(hints)); // getaddrinfo accepts port in string notation, so however // it may seem stupid, we need to convert int to str if (MP_OBJ_IS_SMALL_INT(args[1])) { @@ -363,23 +365,35 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { char buf[6]; sprintf(buf, "%d", port); serv = buf; + hints.ai_flags = AI_NUMERICSERV; +#ifdef __UCLIBC_MAJOR__ +#if __UCLIBC_MAJOR__ == 0 && (__UCLIBC_MINOR__ < 9 || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ <= 32)) +#warning Working around uClibc bug with numeric service name + // Older versions og uClibc have bugs when numeric ports in service + // arg require also hints.ai_socktype (or hints.ai_protocol) != 0 + // This actually was fixed in 0.9.32.1, but uClibc doesn't allow to + // test for that. + // http://git.uclibc.org/uClibc/commit/libc/inet/getaddrinfo.c?id=bc3be18145e4d5 + // Note that this is crude workaround, precluding UDP socket addresses + // to be returned. TODO: set only if not set by Python args. + hints.ai_socktype = SOCK_STREAM; +#endif +#endif } else { serv = mp_obj_str_get_str(args[1]); } - struct addrinfo hints; - struct addrinfo *addr; - memset(&hints, 0, sizeof(hints)); - int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr); + struct addrinfo *addr_list; + int res = getaddrinfo(host, serv, &hints, &addr_list); if (res != 0) { // CPython: socket.gaierror nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[addrinfo error %d]", res)); } - assert(addr); + assert(addr_list); mp_obj_t list = mp_obj_new_list(0, NULL); - for (; addr; addr = addr->ai_next) { + for (struct addrinfo *addr = addr_list; addr; addr = addr->ai_next) { mp_obj_tuple_t *t = mp_obj_new_tuple(5, NULL); t->items[0] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_family); t->items[1] = MP_OBJ_NEW_SMALL_INT((machine_int_t)addr->ai_socktype); @@ -394,6 +408,7 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) { t->items[4] = mp_obj_new_bytearray(addr->ai_addrlen, addr->ai_addr); mp_obj_list_append(list, t); } + freeaddrinfo(addr_list); return list; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_socket_getaddrinfo_obj, 2, 6, mod_socket_getaddrinfo); @@ -436,8 +451,8 @@ STATIC const mp_obj_dict_t mp_module_socket_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(mp_module_socket_globals_table), - .alloc = ARRAY_SIZE(mp_module_socket_globals_table), + .used = MP_ARRAY_SIZE(mp_module_socket_globals_table), + .alloc = MP_ARRAY_SIZE(mp_module_socket_globals_table), .table = (mp_map_elem_t*)mp_module_socket_globals_table, }, }; diff --git a/unix/modtime.c b/unix/modtime.c index 3cc09e3cd8..006fd0ebd7 100644 --- a/unix/modtime.c +++ b/unix/modtime.c @@ -113,8 +113,8 @@ STATIC const mp_obj_dict_t mp_module_time_globals = { .map = { .all_keys_are_qstrs = 1, .table_is_fixed_array = 1, - .used = ARRAY_SIZE(mp_module_time_globals_table), - .alloc = ARRAY_SIZE(mp_module_time_globals_table), + .used = MP_ARRAY_SIZE(mp_module_time_globals_table), + .alloc = MP_ARRAY_SIZE(mp_module_time_globals_table), .table = (mp_map_elem_t*)mp_module_time_globals_table, }, }; diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 3426ae44fe..1559bdb359 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -53,7 +53,9 @@ #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED) // Define to 1 to use untested inefficient GC helper implementation // (if more efficient arch-specific one is not available). +#ifndef MICROPY_GCREGS_SETJMP #define MICROPY_GCREGS_SETJMP (0) +#endif extern const struct _mp_obj_module_t mp_module_os; extern const struct _mp_obj_module_t mp_module_time; |