summaryrefslogtreecommitdiff
path: root/py/vstr.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-01-21 23:08:36 +0000
committerDamien George <damien.p.george@gmail.com>2015-01-21 23:18:02 +0000
commit77089bebd4888ab35fcda3d02460ac8304426bff (patch)
tree76fed99be176058a4f9ab1bcc337e2e515a919d1 /py/vstr.c
parent05005f679e00241e15a87751d89327f2c4630cb6 (diff)
py: Add comments for vstr_init and mp_obj_new_str.
Diffstat (limited to 'py/vstr.c')
-rw-r--r--py/vstr.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/py/vstr.c b/py/vstr.c
index 63358d595..e71a6b7bc 100644
--- a/py/vstr.c
+++ b/py/vstr.c
@@ -35,6 +35,8 @@
// returned value is always at least 1 greater than argument
#define ROUND_ALLOC(a) (((a) & ((~0) - 7)) + 8)
+// Init the vstr so it allocs exactly given number of bytes.
+// Length is set to zero, and null byte written in first position.
void vstr_init(vstr_t *vstr, size_t alloc) {
if (alloc < 2) {
// need at least 1 byte for the null byte at the end
@@ -52,6 +54,8 @@ void vstr_init(vstr_t *vstr, size_t alloc) {
vstr->fixed_buf = false;
}
+// Init the vstr so it allocs exactly enough ram to hold given length (plus the
+// null terminating byte), set the length, and write the null byte at the end.
void vstr_init_len(vstr_t *vstr, size_t len) {
vstr_init(vstr, len + 1);
vstr_add_len(vstr, len);