Commit Graph

590 Commits

Author SHA1 Message Date
Paul Sokolovsky 5ae3ddcc9a unix/main: Check pending exception at the end of code block execution.
Usually this checking is done by VM on jump instructions, but for linear
sequences of instructions and builtin functions this won't happen. Particular
target of this change is long-running builtin functions like time.sleep().
2015-12-04 19:16:56 +02:00
Paul Sokolovsky 30d0cf4885 unix/mpconfigport: Typo fix in comment. 2015-12-03 01:41:26 +02:00
Paul Sokolovsky d735278c9f unix/mpconfigport.h: For MICROPY_NO_ALLOCA=1, don't even include alloca.h. 2015-12-02 16:05:02 +02:00
Paul Sokolovsky 3376875bc8 unix/modtime: sleep(): Return early if KeyboardInterrupt is pending
As set by signal handler. This assumes that exception will be raised
somewhere else, which so far doesn't happen for single function call.
Still, it makes sense to handle that in some common place.
2015-12-02 00:37:25 +02:00
Paul Sokolovsky bd33aa313e unix/moduselect: Support growing of poll array. 2015-11-30 00:54:14 +02:00
Damien George 999cedb90f py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.
This allows the mp_obj_t type to be configured to something other than a
pointer-sized primitive type.

This patch also includes additional changes to allow the code to compile
when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of
mp_uint_t, and various casts.
2015-11-29 14:25:35 +00:00
Damien George cbf7674025 py: Add MP_ROM_* macros and mp_rom_* types and use them. 2015-11-29 14:25:04 +00:00
Paul Sokolovsky fad7d9317b unix/modtime: Unbreak Windows build after changes to check select() result. 2015-11-29 14:31:58 +02:00
Paul Sokolovsky 0bb57bf5bf unix/modtime: sleep(): Automatically restart after receiving EINTR.
THis is required to deal well with signals, signals being the closest
analogue of hardware interrupts for POSIX. This is also CPython 3.5
compliant behavior (PEP 475).

The main problem implementing this is to figure out how much time was
spent in waiting so far/how much is remaining. It's well-known fact that
Linux updates select()'s timeout value when returning with EINTR to the
remaining wait time. Here's what POSIX-based standards say about this:
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/pselect.html):

"Upon successful completion, the select() function may modify the object
pointed to by the timeout argument."

I.e. it allows to modify timeout value, but doesn't say how exactly it is
modified. And actually, it allows such modification only "upon successful
completion", which returning with EINTR error hardly is.

POSIX also allows to request automatic EINTR restart for system calls using
sigaction call with SA_RESTART flag, but here's what the same document says
about it:

"If SA_RESTART has been set for the interrupting signal, it is
implementation-defined whether the function restarts or returns with
[EINTR]."

In other words, POSIX doesn't leave room for both portable and efficient
handling of this matter, so the code just allows to manually select
Linux-compatible behavior with MICROPY_SELECT_REMAINING_TIME option,
or otherwise will just raise OSError. When systems with non-Linux behavior
are found, they can be handled separately.
2015-11-29 14:21:06 +02:00
Paul Sokolovsky 698a6a9d7d unix/moduselect: poll.register(): Reuse freed entries in poll array. 2015-11-29 00:06:51 +02:00
Paul Sokolovsky 19920e25f9 unix/moduselect: Fix bug in poll.poll() scanning loop. 2015-11-28 17:34:46 +02:00
Damien George 7a5a4fe271 unix/unix_mphal: Use size_t instead of mp_uint_t in stdout_tx_strn decls. 2015-11-27 14:03:53 +00:00
Paul Sokolovsky 7dec35d7cc unix/modos: Remove duplicate level of #if MICROPY_PY_OS_STATVFS. 2015-11-26 17:46:26 +02:00
Paul Sokolovsky 9f10d3fb63 unix/main: Get rid of perror() which uses stdio. 2015-11-23 00:10:38 +02:00
Paul Sokolovsky c3280d83e7 unix: Use printf() implementation in terms of mp_printf().
In other words, unix port now uses overriden printf(), instead of using
libc's. This should remove almost all dependency on libc stdio (which
is bloated).
2015-11-22 00:44:41 +02:00
Paul Sokolovsky ede1f547e7 unix/modsocket: Use snprintf(), as defined by lib/utils/printf.c. 2015-11-21 17:21:49 +02:00
Paul Sokolovsky 295ea12411 py/emitglue: Host definition of mp_verbose_flag.
This may not seem like the ideal place, but is actually the only place
in py/ where it gets referenced, so is just right.
2015-11-21 16:54:15 +02:00
Paul Sokolovsky 3ba61656bd unix/modsocket: Implement sockaddr() function to decode raw socket address.
Return tuple of (address_family, net_addr, [port, [extra_data]]). net_addr
is still raw network address as bytes object, but suitable for passing to
inet_ntop() function. At the very least, sockaddr() will separate address
family value from binary socket address (and currently, only AF_INET family
is decoded).
2015-11-21 01:38:59 +02:00
Paul Sokolovsky 2ae7ced721 unix/modsocket: Removed dangling references to sockaddr_in_type. 2015-11-20 21:32:27 +02:00
Paul Sokolovsky acb743da64 unix/modffi: Mark 'O' type specifier as implemented. 2015-11-20 17:51:37 +02:00
Damien George 54df549b5f unix/moduselect: Initialise variable so can compile in non-debug mode. 2015-11-20 12:51:00 +00:00
Paul Sokolovsky 65971f5160 unix: Add "uselect" module, with poll() function.
Underlyingly, uses standard POSIX poll() for portability.
2015-11-17 00:35:57 +02:00
Paul Sokolovsky 79c4ec1102 unix/input: Switch to POSIX I/O for history reading/writing. 2015-11-16 07:40:56 +02:00
Paul Sokolovsky ec314c951d unix/modos: getenv(): Handle non-existing envvar correctly. 2015-11-14 17:12:04 +02:00
Paul Sokolovsky 908f5159cf unix/modos: Add Windows workaround for mkdir(). 2015-11-14 02:35:38 +02:00
Paul Sokolovsky 27dafa5ed5 unix/modos: Add mkdir().
Dependency of upip.
2015-11-13 22:26:51 +02:00
Paul Sokolovsky d8557834c0 unix/modos: Add getenv().
Dependency of upip.
2015-11-13 21:30:06 +02:00
Paul Sokolovsky a01f6c9ae7 unix/main: Remove stray mp_printf() from previous commit. 2015-11-13 17:33:42 +02:00
Paul Sokolovsky 66fd3e4a7b unix: Use standard mphalport.h header.
This also unbreaks "make minimal".
2015-11-13 15:44:26 +02:00
Paul Sokolovsky 3a6b3d230c main.c: Switch stderr printing from ANSI C to native POSIX. 2015-11-13 15:29:42 +02:00
Paul Sokolovsky 94f9330d3e unix: Allow to override MICROPY_PY_MATH_SPECIAL_FUNCTIONS from command-line. 2015-11-13 15:24:57 +02:00
Paul Sokolovsky 6d1eabfeaa unix/mpconfigport: Move log2() definition to modmath.c.
It's safer to define it where it's used, defining it for all source files
may lead to hard to diagnose conflicts in corner cases.
2015-11-13 15:24:48 +02:00
Paul Sokolovsky f882d53fcd unix/main: Use builtin unichar_isdigit() in preference if libc's.
Less dependencies.
2015-11-13 01:57:08 +02:00
Paul Sokolovsky 3c7e1b80ac unix/modjni: Add missing get_jclass_name() function. 2015-11-11 16:43:27 +02:00
Paul Sokolovsky 6e68a68d18 unix/gccollect: Fallback to setjmp-based register fetching automatically.
Now, if we build for an architecture which doesn't have dedicated support
for getting registers for GC scanning, fallback to setjmp-based method
automatically. It's still possible to force setjmp-based implementation
on archs with dedicated support (e.g. for testing, or for peculiar calling
conventions/optimizations).
2015-11-08 16:05:33 +02:00
Paul Sokolovsky 06f70973f7 unix/unix_mphal: Typo fix in comment. 2015-11-03 00:36:46 +03:00
Damien George 731f359292 all: Add py/mphal.h and use it in all ports.
py/mphal.h contains declarations for generic mp_hal_XXX functions, such
as stdio and delay/ticks, which ports should provide definitions for.  A
port will also provide mphalport.h with further HAL declarations.
2015-10-31 19:14:30 +03:00
Paul Sokolovsky 404dae80a9 unix, stmhal: Introduce mp_hal_delay_ms(), mp_hal_ticks_ms().
These MPHAL functions are intended to replace previously used HAL_Delay(),
HAL_GetTick() to provide better naming and MPHAL separation (they are
fully equivalent otherwise).

Also, refactor extmod/modlwip to use them.
2015-10-27 23:31:42 +03:00
Paul Sokolovsky 91f2168dd5 unix/modjni: Actually check argument type when doing method resolution.
This is required to properly select among overloaded methods. It however
relies on java.lang.Object-overloaded method to come last, which appears
to be the case for OpenJDK.
2015-10-23 00:33:54 +03:00
Paul Sokolovsky 9ebd4dabf2 unix/modjni: Don't pass Java object to a method which doesn't expect it.
For example, don't pass Integer to double method. This is still not
selective enough to choose the right overloaded method maong those
taking objects.
2015-10-22 01:35:17 +03:00
Paul Sokolovsky 8e6e9eaea5 unix: Use "Ctrl" as a name of the key, not "CTRL". 2015-10-20 12:30:36 +03:00
Paul Sokolovsky 2c040edef8 libffi: Skip building docs.
This requires makeinfo installed and wastes time (especially in CI).
2015-10-19 22:30:03 +03:00
Paul Sokolovsky 39a380b621 unix/modos: Android Bionic lacks statvfs(), has BSD statfs(). 2015-10-19 21:43:20 +03:00
Paul Sokolovsky e0f5df579b all: Make netutils.h available to all ports by default.
Generally, ports should inherit INC from py.mk, append to it, not
overwrite it. TODO: Likely should do the same for other vars too.
2015-10-19 18:32:42 +03:00
Paul Sokolovsky 8ee153f234 unix/modtime: Implement ticks_ms(), ticks_us() and ticks_diff().
All of these functions return positive small int, thus range is 2 bits less
than word size (30 bit on 32-bit systems, 62 bit on 64-bit systems).
2015-10-19 17:48:27 +03:00
Paul Sokolovsky fd379db286 unix/modtime: Implement sleep_ms(), sleep_us(). 2015-10-19 17:48:27 +03:00
Paul Sokolovsky 949c5c9180 unix/unix_mphal: Implement HAL_Delay() and HAL_GetTick(). 2015-10-19 00:31:37 +03:00
Paul Sokolovsky 2ca7b05552 unix/modos: Checking config macros requires mpconfig.h. 2015-10-18 03:05:47 +03:00
Paul Sokolovsky f8e9ef5cd0 unix/modos: Guard sys/statvfs.h include with MICROPY_PY_OS_STATVFS check.
E.g. Windows lacks this header.
2015-10-18 02:54:20 +03:00
Paul Sokolovsky c3000b6f69 unix/modos: Add statvfs() function.
Another function (like stat) which is problematic to deal with on ABI level
(FFI), as struct statvfs layout may differ unpredictably between OSes and
even different versions of a same OS. So, implement it in C, returning a
10-element tuple of f_bsize, f_frsize, f_blocks, f_bfree, f_bavail, f_files,
f_ffree, f_favail, f_flag, f_namemax. This is exactly the order described
in Python3 docs, https://docs.python.org/3/library/os.html#os.statvfs
(but note that os.statvfs() should make these values available as
attributes).
2015-10-18 01:21:23 +03:00