diff options
Diffstat (limited to 'unix')
-rw-r--r-- | unix/Makefile | 2 | ||||
-rw-r--r-- | unix/gccollect.c | 12 | ||||
-rw-r--r-- | unix/input.c | 2 | ||||
-rw-r--r-- | unix/main.c | 21 | ||||
-rw-r--r-- | unix/modffi.c | 2 | ||||
-rw-r--r-- | unix/modos.c | 2 | ||||
-rw-r--r-- | unix/modsocket.c | 27 | ||||
-rw-r--r-- | unix/modtime.c | 2 | ||||
-rw-r--r-- | unix/mpconfigport.h | 1 |
9 files changed, 44 insertions, 27 deletions
diff --git a/unix/Makefile b/unix/Makefile index 9a85f59e1c..afe268ae45 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -18,7 +18,7 @@ INC += -I$(PY_SRC) INC += -I$(BUILD) # compiler settings -CWARN = -Wall -Werror +CWARN = -Wall -Werror -Wno-error=cpp CFLAGS = $(INC) $(CWARN) -ansi -std=gnu99 -DUNIX $(CFLAGS_MOD) $(COPT) $(CFLAGS_EXTRA) # Debugging/Optimization diff --git a/unix/gccollect.c b/unix/gccollect.c index 4f3b786e72..be05ff3ebc 100644 --- a/unix/gccollect.c +++ b/unix/gccollect.c @@ -26,8 +26,8 @@ #include <stdio.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "gc.h" #if MICROPY_ENABLE_GC @@ -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/input.c b/unix/input.c index 4d856f2ff8..19ca649c9f 100644 --- a/unix/input.c +++ b/unix/input.c @@ -41,8 +41,6 @@ #include <readline/history.h> #endif -#define CTRL_D '\x04' - char *prompt(char *p) { #if MICROPY_USE_READLINE char *line = readline(p); diff --git a/unix/main.c b/unix/main.c index 26736e4318..1bee639eb2 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(); @@ -149,7 +147,7 @@ STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { } STATIC void do_repl(void) { - printf("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; UNIX version\n"); + printf("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_PY_SYS_PLATFORM " version\n"); for (;;) { char *line = prompt(">>> "); @@ -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,7 @@ 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_set_limit(32768); pre_process_options(argc, argv); @@ -365,7 +361,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 +374,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 f1b219987b..48666aef0b 100644 --- a/unix/modffi.c +++ b/unix/modffi.c @@ -100,6 +100,8 @@ STATIC ffi_type *char2ffi_type(char c) switch (c) { case 'b': return &ffi_type_schar; case 'B': return &ffi_type_uchar; + case 'h': return &ffi_type_sshort; + case 'H': return &ffi_type_ushort; case 'i': return &ffi_type_sint; case 'I': return &ffi_type_uint; case 'l': return &ffi_type_slong; diff --git a/unix/modos.c b/unix/modos.c index 2e02ef0aa7..9b034cdbc2 100644 --- a/unix/modos.c +++ b/unix/modos.c @@ -30,8 +30,8 @@ #include <unistd.h> #include <errno.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "nlr.h" #include "qstr.h" #include "obj.h" diff --git a/unix/modsocket.c b/unix/modsocket.c index 8c5c9706c6..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); diff --git a/unix/modtime.c b/unix/modtime.c index 006fd0ebd7..286d8ea97e 100644 --- a/unix/modtime.c +++ b/unix/modtime.c @@ -30,8 +30,8 @@ #include <sys/time.h> #include <math.h> -#include "misc.h" #include "mpconfig.h" +#include "misc.h" #include "qstr.h" #include "obj.h" #include "runtime.h" diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 1559bdb359..763b34ba3e 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -41,6 +41,7 @@ #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_STREAMS_NON_BLOCK (1) #define MICROPY_OPT_COMPUTED_GOTO (1) +#define MICROPY_PY_BUILTINS_STR_UNICODE (0) #define MICROPY_PY_BUILTINS_FROZENSET (1) #define MICROPY_PY_SYS_EXIT (1) #define MICROPY_PY_SYS_PLATFORM "linux" |