diff options
author | Damien George <damien.p.george@gmail.com> | 2017-08-14 12:19:09 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-08-14 12:19:09 +1000 |
commit | bb254ba0ea89ce60dd6deab94991b2651c00dff3 (patch) | |
tree | fa2b66f3a1a9fd4bb90b2c83ce9954099b06fe01 /unix | |
parent | 5e76ea4affd0bd46e67b456496818803010a2d24 (diff) | |
parent | e4e4526954f8bcd88ceb21fe789963bfa710fa4f (diff) | |
download | micropython-bb254ba0ea89ce60dd6deab94991b2651c00dff3.tar.gz micropython-bb254ba0ea89ce60dd6deab94991b2651c00dff3.zip |
Merge tag 'v1.8.3' into parse-bytecode
Many small improvements and additions, with btree support in ESP8266 port
This release brings various improvements and additions to the core,
extended modules and the ESP8266 port, as well as enhancements to the docs.
There is now a "threshold" function in the gc module for the user to
configure the garbage collector to run earlier than usual, in order to help
reduce fragmentation of the heap. The btree module is now available in the
ESP8266 port, and there is improved WebREPL file transfer: get file is now
non-blocking (this change requires an update of the client software).
py core:
- nlrx64.S: prefix mp_thread_get_state with an underscore on Mac
- stream: implement 2- and 3-arg write() method as an extension to CPython
- gc: implement GC running by allocation threshold, user configurable
- fix nlrthumb.c when DEBUG=1 is defined
- obj: issue a warning when str and bytes objects are compared
- mpconfig.h: fix description for MICROPY_PY_STR_BYTES_CMP_WARN
- objstrunicode: str_index_to_ptr: should handle bytes too
- objstrunicode: str_index_to_ptr: implement positive indexing properly
- stream: implement generic flush() method, in terms of C-level ioctl
- objstringio: add MP_STREAM_FLUSH ioctl and flush() method
- objstringio: implement MP_STREAM_SEEK ioctl and add seek() method
- stream: add adapter methods with POSIX-compatible signatures
- mpconfig.h: add MICROPY_STREAMS_POSIX_API setting
- py.mk: extra switches to build "embedded" BerkeleyDB BTree lib
- mkrules.mk: allow to add more items for "clean" target using CLEAN_EXTRA
- objstr: make .partition()/.rpartition() methods configurable
- mpconfig.h: define MP_ALWAYSINLINE for reuse
extmod:
- modussl: rename to modussl_axtls.c, to allow impl using other SSL libs
- modussl_axtls: further changes to allow alternative SSL modules
- modussl_axtls: add dummy setblocking() method
- vfs_fat: implement rmdir() method (aliases to unlink)
- modussl_axtls: use mp_stream_close() method
- modwebrepl: use mp_stream_close() method
- modbtree: check __bt_open() return value for error
- modbtree: switch to accepting stream object instead of filename
- modbtree: implement __contains__ operation
- modwebrepl: factor out "GET" iteration to write_file_chunk()
- modwebrepl: make GET_FILE operation non-blocking
- modbtree: open(): add option kwargs
- modwebsocket: add readline method
- modwebsocket: make compatible with non-default object models
- modwebsocket: use mp_rom_map_elem_t and friends
- modwebrepl: add GET_VER operation to query MicroPython version
lib:
- axtls: upgrade to axTLS 1.5.4 + MicroPython patchset
- axtls: update, fixes esp8266 build
- utils/stdout_helpers: move from minimal/uart_extra.c for reuse
- embed/abort_: implementation of abort_() function raising uPy exception
- berkeley-db-1.xx: switch to "embedded" branch
- berkeley-db-1.xx: update, sets default page size to 4096
tests:
- add test for extended arguments to stream .write() method
- extmod/machine_pinbase: skip if machine.PinBase is not available
- bytes_compare: rework test for bytes <-> str comparison
- extmod/btree1: close database at the end of test
- unicode_subscr.py: detailed test for subscripting unicode strings
- run-tests: make "regex'ed .exp" facility available to device tests
- io/bytesio_ext: test for .seek()/.flush() on BytesIO
- extmod/btree1: tests against in-memory DB (using io.BytesIO)
- machine_mem.py: too non-portable, rework as an example for unix port
- machine1: revamp to work with unix port (which has "umachine")
- basics: bytes/str.partition/rpartition are now optional
mpy-cross:
- fix Makefile to handle gc-sections linker flags on OS X
- use binary file translation mode for creating mpy files on windows
- fix mingw and msys2 compilation
minimal port:
- disable MICROPY_GC_ALLOC_THRESHOLD
unix port:
- mpthreadport: adjust minimum thread stack, and stack limit check
- cache libaxtls.a in local build dir
- disable MICROPY_GC_ALLOC_THRESHOLD for minimal build
- enable MICROPY_PY_STR_BYTES_CMP_WARN
- mpconfigport.h: include stdio.h by default
- file: implement MP_STREAM_FLUSH ioctl
- file: ioctl(): check that file is open before operations
- file: fdfile_ioctl(): fix argument to check_fd_is_open()
- file: use generic stream flush() method
- enable websocket module
- moduselect: allow poll.register(), etc. accept fd-like objects
stmhal port:
- fix malloc when used with external libraries
- make SPI NSS pin definition optional
- fix I2C mappings for STM32F429DISC board
esp8266 port:
- select axTLS for SSL implementation, following recent refactor
- moduos: add rmdir() function
- cache Xtensa-built libaxtls.a in local build dir
- enable MICROPY_PY_STR_BYTES_CMP_WARN
- dupterm_task_init() should be called before running _boot.py, etc
- _boot.py: set GC alloc threshold to half of heap size
- _boot.py: decrease GC alloc threshold to quarter of heap size
- modpybuart: fix UART parity setting
- axtls_helpers: remove abort_(), now in lib/embed/
- mpconfigport.h: include sys/types.h for POSIX types definitions
- esp_mphal: implement libc's errno
- enable btree module
- eagle.rom.addr.v6.ld: add Enable_QMode symbol from SDK 2.0.0
- make APA102 driver inclusion configurable
- makeimg.py: store firmware size as last 4 bytes of padding area
- makeimg.py: append md5 hash to the generated binary
- modesp: add check_fw() function to check integrity of the firmware
- scripts/port_diag.py: include esp.check_fw() call
- flashbdev: reserve extra sysparam sector for SDK 2.0.0 compatibility
- scripts/inisetup: add commented-out call to esp.osdebug(None)
- modmachine: implement idle() function
- esp_mphal.h: add mp_hal_ticks_cpu() for reuse
- modutime: actually implement ticks_cpu()
- modmachine: implement dummy sleep() function
- tutorial/intro: reword para abou -fm dio switch
- modules/flashbdev: start filesystem at 0x90000
- esp8266.ld: increase firmware image size to 0x90000 (576K)
docs:
- add DHT to ESP8266 Quick Ref and Tutorial
- fix some spelling mistakes
- array: document array module
- library/index: include array module in ToC
- esp8266/intro: rename to "Getting started" from "Introduction"
- esp8266/intro: add troubleshooting section
- esp8266/quickref: link to installation instructions
- esp8266/tutorial/intro: add anchor for link from quickeref
- esp8266/intro: focus on hazards of unearthed power wrt electronics
- uio: mention seek()/flush() support for io.BytesIO
misc:
- logo/1bit-logo A black & white version of the logo
examples:
- http_server*: update for buffered-like streams (read line by line)
- embedding: example for embedding MicroPython in an app
- embedding: add README
- http_client*: be sure to close socket
- network: split recv- and read-based HTTP servers
qemu-arm:
- enable gcc LTO option for nlrthumb.c
Diffstat (limited to 'unix')
-rw-r--r-- | unix/Makefile | 7 | ||||
-rw-r--r-- | unix/fdfile.h | 41 | ||||
-rw-r--r-- | unix/file.c | 47 | ||||
-rw-r--r-- | unix/modsocket.c | 10 | ||||
-rw-r--r-- | unix/moduselect.c | 22 | ||||
-rw-r--r-- | unix/mpconfigport.h | 9 | ||||
-rw-r--r-- | unix/mpconfigport.mk | 1 | ||||
-rw-r--r-- | unix/mpconfigport_minimal.h | 1 | ||||
-rw-r--r-- | unix/mpthreadport.c | 12 |
9 files changed, 112 insertions, 38 deletions
diff --git a/unix/Makefile b/unix/Makefile index 2e0cbfd35a..cb9a999f08 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -263,6 +263,8 @@ freedos: MICROPY_PY_JNI=0 # build an interpreter for coverage testing and do the testing +# btree module is disabled, because with extra warnings enabled, +# building berkeleydb errors out coverage: $(MAKE) COPT="-O0" MICROPY_PY_BTREE=0 CFLAGS_EXTRA='-DMP_CONFIGFILE="<mpconfigport_coverage.h>" -fprofile-arcs -ftest-coverage -Wdouble-promotion -Wformat -Wmissing-declarations -Wmissing-prototypes -Wold-style-definition -Wpointer-arith -Wshadow -Wsign-compare -Wuninitialized -Wunused-parameter -DMICROPY_UNIX_COVERAGE' LDFLAGS_EXTRA='-fprofile-arcs -ftest-coverage' BUILD=build-coverage PROG=micropython_coverage @@ -308,11 +310,14 @@ libffi: ../configure $(CROSS_COMPILE_HOST) --prefix=$$PWD/out --disable-structs CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="-Os -fomit-frame-pointer -fstrict-aliasing -ffast-math -fno-exceptions"; \ make install-exec-recursive; make -C include install-data-am -axtls: ../lib/axtls/README +axtls: $(BUILD)/libaxtls.a + +$(BUILD)/libaxtls.a: ../lib/axtls/README | $(OBJ_DIRS) cd ../lib/axtls; cp config/upyconfig config/.config cd ../lib/axtls; make oldconfig -B cd ../lib/axtls; make clean cd ../lib/axtls; make all CC="$(CC)" LD="$(LD)" + cp ../lib/axtls/_stage/libaxtls.a $@ ../lib/axtls/README: @echo "You cloned without --recursive, fetching submodules for you." diff --git a/unix/fdfile.h b/unix/fdfile.h new file mode 100644 index 0000000000..8e8e97c795 --- /dev/null +++ b/unix/fdfile.h @@ -0,0 +1,41 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2016 Paul Sokolovsky + * + * 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. + */ + +#include "py/obj.h" + +#ifndef __MICROPY_INCLUDED_UNIX_FILE_H__ +#define __MICROPY_INCLUDED_UNIX_FILE_H__ + +typedef struct _mp_obj_fdfile_t { + mp_obj_base_t base; + int fd; +} mp_obj_fdfile_t; + +extern const mp_obj_type_t mp_type_fileio; +extern const mp_obj_type_t mp_type_textio; + +#endif // __MICROPY_INCLUDED_UNIX_FILE_H__ diff --git a/unix/file.c b/unix/file.c index a7620e079e..203a5a3abe 100644 --- a/unix/file.c +++ b/unix/file.c @@ -36,6 +36,7 @@ #include "py/stream.h" #include "py/builtin.h" #include "py/mphal.h" +#include "fdfile.h" #if MICROPY_PY_IO @@ -43,11 +44,6 @@ #define fsync _commit #endif -typedef struct _mp_obj_fdfile_t { - mp_obj_base_t base; - int fd; -} mp_obj_fdfile_t; - #ifdef MICROPY_CPYTHON_COMPAT STATIC void check_fd_is_open(const mp_obj_fdfile_t *o) { if (o->fd < 0) { @@ -105,29 +101,30 @@ STATIC mp_uint_t fdfile_write(mp_obj_t o_in, const void *buf, mp_uint_t size, in STATIC mp_uint_t fdfile_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_fdfile_t *o = MP_OBJ_TO_PTR(o_in); - if (request == MP_STREAM_SEEK) { - struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg; - off_t off = lseek(o->fd, s->offset, s->whence); - if (off == (off_t)-1) { - *errcode = errno; - return MP_STREAM_ERROR; + check_fd_is_open(o); + switch (request) { + case MP_STREAM_SEEK: { + struct mp_stream_seek_t *s = (struct mp_stream_seek_t*)arg; + off_t off = lseek(o->fd, s->offset, s->whence); + if (off == (off_t)-1) { + *errcode = errno; + return MP_STREAM_ERROR; + } + s->offset = off; + return 0; } - s->offset = off; - return 0; - } else { - *errcode = EINVAL; - return MP_STREAM_ERROR; + case MP_STREAM_FLUSH: + if (fsync(o->fd) < 0) { + *errcode = errno; + return MP_STREAM_ERROR; + } + return 0; + default: + *errcode = EINVAL; + return MP_STREAM_ERROR; } } -STATIC mp_obj_t fdfile_flush(mp_obj_t self_in) { - mp_obj_fdfile_t *self = MP_OBJ_TO_PTR(self_in); - check_fd_is_open(self); - fsync(self->fd); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fdfile_flush_obj, fdfile_flush); - STATIC mp_obj_t fdfile_close(mp_obj_t self_in) { mp_obj_fdfile_t *self = MP_OBJ_TO_PTR(self_in); close(self->fd); @@ -228,7 +225,7 @@ STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_seek), MP_ROM_PTR(&mp_stream_seek_obj) }, { MP_ROM_QSTR(MP_QSTR_tell), MP_ROM_PTR(&mp_stream_tell_obj) }, - { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&fdfile_flush_obj) }, + { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&mp_stream_flush_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&fdfile_close_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&fdfile___exit___obj) }, diff --git a/unix/modsocket.c b/unix/modsocket.c index cd68b20a45..56bab3494a 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -62,12 +62,14 @@ #define MICROPY_SOCKET_EXTRA (0) +// This type must "inherit" from mp_obj_fdfile_t, i.e. matching subset of +// fields should have the same layout. typedef struct _mp_obj_socket_t { mp_obj_base_t base; int fd; } mp_obj_socket_t; -STATIC const mp_obj_type_t usocket_type; +const mp_obj_type_t mp_type_socket; // Helper functions #define RAISE_ERRNO(err_flag, error_val) \ @@ -80,7 +82,7 @@ static inline mp_obj_t mp_obj_from_sockaddr(const struct sockaddr *addr, socklen STATIC mp_obj_socket_t *socket_new(int fd) { mp_obj_socket_t *o = m_new_obj(mp_obj_socket_t); - o->base.type = &usocket_type; + o->base.type = &mp_type_socket; o->fd = fd; return o; } @@ -374,7 +376,7 @@ STATIC const mp_stream_p_t usocket_stream_p = { .write = socket_write, }; -STATIC const mp_obj_type_t usocket_type = { +const mp_obj_type_t mp_type_socket = { { &mp_type_type }, .name = MP_QSTR_socket, .print = socket_print, @@ -550,7 +552,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_sockaddr_obj, mod_socket_sockaddr); STATIC const mp_rom_map_elem_t mp_module_socket_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usocket) }, - { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&usocket_type) }, + { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&mp_type_socket) }, { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&mod_socket_getaddrinfo_obj) }, { MP_ROM_QSTR(MP_QSTR_inet_pton), MP_ROM_PTR(&mod_socket_inet_pton_obj) }, { MP_ROM_QSTR(MP_QSTR_inet_ntop), MP_ROM_PTR(&mod_socket_inet_ntop_obj) }, diff --git a/unix/moduselect.c b/unix/moduselect.c index 13cb3f1fa8..38f8d11ed8 100644 --- a/unix/moduselect.c +++ b/unix/moduselect.c @@ -38,6 +38,9 @@ #include "py/objlist.h" #include "py/objtuple.h" #include "py/mphal.h" +#include "fdfile.h" + +extern const mp_obj_type_t mp_type_socket; // Flags for poll() #define FLAG_ONESHOT (1) @@ -51,10 +54,23 @@ typedef struct _mp_obj_poll_t { struct pollfd *entries; } mp_obj_poll_t; +STATIC int get_fd(mp_obj_t fdlike) { + int fd; + // Shortcut for fdfile compatible types + if (MP_OBJ_IS_TYPE(fdlike, &mp_type_fileio) || MP_OBJ_IS_TYPE(fdlike, &mp_type_socket)) { + mp_obj_fdfile_t *fdfile = MP_OBJ_TO_PTR(fdlike); + fd = fdfile->fd; + } else { + fd = mp_obj_get_int(fdlike); + } + return fd; +} + /// \method register(obj[, eventmask]) STATIC mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); - int fd = mp_obj_get_int(args[1]); + int fd = get_fd(args[1]); + mp_uint_t flags; if (n_args == 3) { flags = mp_obj_get_int(args[2]); @@ -95,7 +111,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_register_obj, 2, 3, poll_register); STATIC mp_obj_t poll_unregister(mp_obj_t self_in, mp_obj_t obj_in) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in); struct pollfd *entries = self->entries; - int fd = mp_obj_get_int(obj_in); + int fd = get_fd(obj_in); for (int i = self->len - 1; i >= 0; i--) { if (entries->fd == fd) { entries->fd = -1; @@ -113,7 +129,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(poll_unregister_obj, poll_unregister); STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmask_in) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in); struct pollfd *entries = self->entries; - int fd = mp_obj_get_int(obj_in); + int fd = get_fd(obj_in); for (int i = self->len - 1; i >= 0; i--) { if (entries->fd == fd) { entries->events = mp_obj_get_int(eventmask_in); diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 06c4edc1e2..c449e7316f 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -63,6 +63,7 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_STREAMS_NON_BLOCK (1) +#define MICROPY_STREAMS_POSIX_API (1) #define MICROPY_OPT_COMPUTED_GOTO (1) #ifndef MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE #define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (1) @@ -72,6 +73,7 @@ #define MICROPY_PY_DESCRIPTORS (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_BUILTINS_STR_CENTER (1) +#define MICROPY_PY_BUILTINS_STR_PARTITION (1) #define MICROPY_PY_BUILTINS_STR_SPLITLINES (1) #define MICROPY_PY_BUILTINS_MEMORYVIEW (1) #define MICROPY_PY_BUILTINS_FROZENSET (1) @@ -111,7 +113,7 @@ #define MICROPY_PY_URE (1) #define MICROPY_PY_UHEAPQ (1) #define MICROPY_PY_UHASHLIB (1) -#if MICROPY_PY_USSL +#if MICROPY_PY_USSL && MICROPY_SSL_AXTLS #define MICROPY_PY_UHASHLIB_SHA1 (1) #endif #define MICROPY_PY_UBINASCII (1) @@ -119,6 +121,7 @@ #ifndef MICROPY_PY_USELECT #define MICROPY_PY_USELECT (1) #endif +#define MICROPY_PY_WEBSOCKET (1) #define MICROPY_PY_MACHINE (1) #define MICROPY_PY_MACHINE_PULSE (1) #define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr @@ -138,6 +141,7 @@ // names in exception messages (may require more RAM). #define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED) #define MICROPY_WARNINGS (1) +#define MICROPY_PY_STR_BYTES_CMP_WARN (1) // Define to 1 to use undertested inefficient GC helper implementation // (if more efficient arch-specific one is not available). @@ -300,3 +304,6 @@ void mp_unix_mark_exec(void); #ifndef _DIRENT_HAVE_D_INO #define _DIRENT_HAVE_D_INO (1) #endif + +// For debugging purposes, make printf() available to any source file. +#include <stdio.h> diff --git a/unix/mpconfigport.mk b/unix/mpconfigport.mk index 9f826661a9..f7912141af 100644 --- a/unix/mpconfigport.mk +++ b/unix/mpconfigport.mk @@ -28,6 +28,7 @@ MICROPY_PY_FFI = 1 # ussl module requires axtls MICROPY_PY_USSL = 1 +MICROPY_SSL_AXTLS = 1 # jni module requires JVM/JNI MICROPY_PY_JNI = 0 diff --git a/unix/mpconfigport_minimal.h b/unix/mpconfigport_minimal.h index 2ab95c67af..054e82c243 100644 --- a/unix/mpconfigport_minimal.h +++ b/unix/mpconfigport_minimal.h @@ -34,6 +34,7 @@ #define MICROPY_ALLOC_PARSE_CHUNK_INIT (64) #define MICROPY_ALLOC_PATH_MAX (PATH_MAX) #define MICROPY_ENABLE_GC (1) +#define MICROPY_GC_ALLOC_THRESHOLD (0) #define MICROPY_ENABLE_FINALISER (0) #define MICROPY_STACK_CHECK (0) #define MICROPY_COMP_CONST (0) diff --git a/unix/mpthreadport.c b/unix/mpthreadport.c index e5cfe7a669..663d3a5dee 100644 --- a/unix/mpthreadport.c +++ b/unix/mpthreadport.c @@ -134,11 +134,14 @@ void mp_thread_start(void) { } void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) { - // default stack size is 8k machine-words, minimum is 2k + // default stack size is 8k machine-words if (*stack_size == 0) { *stack_size = 8192 * BYTES_PER_WORD; - } else if (*stack_size < 2048 * BYTES_PER_WORD) { - *stack_size = 2048 * BYTES_PER_WORD; + } + + // minimum stack size is set by pthreads + if (*stack_size < PTHREAD_STACK_MIN) { + *stack_size = PTHREAD_STACK_MIN; } // set thread attributes @@ -163,7 +166,8 @@ void mp_thread_create(void *(*entry)(void*), void *arg, size_t *stack_size) { } // adjust stack_size to provide room to recover from hitting the limit - *stack_size -= 1024 * BYTES_PER_WORD; + // this value seems to be about right for both 32-bit and 64-bit builds + *stack_size -= 8192; // add thread to linked list of all threads thread_t *th = malloc(sizeof(thread_t)); |