From 58676fc2c75b8dcf1661ee65eb2384bd7f59990b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 14 Apr 2014 01:45:06 +0300 Subject: [PATCH] objstr: Allow to define statically allocated str objects. Similar to tuples, lists, dicts. Statically allocated strings don't have hash computed. --- py/objstr.c | 8 +------- py/objstr.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 py/objstr.h diff --git a/py/objstr.c b/py/objstr.c index 0f9e4fdda4..08db2af669 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -10,13 +10,7 @@ #include "runtime0.h" #include "runtime.h" #include "pfenv.h" - -typedef struct _mp_obj_str_t { - mp_obj_base_t base; - machine_uint_t hash : 16; // XXX here we assume the hash size is 16 bits (it is at the moment; see qstr.c) - machine_uint_t len : 16; // len == number of bytes used in data, alloc = len + 1 because (at the moment) we also append a null byte - const byte *data; -} mp_obj_str_t; +#include "objstr.h" STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t *args); const mp_obj_t mp_const_empty_bytes; diff --git a/py/objstr.h b/py/objstr.h new file mode 100644 index 0000000000..a32ba53b1d --- /dev/null +++ b/py/objstr.h @@ -0,0 +1,10 @@ +typedef struct _mp_obj_str_t { + mp_obj_base_t base; + // XXX here we assume the hash size is 16 bits (it is at the moment; see qstr.c) + machine_uint_t hash : 16; + // len == number of bytes used in data, alloc = len + 1 because (at the moment) we also append a null byte + machine_uint_t len : 16; + const byte *data; +} mp_obj_str_t; + +#define MP_DEFINE_STR_OBJ(obj_name, str) mp_obj_str_t obj_name = {{&mp_type_str}, 0, sizeof(str) - 1, (const byte*)str};