<feed xmlns='http://www.w3.org/2005/Atom'>
<title>suspect-devices/circuitpython/py/stream.h, branch 6.0.0</title>
<subtitle>CircuitPython - a Python implementation for teaching coding with microcontrollers</subtitle>
<id>https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=6.0.0</id>
<link rel='self' href='https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=6.0.0'/>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/'/>
<updated>2020-07-06T18:16:25+00:00</updated>
<entry>
<title>Add license to some obvious files.</title>
<updated>2020-07-06T18:16:25+00:00</updated>
<author>
<name>Diego Elio Pettenò</name>
<email>flameeyes@flameeyes.com</email>
</author>
<published>2020-06-03T22:40:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=34b4993d63a6b576f29d624385c681f679b4124c'/>
<id>urn:sha1:34b4993d63a6b576f29d624385c681f679b4124c</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Fix up end of file and trailing whitespace.</title>
<updated>2020-06-03T09:56:35+00:00</updated>
<author>
<name>Diego Elio Pettenò</name>
<email>flameeyes@flameeyes.com</email>
</author>
<published>2020-05-30T09:44:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=dd5d7c86d22807c021dd1711eb7dd3daebc5cfcf'/>
<id>urn:sha1:dd5d7c86d22807c021dd1711eb7dd3daebc5cfcf</id>
<content type='text'>
This can be enforced by pre-commit, but correct it separately to make it easier to review.
</content>
</entry>
<entry>
<title>protocols: Allow them to be (optionally) type-safe</title>
<updated>2019-12-04T15:29:57+00:00</updated>
<author>
<name>Jeff Epler</name>
<email>jepler@gmail.com</email>
</author>
<published>2019-12-03T20:50:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=238e12123690debaf2cf8488fb2a4d4003a06506'/>
<id>urn:sha1:238e12123690debaf2cf8488fb2a4d4003a06506</id>
<content type='text'>
Protocols are nice, but there is no way for C code to verify whether
a type's "protocol" structure actually implements some particular
protocol.  As a result, you can pass an object that implements the
"vfs" protocol to one that expects the "stream" protocol, and the
opposite of awesomeness ensues.

This patch adds an OPTIONAL (but enabled by default) protocol identifier
as the first member of any protocol structure.  This identifier is
simply a unique QSTR chosen by the protocol designer and used by each
protocol implementer.  When checking for protocol support, instead of
just checking whether the object's type has a non-NULL protocol field,
use `mp_proto_get` which implements the protocol check when possible.

The existing protocols are now named:
    protocol_framebuf
    protocol_i2c
    protocol_pin
    protocol_stream
    protocol_spi
    protocol_vfs
(most of these are unused in CP and are just inherited from MP; vfs and
stream are definitely used though)

I did not find any crashing examples, but here's one to give a flavor of what
is improved, using `micropython_coverage`.  Before the change,
the vfs "ioctl" protocol is invoked, and the result is not intelligible
as json (but it could have resulted in a hard fault, potentially):

    &gt;&gt;&gt; import uos, ujson
    &gt;&gt;&gt; u = uos.VfsPosix('/tmp')
    &gt;&gt;&gt; ujson.load(u)
    Traceback (most recent call last):
      File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    ValueError: syntax error in JSON

After the change, the vfs object is correctly detected as not supporting
the stream protocol:
    &gt;&gt;&gt; ujson.load(p)
    Traceback (most recent call last):
      File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    OSError: stream operation not supported
</content>
</entry>
<entry>
<title>Support print("", flush=True)</title>
<updated>2019-02-16T00:53:19+00:00</updated>
<author>
<name>Scott Shawcroft</name>
<email>scott@tannewt.org</email>
</author>
<published>2019-02-16T00:53:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=e6b140e7a0cf07fa365269e7801bb111565cb478'/>
<id>urn:sha1:e6b140e7a0cf07fa365269e7801bb111565cb478</id>
<content type='text'>
Fixes #1127
</content>
</entry>
<entry>
<title>UART changes: timeout in secs, write bytes, etc.</title>
<updated>2018-12-03T17:04:32+00:00</updated>
<author>
<name>Dan Halbert</name>
<email>halbert@halwitz.org</email>
</author>
<published>2018-12-03T16:00:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=80db2cec99ca5c995a0302b1d6d00ad77cfcd736'/>
<id>urn:sha1:80db2cec99ca5c995a0302b1d6d00ad77cfcd736</id>
<content type='text'>
</content>
</entry>
<entry>
<title>py/stream: Introduce and use efficient mp_get_stream to access stream_p.</title>
<updated>2018-06-18T02:35:56+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2018-06-13T01:54:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=6abede2ca9e221b6aefcaccbda0c89e367507df1'/>
<id>urn:sha1:6abede2ca9e221b6aefcaccbda0c89e367507df1</id>
<content type='text'>
The existing mp_get_stream_raise() helper does explicit checks that the
input object is a real pointer object, has a non-NULL stream protocol, and
has the desired stream C method (read/write/ioctl).  In most cases it is
not necessary to do these checks because it is guaranteed that the input
object has the stream protocol and desired C methods.  For example, native
objects that use the stream wrappers (eg mp_stream_readinto_obj) in their
locals dict always have the stream protocol (or else they shouldn't have
these wrappers in their locals dict).

This patch introduces an efficient mp_get_stream() which doesn't do any
checks and just extracts the stream protocol struct.  This should be used
in all cases where the argument object is known to be a stream.  The
existing mp_get_stream_raise() should be used primarily to verify that an
object does have the correct stream protocol methods.

All uses of mp_get_stream_raise() in py/stream.c have been converted to use
mp_get_stream() because the argument is guaranteed to be a proper stream
object.

This patch improves efficiency of stream operations and reduces code size.
</content>
</entry>
<entry>
<title>py/stream: Move definition of mp_stream_p_t from obj.h to stream.h.</title>
<updated>2018-06-04T06:53:17+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2018-06-04T06:53:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=1427f8f593062a9f428d40e8d3536c6a97adc479'/>
<id>urn:sha1:1427f8f593062a9f428d40e8d3536c6a97adc479</id>
<content type='text'>
Since a long time now, mp_obj_type_t no longer refers explicitly to
mp_stream_p_t but rather to an abstract "const void *protocol".  So there's
no longer any need to define mp_stream_p_t in obj.h and it can go with all
its associated definitions in stream.h.  Pretty much all users of this type
will already include the stream header.
</content>
</entry>
<entry>
<title>py/stream: Use uPy errno instead of system's for non-blocking check.</title>
<updated>2018-05-01T05:54:50+00:00</updated>
<author>
<name>Ayke van Laethem</name>
<email>aykevanlaethem@gmail.com</email>
</author>
<published>2018-04-24T15:43:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=d43c7377564b3e1be36f627a465df2c5779a1ae8'/>
<id>urn:sha1:d43c7377564b3e1be36f627a465df2c5779a1ae8</id>
<content type='text'>
This is a more consistent use of errno codes.  For example, it may be that
a stream returns MP_EAGAIN but the mp_is_nonblocking_error() macro doesn't
catch this value because it checks for EAGAIN instead (which may have a
different value than MP_EAGAIN when MICROPY_USE_INTERNAL_ERRNO is enabled).
</content>
</entry>
<entry>
<title>py/stream: Switch stream close operation from method to ioctl.</title>
<updated>2018-04-10T03:41:32+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2018-03-07T06:48:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=cf31d384f1d2ca09f817f154892eaa6860c10144'/>
<id>urn:sha1:cf31d384f1d2ca09f817f154892eaa6860c10144</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>py/objstringio: Fix regression with handling SEEK_SET.</title>
<updated>2017-08-20T19:02:41+00:00</updated>
<author>
<name>Paul Sokolovsky</name>
<email>pfalcon@users.sourceforge.net</email>
</author>
<published>2017-08-20T18:32:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=0cd9ab77550eada4def492a3a25286ead71a3b24'/>
<id>urn:sha1:0cd9ab77550eada4def492a3a25286ead71a3b24</id>
<content type='text'>
For SEEK_SET, offset should be treated as unsigned, to allow full-width
stream sizes (e.g. 32-bit instead of 31-bit). This is now fully documented
in stream.h. Also, seek symbolic constants are added.
</content>
</entry>
</feed>
