Numworks Epsilon  1.4.1
Graphing Calculator Operating System
stream.c
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2013, 2014 Damien P. George
7  * Copyright (c) 2014 Paul Sokolovsky
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy
10  * of this software and associated documentation files (the "Software"), to deal
11  * in the Software without restriction, including without limitation the rights
12  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the Software is
14  * furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included in
17  * all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25  * THE SOFTWARE.
26  */
27 
28 #include <string.h>
29 #include <unistd.h>
30 
31 #include "py/objstr.h"
32 #include "py/stream.h"
33 #include "py/runtime.h"
34 
35 #if MICROPY_STREAMS_NON_BLOCK
36 #include <errno.h>
37 #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
38 #define EWOULDBLOCK 140
39 #endif
40 #endif
41 
42 // This file defines generic Python stream read/write methods which
43 // dispatch to the underlying stream interface of an object.
44 
45 // TODO: should be in mpconfig.h
46 #define DEFAULT_BUFFER_SIZE 256
47 
49 
50 #define STREAM_CONTENT_TYPE(stream) (((stream)->is_text) ? &mp_type_str : &mp_type_bytes)
51 
52 // Returns error condition in *errcode, if non-zero, return value is number of bytes written
53 // before error condition occurred. If *errcode == 0, returns total bytes written (which will
54 // be equal to input size).
55 mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode, byte flags) {
56  byte *buf = buf_;
58  typedef mp_uint_t (*io_func_t)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
59  io_func_t io_func;
60  const mp_stream_p_t *stream_p = s->type->protocol;
61  if (flags & MP_STREAM_RW_WRITE) {
62  io_func = (io_func_t)stream_p->write;
63  } else {
64  io_func = stream_p->read;
65  }
66 
67  *errcode = 0;
68  mp_uint_t done = 0;
69  while (size > 0) {
70  mp_uint_t out_sz = io_func(stream, buf, size, errcode);
71  // For read, out_sz == 0 means EOF. For write, it's unspecified
72  // what it means, but we don't make any progress, so returning
73  // is still the best option.
74  if (out_sz == 0) {
75  return done;
76  }
77  if (out_sz == MP_STREAM_ERROR) {
78  // If we read something before getting EAGAIN, don't leak it
79  if (mp_is_nonblocking_error(*errcode) && done != 0) {
80  *errcode = 0;
81  }
82  return done;
83  }
84  if (flags & MP_STREAM_RW_ONCE) {
85  return out_sz;
86  }
87 
88  buf += out_sz;
89  size -= out_sz;
90  done += out_sz;
91  }
92  return done;
93 }
94 
95 const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) {
96  mp_obj_type_t *type = mp_obj_get_type(self_in);
97  const mp_stream_p_t *stream_p = type->protocol;
98  if (stream_p == NULL
99  || ((flags & MP_STREAM_OP_READ) && stream_p->read == NULL)
100  || ((flags & MP_STREAM_OP_WRITE) && stream_p->write == NULL)
101  || ((flags & MP_STREAM_OP_IOCTL) && stream_p->ioctl == NULL)) {
102  // CPython: io.UnsupportedOperation, OSError subclass
103  mp_raise_msg(&mp_type_OSError, "stream operation not supported");
104  }
105  return stream_p;
106 }
107 
109  // TODO: Still consider using ioctl for close
110  mp_obj_t dest[2];
111  mp_load_method(stream, MP_QSTR_close, dest);
112  return mp_call_method_n_kw(0, 0, dest);
113 }
114 
115 STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags) {
117 
118  // What to do if sz < -1? Python docs don't specify this case.
119  // CPython does a readall, but here we silently let negatives through,
120  // and they will cause a MemoryError.
121  mp_int_t sz;
122  if (n_args == 1 || ((sz = mp_obj_get_int(args[1])) == -1)) {
123  return stream_readall(args[0]);
124  }
125 
126  #if MICROPY_PY_BUILTINS_STR_UNICODE
127  if (stream_p->is_text) {
128  // We need to read sz number of unicode characters. Because we don't have any
129  // buffering, and because the stream API can only read bytes, we must read here
130  // in units of bytes and must never over read. If we want sz chars, then reading
131  // sz bytes will never over-read, so we follow this approach, in a loop to keep
132  // reading until we have exactly enough chars. This will be 1 read for text
133  // with ASCII-only chars, and about 2 reads for text with a couple of non-ASCII
134  // chars. For text with lots of non-ASCII chars, it'll be pretty inefficient
135  // in time and memory.
136 
137  vstr_t vstr;
138  vstr_init(&vstr, sz);
139  mp_uint_t more_bytes = sz;
140  mp_uint_t last_buf_offset = 0;
141  while (more_bytes > 0) {
142  char *p = vstr_add_len(&vstr, more_bytes);
143  int error;
144  mp_uint_t out_sz = mp_stream_read_exactly(args[0], p, more_bytes, &error);
145  if (error != 0) {
146  vstr_cut_tail_bytes(&vstr, more_bytes);
147  if (mp_is_nonblocking_error(error)) {
148  // With non-blocking streams, we read as much as we can.
149  // If we read nothing, return None, just like read().
150  // Otherwise, return data read so far.
151  // TODO what if we have read only half a non-ASCII char?
152  if (vstr.len == 0) {
153  vstr_clear(&vstr);
154  return mp_const_none;
155  }
156  break;
157  }
158  mp_raise_OSError(error);
159  }
160 
161  if (out_sz < more_bytes) {
162  // Finish reading.
163  // TODO what if we have read only half a non-ASCII char?
164  vstr_cut_tail_bytes(&vstr, more_bytes - out_sz);
165  if (out_sz == 0) {
166  break;
167  }
168  }
169 
170  // count chars from bytes just read
171  for (mp_uint_t off = last_buf_offset;;) {
172  byte b = vstr.buf[off];
173  int n;
174  if (!UTF8_IS_NONASCII(b)) {
175  // 1-byte ASCII char
176  n = 1;
177  } else if ((b & 0xe0) == 0xc0) {
178  // 2-byte char
179  n = 2;
180  } else if ((b & 0xf0) == 0xe0) {
181  // 3-byte char
182  n = 3;
183  } else if ((b & 0xf8) == 0xf0) {
184  // 4-byte char
185  n = 4;
186  } else {
187  // TODO
188  n = 5;
189  }
190  if (off + n <= vstr.len) {
191  // got a whole char in n bytes
192  off += n;
193  sz -= 1;
194  last_buf_offset = off;
195  if (off >= vstr.len) {
196  more_bytes = sz;
197  break;
198  }
199  } else {
200  // didn't get a whole char, so work out how many extra bytes are needed for
201  // this partial char, plus bytes for additional chars that we want
202  more_bytes = (off + n - vstr.len) + (sz - 1);
203  break;
204  }
205  }
206  }
207 
208  return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
209  }
210  #endif
211 
212  vstr_t vstr;
213  vstr_init_len(&vstr, sz);
214  int error;
215  mp_uint_t out_sz = mp_stream_rw(args[0], vstr.buf, sz, &error, flags);
216  if (error != 0) {
217  vstr_clear(&vstr);
218  if (mp_is_nonblocking_error(error)) {
219  // https://docs.python.org/3.4/library/io.html#io.RawIOBase.read
220  // "If the object is in non-blocking mode and no bytes are available,
221  // None is returned."
222  // This is actually very weird, as naive truth check will treat
223  // this as EOF.
224  return mp_const_none;
225  }
226  mp_raise_OSError(error);
227  } else {
228  vstr.len = out_sz;
229  return mp_obj_new_str_from_vstr(STREAM_CONTENT_TYPE(stream_p), &vstr);
230  }
231 }
232 
233 STATIC mp_obj_t stream_read(size_t n_args, const mp_obj_t *args) {
234  return stream_read_generic(n_args, args, MP_STREAM_RW_READ);
235 }
236 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj, 1, 2, stream_read);
237 
238 STATIC mp_obj_t stream_read1(size_t n_args, const mp_obj_t *args) {
240 }
241 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read1_obj, 1, 2, stream_read1);
242 
243 mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, size_t len, byte flags) {
245 
246  int error;
247  mp_uint_t out_sz = mp_stream_rw(self_in, (void*)buf, len, &error, flags);
248  if (error != 0) {
249  if (mp_is_nonblocking_error(error)) {
250  // http://docs.python.org/3/library/io.html#io.RawIOBase.write
251  // "None is returned if the raw stream is set not to block and
252  // no single byte could be readily written to it."
253  return mp_const_none;
254  }
255  mp_raise_OSError(error);
256  } else {
257  return MP_OBJ_NEW_SMALL_INT(out_sz);
258  }
259 }
260 
261 // XXX hack
262 void mp_stream_write_adaptor(void *self, const char *buf, size_t len) {
264 }
265 
267  mp_buffer_info_t bufinfo;
268  mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
269  size_t max_len = (size_t)-1;
270  size_t off = 0;
271  if (n_args == 3) {
272  max_len = mp_obj_get_int_truncated(args[2]);
273  } else if (n_args == 4) {
274  off = mp_obj_get_int_truncated(args[2]);
275  max_len = mp_obj_get_int_truncated(args[3]);
276  if (off > bufinfo.len) {
277  off = bufinfo.len;
278  }
279  }
280  bufinfo.len -= off;
281  return mp_stream_write(args[0], (byte*)bufinfo.buf + off, MIN(bufinfo.len, max_len), MP_STREAM_RW_WRITE);
282 }
283 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_write_obj, 2, 4, stream_write_method);
284 
286  mp_buffer_info_t bufinfo;
287  mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ);
288  return mp_stream_write(self_in, bufinfo.buf, bufinfo.len, MP_STREAM_RW_WRITE | MP_STREAM_RW_ONCE);
289 }
290 MP_DEFINE_CONST_FUN_OBJ_2(mp_stream_write1_obj, stream_write1_method);
291 
292 STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) {
294  mp_buffer_info_t bufinfo;
296 
297  // CPython extension: if 2nd arg is provided, that's max len to read,
298  // instead of full buffer. Similar to
299  // https://docs.python.org/3/library/socket.html#socket.socket.recv_into
300  mp_uint_t len = bufinfo.len;
301  if (n_args > 2) {
302  len = mp_obj_get_int(args[2]);
303  if (len > bufinfo.len) {
304  len = bufinfo.len;
305  }
306  }
307 
308  int error;
309  mp_uint_t out_sz = mp_stream_read_exactly(args[0], bufinfo.buf, len, &error);
310  if (error != 0) {
311  if (mp_is_nonblocking_error(error)) {
312  return mp_const_none;
313  }
314  mp_raise_OSError(error);
315  } else {
316  return MP_OBJ_NEW_SMALL_INT(out_sz);
317  }
318 }
319 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_readinto_obj, 2, 3, stream_readinto);
320 
322  const mp_stream_p_t *stream_p = mp_get_stream_raise(self_in, MP_STREAM_OP_READ);
323 
324  mp_uint_t total_size = 0;
325  vstr_t vstr;
327  char *p = vstr.buf;
328  mp_uint_t current_read = DEFAULT_BUFFER_SIZE;
329  while (true) {
330  int error;
331  mp_uint_t out_sz = stream_p->read(self_in, p, current_read, &error);
332  if (out_sz == MP_STREAM_ERROR) {
333  if (mp_is_nonblocking_error(error)) {
334  // With non-blocking streams, we read as much as we can.
335  // If we read nothing, return None, just like read().
336  // Otherwise, return data read so far.
337  if (total_size == 0) {
338  return mp_const_none;
339  }
340  break;
341  }
342  mp_raise_OSError(error);
343  }
344  if (out_sz == 0) {
345  break;
346  }
347  total_size += out_sz;
348  if (out_sz < current_read) {
349  current_read -= out_sz;
350  p += out_sz;
351  } else {
352  p = vstr_extend(&vstr, DEFAULT_BUFFER_SIZE);
353  current_read = DEFAULT_BUFFER_SIZE;
354  }
355  }
356 
357  vstr.len = total_size;
358  return mp_obj_new_str_from_vstr(STREAM_CONTENT_TYPE(stream_p), &vstr);
359 }
360 
361 // Unbuffered, inefficient implementation of readline() for raw I/O files.
364 
365  mp_int_t max_size = -1;
366  if (n_args > 1) {
367  max_size = MP_OBJ_SMALL_INT_VALUE(args[1]);
368  }
369 
370  vstr_t vstr;
371  if (max_size != -1) {
372  vstr_init(&vstr, max_size);
373  } else {
374  vstr_init(&vstr, 16);
375  }
376 
377  while (max_size == -1 || max_size-- != 0) {
378  char *p = vstr_add_len(&vstr, 1);
379  int error;
380  mp_uint_t out_sz = stream_p->read(args[0], p, 1, &error);
381  if (out_sz == MP_STREAM_ERROR) {
382  if (mp_is_nonblocking_error(error)) {
383  if (vstr.len == 1) {
384  // We just incremented it, but otherwise we read nothing
385  // and immediately got EAGAIN. This case is not well
386  // specified in
387  // https://docs.python.org/3/library/io.html#io.IOBase.readline
388  // unlike similar case for read(). But we follow the latter's
389  // behavior - return None.
390  vstr_clear(&vstr);
391  return mp_const_none;
392  } else {
393  goto done;
394  }
395  }
396  mp_raise_OSError(error);
397  }
398  if (out_sz == 0) {
399 done:
400  // Back out previously added byte
401  // Consider, what's better - read a char and get OutOfMemory (so read
402  // char is lost), or allocate first as we do.
403  vstr_cut_tail_bytes(&vstr, 1);
404  break;
405  }
406  if (*p == '\n') {
407  break;
408  }
409  }
410 
411  return mp_obj_new_str_from_vstr(STREAM_CONTENT_TYPE(stream_p), &vstr);
412 }
413 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_unbuffered_readline_obj, 1, 2, stream_unbuffered_readline);
414 
415 // TODO take an optional extra argument (what does it do exactly?)
417  mp_obj_t lines = mp_obj_new_list(0, NULL);
418  for (;;) {
419  mp_obj_t line = stream_unbuffered_readline(1, &self);
420  if (!mp_obj_is_true(line)) {
421  break;
422  }
423  mp_obj_list_append(lines, line);
424  }
425  return lines;
426 }
427 MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_unbuffered_readlines_obj, stream_unbuffered_readlines);
428 
430  mp_obj_t l_in = stream_unbuffered_readline(1, &self);
431  if (mp_obj_is_true(l_in)) {
432  return l_in;
433  }
434  return MP_OBJ_STOP_ITERATION;
435 }
436 
437 STATIC mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) {
439 
440  struct mp_stream_seek_t seek_s;
441  // TODO: Could be uint64
442  seek_s.offset = mp_obj_get_int(args[1]);
443  seek_s.whence = SEEK_SET;
444  if (n_args == 3) {
445  seek_s.whence = mp_obj_get_int(args[2]);
446  }
447 
448  // In POSIX, it's error to seek before end of stream, we enforce it here.
449  if (seek_s.whence == SEEK_SET && seek_s.offset < 0) {
451  }
452 
453  int error;
454  mp_uint_t res = stream_p->ioctl(args[0], MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &error);
455  if (res == MP_STREAM_ERROR) {
456  mp_raise_OSError(error);
457  }
458 
459  // TODO: Could be uint64
460  return mp_obj_new_int_from_uint(seek_s.offset);
461 }
462 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_seek_obj, 2, 3, stream_seek);
463 
467  const mp_obj_t args[3] = {self, offset, whence};
468  return stream_seek(3, args);
469 }
470 MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_tell_obj, stream_tell);
471 
473  const mp_stream_p_t *stream_p = mp_get_stream_raise(self, MP_STREAM_OP_IOCTL);
474  int error;
475  mp_uint_t res = stream_p->ioctl(self, MP_STREAM_FLUSH, 0, &error);
476  if (res == MP_STREAM_ERROR) {
477  mp_raise_OSError(error);
478  }
479  return mp_const_none;
480 }
481 MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_flush_obj, stream_flush);
482 
483 STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) {
485 
486  mp_buffer_info_t bufinfo;
487  uintptr_t val = 0;
488  if (n_args > 2) {
489  if (mp_get_buffer(args[2], &bufinfo, MP_BUFFER_WRITE)) {
490  val = (uintptr_t)bufinfo.buf;
491  } else {
492  val = mp_obj_get_int_truncated(args[2]);
493  }
494  }
495 
496  int error;
497  mp_uint_t res = stream_p->ioctl(args[0], mp_obj_get_int(args[1]), val, &error);
498  if (res == MP_STREAM_ERROR) {
499  mp_raise_OSError(error);
500  }
501 
502  return mp_obj_new_int(res);
503 }
504 MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_ioctl_obj, 2, 3, stream_ioctl);
505 
506 #if MICROPY_STREAMS_POSIX_API
507 /*
508  * POSIX-like functions
509  *
510  * These functions have POSIX-compatible signature (except for "void *stream"
511  * first argument instead of "int fd"). They are useful to port existing
512  * POSIX-compatible software to work with MicroPython streams.
513  */
514 
515 // errno-like variable. If any of the functions below returned with error
516 // status, this variable will contain error no.
517 int mp_stream_errno;
518 
519 ssize_t mp_stream_posix_write(mp_obj_t stream, const void *buf, size_t len) {
521  const mp_stream_p_t *stream_p = o->type->protocol;
522  mp_uint_t out_sz = stream_p->write(stream, buf, len, &mp_stream_errno);
523  if (out_sz == MP_STREAM_ERROR) {
524  return -1;
525  } else {
526  return out_sz;
527  }
528 }
529 
530 ssize_t mp_stream_posix_read(mp_obj_t stream, void *buf, size_t len) {
532  const mp_stream_p_t *stream_p = o->type->protocol;
533  mp_uint_t out_sz = stream_p->read(stream, buf, len, &mp_stream_errno);
534  if (out_sz == MP_STREAM_ERROR) {
535  return -1;
536  } else {
537  return out_sz;
538  }
539 }
540 
541 off_t mp_stream_posix_lseek(mp_obj_t stream, off_t offset, int whence) {
542  const mp_obj_base_t* o = (mp_obj_base_t*)MP_OBJ_TO_PTR(stream);
543  const mp_stream_p_t *stream_p = o->type->protocol;
544  struct mp_stream_seek_t seek_s;
545  seek_s.offset = offset;
546  seek_s.whence = whence;
547  mp_uint_t res = stream_p->ioctl(stream, MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &mp_stream_errno);
548  if (res == MP_STREAM_ERROR) {
549  return -1;
550  }
551  return seek_s.offset;
552 }
553 
554 int mp_stream_posix_fsync(mp_obj_t stream) {
556  const mp_stream_p_t *stream_p = o->type->protocol;
557  mp_uint_t res = stream_p->ioctl(stream, MP_STREAM_FLUSH, 0, &mp_stream_errno);
558  if (res == MP_STREAM_ERROR) {
559  return -1;
560  }
561  return res;
562 }
563 
564 #endif
intptr_t mp_int_t
Definition: mpconfigport.h:73
#define MP_BUFFER_WRITE
Definition: obj.h:455
uintptr_t mp_uint_t
Definition: mpconfigport.h:74
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
Definition: runtime.c:1448
Definition: misc.h:142
#define MP_BUFFER_READ
Definition: obj.h:454
#define MP_EINVAL
Definition: mperrno.h:112
char * vstr_extend(vstr_t *vstr, size_t size)
Definition: vstr.c:93
STATIC mp_obj_t stream_flush(mp_obj_t self)
Definition: stream.c:472
#define mp_const_none
Definition: obj.h:614
#define MIN(x, y)
Definition: table_view.cpp:8
#define MP_STREAM_OP_WRITE
Definition: stream.h:79
#define SEEK_CUR
Definition: mpconfigport.h:78
mp_off_t offset
Definition: stream.h:56
void vstr_init_len(vstr_t *vstr, size_t len)
Definition: vstr.c:52
char * buf
Definition: misc.h:145
mp_uint_t(* read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode)
Definition: obj.h:467
#define mp_stream_read_exactly(stream, buf, size, err)
Definition: stream.h:96
STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags)
Definition: stream.c:115
unsigned int size_t
Definition: stddef.h:7
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
Definition: obj.c:512
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
Definition: obj.c:40
void vstr_init(vstr_t *vstr, size_t alloc)
Definition: vstr.c:40
unsigned int uintptr_t
Definition: stdint.h:14
#define MP_OBJ_FROM_PTR(p)
Definition: obj.h:233
STATIC mp_obj_t stream_write1_method(mp_obj_t self_in, mp_obj_t arg)
Definition: stream.c:285
MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_unbuffered_readlines_obj, stream_unbuffered_readlines)
const mp_stream_p_t * mp_get_stream_raise(mp_obj_t self_in, int flags)
Definition: stream.c:95
STATIC mp_obj_t stream_unbuffered_readlines(mp_obj_t self)
Definition: stream.c:416
mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items)
Definition: objlist.c:470
size_t len
Definition: obj.h:447
size_t len
Definition: misc.h:144
mp_int_t mp_obj_get_int(mp_const_obj_t arg)
Definition: obj.c:225
const void * protocol
Definition: obj.h:527
mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self)
Definition: stream.c:429
#define STATIC
Definition: mpconfig.h:1178
mp_uint_t(* ioctl)(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode)
Definition: obj.h:469
#define MP_STREAM_FLUSH
Definition: stream.h:35
#define MP_OBJ_SMALL_INT_VALUE(o)
Definition: obj.h:86
int ssize_t
Definition: stddef.h:6
char * vstr_add_len(vstr_t *vstr, size_t len)
Definition: vstr.c:124
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest)
Definition: runtime.c:1076
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj, 1, 2, stream_read)
STATIC mp_obj_t stream_read(size_t n_args, const mp_obj_t *args)
Definition: stream.c:233
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg)
Definition: objlist.c:234
STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args)
Definition: stream.c:483
#define MP_OBJ_NEW_SMALL_INT(small_int)
Definition: obj.h:87
#define MP_STREAM_RW_WRITE
Definition: stream.h:92
mp_obj_t mp_stream_close(mp_obj_t stream)
Definition: stream.c:108
STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args)
Definition: stream.c:292
#define mp_is_nonblocking_error(errno)
Definition: stream.h:111
#define NULL
Definition: stddef.h:4
const mp_obj_type_t mp_type_OSError
NORETURN void mp_raise_OSError(int errno_)
Definition: runtime.c:1464
const mp_obj_type_t mp_type_str
Definition: objstr.c:1950
mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value)
Definition: objint.c:343
MP_DEFINE_CONST_FUN_OBJ_2(mp_stream_write1_obj, stream_write1_method)
STATIC mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args)
Definition: stream.c:266
#define MP_STREAM_SEEK
Definition: stream.h:36
#define STREAM_CONTENT_TYPE(stream)
Definition: stream.c:50
args
Definition: i18n.py:175
mp_obj_t mp_obj_new_int(mp_int_t value)
Definition: objint.c:353
#define MP_STREAM_OP_IOCTL
Definition: stream.h:80
unsigned char byte
Definition: misc.h:37
mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr)
Definition: objstr.c:1998
#define MP_STREAM_ERROR
Definition: stream.h:32
void mp_stream_write_adaptor(void *self, const char *buf, size_t len)
Definition: stream.c:262
mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, size_t len, byte flags)
Definition: stream.c:243
mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: runtime.c:639
mp_uint_t(* write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode)
Definition: obj.h:468
STATIC mp_obj_t stream_tell(mp_obj_t self)
Definition: stream.c:464
STATIC mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args)
Definition: stream.c:437
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
Definition: obj.c:524
mp_uint_t is_text
Definition: obj.h:470
#define MP_OBJ_TO_PTR(o)
Definition: obj.h:228
STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args)
Definition: stream.c:362
#define UTF8_IS_NONASCII(ch)
Definition: misc.h:137
#define MP_STREAM_RW_ONCE
Definition: stream.h:93
#define MP_OBJ_STOP_ITERATION
Definition: obj.h:74
#define DEFAULT_BUFFER_SIZE
Definition: stream.c:46
uint64_t mp_obj_t
Definition: obj.h:39
#define MP_STREAM_RW_READ
Definition: stream.h:91
mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode, byte flags)
Definition: stream.c:55
STATIC mp_obj_t stream_read1(size_t n_args, const mp_obj_t *args)
Definition: stream.c:238
mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg)
Definition: obj.c:247
void vstr_clear(vstr_t *vstr)
Definition: vstr.c:70
bool mp_obj_is_true(mp_obj_t arg)
Definition: obj.c:108
#define MP_STREAM_OP_READ
Definition: stream.h:78
STATIC mp_obj_t stream_readall(mp_obj_t self_in)
Definition: stream.c:321
void * buf
Definition: obj.h:446
void vstr_cut_tail_bytes(vstr_t *vstr, size_t bytes_to_cut)
Definition: vstr.c:216
#define SEEK_SET
Definition: unistd.h:4