LCOV - code coverage report
Current view: top level - examples/usercmodule/subpackage - modexamplepackage.c (source / functions) Hit Total Coverage
Test: unix_coverage_v1.24.0-74-g406bccc75.info Lines: 14 14 100.0 %
Date: 2024-12-03 15:10:00 Functions: 4 4 100.0 %
Branches: 2 2 100.0 %

           Branch data     Line data    Source code
       1                 :            : // Include MicroPython API.
       2                 :            : #include "py/runtime.h"
       3                 :            : 
       4                 :            : // Define example_package.foo.bar.f()
       5                 :          4 : static mp_obj_t example_package_foo_bar_f(void) {
       6                 :          4 :     mp_printf(&mp_plat_print, "example_package.foo.bar.f\n");
       7                 :          4 :     return mp_const_none;
       8                 :            : }
       9                 :            : static MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_bar_f_obj, example_package_foo_bar_f);
      10                 :            : 
      11                 :            : // Define all attributes of the second-level sub-package (example_package.foo.bar).
      12                 :            : static const mp_rom_map_elem_t example_package_foo_bar_globals_table[] = {
      13                 :            :     { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package_dot_foo_dot_bar) },
      14                 :            :     { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_foo_bar_f_obj) },
      15                 :            : };
      16                 :            : static MP_DEFINE_CONST_DICT(example_package_foo_bar_globals, example_package_foo_bar_globals_table);
      17                 :            : 
      18                 :            : // Define example_package.foo.bar module object.
      19                 :            : const mp_obj_module_t example_package_foo_bar_user_cmodule = {
      20                 :            :     .base = { &mp_type_module },
      21                 :            :     .globals = (mp_obj_dict_t *)&example_package_foo_bar_globals,
      22                 :            : };
      23                 :            : 
      24                 :            : // Define example_package.foo.f()
      25                 :          4 : static mp_obj_t example_package_foo_f(void) {
      26                 :          4 :     mp_printf(&mp_plat_print, "example_package.foo.f\n");
      27                 :          4 :     return mp_const_none;
      28                 :            : }
      29                 :            : static MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_f_obj, example_package_foo_f);
      30                 :            : 
      31                 :            : // Define all attributes of the first-level sub-package (example_package.foo).
      32                 :            : static const mp_rom_map_elem_t example_package_foo_globals_table[] = {
      33                 :            :     { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package_dot_foo) },
      34                 :            :     { MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&example_package_foo_bar_user_cmodule) },
      35                 :            :     { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_foo_f_obj) },
      36                 :            : };
      37                 :            : static MP_DEFINE_CONST_DICT(example_package_foo_globals, example_package_foo_globals_table);
      38                 :            : 
      39                 :            : // Define example_package.foo module object.
      40                 :            : const mp_obj_module_t example_package_foo_user_cmodule = {
      41                 :            :     .base = { &mp_type_module },
      42                 :            :     .globals = (mp_obj_dict_t *)&example_package_foo_globals,
      43                 :            : };
      44                 :            : 
      45                 :            : // Define example_package.f()
      46                 :          2 : static mp_obj_t example_package_f(void) {
      47                 :          2 :     mp_printf(&mp_plat_print, "example_package.f\n");
      48                 :          2 :     return mp_const_none;
      49                 :            : }
      50                 :            : static MP_DEFINE_CONST_FUN_OBJ_0(example_package_f_obj, example_package_f);
      51                 :            : 
      52                 :          6 : static mp_obj_t example_package___init__(void) {
      53         [ +  + ]:          6 :     if (!MP_STATE_VM(example_package_initialised)) {
      54                 :            :         // __init__ for builtins is called each time the module is imported,
      55                 :            :         //   so ensure that initialisation only happens once.
      56                 :          2 :         MP_STATE_VM(example_package_initialised) = true;
      57                 :          2 :         mp_printf(&mp_plat_print, "example_package.__init__\n");
      58                 :            :     }
      59                 :          6 :     return mp_const_none;
      60                 :            : }
      61                 :            : static MP_DEFINE_CONST_FUN_OBJ_0(example_package___init___obj, example_package___init__);
      62                 :            : 
      63                 :            : // The "initialised" state is stored on mp_state so that it is cleared on soft
      64                 :            : // reset.
      65                 :            : MP_REGISTER_ROOT_POINTER(int example_package_initialised);
      66                 :            : 
      67                 :            : // Define all attributes of the top-level package (example_package).
      68                 :            : static const mp_rom_map_elem_t example_package_globals_table[] = {
      69                 :            :     { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package) },
      70                 :            :     { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&example_package___init___obj) },
      71                 :            :     { MP_ROM_QSTR(MP_QSTR_foo), MP_ROM_PTR(&example_package_foo_user_cmodule) },
      72                 :            :     { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_f_obj) },
      73                 :            : };
      74                 :            : static MP_DEFINE_CONST_DICT(example_package_globals, example_package_globals_table);
      75                 :            : 
      76                 :            : // Define module object.
      77                 :            : const mp_obj_module_t example_package_user_cmodule = {
      78                 :            :     .base = { &mp_type_module },
      79                 :            :     .globals = (mp_obj_dict_t *)&example_package_globals,
      80                 :            : };
      81                 :            : 
      82                 :            : // Register the module to make it available in Python.
      83                 :            : // Note: subpackages should not be registered with MP_REGISTER_MODULE.
      84                 :            : MP_REGISTER_MODULE(MP_QSTR_example_package, example_package_user_cmodule);

Generated by: LCOV version 1.15-5-g462f71d