Commit Graph

828 Commits

Author SHA1 Message Date
Alexander Steffen
55f33240f3 all: Use the name MicroPython consistently in comments
There were several different spellings of MicroPython present in comments,
when there should be only one.
2017-07-31 18:35:40 +10:00
Paul Sokolovsky
e280122b14 unix/modjni: Convert to mp_rom_map_elem_t. 2017-07-30 10:03:14 +03:00
Alexander Steffen
299bc62586 all: Unify header guard usage.
The code conventions suggest using header guards, but do not define how
those should look like and instead point to existing files. However, not
all existing files follow the same scheme, sometimes omitting header guards
altogether, sometimes using non-standard names, making it easy to
accidentally pick a "wrong" example.

This commit ensures that all header files of the MicroPython project (that
were not simply copied from somewhere else) follow the same pattern, that
was already present in the majority of files, especially in the py folder.

The rules are as follows.

Naming convention:
* start with the words MICROPY_INCLUDED
* contain the full path to the file
* replace special characters with _

In addition, there are no empty lines before #ifndef, between #ifndef and
one empty line before #endif. #endif is followed by a comment containing
the name of the guard macro.

py/grammar.h cannot use header guards by design, since it has to be
included multiple times in a single C file. Several other files also do not
need header guards as they are only used internally and guaranteed to be
included only once:
* MICROPY_MPHALPORT_H
* mpconfigboard.h
* mpconfigport.h
* mpthreadport.h
* pin_defs_*.h
* qstrdefs*.h
2017-07-18 11:57:39 +10:00
Damien George
1e6fd9f2b4 unix/Makefile: Disable assertions in the standard unix executable.
Reasons to disable:
- the code is relatively robust so doesn't need full checking in the
  main executable, and the coverage build is used for full testing
  with assertions still enabled;
- reduces code size noticeably, by 27k for x86-64 and 20k for x86;
- allows to more easily track changes in code size, since assertions
  can skew things.
2017-07-12 11:57:03 +10:00
Damien George
d0db93cf1f unix/modsocket: Remove unnecessary asserts.
These checks are already made, and errors reported, by the uPy runtime.
2017-07-12 11:43:35 +10:00
Damien George
e66fd56852 py/repl: Change mp_uint_t to size_t in repl helpers. 2017-07-04 23:44:54 +10:00
Damien George
369e7fd178 tests/unix/extra_coverage: Add test for mp_vprintf with bad fmt spec. 2017-06-30 12:25:42 +10:00
Paul Sokolovsky
9ae0713cef unix/mpconfigport.mk: Update descriptions of readline and TLS options. 2017-06-17 15:44:28 +03:00
Damien George
48d867b4a6 all: Make more use of mp_raise_{msg,TypeError,ValueError} helpers. 2017-06-15 11:54:41 +10:00
Paul Sokolovsky
d42b80fd64 unix/modtime: Replace strftime() with localtime().
Baremetal ports standardized on providing localtime(). localtime() offers
more functionality, in particular, strftime() can be completely implemented
in Python with localtime().
2017-06-11 21:16:35 +03:00
Tamas TEVESZ
d80c951f71 unix/Makefile: replace references to make with $(MAKE)
make is not always GNU make; the latter  may go by different names.
This helps builds on systems where the default make is not GNU make.
2017-06-08 13:42:23 +10:00
Damien George
d92898a35a unix: Convert to use core-provided version of built-in import(). 2017-06-01 16:02:49 +10:00
Ville Skyttä
ca16c38210 various: Spelling fixes 2017-05-29 11:36:05 +03:00
Damien George
d77862279e unix/Makefile: Don't add frozen bytecode to minimal build. 2017-05-26 18:12:30 +10:00
Paul Sokolovsky
a4e38db30d unix: Move upip to frozen bytecode dir.
For x86_64 build, this saves only 128 bytes on the final executable
size, but still an improvement.
2017-05-12 18:32:25 +03:00
Paul Sokolovsky
5c312861a6 unix/Makefile: Enable frozen bytecode modules dir. 2017-05-12 18:31:22 +03:00
Damien George
f1609bc843 ports: Add ilistdir in uos module. 2017-05-10 12:13:53 +10:00
Paul Sokolovsky
edc02bd952 unix/main: Implement -m option for packages. 2017-05-09 14:22:21 +03:00
Paul Sokolovsky
c1e0eb7afe unix/main: Don't allow to specify too small heap size.
This will lead to crash like:

FATAL: uncaught NLR 80a5420

On x86_32, the minimum heap size is smaller, but not 2 times, so just
use value which works for x86_64.
2017-05-06 11:43:37 +03:00
Paul Sokolovsky
d7da2dba07 py/modio: Implement uio.resource_stream(package, resource_path).
The with semantics of this function is close to
pkg_resources.resource_stream() function from setuptools, which
is the canonical way to access non-source files belonging to a package
(resources), regardless of what medium the package uses (e.g. individual
source files vs zip archive). In the case of MicroPython, this function
allows to access resources which are frozen into the executable, besides
accessing resources in the file system.

This is initial stage of the implementation, which actually doesn't
implement "package" part of the semantics, just accesses frozen resources
from "root", or filesystem resource - from current dir.
2017-05-03 01:47:08 +03:00
Paul Sokolovsky
11bc21dfa8 unix/main: Ignore SIGPIPE signal, instead make EPIPE arrive.
Do not raise SIGPIPE, instead return EPIPE. Otherwise, e.g. writing
to peer-closed socket will lead to sudden termination of MicroPython
process. SIGPIPE is particularly nasty, because unix shell doesn't
print anything for it, so the above looks like completely sudden and
silent termination for unknown reason. Ignoring SIGPIPE is also what
CPython does. Note that this may lead to problems using MicroPython
scripts as pipe filters, but again, that's what CPython does. So,
scripts which want to follow unix shell pipe semantics (where SIGPIPE
means "pipe was requested to terminate, it's not an error"), should
catch EPIPE themselves.
2017-05-01 18:47:26 +03:00
Damien George
7743b1523e unix: Remove obsolete MICROPY_FATFS macro.
It doesn't do anything.  The VFS feature is controlled by MICROPY_VFS and
the FatFS driver, by MICROPY_VFS_FAT (which are set in mpconfigport.h).
2017-04-26 11:16:52 +10:00
Damien George
03053f82db mpy-cross, unix, windows, stmhal: Enable return-if-else optimisation.
Prior to making this a config option it was previously available on these
(and all other) ports, and it makes sense to keep it enabled for mpy-cross
as well as ports that have a decent amount of space for the code.
2017-04-22 15:12:48 +10:00
Damien George
fe79234ca0 unix: Enabled high-quality float hashing in coverage build. 2017-04-12 13:38:17 +10:00
Damien George
6c564aa408 unix, windows: Use core-provided KeyboardInterrupt exception object. 2017-04-11 13:31:49 +10:00
Damien George
4c307bfba1 all: Move BYTES_PER_WORD definition from ports to py/mpconfig.h
It can still be overwritten by a port in mpconfigport.h but for almost
all cases one can use the provided default.
2017-04-01 11:39:38 +11:00
Damien George
b6c7e4b143 all: Use full path name when including mp-readline/timeutils/netutils.
This follows the pattern of how all other headers are now included, and
makes it explicit where the header file comes from.  This patch also
removes -I options from Makefile's that specify the mp-readline/timeutils/
netutils directories, which are no longer needed.
2017-03-31 22:29:39 +11:00
Pavol Rusnak
6e6c01b971 unix: Convert mp_uint_t to size_t in alloc.c. 2017-03-31 13:18:47 +11:00
Damien George
46e98d9ea7 unix: Convert mp_uint_t to size_t for use of mp_obj_list_get. 2017-03-29 12:56:17 +11:00
Damien George
29424304d9 unix: Use mp_obj_str_get_str instead of mp_obj_str_get_data. 2017-03-25 19:54:07 +11:00
Krzysztof Blazewicz
75589272ef all/Makefile: Remove -ansi from GCC flags, its ignored anyway.
The -ansi flag is used for C dialect selection and it is equivalent to -std=c90.
Because it goes right before -std=gnu99 it is ignored as for conflicting flags
GCC always uses the last one.
2017-03-23 15:32:12 +11:00
Damien George
74faf4c5fc unix/coverage: Enable scheduler and add tests for it. 2017-03-20 15:20:26 +11:00
Damien George
c138b21ceb unix: Use mp_handle_pending() in time.sleep(). 2017-03-20 15:20:26 +11:00
Rami Ali
77cbd173df tests: Improve binary.c test coverage. 2017-03-14 18:27:29 +11:00
Damien George
33a77ea25f unix/main: Refactor to put lexer constructors all in one place.
The lexer can now raise an exception on construction so it must go within
an nlr handler block.
2017-03-14 11:52:05 +11:00
Paul Sokolovsky
fe866d996f unix/moduselect: Properly implement ipoll object iteration.
TODO: There's another issue to care about: poll set being modified during
iteration.
2017-03-05 13:51:22 +01:00
Damien George
5e83a75c78 unix: Remove remaining, obsolete traces of GNU readline support. 2017-03-03 17:55:40 +11:00
Damien George
f1ea3bc72b unix/modmachine: Add Signal class to machine module. 2017-03-02 16:08:20 +11:00
Damien George
ae8d867586 py: Add iter_buf to getiter type method.
Allows to iterate over the following without allocating on the heap:
- tuple
- list
- string, bytes
- bytearray, array
- dict (not dict.keys, dict.values, dict.items)
- set, frozenset

Allows to call the following without heap memory:
- all, any, min, max, sum

TODO: still need to allocate stack memory in bytecode for iter_buf.
2017-02-16 18:38:06 +11:00
Paul Sokolovsky
16a3534ad4 unix/moduselect: Implement ipoll() method with no-allocation policy.
ipoll() allows to poll streams without allocating any memory: this method
returns an iterator (a poll object itself), and the iterator yields
preallocated "callee-owned tuple" with polling results for each active
stream. The only operation a caller is allowed to do with this tuple is
extracting values from it (storing the tuple as a whole somewhere is
not allowed).
2017-02-13 00:23:23 +03:00
dmazzella
18e6569166 py/objtype: Implement __delattr__ and __setattr__.
This patch implements support for class methods __delattr__ and __setattr__
for customising attribute access.  It is controlled by the config option
MICROPY_PY_DELATTR_SETATTR and is disabled by default.
2017-02-09 12:40:15 +11:00
Paul Sokolovsky
de48a27d60 unix/main: Properly handle MICROPYPATH starting with ':'.
In other words, where first path component is an empty string.
2017-02-07 02:13:01 +03:00
Nikita Melentev
5bea6ea808 unix: Fix freedos port build problems. 2017-02-06 15:25:42 +11:00
Nicko van Someren
df0117c8ae py: Added optimised support for 3-argument calls to builtin.pow()
Updated modbuiltin.c to add conditional support for 3-arg calls to
pow() using MICROPY_PY_BUILTINS_POW3 config parameter. Added support in
objint_mpz.c for for optimised implementation.
2017-02-02 22:23:10 +03:00
Damien George
30beed119f unix/modos: Remove VfsFat from uos module, it's now in uos_vfs module. 2017-01-30 12:26:08 +11:00
Damien George
0bd61d23b9 extmod/vfs_fat: Remove MICROPY_FATFS_OO config option.
Everyone should now be using the new ooFatFs library.  The old one is no
longer supported and will be removed.
2017-01-30 12:26:07 +11:00
Damien George
95635ade8b unix/mpconfigport.h: Remove obsolete MICROPY_FATFS_VOLUMES config. 2017-01-30 12:26:07 +11:00
Damien George
1808b2e8d5 extmod: Remove MICROPY_FSUSERMOUNT and related files.
Replaced by MICROPY_VFS and the VFS sub-system.
2017-01-30 12:26:07 +11:00
Damien George
9225ce6a14 unix/fatfs_port: Include new oofatfs header. 2017-01-27 23:22:15 +11:00
Damien George
f1e04148a1 unix: Change to use new generic VFS sub-system in coverage build.
This patch includes a new module "uos_vfs" which can be used for testing
the VFS syb-system.
2017-01-27 17:21:45 +11:00