Skip to content

Commit

Permalink
Replace global "static" -> "STATIC", to allow "analysis builds". Part 1.
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
Paul Sokolovsky committed Feb 12, 2014
1 parent 1d1e38d commit d5df6cd
Show file tree
Hide file tree
Showing 25 changed files with 269 additions and 271 deletions.
6 changes: 6 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ typedef long long mp_longint_impl_t;
/*****************************************************************************/
/* Miscellaneous settings */

// Allow to override static modifier for global objects, e.g. to use with
// object code analysis tools which don't support static symbols.
#ifndef STATIC
#define STATIC static
#endif

#define BITS_PER_BYTE (8)
#define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
// machine_int_t value with most significant bit set
Expand Down
38 changes: 19 additions & 19 deletions py/objarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ typedef struct _mp_obj_array_t {
void *items;
} mp_obj_array_t;

static mp_obj_t array_iterator_new(mp_obj_t array_in);
static mp_obj_array_t *array_new(char typecode, uint n);
static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg);
STATIC mp_obj_t array_iterator_new(mp_obj_t array_in);
STATIC mp_obj_array_t *array_new(char typecode, uint n);
STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg);

/******************************************************************************/
/* array */

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

static machine_int_t array_get_el(mp_obj_array_t *o, int index) {
STATIC machine_int_t array_get_el(mp_obj_array_t *o, int index) {
machine_int_t val = 0;
switch (o->typecode) {
case 'b':
Expand Down Expand Up @@ -89,7 +89,7 @@ static machine_int_t array_get_el(mp_obj_array_t *o, int index) {
return val;
}

static void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) {
STATIC void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) {
machine_int_t val = mp_obj_int_get(val_in);
switch (o->typecode) {
case 'b':
Expand Down Expand Up @@ -121,7 +121,7 @@ static void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) {
}


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

static mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
uint len;
// Try to create array of exact len if initializer len is known
mp_obj_t len_in = mp_obj_len_maybe(initializer);
Expand All @@ -168,7 +168,7 @@ static mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
return array;
}

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

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

static mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
STATIC mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
mp_obj_array_t *o = o_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(o->len != 0);
Expand All @@ -198,7 +198,7 @@ static mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
}
}

static mp_obj_t array_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
STATIC mp_obj_t array_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_array_t *o = lhs;
switch (op) {
case RT_BINARY_OP_SUBSCR:
Expand All @@ -214,7 +214,7 @@ static mp_obj_t array_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
}
}

static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
assert(MP_OBJ_IS_TYPE(self_in, &array_type));
mp_obj_array_t *self = self_in;
if (self->free == 0) {
Expand All @@ -227,23 +227,23 @@ static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
self->free--;
return mp_const_none; // return None, as per CPython
}
static MP_DEFINE_CONST_FUN_OBJ_2(array_append_obj, array_append);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(array_append_obj, array_append);

static bool array_store_item(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
STATIC bool array_store_item(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
mp_obj_array_t *o = self_in;
uint index = mp_get_index(o->base.type, o->len, index_in);
array_set_el(o, index, value);
return true;
}

static machine_int_t array_get_buffer(mp_obj_t o_in, buffer_info_t *bufinfo, int flags) {
STATIC machine_int_t array_get_buffer(mp_obj_t o_in, buffer_info_t *bufinfo, int flags) {
mp_obj_array_t *o = o_in;
bufinfo->buf = o->items;
bufinfo->len = o->len * array_get_el_size(o->typecode);
return 0;
}

static const mp_method_t array_type_methods[] = {
STATIC const mp_method_t array_type_methods[] = {
{ "append", &array_append_obj },
{ NULL, NULL },
};
Expand All @@ -261,7 +261,7 @@ const mp_obj_type_t array_type = {
.buffer_p = { .get_buffer = array_get_buffer },
};

static mp_obj_array_t *array_new(char typecode, uint n) {
STATIC mp_obj_array_t *array_new(char typecode, uint n) {
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
o->base.type = &array_type;
o->typecode = typecode;
Expand Down Expand Up @@ -311,7 +311,7 @@ mp_obj_t array_it_iternext(mp_obj_t self_in) {
}
}

static const mp_obj_type_t array_it_type = {
STATIC const mp_obj_type_t array_it_type = {
{ &mp_const_type },
"array_iterator",
.iternext = array_it_iternext,
Expand Down
10 changes: 5 additions & 5 deletions py/objbool.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef struct _mp_obj_bool_t {
bool value;
} mp_obj_bool_t;

static void bool_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
STATIC void bool_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
mp_obj_bool_t *self = self_in;
if (self->value) {
print(env, "True");
Expand All @@ -23,7 +23,7 @@ static void bool_print(void (*print)(void *env, const char *fmt, ...), void *env
}
}

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

switch (n_args) {
Expand All @@ -33,7 +33,7 @@ static mp_obj_t bool_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
}
}

static mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
machine_int_t value = ((mp_obj_bool_t*)o_in)->value;
switch (op) {
case RT_UNARY_OP_BOOL: return o_in;
Expand All @@ -53,8 +53,8 @@ const mp_obj_type_t bool_type = {
.unary_op = bool_unary_op,
};

static const mp_obj_bool_t false_obj = {{&bool_type}, false};
static const mp_obj_bool_t true_obj = {{&bool_type}, true};
STATIC const mp_obj_bool_t false_obj = {{&bool_type}, false};
STATIC const mp_obj_bool_t true_obj = {{&bool_type}, true};

const mp_obj_t mp_const_false = (mp_obj_t)&false_obj;
const mp_obj_t mp_const_true = (mp_obj_t)&true_obj;
8 changes: 4 additions & 4 deletions py/objcomplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct _mp_obj_complex_t {

mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);

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

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

switch (n_args) {
Expand Down Expand Up @@ -70,7 +70,7 @@ static mp_obj_t complex_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
}
}

static mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
STATIC mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
mp_obj_complex_t *o = o_in;
switch (op) {
case RT_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0);
Expand All @@ -80,7 +80,7 @@ static mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
}
}

static mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
STATIC mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_complex_t *lhs = lhs_in;
return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in);
}
Expand Down
Loading

0 comments on commit d5df6cd

Please sign in to comment.