summaryrefslogtreecommitdiffstatshomepage
path: root/py/misc.h
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-13 23:15:23 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-13 23:31:06 +0200
commit5d2499c63813566b1e35067f6faff3046c7f9d0a (patch)
tree087fb823543cf4fd2c0bd27c6c373c3035e2e54f /py/misc.h
parentca318bba0d97c66d8fb14a089d8fa269a0e1b424 (diff)
downloadmicropython-5d2499c63813566b1e35067f6faff3046c7f9d0a.tar.gz
micropython-5d2499c63813566b1e35067f6faff3046c7f9d0a.zip
Add "buffer management" and "shrink" API calls to vstr.
vstr is initially intended to deal with arbitrary-length strings. By providing a bit lower-level API calls, it will be also useful to deal with arbitrary-length I/O buffers (the difference from strings is that buffers are filled from "outside", via I/O). Another issue, especially aggravated by I/O buffer use, is alloc size vs actual size length. If allocated 1Mb for buffer, but actually read 1 byte, we don't want to keep rest of 1Mb be locked by this I/O result, but rather return it to heap ASAP ("shrink" buffer before passing it to qstr_from_str_take()).
Diffstat (limited to 'py/misc.h')
-rw-r--r--py/misc.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/py/misc.h b/py/misc.h
index 1bf4d8f291..2d6fb978ac 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -58,15 +58,19 @@ typedef struct _vstr_t {
bool had_error;
} vstr_t;
-void vstr_init(vstr_t *vstr);
+void vstr_init(vstr_t *vstr, int alloc);
void vstr_clear(vstr_t *vstr);
vstr_t *vstr_new(void);
+vstr_t *vstr_new_size(int alloc);
void vstr_free(vstr_t *vstr);
void vstr_reset(vstr_t *vstr);
bool vstr_had_error(vstr_t *vstr);
char *vstr_str(vstr_t *vstr);
int vstr_len(vstr_t *vstr);
void vstr_hint_size(vstr_t *vstr, int size);
+char *vstr_extend(vstr_t *vstr, int size);
+bool vstr_set_size(vstr_t *vstr, int size);
+bool vstr_shrink(vstr_t *vstr);
char *vstr_add_len(vstr_t *vstr, int len);
void vstr_add_byte(vstr_t *vstr, byte v);
void vstr_add_char(vstr_t *vstr, unichar chr);