summaryrefslogtreecommitdiff
path: root/docs/develop
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2024-02-27 15:32:29 +1100
committerDamien George <damien@micropython.org>2024-03-07 14:20:42 +1100
commitdecf8e6a8bb940d5829ca3296790631fcece7b21 (patch)
tree55b7cd31de14b73e4b72d49344e9084f402767a9 /docs/develop
parentb3f2f18f927fa2fad10daf63d8c391331f5edf58 (diff)
all: Remove the "STATIC" macro and just use "static" instead.
The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. 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>
Diffstat (limited to 'docs/develop')
-rw-r--r--docs/develop/compiler.rst4
-rw-r--r--docs/develop/library.rst6
-rw-r--r--docs/develop/natmod.rst6
-rw-r--r--docs/develop/porting.rst8
4 files changed, 12 insertions, 12 deletions
diff --git a/docs/develop/compiler.rst b/docs/develop/compiler.rst
index 00cc90f81..0c25ad3a0 100644
--- a/docs/develop/compiler.rst
+++ b/docs/develop/compiler.rst
@@ -98,7 +98,7 @@ Then also edit ``py/lexer.c`` to add the new keyword literal text:
.. code-block:: c
:emphasize-lines: 12
- STATIC const char *const tok_kw[] = {
+ static const char *const tok_kw[] = {
...
"or",
"pass",
@@ -301,7 +301,7 @@ code statement:
.. code-block:: c
- STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) {
+ static void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) {
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
if (vtype == VTYPE_PYOBJ) {
diff --git a/docs/develop/library.rst b/docs/develop/library.rst
index c2a86ea16..830211d81 100644
--- a/docs/develop/library.rst
+++ b/docs/develop/library.rst
@@ -48,16 +48,16 @@ hypothetical new module ``subsystem`` in the file ``modsubsystem.c``:
#if MICROPY_PY_SUBSYSTEM
// info()
- STATIC mp_obj_t py_subsystem_info(void) {
+ static mp_obj_t py_subsystem_info(void) {
return MP_OBJ_NEW_SMALL_INT(42);
}
MP_DEFINE_CONST_FUN_OBJ_0(subsystem_info_obj, py_subsystem_info);
- STATIC const mp_rom_map_elem_t mp_module_subsystem_globals_table[] = {
+ static const mp_rom_map_elem_t mp_module_subsystem_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_subsystem) },
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&subsystem_info_obj) },
};
- STATIC MP_DEFINE_CONST_DICT(mp_module_subsystem_globals, mp_module_subsystem_globals_table);
+ static MP_DEFINE_CONST_DICT(mp_module_subsystem_globals, mp_module_subsystem_globals_table);
const mp_obj_module_t mp_module_subsystem = {
.base = { &mp_type_module },
diff --git a/docs/develop/natmod.rst b/docs/develop/natmod.rst
index 6d15f867b..502ea1c4c 100644
--- a/docs/develop/natmod.rst
+++ b/docs/develop/natmod.rst
@@ -128,7 +128,7 @@ The file ``factorial.c`` contains:
#include "py/dynruntime.h"
// Helper function to compute factorial
- STATIC mp_int_t factorial_helper(mp_int_t x) {
+ static mp_int_t factorial_helper(mp_int_t x) {
if (x == 0) {
return 1;
}
@@ -136,7 +136,7 @@ The file ``factorial.c`` contains:
}
// This is the function which will be called from Python, as factorial(x)
- STATIC mp_obj_t factorial(mp_obj_t x_obj) {
+ static mp_obj_t factorial(mp_obj_t x_obj) {
// Extract the integer from the MicroPython input object
mp_int_t x = mp_obj_get_int(x_obj);
// Calculate the factorial
@@ -145,7 +145,7 @@ The file ``factorial.c`` contains:
return mp_obj_new_int(result);
}
// Define a Python reference to the function above
- STATIC MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial);
+ static MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial);
// This is the entry point and is called when the module is imported
mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
diff --git a/docs/develop/porting.rst b/docs/develop/porting.rst
index 09e61d5d9..99725e100 100644
--- a/docs/develop/porting.rst
+++ b/docs/develop/porting.rst
@@ -262,17 +262,17 @@ To add a custom module like ``myport``, first add the module definition in a fil
#include "py/runtime.h"
- STATIC mp_obj_t myport_info(void) {
+ static mp_obj_t myport_info(void) {
mp_printf(&mp_plat_print, "info about my port\n");
return mp_const_none;
}
- STATIC MP_DEFINE_CONST_FUN_OBJ_0(myport_info_obj, myport_info);
+ static MP_DEFINE_CONST_FUN_OBJ_0(myport_info_obj, myport_info);
- STATIC const mp_rom_map_elem_t myport_module_globals_table[] = {
+ static const mp_rom_map_elem_t myport_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_myport) },
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&myport_info_obj) },
};
- STATIC MP_DEFINE_CONST_DICT(myport_module_globals, myport_module_globals_table);
+ static MP_DEFINE_CONST_DICT(myport_module_globals, myport_module_globals_table);
const mp_obj_module_t myport_module = {
.base = { &mp_type_module },