extmod/modujson: Implement ujson.load() to load JSON from a stream.

This refactors ujson.loads(s) to behave as ujson.load(StringIO(s)).

Increase in code size is: 366 bytes for unix x86-64, 180 bytes for
stmhal, 84 bytes for esp8266.
This commit is contained in:
Damien George
2016-10-13 11:43:28 +11:00
parent f17f3314d0
commit e93c1ca5da
3 changed files with 109 additions and 44 deletions

View File

@@ -30,18 +30,12 @@
#include "py/nlr.h"
#include "py/objstr.h"
#include "py/objstringio.h"
#include "py/runtime.h"
#include "py/stream.h"
#if MICROPY_PY_IO
typedef struct _mp_obj_stringio_t {
mp_obj_base_t base;
vstr_t *vstr;
// StringIO has single pointer used for both reading and writing
mp_uint_t pos;
} mp_obj_stringio_t;
#if MICROPY_CPYTHON_COMPAT
STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) {
if (o->vstr == NULL) {