summaryrefslogtreecommitdiffstatshomepage
path: root/py/stream.c
Commit message (Collapse)AuthorAge
* py/stream: seek: Consistently handle negative offset for SEEK_SET.Paul Sokolovsky2017-08-20
| | | | Per POSIX, this is EINVAL, so raises OSError(EINVAL).
* all: Use the name MicroPython consistently in commentsAlexander Steffen2017-07-31
| | | | | There were several different spellings of MicroPython present in comments, when there should be only one.
* all: Make more use of mp_raise_{msg,TypeError,ValueError} helpers.Damien George2017-06-15
|
* various: Spelling fixesVille Skyttä2017-05-29
|
* all: Remove readall() method, which is equivalent to read() w/o args.Paul Sokolovsky2016-11-14
| | | | | | Its addition was due to an early exploration on how to add CPython-like stream interface. It's clear that it's not needed and just takes up bytes in all ports.
* py/stream: Typo fix in comment.Paul Sokolovsky2016-10-27
|
* py: Use mp_raise_msg helper function where appropriate.Damien George2016-10-17
| | | | | Saves the following number of bytes of code space: 176 for bare-arm, 352 for minimal, 272 for unix x86-64, 140 for stmhal, 120 for esp8266.
* py: Add mp_raise_OSError(errno) helper function.Damien George2016-10-07
| | | | | This is an often used code pattern, and its use reduces code size of the core by about 100 bytes.
* py/stream: Remove unnecessary check for NULL return from vstr_extend.Damien George2016-09-22
| | | | | vstr_extend will now only return NULL if the vstr is a fixed buffer, which in this case it is not.
* py/stream.c: use mp_obj_get_type in mp_get_stream_raiseKrzysztof Blazewicz2016-08-24
| | | | | | | | | | In current state `mp_get_stream_raise` assumes that `self_in` is an object and always performs a pointer derefence which may cause a segfault. This function shall throw an exception whenever `self_in` does not implement a stream protocol, that includes qstr's and numbers. fixes #2331
* py/mpconfig.h: Add MICROPY_STREAMS_POSIX_API setting.Paul Sokolovsky2016-07-30
| | | | | | To filter out even prototypes of mp_stream_posix_*() functions, which require POSIX types like ssize_t & off_t, which may be not available in some ports.
* py/stream: Add adapter methods with POSIX-compatible signatures.Paul Sokolovsky2016-07-30
| | | | | Previoussly such read() and write() methods were used by modussl_axtls, move to py/stream for reuse.
* py/stream: Implement generic flush() method, in terms of C-level ioctl.Paul Sokolovsky2016-07-27
|
* py/stream: Implement 2- and 3-arg write() method as an extension to CPython.Paul Sokolovsky2016-07-14
| | | | | | | | | | | | | | | | | | 3-arg form: stream.write(data, offset, length) 2-arg form: stream.write(data, length) These allow efficient buffer writing without incurring extra memory allocation for slicing or creating memoryview() object, what is important for low-memory ports. All arguments must be positional. It might be not so bad idea to standardize on 3-arg form, but 2-arg case would need check and raising an exception anyway then, so instead it was just made to work.
* all: Rename mp_obj_type_t::stream_p to protocol.Paul Sokolovsky2016-06-18
| | | | | It's now used for more than just stream protocol (e.g. pin protocol), so don't use false names.
* py/stream: Add mp_stream_close() helper function.Paul Sokolovsky2016-05-20
|
* py/stream: Support both "exact size" and "one underlying call" operations.Paul Sokolovsky2016-05-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Both read and write operations support variants where either a) a single call is made to the undelying stream implementation and returned buffer length may be less than requested, or b) calls are repeated until requested amount of data is collected, shorter amount is returned only in case of EOF or error. These operations are available from the level of C support functions to be used by other C modules to implementations of Python methods to be used in user-facing objects. The rationale of these changes is to allow to write concise and robust code to work with *blocking* streams of types prone to short reads, like serial interfaces and sockets. Particular object types may select "exact" vs "once" types of methods depending on their needs. E.g., for sockets, revc() and send() methods continue to be "once", while read() and write() thus converted to "exactly" versions. These changes don't affect non-blocking handling, e.g. trying "exact" method on the non-blocking socket will return as much data as available without blocking. No data available is continued to be signaled as None return value to read() and write(). From the point of view of CPython compatibility, this model is a cross between its io.RawIOBase and io.BufferedIOBase abstract classes. For blocking streams, it works as io.BufferedIOBase model (guaranteeing lack of short reads/writes), while for non-blocking - as io.RawIOBase, returning None in case of lack of data (instead of raising expensive exception, as required by io.BufferedIOBase). Such a cross-behavior should be optimal for MicroPython needs.
* py/stream: Move uPy func obj wrappers to below their respective funcs.Damien George2016-04-10
|
* py/stream: Simplify arg extraction logic for stream_ioctl.Damien George2016-04-10
| | | | | | | Saves 16 bytes of code. Also, use mp_obj_get_int_truncated to allow integers as big as a machine word to be passed as the value.
* py/stream: ioctl(): Properly support 2-arg form.Paul Sokolovsky2016-04-10
|
* py/stream: Fix signed comparison issue.Paul Sokolovsky2016-04-10
|
* py/stream: Add Python-level ioctl() method.Paul Sokolovsky2016-04-10
| | | | | | | Will call underlying C virtual methods of stream interface. This isn't intended to be added to every stream object (it's not in CPython), but is convenient way to expose extra operation on Python side without adding bunch of Python-level methods.
* py/stream: Fix stupid thinko with variable naming/shadowing.Paul Sokolovsky2016-03-27
|
* py/stream: Fix object vs ptr usecase in mp_stream_writeall().Paul Sokolovsky2016-03-24
|
* py/stream: Add mp_stream_writeall() helper function.Paul Sokolovsky2016-03-24
| | | | | Spools entire output buffer to a blocking stream (chunk by chunk if needed).
* py: Change type signature of builtin funs that take variable or kw args.Damien George2016-01-11
| | | | | With this patch the n_args parameter is changed type from mp_uint_t to size_t.
* py: Add mp_get_stream_raise to factor out check for stream methods.Damien George2015-12-09
|
* py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George2015-11-29
| | | | | | | | | 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.
* py: Change mp_print_strn_t func type to use size_t for the str length.Damien George2015-11-29
|
* py/stream: Allow to reuse is_nonblocking_error().Paul Sokolovsky2015-10-18
|
* py: Add stream_tell method, and use for unix and stmhal file tell.blmorris2015-08-13
|
* py: Add mp_obj_get_int_truncated and use it where appropriate.Damien George2015-05-12
| | | | | | mp_obj_get_int_truncated will raise a TypeError if the argument is not an integral type. Use mp_obj_int_get_truncated only when you know the argument is a small or big int.
* py: Change vstr so that it doesn't null terminate buffer by default.Damien George2015-01-28
| | | | | | | | | This cleans up vstr so that it's a pure "variable buffer", and the user can decide whether they need to add a terminating null byte. In most places where vstr is used, the vstr did not need to be null terminated and so this patch saves code size, a tiny bit of RAM, and makes vstr usage more efficient. When null termination is needed it must be done explicitly using vstr_null_terminate.
* stream: readall(): Make sure there's a trailing NUL char.Paul Sokolovsky2015-01-24
|
* stream: Fix readall() implementation in respect to NUL terminator bytes.Paul Sokolovsky2015-01-23
| | | | After vstr refactor. Fixes #1084.
* py: Remove mp_obj_str_builder and use vstr instead.Damien George2015-01-21
| | | | | | | | | | | | With this patch str/bytes construction is streamlined. Always use a vstr to build a str/bytes object. If the size is known beforehand then use vstr_init_len to allocate only required memory. Otherwise use vstr_init and the vstr will grow as needed. Then use mp_obj_new_str_from_vstr to create a str/bytes object using the vstr memory. Saves code ROM: 68 bytes on stmhal, 108 bytes on bare-arm, and 336 bytes on unix x64.
* py: Add mp_obj_new_str_from_vstr, and use it where relevant.Damien George2015-01-21
| | | | | | | | This patch allows to reuse vstr memory when creating str/bytes object. This improves memory usage. Also saves code ROM: 128 bytes on stmhal, 92 bytes on bare-arm, and 88 bytes on unix x64.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.Damien George2014-12-05
| | | | | | | | | | | mp_obj_int_get_truncated is used as a "fast path" int accessor that doesn't check for overflow and returns the int truncated to the machine word size, ie mp_int_t. Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word sized values. Addresses issues #779 and #998.
* py: Make stream seek correctly check for ioctl fn; add seek for textio.Damien George2014-11-16
|
* stream: Implement seek operation support via ioctl, wrapped in generic method.Paul Sokolovsky2014-11-17
| | | | Also, implement for unix port.
* py: Use mp_uint_t where appropriate in stream functions.Damien George2014-10-24
|
* stream: Add optional 2nd "length" arg to .readinto() - extension to CPython.Paul Sokolovsky2014-10-23
| | | | | While extension to file.readinto() definition of CPython, the additional arg is similar to what in CPython available in socket.recv_into().
* unix, stmhal: Implement file.readinto() method.Paul Sokolovsky2014-10-18
| | | | | | Also, usocket.readinto(). Known issue is that .readinto() should be available only for binary files, but micropython uses single method table for both binary and text files.
* py: Improve stream_read so it doesn't need to alloc 2 bits of heap.Damien George2014-10-17
|
* stream: Handle non-blocking errors in readline() properly.Paul Sokolovsky2014-10-16
| | | | | | Just like they handled in other read*(). Note that behavior of readline() in case there's no data when it's called is underspecified in Python lib spec, implemented to behave as read() - return None.
* stream: Return errno value as first arg of OSError exception.Paul Sokolovsky2014-10-16
| | | | This is CPython-compatible convention established yet in acb13886fc837a1bb9.
* py: Small cleanup in stream.c.Damien George2014-08-22
|
* py: Change stream protocol API: fns return uint; is_text for text.Damien George2014-07-27
|
* streams: Treat non-error output size as unsigned.Paul Sokolovsky2014-07-23
|