summaryrefslogtreecommitdiff
path: root/py/stream.c
AgeCommit message (Collapse)Author
2015-10-18py/stream: Allow to reuse is_nonblocking_error().Paul Sokolovsky
2015-08-13py: Add stream_tell method, and use for unix and stmhal file tell.blmorris
2015-05-12py: Add mp_obj_get_int_truncated and use it where appropriate.Damien George
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.
2015-01-28py: Change vstr so that it doesn't null terminate buffer by default.Damien George
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.
2015-01-24stream: readall(): Make sure there's a trailing NUL char.Paul Sokolovsky
2015-01-23stream: Fix readall() implementation in respect to NUL terminator bytes.Paul Sokolovsky
After vstr refactor. Fixes #1084.
2015-01-21py: Remove mp_obj_str_builder and use vstr instead.Damien George
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.
2015-01-21py: Add mp_obj_new_str_from_vstr, and use it where relevant.Damien George
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.
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-12-05py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.Damien George
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.
2014-11-16py: Make stream seek correctly check for ioctl fn; add seek for textio.Damien George
2014-11-17stream: Implement seek operation support via ioctl, wrapped in generic method.Paul Sokolovsky
Also, implement for unix port.
2014-10-24py: Use mp_uint_t where appropriate in stream functions.Damien George
2014-10-23stream: Add optional 2nd "length" arg to .readinto() - extension to CPython.Paul Sokolovsky
While extension to file.readinto() definition of CPython, the additional arg is similar to what in CPython available in socket.recv_into().
2014-10-18unix, stmhal: Implement file.readinto() method.Paul Sokolovsky
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.
2014-10-17py: Improve stream_read so it doesn't need to alloc 2 bits of heap.Damien George
2014-10-16stream: Handle non-blocking errors in readline() properly.Paul Sokolovsky
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.
2014-10-16stream: Return errno value as first arg of OSError exception.Paul Sokolovsky
This is CPython-compatible convention established yet in acb13886fc837a1bb9.
2014-08-22py: Small cleanup in stream.c.Damien George
2014-07-27py: Change stream protocol API: fns return uint; is_text for text.Damien George
2014-07-23streams: Treat non-error output size as unsigned.Paul Sokolovsky
2014-07-23stream: Revert to checking for the correct error value.Paul Sokolovsky
2014-07-21Deal with reading a buffer less than what was allocated.Dave Hylands
With this fix, file_long_read now passes.
2014-07-19py: Add stream reading of n unicode chars; unicode support by default.Damien George
With unicode enabled, this patch allows reading a fixed number of characters from text-mode streams; eg file.read(5) will read 5 unicode chars, which can made of more than 5 bytes. For an ASCII stream (ie no chars > 127) it only needs to do 1 read. If there are lots of non-ASCII chars in a stream, then it needs multiple reads of the underlying object. Adds a new test for this case. Enables unicode support by default on unix and stmhal ports.
2014-07-13stream: Factor out mp_stream_write() method to write a memstring to stream.Paul Sokolovsky
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-06-29windows: Sync mpconfigport.h with the unix' versionstijn
- rearrange/add definitions that were not there so it's easier to compare both - use MICROPY_PY_SYS_PLATFORM in main.c since it's available anyway - define EWOULDBLOCK, it is missing from ingw32
2014-06-27streams: Reading by char count from unicode text streams is not implemented.Paul Sokolovsky
2014-06-13stream: Use mp_obj_is_true() for EOF testing.Paul Sokolovsky
Getting a length of string may be expensive, depending on the underlying implementation.
2014-05-25py: Slightly improve efficiency of mp_obj_new_str; rename str_new.Damien George
Reorder interning logic in mp_obj_new_str, to be more efficient. str_new is globally accessible, so should be prefixed with mp_obj_.
2014-05-15objstringio: Implement io.BytesIO.Paul Sokolovsky
Done in generalized manner, allowing any stream class to be specified as working with bytes.
2014-05-13py, unix: Add copyright for modules I worked closely on.Paul Sokolovsky
2014-05-07stream: Make non-blcoking stream support configurable.Paul Sokolovsky
Enable only on unix. To avoid unpleasant surprises with error codes.
2014-05-07stream: Use standard name of DEFAULT_BUFFER_SIZE.Paul Sokolovsky
2014-05-07stream: Add compliant handling of non-blocking readall().Paul Sokolovsky
2014-05-07stream: Add compliant handling of non-blocking read()/write().Paul Sokolovsky
In case of empty non-blocking read()/write(), both return None. read() cannot return 0, as that means EOF, so returns another value, and then write() just follows. This is still pretty unexpected, and typical "if not len:" check would treat this as EOF. Well, non-blocking files require special handling! This also kind of makes it depending on POSIX, but well, anything else should emulate POSIX anyway ;-).
2014-05-03Add license header to (almost) all files.Damien George
Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-05-03py, stream: Implement readlines for a stream.Damien George
2014-05-02py, unix: Make "mpconfig.h" be first included, as other headers depend on it.Paul Sokolovsky
Specifically, nlr.h does.
2014-04-26streams: Make .write() support arbitrary objects with buffer interface.Paul Sokolovsky
This in particular fixes writing str vs bytes.
2014-04-17py: Add MP_OBJ_STOP_ITERATION and make good use of it.Damien George
Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL. This helps a lot in debugging and understanding of function API.
2014-04-12py: the entire `<unistd.h>` shouldn't be neededIlya Dmitrichenko
2014-04-05py: Replace stream_p with *stream_p in mp_obj_type_t.Damien George
This is to reduce ROM usage. stream_p is used in file and socket types only (at the moment), so seems a good idea to make the protocol functions a pointer instead of the actual structure. It saves 308 bytes of ROM in the stmhal/ port, 928 in unix/.
2014-04-05py: Change nlr_jump to nlr_raise, to aid in debugging.Damien George
This does not affect code size or performance when debugging turned off. To address issue #420.
2014-03-26py: Replace mp_const_stop_iteration object with MP_OBJ_NULL.Damien George
2014-03-17py: Clean up includes.xbe
Remove unnecessary includes. Add includes that improve portability.
2014-02-15Implement proper exception type hierarchy.Damien George
Each built-in exception is now a type, with base type BaseException. C exceptions are created by passing a pointer to the exception type to make an instance of. When raising an exception from the VM, an instance is created automatically if an exception type is raised (as opposed to an exception instance). Exception matching (RT_BINARY_OP_EXCEPTION_MATCH) is now proper. Handling of parse error changed to match new exceptions. mp_const_type renamed to mp_type_type for consistency.
2014-02-12Replace global "static" -> "STATIC", to allow "analysis builds". Part 2.Paul Sokolovsky
2014-02-08Make mp_obj_str_get_data return char* instead of byte*.Damien George
Can't decide which is better for string type, char or byte pointer. Changing to char removes a few casts. Really need to do proper unicode.
2014-01-22file.readline(): Use mp_obj_str_get_data() and fix off-by-one error on EOF.Paul Sokolovsky