Commit Graph

593 Commits

Author SHA1 Message Date
Jeff Epler 014857b34b uzlib: Upgrade to uzlib v2.9 release
This fixes a large number of crashes on malformed inputs.
2018-09-09 20:22:25 -05:00
Noralf Trønnes 39ee12d1ac Fix os.stat() to use 1970 epoch
Commit 95e70cd0ea 'time: Use 1970 epoch' changed epoch for the time
module, but not for other users. This patch does the same for the only
other core timeutils user: extmod/vfs_fat.c:fat_vfs_stat().
Other timeutils users: cc3200, esp8266 and stm32, are not changed.

Ports that don't use long ints, will still get wrong time values from
os.stat().
2018-08-25 20:43:02 +02:00
Scott Shawcroft 96534e598e
Fix unix coverage and update translations. 2018-08-16 17:41:53 -07:00
Scott Shawcroft 2cd166b573
Fix esp and samd 2018-08-16 17:41:35 -07:00
Scott Shawcroft de5a9d72dc
Compress all translated strings with Huffman coding.
This saves code space in builds which use link-time optimization.
The optimization drops the untranslated strings and replaces them
with a compressed_string_t struct. It can then be decompressed to
a c string.

Builds without LTO work as well but include both untranslated
strings and compressed strings.

This work could be expanded to include QSTRs and loaded strings if
a compress method is added to C. Its tracked in #531.
2018-08-16 17:40:57 -07:00
Scott Shawcroft 96ebf5bc3f
Two fixes and translate more strings.
* Fix finding translations with escaped characters.
* Add back \r to translations since its needed by screen.
2018-08-09 13:29:30 -07:00
Dan Halbert f48b70050e merge finished 2018-07-28 13:29:47 -04:00
Dan Halbert bc760dd341 WIP: complete manual inspection of all significant changes 2018-07-23 21:34:25 -04:00
Dan Halbert e2e01efa84 compiles and runs; hangs on import storage;storage.VfsFat.<tab> 2018-07-13 22:51:10 -04:00
Dan Halbert 0d27f4d9a6 continued WIP: almost compiling 2018-07-12 14:13:51 -04:00
Dan Halbert 7c219600a2 WIP: after merge; before testing 2018-07-11 16:45:30 -04:00
Dan Halbert dbf1a2f7d5 allow '/' to be mounted on '/' from Python code 2018-06-21 09:24:40 -04:00
Damien George e8398a5856 extmod: Update to use new mp_get_stream helper.
With this patch objects are only checked that they have the stream protocol
at the start of their use as a stream, and afterwards the efficient
mp_get_stream() helper is used to extract the stream protocol C methods.
2018-06-18 12:35:56 +10:00
Damien George 564abb01a5 extmod/vfs_fat_diskio: Factor disk ioctl code to reduce code size.
Functionality is unchanged.
2018-06-16 18:21:42 +10:00
Dan Halbert e724bc1c4e Fix playing audio from SD card 2018-06-14 18:47:40 -04:00
Damien George d11fb09333 extmod/modussl_axtls: Fix __del__ to point to mp_stream_close_obj. 2018-06-13 13:16:21 +10:00
Damien George 035906419d extmod/uos_dupterm: Use native C stream methods on dupterm object.
This patch changes dupterm to call the native C stream methods on the
connected stream objects, instead of calling the Python readinto/write
methods.  This is much more efficient for native stream objects like UART
and webrepl and doesn't require allocating a special dupterm array.

This change is a minor breaking change from the user's perspective because
dupterm no longer accepts pure user stream objects to duplicate on.  But
with the recent addition of uio.IOBase it is possible to still create such
classes just by inheriting from uio.IOBase, for example:

    import uio, uos

    class MyStream(uio.IOBase):
        def write(self, buf):
            # existing write implementation
        def readinto(self, buf):
            # existing readinto implementation

    uos.dupterm(MyStream())
2018-06-12 15:06:11 +10:00
Yonatan Goldschmidt c2fb725e72 extmod/moduhashlib: Make function objects STATIC.
These are not exported to anyone anyway.
2018-06-12 13:50:11 +10:00
Yonatan Goldschmidt 6963ee9075 extmod/moduhashlib: Allow using the sha256 implementation of mbedTLS. 2018-06-12 13:50:11 +10:00
Yonatan Goldschmidt 6630354ffe extmod/moduhashlib: Allow to disable the sha256 class.
Via the config value MICROPY_PY_UHASHLIB_SHA256.  Default to enabled to
keep backwards compatibility.

Also add default value for the sha1 class, to at least document its
existence.
2018-06-12 13:50:11 +10:00
Yonatan Goldschmidt 38682d4629 extmod/moduhashlib: Reorder funcs so that they are grouped by hash type.
Makes the code much more readable by reducing the number of #ifdefs and
keeping related functions close.
2018-06-12 13:47:20 +10:00
Yonatan Goldschmidt b045ebd354 extmod/moduhashlib: Prefix all Python methods and objects with uhashlib.
For consistency with other modules, and to help avoid clashes with the
actual underlying functions that do the hashing (eg
crypto-algorithms/sha256.c:sha256_update).
2018-06-12 13:44:09 +10:00
Damien George c117effddd extmod/vfs: Introduce a C-level VFS protocol, with fast import_stat.
Following other C-level protocols, this VFS protocol is added to help
abstract away implementation details of the underlying VFS in an efficient
way.  As a starting point, the import_stat function is put into this
protocol so that the VFS sub-system does not need to know about every VFS
implementation in order to do an efficient stat for importing files.

In the future it might be worth adding other functions to this protocol.
2018-06-06 14:33:42 +10:00
Damien George d4ce57e4e3 extmod/vfs: Add fast path for stating VfsPosix filesystem. 2018-06-06 14:28:23 +10:00
Damien George 8d82b0edbd extmod: Add VfsPosix filesystem component.
This VFS component allows to mount a host POSIX filesystem within the uPy
VFS sub-system.  All traditional POSIX file access then goes through the
VFS, allowing to sandbox a uPy process to a certain sub-dir of the host
system, as well as mount other filesystem types alongside the host
filesystem.
2018-06-06 14:28:23 +10:00
Damien George f35aae366c extmod/vfs_fat: Rename FileIO/TextIO types to mp_type_vfs_fat_XXX.
So they don't clash with other VFS implementations.
2018-06-06 14:28:23 +10:00
Damien George 172c23fe5d extmod/vfs: Use u_rom_obj properly in argument structures. 2018-06-06 14:28:23 +10:00
Damien George ea22406f76 extmod/modussl_mbedtls: Use mbedtls_entropy_func for CTR-DRBG entropy.
If mbedtls_ctr_drbg_seed() is available in the mbedtls bulid then so should
be mbedtls_entropy_func().  Then it's up to the port to configure a valid
entropy source, eg via MBEDTLS_ENTROPY_HARDWARE_ALT.
2018-05-31 21:52:29 +10:00
Damien George 98b9f0fc9d extmod/modussl_mbedtls: Populate sock member right away in wrap_socket.
Otherwise the "sock" member may have an undefined value if wrap_socket
fails with an exception and exits early, and then if the finaliser runs it
will try to close an invalid stream object.

Fixes issue #3828.
2018-05-31 21:47:26 +10:00
Damien George 41766ba7e6 extmod/modlwip: Allow to compile with MICROPY_PY_LWIP disabled. 2018-05-21 16:46:30 +10:00
Damien George 1e2a6a84a2 extmod/modlwip: Set POLLHUP flag for sockets that are new.
This matches CPython behaviour on Linux: a socket that is new and not
listening or connected is considered "hung up".

Thanks to @rkojedzinszky for the initial patch, PR #3457.
2018-05-17 23:17:36 +10:00
Damien George 9c2044717c extmod/modlwip: Update to work with lwIP v2.0.
lwIP v2.0.3 has been tested with this lwip module and it works very well.
2018-05-17 12:58:34 +10:00
Scott Shawcroft b46cc9d29a
Merge pull request #817 from jepler/uzlib-as-submodule
uzlib: convert to submodule
2018-05-08 10:34:51 -07:00
Jeff Epler a6072f7ae3 uzlib: convert to submodule
Textualy, the files in lib/uzlib/src were identical to the ones committed
in extmod/uzlib so there should be no behavioral change possible as a
result of this commit.
2018-05-07 20:03:30 -05:00
Jeff Epler 11a97bdffe uhashlib: masquerade as hashlib for python3 compatibility 2018-05-06 12:31:54 -05:00
Jeff Epler 005226ae54 uhashlib: some functions should refuse unicode for python3 compatibility
.. this maybe should be subject to MICROPY_CPYTHON_COMPAT, except that
is not defined in the main circuitpython ports so it would be a change
that makes no difference.
2018-05-06 12:31:54 -05:00
Damien George 318f874cda extmod/modlwip: In ioctl handle case when socket is in an error state.
Using MP_STREAM_POLL_HUP for ERR_RST state follows how *nix handles this
case.
2018-05-04 15:15:04 +10:00
Damien George 5936168150 extmod/uzlib: Fix C-language sequencing error with uzlib_get_byte calls.
The order of function calls in an arithmetic expression is undefined and so
they must be written out as sequential statements.

Thanks to @dv-extrarius for reporting this issue, see issue #3690.
2018-05-02 23:16:22 +10:00
Damien George 89b1c4a60c extmod/vfs: Delegate import_stat to vfs.stat to allow generic FS import. 2018-05-02 17:08:48 +10:00
Jeff Epler c2f0c57a26 ubinascii: masquerade as binascii for python3 compatibility 2018-05-01 17:10:53 -05:00
Jeff Epler 0f869bbbf1 ubinascii: some functions should refuse unicode for python3 compatibility
.. this maybe should be subject to MICROPY_CPYTHON_COMPAT, except that
is not defined in the main circuitpython ports so it would be a change
that makes no difference.
2018-04-30 20:06:29 -05:00
Damien George bdff68db9c extmod/modlwip: Check if getaddrinfo() constraints are supported or not.
In particular don't issue a warning if the passed-in constraints are
actually supported because they are the default values.
2018-04-23 16:38:20 +10:00
armink 6a693db71d extmod/re1.5: Fix compilecode.c compile problem on IAR tool chain.
The 2nd and 3rd args of the ternary operator are treated like they are in
the same expression and must have similar types.  void is not compatible
with int so that's why the compiler is complaining.
2018-04-10 13:54:22 +10:00
Damien George cf31d384f1 py/stream: Switch stream close operation from method to ioctl.
This patch moves the implementation of stream closure from a dedicated
method to the ioctl of the stream protocol, for each type that implements
closing.  The benefits of this are:

1. Rounds out the stream ioctl function, which already includes flush,
   seek and poll (among other things).

2. Makes calling mp_stream_close() on an object slightly more efficient
   because it now no longer needs to lookup the close method and call it,
   rather it just delegates straight to the ioctl function (if it exists).

3. Reduces code size and allows future types that implement the stream
   protocol to be smaller because they don't need a dedicated close method.

Code size reduction is around 200 bytes smaller for x86 archs and around
30 bytes smaller for the bare-metal archs.
2018-04-10 13:41:32 +10:00
Jeff Epler 9c47fd9c13 Specifically give a better error message for setlabel on RO fs 2018-03-27 21:28:19 -05:00
Jeff Epler fe7f405fc7 Add VfsFat.label property
These allow accessing the filesystem label.  For instance,
in boot.py, you can set the label on the built-in storage with:
   storage.remount('/', False)
   storage.getmount('/').label = "NEWLABEL"
   storage.remount('/', True)

Users with multiple CIRCUITPY boards may find it desirable to
choose a different label for each board they own.
2018-03-27 21:28:18 -05:00
Ayke van Laethem fa55b15ac6 extmod/vfs_fat_file: Implement SEEK_CUR for non-zero offset.
CPython doesn't allow SEEK_CUR with non-zero offset for files in text mode,
and uPy inherited this behaviour for both text and binary files.  It makes
sense to provide full support for SEEK_CUR of binary-mode files in uPy, and
to do this in a minimal way means also allowing to use SEEK_CUR with
non-zero offsets on text-mode files.  That seems to be a fair compromise.
2018-03-23 09:19:56 -05:00
Tom Collins 4d3a92c67c extmod/vfs_fat: Add file size as 4th element of uos.ilistdir tuple. 2018-03-12 12:26:36 +11:00
Damien George 58ebeca6a9 drivers/bus: Pull out software SPI implementation to dedicated driver.
This patch takes the software SPI implementation from extmod/machine_spi.c
and moves it to a dedicated file in drivers/bus/softspi.c.  This allows the
SPI driver to be used independently of the uPy runtime, making it a more
general component.
2018-03-10 00:59:43 +11:00
Damien George 21d5527edf extmod/machine_spi: Make SPI protocol structure public.
So it can be referenced directly without the need for the uPy object.
2018-03-02 23:55:08 +11:00