Skip to content

Commit 969a6b3

Browse files
committed
py: Make functions static where appropriate.
1 parent d511079 commit 969a6b3

22 files changed

+100
-103
lines changed

extmod/moductypes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_ob
559559
/// \function addressof()
560560
/// Return address of object's data (applies to object providing buffer
561561
/// interface).
562-
mp_obj_t uctypes_struct_addressof(mp_obj_t buf) {
562+
STATIC mp_obj_t uctypes_struct_addressof(mp_obj_t buf) {
563563
mp_buffer_info_t bufinfo;
564564
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
565565
return mp_obj_new_int((mp_int_t)bufinfo.buf);
@@ -570,7 +570,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof
570570
/// Capture memory at given address of given size as bytearray. Memory is
571571
/// captured by reference (and thus memory pointed by bytearray may change
572572
/// or become invalid at later time). Use bytes_at() to capture by value.
573-
mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) {
573+
STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) {
574574
return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr));
575575
}
576576
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at);
@@ -579,7 +579,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytear
579579
/// Capture memory at given address of given size as bytes. Memory is
580580
/// captured by value, i.e. copied. Use bytearray_at() to capture by reference
581581
/// ("zero copy").
582-
mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
582+
STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
583583
return mp_obj_new_bytes((void*)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
584584
}
585585
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);

extmod/modure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ STATIC const mp_obj_type_t re_type = {
175175
.locals_dict = (mp_obj_t)&re_locals_dict,
176176
};
177177

178-
mp_obj_t mod_re_compile(uint n_args, const mp_obj_t *args) {
178+
STATIC mp_obj_t mod_re_compile(uint n_args, const mp_obj_t *args) {
179179
const char *re_str = mp_obj_str_get_str(args[0]);
180180
int size = re1_5_sizecode(re_str);
181181
mp_obj_re_t *o = m_new_obj_var(mp_obj_re_t, char, size);

py/asmx86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void asm_x86_add_r32_r32(asm_x86_t *as, int dest_r32, int src_r32) {
325325
asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_ADD_R32_TO_RM32);
326326
}
327327

328-
void asm_x86_add_i32_to_r32(asm_x86_t *as, int src_i32, int dest_r32) {
328+
STATIC void asm_x86_add_i32_to_r32(asm_x86_t *as, int src_i32, int dest_r32) {
329329
if (SIGNED_FIT8(src_i32)) {
330330
asm_x86_write_byte_2(as, OPCODE_ADD_I8_TO_RM32, MODRM_R32(0) | MODRM_RM_REG | MODRM_RM_R32(dest_r32));
331331
asm_x86_write_byte_1(as, src_i32 & 0xff);

py/compile.c

Lines changed: 53 additions & 56 deletions
Large diffs are not rendered by default.

py/emitinlinethumb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct _emit_inline_asm_t {
6161
asm_thumb_t *as;
6262
};
6363

64-
void emit_inline_thumb_error(emit_inline_asm_t *emit, const char *fmt, ...) {
64+
STATIC void emit_inline_thumb_error(emit_inline_asm_t *emit, const char *fmt, ...) {
6565
printf("SyntaxError: ");
6666
emit->success = false;
6767
va_list ap;

py/modcmath.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern const mp_obj_float_t mp_math_pi_obj;
4747

4848
/// \function phase(z)
4949
/// Returns the phase of the number `z`, in the range (-pi, +pi].
50-
mp_obj_t mp_cmath_phase(mp_obj_t z_obj) {
50+
STATIC mp_obj_t mp_cmath_phase(mp_obj_t z_obj) {
5151
mp_float_t real, imag;
5252
mp_obj_get_complex(z_obj, &real, &imag);
5353
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(atan2)(imag, real));
@@ -56,7 +56,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_phase_obj, mp_cmath_phase);
5656

5757
/// \function polar(z)
5858
/// Returns, as a tuple, the polar form of `z`.
59-
mp_obj_t mp_cmath_polar(mp_obj_t z_obj) {
59+
STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) {
6060
mp_float_t real, imag;
6161
mp_obj_get_complex(z_obj, &real, &imag);
6262
mp_obj_t tuple[2] = {
@@ -69,7 +69,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_polar_obj, mp_cmath_polar);
6969

7070
/// \function rect(r, phi)
7171
/// Returns the complex number with modulus `r` and phase `phi`.
72-
mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) {
72+
STATIC mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) {
7373
mp_float_t r = mp_obj_get_float(r_obj);
7474
mp_float_t phi = mp_obj_get_float(phi_obj);
7575
return mp_obj_new_complex(r * MICROPY_FLOAT_C_FUN(cos)(phi), r * MICROPY_FLOAT_C_FUN(sin)(phi));
@@ -78,7 +78,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_cmath_rect_obj, mp_cmath_rect);
7878

7979
/// \function exp(z)
8080
/// Return the exponential of `z`.
81-
mp_obj_t mp_cmath_exp(mp_obj_t z_obj) {
81+
STATIC mp_obj_t mp_cmath_exp(mp_obj_t z_obj) {
8282
mp_float_t real, imag;
8383
mp_obj_get_complex(z_obj, &real, &imag);
8484
mp_float_t exp_real = MICROPY_FLOAT_C_FUN(exp)(real);
@@ -89,7 +89,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_exp_obj, mp_cmath_exp);
8989
/// \function log(z)
9090
/// Return the natural logarithm of `z`. The branch cut is along the negative real axis.
9191
// TODO can take second argument, being the base
92-
mp_obj_t mp_cmath_log(mp_obj_t z_obj) {
92+
STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) {
9393
mp_float_t real, imag;
9494
mp_obj_get_complex(z_obj, &real, &imag);
9595
return mp_obj_new_complex(0.5 * MICROPY_FLOAT_C_FUN(log)(real*real + imag*imag), MICROPY_FLOAT_C_FUN(atan2)(imag, real));
@@ -98,7 +98,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log);
9898

9999
/// \function log10(z)
100100
/// Return the base-10 logarithm of `z`. The branch cut is along the negative real axis.
101-
mp_obj_t mp_cmath_log10(mp_obj_t z_obj) {
101+
STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) {
102102
mp_float_t real, imag;
103103
mp_obj_get_complex(z_obj, &real, &imag);
104104
return mp_obj_new_complex(0.5 * MICROPY_FLOAT_C_FUN(log10)(real*real + imag*imag), MICROPY_FLOAT_C_FUN(atan2)(imag, real));
@@ -107,7 +107,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10);
107107

108108
/// \function sqrt(z)
109109
/// Return the square-root of `z`.
110-
mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) {
110+
STATIC mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) {
111111
mp_float_t real, imag;
112112
mp_obj_get_complex(z_obj, &real, &imag);
113113
mp_float_t sqrt_abs = MICROPY_FLOAT_C_FUN(pow)(real*real + imag*imag, 0.25);
@@ -118,7 +118,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sqrt_obj, mp_cmath_sqrt);
118118

119119
/// \function cos(z)
120120
/// Return the cosine of `z`.
121-
mp_obj_t mp_cmath_cos(mp_obj_t z_obj) {
121+
STATIC mp_obj_t mp_cmath_cos(mp_obj_t z_obj) {
122122
mp_float_t real, imag;
123123
mp_obj_get_complex(z_obj, &real, &imag);
124124
return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), -MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag));
@@ -127,7 +127,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_cos_obj, mp_cmath_cos);
127127

128128
/// \function sin(z)
129129
/// Return the sine of `z`.
130-
mp_obj_t mp_cmath_sin(mp_obj_t z_obj) {
130+
STATIC mp_obj_t mp_cmath_sin(mp_obj_t z_obj) {
131131
mp_float_t real, imag;
132132
mp_obj_get_complex(z_obj, &real, &imag);
133133
return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag));

py/modmath.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@
4141

4242
//TODO: Change macros to check for overflow and raise OverflowError or RangeError
4343
#define MATH_FUN_1(py_name, c_name) \
44-
mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \
44+
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \
4545
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
4646

4747
#define MATH_FUN_2(py_name, c_name) \
48-
mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj, mp_obj_t y_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj), mp_obj_get_float(y_obj))); } \
48+
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj, mp_obj_t y_obj) { return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj), mp_obj_get_float(y_obj))); } \
4949
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name);
5050

5151
#define MATH_FUN_1_TO_BOOL(py_name, c_name) \
52-
mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return MP_BOOL(c_name(mp_obj_get_float(x_obj))); } \
52+
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return MP_BOOL(c_name(mp_obj_get_float(x_obj))); } \
5353
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
5454

5555
#define MATH_FUN_1_TO_INT(py_name, c_name) \
56-
mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_int((mp_int_t)MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \
56+
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { mp_int_t x = MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj)); return mp_obj_new_int(x); } \
5757
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
5858

5959
// These are also used by cmath.c
@@ -142,7 +142,7 @@ MATH_FUN_1(lgamma, lgamma)
142142

143143
/// \function frexp(x)
144144
/// Converts a floating-point number to fractional and integral components.
145-
mp_obj_t mp_math_frexp(mp_obj_t x_obj) {
145+
STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) {
146146
int int_exponent = 0;
147147
mp_float_t significand = MICROPY_FLOAT_C_FUN(frexp)(mp_obj_get_float(x_obj), &int_exponent);
148148
mp_obj_t tuple[2];
@@ -153,7 +153,7 @@ mp_obj_t mp_math_frexp(mp_obj_t x_obj) {
153153
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp);
154154

155155
/// \function modf(x)
156-
mp_obj_t mp_math_modf(mp_obj_t x_obj) {
156+
STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) {
157157
mp_float_t int_part = 0.0;
158158
mp_float_t fractional_part = MICROPY_FLOAT_C_FUN(modf)(mp_obj_get_float(x_obj), &int_part);
159159
mp_obj_t tuple[2];
@@ -166,13 +166,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf);
166166
// Angular conversions
167167

168168
/// \function radians(x)
169-
mp_obj_t mp_math_radians(mp_obj_t x_obj) {
169+
STATIC mp_obj_t mp_math_radians(mp_obj_t x_obj) {
170170
return mp_obj_new_float(mp_obj_get_float(x_obj) * M_PI / 180.0);
171171
}
172172
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians);
173173

174174
/// \function degrees(x)
175-
mp_obj_t mp_math_degrees(mp_obj_t x_obj) {
175+
STATIC mp_obj_t mp_math_degrees(mp_obj_t x_obj) {
176176
return mp_obj_new_float(mp_obj_get_float(x_obj) * 180.0 / M_PI);
177177
}
178178
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees);

py/objboundmeth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ STATIC void bound_meth_print(void (*print)(void *env, const char *fmt, ...), voi
5050
}
5151
#endif
5252

53-
mp_obj_t bound_meth_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
53+
STATIC mp_obj_t bound_meth_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
5454
mp_obj_bound_meth_t *self = self_in;
5555

5656
// need to insert self->self before all other args and then call self->meth

py/objclosure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef struct _mp_obj_closure_t {
4141
mp_obj_t closed[];
4242
} mp_obj_closure_t;
4343

44-
mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
44+
STATIC mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
4545
mp_obj_closure_t *self = self_in;
4646

4747
// need to concatenate closed-over-vars and args

py/objdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ STATIC const mp_obj_type_t dict_view_type = {
491491
.getiter = dict_view_getiter,
492492
};
493493

494-
mp_obj_t mp_obj_new_dict_view(mp_obj_dict_t *dict, mp_dict_view_kind_t kind) {
494+
STATIC mp_obj_t mp_obj_new_dict_view(mp_obj_dict_t *dict, mp_dict_view_kind_t kind) {
495495
mp_obj_dict_view_t *o = m_new_obj(mp_obj_dict_view_t);
496496
o->base.type = &dict_view_type;
497497
o->dict = dict;

0 commit comments

Comments
 (0)