Commit Graph

748 Commits

Author SHA1 Message Date
Damien George 94d2919b77 unix/modtime: Release the GIL when sleeping. 2016-06-28 11:28:50 +01:00
Damien George f443504f86 unix/mpthreadport: Suppress compiler warning about unused arguments. 2016-06-28 11:28:50 +01:00
Damien George f1dbd2909e unix/gccollect: Provide declaration of exported function. 2016-06-28 11:28:50 +01:00
Damien George c2508ac8bd unix/mpthreadport: Use SA_SIGINFO for GC signal handler.
SA_SIGINFO allows the signal handler to access more information about
the signal, especially useful in a threaded environment.  The extra
information is not currently used but it may prove useful in the future.
2016-06-28 11:28:49 +01:00
Damien George dbd54e0b5b unix: Implement garbage collection with threading.
This patch allows any given thread to do a proper garbage collection and
scan all the pointers of all active threads.
2016-06-28 11:28:49 +01:00
Damien George f1b6db2218 unix/file: If write syscall returns because of EINTR then try again.
As per PEP-475.
2016-06-28 11:28:49 +01:00
Damien George 801d1b3803 py/modthread: Implement lock object, for creating a mutex. 2016-06-28 11:28:49 +01:00
Damien George 707f98f207 py/modthread: Add stack_size() function. 2016-06-28 11:28:48 +01:00
Damien George a791be936a unix: Add basic thread support using pthreads.
Has the ability to create new threads.
2016-06-28 11:28:48 +01:00
Damien George 330165a2cc py: Add MP_STATE_THREAD to hold state specific to a given thread. 2016-06-28 11:09:31 +01:00
Martin Müller f2892bd77d unix: Fix Makefile to handle gc-sections linker flags on Mac OS.
The linker flag --gc-sections is not available on the linker used on
Mac OS X which results in an error when linking micropython on Mac OS X.
Therefore move this option to the LDFLAGS_ARCH variable on non Darwin
systems. According to http://stackoverflow.com/a/17710056 the equivalent
to --gc-sections is -dead_strip thus this option is used for the
LDFLAGS_ARCH on Darwin systems.
2016-06-27 22:31:55 +01:00
Paul Sokolovsky e68811dbbf unix/modmachine: Enable time_pulse_us() function. 2016-06-19 00:21:17 +03:00
Paul Sokolovsky ad229477c6 unix/modmachine: Include PinBase class. 2016-06-18 23:40:28 +03:00
Paul Sokolovsky 07209f8592 all: Rename mp_obj_type_t::stream_p to protocol.
It's now used for more than just stream protocol (e.g. pin protocol), so
don't use false names.
2016-06-18 18:44:57 +03:00
Paul Sokolovsky cbffd0aadd unix: Disable FatFs VFS for normal build, keep enabled for coverage.
It's enabled mostly for unit testing, and we do that in full with coverage
build.
2016-06-18 00:58:57 +03:00
Paul Sokolovsky 7c8d76fad3 unix/alloc: Make coverage build and its overzealous warnings happy. 2016-06-18 00:36:13 +03:00
Paul Sokolovsky c9598604c6 unix/alloc: Add option to use uPy's alloc-exec implementation even for libffi.
When built for Linux, libffi includes very bloated and workaround exec-alloc
implementation required to work around SELinux and other "sekuritee" features
which real people don't use. MicroPython has own alloc-exec implementation,
used to alloc memory for @micropython.native code. With this option enabled,
uPy's implementation will override libffi's. This saves 11K on x86_64 (and
that accounts for more than half of the libffi code size).

TODO: Possibly, we want to refactor this option to allow either use uPy's
implementation even for libffi, or allow to use libffi's implementation even
for uPy.
2016-06-18 00:18:01 +03:00
Paul Sokolovsky 9b43a7d1be unix/Makefile: libffi: Build with -Os.
Also try to use -fno-exceptions. Other options taken from libffi's configure
defaults.
2016-06-18 00:17:47 +03:00
Paul Sokolovsky 6f8880d0ab unix: Move "utime" module config to C level instead of make level. 2016-06-17 23:35:00 +03:00
Paul Sokolovsky df453f0652 unix: Time to build with --gc-sections.
This actually saves "only" 6K for x86_64 build, as we're still more or less
careful to #ifdef unneeded code. But relying on --gc-sections in a "lazy"
manner would allow to make #ifdef'ing less pervasive (not suggested right
away, but an option for the future).
2016-06-17 02:38:20 +03:00
Paul Sokolovsky acaa30b604 unix: Deprecate support for GNU Readline (MICROPY_USE_READLINE=2).
MicroPython own readline implementation is superior now by providing
automatic indentation and completion (completion for GNU Readline was
never implemented). MICROPY_USE_READLINE=2 also wasn't build for a long
time and probably broken.

If GNU Readline is still beneficial for some cases, it can be achieved
with external wrappers like "rlwrap" (there will be the same level of
functionality, as again, there never was deep integration, like completion
support).
2016-06-16 03:28:58 +03:00
Paul Sokolovsky b5190f1df3 unix/mpconfigport_minimal.h: Clearly mark where user-define config ends.
TODO: Do the same for other config files.
2016-06-16 01:20:32 +03:00
Paul Sokolovsky cd796f85af unix: Unbreak "minimal" target by disabling FatFs.
Was broken since introduction of FatFs support.
2016-06-16 00:03:24 +03:00
Paul Sokolovsky 0f5bf1aafe py/mpconfig.h: MP_NOINLINE is universally useful, move from unix port. 2016-06-15 23:52:00 +03:00
Robert HH ee009d713a extmod/vfs_fat.c: Add vfs.stat().
The call to stat() returns a 10 element tuple consistent to the os.stat()
call. At the moment, the only relevant information returned are file
type and file size.
2016-05-31 13:03:12 +03:00
Paul Sokolovsky 4889b6ff9b unix/Makefile: "make axtls": Automatically fetch submodules if missing.
Try to emulate "you can build without reading instructions" behavior as far
as possible.
2016-05-28 21:03:48 +03:00
Paul Sokolovsky 6055d411a9 unix/mpconfigport.mk: Document MICROPY_STANDALONE make-level option.
Avoid using system libraries, use copies bundled with MicroPython as
submodules (currently affects only libffi, other dependencies either
already used as bundled-only (axtls), or can't be bundled (so far),
like libjni).
2016-05-28 20:38:14 +03:00
Paul Sokolovsky f5d63bcd23 unix: Enable "ussl" module.
ussl was in testing mode for 8 months, and now enabled in other ports
(e.g. esp8266), so time for unix port to catch up.
2016-05-26 02:12:11 +03:00
Paul Sokolovsky 37f9761801 unix/Makefile: nanbox build is not compatible with modussl, disable. 2016-05-26 02:11:17 +03:00
Damien George 2133924e46 unix: Support frozen packages.
To use, put your directory structure with .py files in frozen/ and then:

    make FROZEN_MPY_DIR=frozen
2016-05-23 15:19:53 +01:00
Paul Sokolovsky 1b5abfcaae py/objstr: Implement str.center().
Disabled by default, enabled in unix port. Need for this method easily
pops up when working with text UI/reporting, and coding workalike
manually again and again counter-productive.
2016-05-22 00:13:44 +03:00
Paul Sokolovsky b580958216 unix/unix_mphal: Implement mp_hal_ticks_us().
Similar to existing mp_hal_ticks_ms().
2016-05-21 02:16:35 +03:00
Paul Sokolovsky 92a342a011 unix/mpconfigport_coverage.h: Add dedicated config file for coverage build.
This allows to enable the options which aren't enabled in the normal unix
config (as unix port is no longer an enable-all port).
2016-05-18 00:58:32 +03:00
Damien George 1e024de7be unix: Add ability to include frozen bytecode in the build.
To use frozen bytecode make a subdirectory under the unix/ directory
(eg frozen/), put .py files there, then run:

    make FROZEN_MPY_DIR=frozen

Be sure to build from scratch.  The .py files will then be available for
importing.
2016-05-16 23:17:11 +01:00
Damien George 088127d91c unix: Enable uerrno module. 2016-05-10 23:30:39 +01:00
Pavol Rusnak bc7ca7ca01 unix/mphalport: Add mp_hal_delay_us() for consistency with other ports. 2016-05-07 21:18:44 +03:00
Martin Müller 31fc81d3b8 unix/Makefile: Make install more compatible (BSD, etc.).
The current install command uses the flag -D which is specific to the
install command from GNU coreutils, but isn't available for the BSD
version. This solution uses the -d flag which should be commonly
available to create the target directory. Afterwards the target files
are installed to this directory seperately.
2016-04-28 21:45:27 +03:00
Paul Sokolovsky 270dd29320 unix: Make sure build dir exists before accessing it for freezing upip. 2016-04-19 11:41:40 +03:00
Jan Čapek d76c65f599 py: Add rules for automated extraction of qstrs from sources.
- add template rule that converts a specified source file into a qstring file

- add special rule for generating a central header that contains all
  extracted/autogenerated strings - defined by QSTR_DEFS_COLLECTED
  variable. Each platform appends a list of sources that may contain
  qstrings into a new build variable: SRC_QSTR. Any autogenerated
  prerequisities are should be appened to SRC_QSTR_AUTO_DEPS variable.

- remove most qstrings from py/qstrdefs, keep only qstrings that
  contain special characters - these cannot be easily detected in the
  sources without additional annotations

- remove most manual qstrdefs, use qstrdef autogen for: py, cc3200,
  stmhal, teensy, unix, windows, pic16bit:

   - remove all micropython generic qstrdefs except for the special strings that contain special characters (e.g. /,+,<,> etc.)
   - remove all port specific qstrdefs except for special strings
   - append sources for qstr generation in platform makefiles (SRC_QSTR)
2016-04-16 13:18:09 +01:00
Paul Sokolovsky 9b0714b24c py: Declare help, input, open builtins in core.
These are *defined* per-port, but why redeclare them again and again.
2016-04-15 00:07:56 +03:00
Damien George 0a2e9650f5 py: Add ability to have frozen persistent bytecode from .mpy files.
The config variable MICROPY_MODULE_FROZEN is now made of two separate
parts: MICROPY_MODULE_FROZEN_STR and MICROPY_MODULE_FROZEN_MPY.  This
allows to have none, either or both of frozen strings and frozen mpy
files (aka frozen bytecode).
2016-04-13 16:07:47 +01:00
Paul Sokolovsky 47442d9f52 lib/utils/printf: Rework overriding printer of DEBUG_printf().
By default it uses mp_plat_print, but a port may override it to another
value with MICROPY_DEBUG_PRINTER_DEST.
2016-04-13 11:53:12 +03:00
Paul Sokolovsky 1a327c4fa3 unix: Build with MICROPY_PY_UHASHLIB_SHA1 if already building with axTLS. 2016-04-11 21:58:58 +03:00
pohmelie b32b0d38fe unix: freedos strip and size names for binaries
After this you need only one path for build (path/to/djgpp/bin). Original patch made by @dhylands
2016-04-08 20:15:37 +03:00
Paul Sokolovsky 1b811b946e unix/modsocket: Use mp_const_empty_map instead of creating empty map. 2016-04-04 23:43:16 +03:00
pohmelie cee888255b unix: djgpp errno.h have no ENOTSUP, so define it to Linux value. 2016-04-03 23:23:01 +03:00
Paul Sokolovsky a5d2af7949 unix/file: "encoding" arg to open() isn't kw-only.
And with "buffering" arg introduced, it's non possible to make it
non-kwonly.
2016-04-02 17:23:51 +03:00
Paul Sokolovsky e5fa163a4c unix/file: Parse "buffering" argument of open() builtin.
It's ignored (unbuffered, raw I/O is used), but least makes it compatible
with CPython.
2016-04-02 17:23:46 +03:00
Pavol Rusnak 3d4a535208 unix: implement -i option (inspect - start REPL after script is finished) 2016-04-01 12:35:45 +03:00
Paul Sokolovsky 13394a632d unix/unix_mphal: Hack to make uos.dupterm() actually work.
See https://github.com/micropython/micropython/issues/1736 for the
list of complications. This workaround instead of duplicating REPL
to another stream, switches to it, because read(STDIN) we use otherwise
is blocking call, so it and custom REPL stream can't be used together.
2016-03-27 14:02:03 +03:00
Paul Sokolovsky dc320164d8 unix/modsocket: Add comment regarding close() error checking (which is none). 2016-03-02 00:20:48 +02:00
Damien George ac23662550 unix: Enabled importing of persistent bytecode (.mpy files). 2016-02-25 10:12:30 +00:00
Paul Sokolovsky 46a0ac02c5 extmod/vfs_fat_ffconf: Reusable FatFs module, move from stmhal/ffconf.
TODO: Probably merge into vfs_fat_diskio.
2016-02-15 00:19:27 +02:00
Paul Sokolovsky 6b0c88256b extmod/vfs_fat_file: Reusable FatFs module, move from stmhal/file. 2016-02-15 00:16:46 +02:00
Paul Sokolovsky 8cb78e0e53 extmod/vfs_fat_diskio: Reusable FatFs module, move from stmhal/diskio. 2016-02-15 00:08:37 +02:00
Paul Sokolovsky 72085a669b py/mpstate.h: fs_user_mount is now standard, reusable uPy functionality. 2016-02-15 00:02:03 +02:00
Paul Sokolovsky 8a43a41b3a unix: Enable VfsFat support. 2016-02-14 19:15:22 +02:00
Paul Sokolovsky a63a4761cd unix/file: Stop assuming that O_RDWR == O_RDONLY | O_WRONLY.
That's not true e.g. on Linux.
2016-02-06 21:59:44 +02:00
Damien George 9e677114e4 py/mpprint: Fix sign extension when printf'ing %u, %x and %X. 2016-02-01 15:08:42 +00:00
Paul Sokolovsky d3b1f0b627 py/runtime: mp_stack_ctrl_init() should be called immediately on startup.
Calling it from mp_init() is too late for some ports (like Unix), and leads
to incomplete stack frame being captured, with following GC issues. So, now
each port should call mp_stack_ctrl_init() on its own, ASAP after startup,
and taking special precautions so it really was called before stack variables
get allocated (because if such variable with a pointer is missed, it may lead
to over-collecting (typical symptom is segfaulting)).
2016-01-29 02:13:42 +02:00
Paul Sokolovsky 850212203a unix/main: Remove debug code left from MP_OBJ_TO_PTR refactor. 2016-01-29 01:00:36 +02:00
Dave Hylands 6a804cbaba lib/utils/printf: Fix printf on release builds
When using newer glibc's the compiler automatically sets
_FORTIFY_SOURCE when building with -O1 and this causes
a special inlined version of printf to be declared which
then bypasses our version of printf.
2016-01-28 22:31:24 +02:00
Paul Sokolovsky ac37e0fd1f unix/modsocket: sockaddr(): Handle AF_INET6 addresses. 2016-01-27 18:02:17 +02:00
Damien George a53af6c875 extmod/modurandom: Add some extra random functions.
Functions added are:
- randint
- randrange
- choice
- random
- uniform

They are enabled with configuration variable
MICROPY_PY_URANDOM_EXTRA_FUNCS, which is disabled by default.  It is
enabled for unix coverage build and stmhal.
2016-01-26 15:27:00 +00:00
Paul Sokolovsky cb4fbc8861 unix/modsocket: accept(): Make IPv6-clean.
By reserving enough space for peer address.
2016-01-21 23:55:20 +02:00
Paul Sokolovsky a58a91eb04 extmod/modurandom: Add "urandom" module.
Seedable and reproducible pseudo-random number generator. Implemented
functions are getrandbits(n) (n <= 32) and seed().

The algorithm used is Yasmarang by Ilya Levin:
http://www.literatecode.com/yasmarang
2016-01-17 12:13:01 +02:00
Damien George 31dd312f83 unix/modffi: Allow to compile modffi in OBJ_REPR_D mode. 2016-01-15 14:26:24 +00:00
Damien George 55ad083061 unix/.gitignore: Add nanbox build output to ignore list. 2016-01-15 14:25:53 +00:00
Damien George d8b08cf5fc unix: Add option to build 64-bit NaN-boxing interpreter.
Build using: make nanbox
2016-01-15 11:12:08 +00:00
Damien George c9845a0685 unix: Allow to build coverage build with OBJ_REPR_D. 2016-01-11 16:30:58 +00:00
Dave Hylands 11b97d7ec5 unix: Add socket.inet_ntop function 2016-01-11 12:08:07 +02:00
Damien George 5b3f0b7f39 py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.
The first argument to the type.make_new method is naturally a uPy type,
and all uses of this argument cast it directly to a pointer to a type
structure.  So it makes sense to just have it a pointer to a type from
the very beginning (and a const pointer at that).  This patch makes
such a change, and removes all unnecessary casting to/from mp_obj_t.
2016-01-11 00:49:27 +00:00
Damien George 4b72b3a133 py: Change type signature of builtin funs that take variable or kw args.
With this patch the n_args parameter is changed type from mp_uint_t to
size_t.
2016-01-11 00:49:27 +00:00
Damien George a0c97814df py: Change type of .make_new and .call args: mp_uint_t becomes size_t.
This patch changes the type signature of .make_new and .call object method
slots to use size_t for n_args and n_kw (was mp_uint_t.  Makes code more
efficient when mp_uint_t is larger than a machine word.  Doesn't affect
ports when size_t and mp_uint_t have the same size.
2016-01-11 00:48:41 +00:00
Paul Sokolovsky 8175877ad6 unix/modtime: strftime(): Support 2nd argument, but as time_t value.
Instead of struct tm like structure, as required by CPython.
2016-01-10 12:08:27 +02:00
Damien George 1b0aab621b py: Change struct and macro for builtin fun so they can be type checked. 2016-01-03 11:53:44 +00:00
Damien George ae4865efa1 unix/Makefile: Move include of mpconfigport.mk to before mkenv.mk.
So that if MICROPY_FORCE_32BIT is set mpconfigport.mk it influences
mkenv.mk.
2016-01-02 21:56:03 +00:00
Paul Sokolovsky 09630e48ce unix/.gitignore: Ignore gcov files. 2016-01-02 14:50:17 +02:00
Paul Sokolovsky 98f7729848 unix/unix_mphal: Be sure to wrap dupterm code with MICROPY_PY_OS_DUPTERM. 2016-01-01 22:55:45 +02:00
Paul Sokolovsky 8fa9264430 unix/unix_mphal: Handle exceptions in call to dupterm's .read(). 2016-01-01 22:39:29 +02:00
Paul Sokolovsky 30b7344eb0 extmod/moduos_dupterm: Make mp_uos_dupterm_tx_strn() function reusable.
Function to actually spool output terminal data to dupterm object.
2016-01-01 16:43:35 +02:00
Paul Sokolovsky 00ee84e1e1 py: Clean up instantiation of dupterm object.
To comply with already established scheme for extmod's.
2016-01-01 14:22:57 +02:00
Paul Sokolovsky 9bbfd5efd4 py/mpconfig: Make configuration of dupterm object reusable. 2016-01-01 13:16:18 +02:00
Paul Sokolovsky ddea7cb702 extmod/moduos_dupterm: Make uos.dupterm() implementation reusable.
That's just function which sets/gets dup terminal object, and can be
easily reused across ports.
2016-01-01 13:04:32 +02:00
Paul Sokolovsky 2c1620ce1f unix: Implement uos.dupterm(). Conditional on MICROPY_PY_OS_DUPTERM. 2015-12-28 01:13:21 +02:00
Paul Sokolovsky 1c9210bc2b unix/unix_mphal: Raise KeyboardInterrupt straight from signal handler.
POSIX doesn't guarantee something like that to work, but it works on any
system with careful signal implementation. Roughly, the requirement is
that signal handler is executed in the context of the process, its main
thread, etc. This is true for Linux. Also tested to work without issues
on MacOSX.
2015-12-23 00:07:00 +02:00
Damien George e9751d2ac0 unix: Properly cancel REPL input when Ctrl-C is pressed. 2015-12-22 22:06:09 +00:00
Dave Hylands 755b01439b unix: machine_mem improvements
This basically introduces the MICROPY_MACHINE_MEM_GET_READ_ADDR
and MICROPY_MACHINE_MEM_GET_WRITE_ADDR macros. If one of them is
not defined, then a default identity function is provided.
2015-12-18 22:01:03 +02:00
Paul Sokolovsky 2eb844e0b4 ports: Rename "machine" module to "umachine".
To let unix port implement "machine" functionality on Python level, and
keep consistent naming in other ports (baremetal ports will use magic
module "symlinking" to still load it on "import machine").

Fixes #1701.
2015-12-18 02:39:52 +02:00
Paul Sokolovsky 5efd3f0dca windows: Make keyboard_interrupt_obj available, it's standard feature. 2015-12-18 01:07:27 +02:00
Paul Sokolovsky 3c2b377711 unix/unix_mphal: Just consistently set sigaction.sa_flags to 0. 2015-12-18 01:07:27 +02:00
Paul Sokolovsky 3db2b23060 unix/unix_mphal: Properly initialize struct sigaction.
This solves long-standing non-deterministic bug, which manifested itself
on x86 32-bit (at least of reported cases) - segfault on Ctrl+C (i.e.
SIGINT).
2015-12-17 23:24:35 +02:00
Damien George 0d7de08e06 unix: Change define logic of _DIRENT_HAVE_D_INO to match other macros. 2015-12-16 14:17:56 +00:00
pohmelie 64a909ef51 unix: Add FreeDos target 2015-12-16 13:28:12 +00:00
Damien George a1528364b3 unix/modos: Fix silly bugs in ilistdir tuple creation. 2015-12-16 13:26:20 +00:00
Damien George 3386477b29 unix/modos: Allow to configure use of d_ino using _DIRENT_HAVE_D_INO.
Ports will need to #define _DIRENT_HAVE_D_INO (0) to disable d_ino use.
2015-12-16 13:21:09 +00:00
Paul Sokolovsky 130fde8130 uos: Add errno() function to get/set errno value. 2015-12-16 00:38:26 +02:00
Paul Sokolovsky d874702fe1 unix/modos: Implement ilistdir().
ilistdir() returns iterator which yields triples of (name, type, ino)
where ino is inode number for entry's data, type of entry (file/dir/etc.),
and name of file/dir. listdir() can be easily implemented in terms of this
iterator (which is otherwise more efficient in terms of memory use and may
save expensive call to stat() for each returned entry).

CPython has os.scandir() which also returns an iterator, but it yields
more complex objects of DirEntry type. scandir() can also be easily
implemented in terms of ilistdir().
2015-12-14 23:48:12 +02:00
Paul Sokolovsky 8fb255dc34 unix/modtime: Add strftime() function (only single argument is supported).
Following "don't rely on FFI for basic functionality" approach.
2015-12-14 00:10:57 +02:00
Paul Sokolovsky 2d11b17419 unix/moduselect: Make configurable with MICROPY_PY_USELECT. 2015-12-13 08:47:42 +02:00