py: Change vstr so that it doesn't null terminate buffer by default.
This cleans up vstr so that it's a pure "variable buffer", and the user
can decide whether they need to add a terminating null byte. In most
places where vstr is used, the vstr did not need to be null terminated
and so this patch saves code size, a tiny bit of RAM, and makes vstr
usage more efficient. When null termination is needed it must be
done explicitly using vstr_null_terminate.
diff --git a/py/compile.c b/py/compile.c
index 85f5dab..8e4723f 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -555,7 +555,7 @@
} else {
vstr_printf(vstr, ")");
}
- EMIT_ARG(load_const_verbatim_str, vstr_str(vstr));
+ EMIT_ARG(load_const_verbatim_strn, vstr_str(vstr), vstr_len(vstr));
vstr_free(vstr);
} else {
if (!MP_PARSE_NODE_IS_NULL(pn)) {
@@ -1538,7 +1538,7 @@
// build the "fromlist" tuple
#if MICROPY_EMIT_CPYTHON
- EMIT_ARG(load_const_verbatim_str, "('*',)");
+ EMIT_ARG(load_const_verbatim_strn, "('*',)", 6);
#else
EMIT_ARG(load_const_str, MP_QSTR__star_, false);
EMIT_ARG(build_tuple, 1);
@@ -1576,7 +1576,7 @@
vstr_printf(vstr, ",");
}
vstr_printf(vstr, ")");
- EMIT_ARG(load_const_verbatim_str, vstr_str(vstr));
+ EMIT_ARG(load_const_verbatim_strn, vstr_str(vstr), vstr_len(vstr));
vstr_free(vstr);
}
#else