all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This commit is contained in:
committed by
Damien George
parent
b3f2f18f92
commit
decf8e6a8b
56
py/objtype.c
56
py/objtype.c
@@ -44,12 +44,12 @@
|
||||
#define ENABLE_SPECIAL_ACCESSORS \
|
||||
(MICROPY_PY_DESCRIPTORS || MICROPY_PY_DELATTR_SETATTR || MICROPY_PY_BUILTINS_PROPERTY)
|
||||
|
||||
STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
static mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
|
||||
/******************************************************************************/
|
||||
// instance object
|
||||
|
||||
STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_type_t **last_native_base) {
|
||||
static int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_type_t **last_native_base) {
|
||||
int count = 0;
|
||||
for (;;) {
|
||||
if (type == &mp_type_object) {
|
||||
@@ -84,17 +84,17 @@ STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_t
|
||||
|
||||
// This wrapper function is allows a subclass of a native type to call the
|
||||
// __init__() method (corresponding to type->make_new) of the native type.
|
||||
STATIC mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *args) {
|
||||
static mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
const mp_obj_type_t *native_base = NULL;
|
||||
instance_count_native_bases(self->base.type, &native_base);
|
||||
self->subobj[0] = MP_OBJ_TYPE_GET_SLOT(native_base, make_new)(native_base, n_args - 1, 0, args + 1);
|
||||
return mp_const_none;
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(native_base_init_wrapper_obj, 1, MP_OBJ_FUN_ARGS_MAX, native_base_init_wrapper);
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(native_base_init_wrapper_obj, 1, MP_OBJ_FUN_ARGS_MAX, native_base_init_wrapper);
|
||||
|
||||
#if !MICROPY_CPYTHON_COMPAT
|
||||
STATIC
|
||||
static
|
||||
#endif
|
||||
mp_obj_instance_t *mp_obj_new_instance(const mp_obj_type_t *class, const mp_obj_type_t **native_base) {
|
||||
size_t num_native_bases = instance_count_native_bases(class, native_base);
|
||||
@@ -132,7 +132,7 @@ struct class_lookup_data {
|
||||
bool is_type;
|
||||
};
|
||||
|
||||
STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_type_t *type) {
|
||||
static void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_type_t *type) {
|
||||
assert(lookup->dest[0] == MP_OBJ_NULL);
|
||||
assert(lookup->dest[1] == MP_OBJ_NULL);
|
||||
for (;;) {
|
||||
@@ -235,7 +235,7 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_t
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
qstr meth = (kind == PRINT_STR) ? MP_QSTR___str__ : MP_QSTR___repr__;
|
||||
mp_obj_t member[2] = {MP_OBJ_NULL};
|
||||
@@ -277,7 +277,7 @@ STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k
|
||||
mp_printf(print, "<%s object at %p>", mp_obj_get_type_str(self_in), self);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
assert(mp_obj_is_instance_type(self));
|
||||
|
||||
// look for __new__ function
|
||||
@@ -392,7 +392,7 @@ const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
static mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
#if MICROPY_PY_SYS_GETSIZEOF
|
||||
@@ -530,7 +530,7 @@ const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
static mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
// Note: For ducktyping, CPython does not look in the instance members or use
|
||||
// __getattr__ or __getattribute__. It only looks in the class dictionary.
|
||||
mp_obj_instance_t *lhs = MP_OBJ_TO_PTR(lhs_in);
|
||||
@@ -572,7 +572,7 @@ STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t
|
||||
return res;
|
||||
}
|
||||
|
||||
STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
static void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
// logic: look in instance members then class locals
|
||||
assert(mp_obj_is_instance_type(mp_obj_get_type(self_in)));
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
@@ -669,7 +669,7 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des
|
||||
}
|
||||
}
|
||||
|
||||
STATIC bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
|
||||
static bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
if (!(self->base.type->flags & MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS)) {
|
||||
@@ -792,7 +792,7 @@ skip_special_accessors:
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
static void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
if (dest[0] == MP_OBJ_NULL) {
|
||||
mp_obj_instance_load_attr(self_in, attr, dest);
|
||||
} else {
|
||||
@@ -802,7 +802,7 @@ STATIC void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
static mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_obj_t member[4] = {MP_OBJ_NULL, MP_OBJ_NULL, index, value};
|
||||
struct class_lookup_data lookup = {
|
||||
@@ -837,7 +837,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_obj_instance_get_call(mp_obj_t self_in, mp_obj_t *member) {
|
||||
static mp_obj_t mp_obj_instance_get_call(mp_obj_t self_in, mp_obj_t *member) {
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
struct class_lookup_data lookup = {
|
||||
.obj = self,
|
||||
@@ -903,7 +903,7 @@ mp_obj_t mp_obj_instance_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf)
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||
static mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_obj_t member[2] = {MP_OBJ_NULL};
|
||||
struct class_lookup_data lookup = {
|
||||
@@ -929,7 +929,7 @@ STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo,
|
||||
// - creating a new class (a new type) creates a new mp_obj_type_t
|
||||
|
||||
#if ENABLE_SPECIAL_ACCESSORS
|
||||
STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) {
|
||||
static bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) {
|
||||
#if MICROPY_PY_DELATTR_SETATTR
|
||||
if (key == MP_OBJ_NEW_QSTR(MP_QSTR___setattr__) || key == MP_OBJ_NEW_QSTR(MP_QSTR___delattr__)) {
|
||||
return true;
|
||||
@@ -956,13 +956,13 @@ STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) {
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_printf(print, "<class '%q'>", self->name);
|
||||
}
|
||||
|
||||
STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
|
||||
mp_arg_check_num(n_args, n_kw, 1, 3, false);
|
||||
@@ -982,7 +982,7 @@ STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
// instantiate an instance of a class
|
||||
|
||||
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
@@ -1002,7 +1002,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp
|
||||
return o;
|
||||
}
|
||||
|
||||
STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
static void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
assert(mp_obj_is_type(self_in, &mp_type_type));
|
||||
mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
||||
@@ -1235,7 +1235,7 @@ typedef struct _mp_obj_super_t {
|
||||
mp_obj_t obj;
|
||||
} mp_obj_super_t;
|
||||
|
||||
STATIC void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
static void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
(void)kind;
|
||||
mp_obj_super_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_print_str(print, "<super: ");
|
||||
@@ -1245,7 +1245,7 @@ STATIC void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind
|
||||
mp_print_str(print, ">");
|
||||
}
|
||||
|
||||
STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
(void)type_in;
|
||||
// 0 arguments are turned into 2 in the compiler
|
||||
// 1 argument is not yet implemented
|
||||
@@ -1258,7 +1258,7 @@ STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
static void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
if (dest[0] != MP_OBJ_NULL) {
|
||||
// not load attribute
|
||||
return;
|
||||
@@ -1386,7 +1386,7 @@ bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
static mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
size_t len;
|
||||
mp_obj_t *items;
|
||||
if (mp_obj_is_type(classinfo, &mp_type_type)) {
|
||||
@@ -1407,7 +1407,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
return mp_const_false;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
static mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
if (!mp_obj_is_type(object, &mp_type_type)) {
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("issubclass() arg 1 must be a class"));
|
||||
}
|
||||
@@ -1416,7 +1416,7 @@ STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) {
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_issubclass_obj, mp_builtin_issubclass);
|
||||
|
||||
STATIC mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo) {
|
||||
static mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo) {
|
||||
return mp_obj_is_subclass(MP_OBJ_FROM_PTR(mp_obj_get_type(object)), classinfo);
|
||||
}
|
||||
|
||||
@@ -1438,7 +1438,7 @@ mp_obj_t mp_obj_cast_to_native_base(mp_obj_t self_in, mp_const_obj_t native_type
|
||||
/******************************************************************************/
|
||||
// staticmethod and classmethod types (probably should go in a different file)
|
||||
|
||||
STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
static mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
assert(self == &mp_type_staticmethod || self == &mp_type_classmethod);
|
||||
|
||||
mp_arg_check_num(n_args, n_kw, 1, 1, false);
|
||||
|
||||
Reference in New Issue
Block a user