8000 objstr: Allow to define statically allocated str objects. · lurch/micropython@58676fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 58676fc

Browse files
committed
objstr: Allow to define statically allocated str objects.
Similar to tuples, lists, dicts. Statically allocated strings don't have hash computed.
1 parent 59e269c commit 58676fc

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

py/objstr.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
#include "runtime0.h"
1111
#include "runtime.h"
1212
#include "pfenv.h"
13-
14-
typedef struct _mp_obj_str_t {
15-
mp_obj_base_t base;
16-
machine_uint_t hash : 16; // XXX here we assume the hash size is 16 bits (it is at the moment; see qstr.c)
17-
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
18-
const byte *data;
19-
} mp_obj_str_t;
13+
#include "objstr.h"
2014

2115
STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, uint n_args, const mp_obj_t *args);
2216
const mp_obj_t mp_const_empty_bytes;

py/objstr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
typedef struct _mp_obj_str_t {
2+
mp_obj_base_t base;
3+
// XXX here we assume the hash size is 16 bits (it is at the moment; see qstr.c)
4+
machine_uint_t hash : 16;
5+
// len == number of bytes used in data, alloc = len + 1 because (at the moment) we also append a null byte
6+
machine_uint_t len : 16;
7+
const byte *data;
8+
} mp_obj_str_t;
9+
10+
#define MP_DEFINE_STR_OBJ(obj_name, str) mp_obj_str_t obj_name = {{&mp_type_str}, 0, sizeof(str) - 1, (const byte*)str};

0 commit comments

Comments
 (0)
0