LCOV - code coverage report
Current view: top level - examples/usercmodule/cppexample - example.cpp (source / functions) Hit Total Coverage
Test: unix_coverage_v1.22.0-393-gdf4191378.info Lines: 10 10 100.0 %
Date: 2024-05-24 15:18:56 Functions: 2 2 100.0 %
Branches: 5 10 50.0 %

           Branch data     Line data    Source code
       1                 :            : extern "C" {
       2                 :            : #include <examplemodule.h>
       3                 :            : #include <py/objstr.h>
       4                 :            : 
       5                 :            : // Here we implement the function using C++ code, but since it's
       6                 :            : // declaration has to be compatible with C everything goes in extern "C" scope.
       7                 :          2 : mp_obj_t cppfunc(mp_obj_t a_obj, mp_obj_t b_obj) {
       8                 :            :     // The following no-ops are just here to verify the static assertions used in
       9                 :            :     // the public API all compile with C++.
      10                 :          2 :     MP_STATIC_ASSERT_STR_ARRAY_COMPATIBLE;
      11   [ -  +  -  +  :          2 :     if (mp_obj_is_type(a_obj, &mp_type_BaseException)) {
          -  +  -  +  -  
                      + ]
      12                 :            :     }
      13                 :            : 
      14                 :            :     // Prove we have (at least) C++11 features.
      15                 :          2 :     const auto a = mp_obj_get_int(a_obj);
      16                 :          2 :     const auto b = mp_obj_get_int(b_obj);
      17                 :          6 :     const auto sum = [&]() {
      18                 :          2 :         return mp_obj_new_int(a + b);
      19                 :          2 :     } ();
      20                 :            :     // Prove we're being scanned for QSTRs.
      21                 :          2 :     mp_obj_t tup[] = {sum, MP_ROM_QSTR(MP_QSTR_hellocpp)};
      22                 :          2 :     return mp_obj_new_tuple(2, tup);
      23                 :            : }
      24                 :            : }

Generated by: LCOV version 1.15-5-g462f71d