Skip to content

Commit d5df6cd

Browse files
committed
Replace global "static" -> "STATIC", to allow "analysis builds". Part 1.
Some tools do not support local/static symbols (one example is GNU ld map file). Exposing all functions will allow to do detailed size comparisons, etc. Also, added bunch of statics where they were missing, and replaced few identity functions with global mp_identity().
1 parent 1d1e38d commit d5df6cd

25 files changed

+269
-271
lines changed

py/mpconfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ typedef long long mp_longint_impl_t;
110110
/*****************************************************************************/
111111
/* Miscellaneous settings */
112112

113+
// Allow to override static modifier for global objects, e.g. to use with
114+
// object code analysis tools which don't support static symbols.
115+
#ifndef STATIC
116+
#define STATIC static
117+
#endif
118+
113119
#define BITS_PER_BYTE (8)
114120
#define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
115121
// machine_int_t value with most significant bit set

py/objarray.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ typedef struct _mp_obj_array_t {
2929
void *items;
3030
} mp_obj_array_t;
3131

32-
static mp_obj_t array_iterator_new(mp_obj_t array_in);
33-
static mp_obj_array_t *array_new(char typecode, uint n);
34-
static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg);
32+
STATIC mp_obj_t array_iterator_new(mp_obj_t array_in);
33+
STATIC mp_obj_array_t *array_new(char typecode, uint n);
34+
STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg);
3535

3636
/******************************************************************************/
3737
/* array */
3838

39-
static machine_int_t array_get_el_size(char typecode) {
39+
STATIC machine_int_t array_get_el_size(char typecode) {
4040
// This assumes that unsigned and signed types are of the same type,
4141
// which is invariant for [u]intN_t.
4242
switch (typecode) {
@@ -57,7 +57,7 @@ static machine_int_t array_get_el_size(char typecode) {
5757
return -1;
5858
}
5959

60-
static machine_int_t array_get_el(mp_obj_array_t *o, int index) {
60+
STATIC machine_int_t array_get_el(mp_obj_array_t *o, int index) {
6161
machine_int_t val = 0;
6262
switch (o->typecode) {
6363
case 'b':
@@ -89,7 +89,7 @@ static machine_int_t array_get_el(mp_obj_array_t *o, int index) {
8989
return val;
9090
}
9191

92-
static void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) {
92+
STATIC void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) {
9393
machine_int_t val = mp_obj_int_get(val_in);
9494
switch (o->typecode) {
9595
case 'b':
@@ -121,7 +121,7 @@ static void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) {
121121
}
122122

123123

124-
static void array_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
124+
STATIC void array_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
125125
mp_obj_array_t *o = o_in;
126126
if (o->typecode == BYTEARRAY_TYPECODE) {
127127
print(env, "bytearray(b", o->typecode);
@@ -142,7 +142,7 @@ static void array_print(void (*print)(void *env, const char *fmt, ...), void *en
142142
print(env, ")");
143143
}
144144

145-
static mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
145+
STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
146146
uint len;
147147
// Try to create array of exact len if initializer len is known
148148
mp_obj_t len_in = mp_obj_len_maybe(initializer);
@@ -168,7 +168,7 @@ static mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
168168
return array;
169169
}
170170

171-
static mp_obj_t array_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
171+
STATIC mp_obj_t array_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
172172
if (n_args < 1 || n_args > 2) {
173173
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "unexpected # of arguments, %d given", n_args));
174174
}
@@ -184,12 +184,12 @@ static mp_obj_t array_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
184184

185185
// This is top-level factory function, not virtual method
186186
// TODO: "bytearray" really should be type, not function
187-
static mp_obj_t mp_builtin_bytearray(mp_obj_t arg) {
187+
STATIC mp_obj_t mp_builtin_bytearray(mp_obj_t arg) {
188188
return array_construct(BYTEARRAY_TYPECODE, arg);
189189
}
190190
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_bytearray_obj, mp_builtin_bytearray);
191191

192-
static mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
192+
STATIC mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
193193
mp_obj_array_t *o = o_in;
194194
switch (op) {
195195
case RT_UNARY_OP_BOOL: return MP_BOOL(o->len != 0);
@@ -198,7 +198,7 @@ static mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
198198
}
199199
}
200200

201-
static mp_obj_t array_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
201+
STATIC mp_obj_t array_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
202202
mp_obj_array_t *o = lhs;
203203
switch (op) {
204204
case RT_BINARY_OP_SUBSCR:
@@ -214,7 +214,7 @@ static mp_obj_t array_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
214214
}
215215
}
216216

217-
static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
217+
STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
218218
assert(MP_OBJ_IS_TYPE(self_in, &array_type));
219219
mp_obj_array_t *self = self_in;
220220
if (self->free == 0) {
@@ -227,23 +227,23 @@ static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
227227
self->free--;
228228
return mp_const_none; // return None, as per CPython
229229
}
230-
static MP_DEFINE_CONST_FUN_OBJ_2(array_append_obj, array_append);
230+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(array_append_obj, array_append);
231231

232-
static bool array_store_item(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
232+
STATIC bool array_store_item(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
233233
mp_obj_array_t *o = self_in;
234234
uint index = mp_get_index(o->base.type, o->len, index_in);
235235
array_set_el(o, index, value);
236236
return true;
237237
}
238238

239-
static machine_int_t array_get_buffer(mp_obj_t o_in, buffer_info_t *bufinfo, int flags) {
239+
STATIC machine_int_t array_get_buffer(mp_obj_t o_in, buffer_info_t *bufinfo, int flags) {
240240
mp_obj_array_t *o = o_in;
241241
bufinfo->buf = o->items;
242242
bufinfo->len = o->len * array_get_el_size(o->typecode);
243243
return 0;
244244
}
245245

246-
static const mp_method_t array_type_methods[] = {
246+
STATIC const mp_method_t array_type_methods[] = {
247247
{ "append", &array_append_obj },
248248
{ NULL, NULL },
249249
};
@@ -261,7 +261,7 @@ const mp_obj_type_t array_type = {
261261
.buffer_p = { .get_buffer = array_get_buffer },
262262
};
263263

264-
static mp_obj_array_t *array_new(char typecode, uint n) {
264+
STATIC mp_obj_array_t *array_new(char typecode, uint n) {
265265
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
266266
o->base.type = &array_type;
267267
o->typecode = typecode;
@@ -311,7 +311,7 @@ mp_obj_t array_it_iternext(mp_obj_t self_in) {
311311
}
312312
}
313313

314-
static const mp_obj_type_t array_it_type = {
314+
STATIC const mp_obj_type_t array_it_type = {
315315
{ &mp_const_type },
316316
"array_iterator",
317317
.iternext = array_it_iternext,

py/objbool.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typedef struct _mp_obj_bool_t {
1414
bool value;
1515
} mp_obj_bool_t;
1616

17-
static void bool_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
17+
STATIC void bool_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
1818
mp_obj_bool_t *self = self_in;
1919
if (self->value) {
2020
print(env, "True");
@@ -23,7 +23,7 @@ static void bool_print(void (*print)(void *env, const char *fmt, ...), void *env
2323
}
2424
}
2525

26-
static mp_obj_t bool_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
26+
STATIC mp_obj_t bool_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
2727
// TODO check n_kw == 0
2828

2929
switch (n_args) {
@@ -33,7 +33,7 @@ static mp_obj_t bool_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
3333
}
3434
}
3535

36-
static mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
36+
STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
3737
machine_int_t value = ((mp_obj_bool_t*)o_in)->value;
3838
switch (op) {
3939
case RT_UNARY_OP_BOOL: return o_in;
@@ -53,8 +53,8 @@ const mp_obj_type_t bool_type = {
5353
.unary_op = bool_unary_op,
5454
};
5555

56-
static const mp_obj_bool_t false_obj = {{&bool_type}, false};
57-
static const mp_obj_bool_t true_obj = {{&bool_type}, true};
56+
STATIC const mp_obj_bool_t false_obj = {{&bool_type}, false};
57+
STATIC const mp_obj_bool_t true_obj = {{&bool_type}, true};
5858

5959
const mp_obj_t mp_const_false = (mp_obj_t)&false_obj;
6060
const mp_obj_t mp_const_true = (mp_obj_t)&true_obj;

py/objcomplex.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct _mp_obj_complex_t {
2121

2222
mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
2323

24-
void complex_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
24+
STATIC void complex_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
2525
mp_obj_complex_t *o = o_in;
2626
if (o->real == 0) {
2727
print(env, "%.8gj", (double) o->imag);
@@ -30,7 +30,7 @@ void complex_print(void (*print)(void *env, const char *fmt, ...), void *env, mp
3030
}
3131
}
3232

33-
static mp_obj_t complex_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
33+
STATIC mp_obj_t complex_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
3434
// TODO check n_kw == 0
3535

3636
switch (n_args) {
@@ -70,7 +70,7 @@ static mp_obj_t complex_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
7070
}
7171
}
7272

73-
static mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
73+
STATIC mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
7474
mp_obj_complex_t *o = o_in;
7575
switch (op) {
7676
case RT_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0);
@@ -80,7 +80,7 @@ static mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
8080
}
8181
}
8282

83-
static mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
83+
STATIC mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
8484
mp_obj_complex_t *lhs = lhs_in;
8585
return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in);
8686
}

0 commit comments

Comments
 (0)