unix/coveragecpp: Verify struct-initializing macros' C++-compatibility.
Add code using all relevant macros to make sure they initialize structs correctly. Signed-off-by: stijn <stijn@ignitron.net>
This commit is contained in:
parent
02eea0da24
commit
9a377801dc
1 changed files with 51 additions and 0 deletions
|
|
@ -17,10 +17,61 @@ extern "C" {
|
|||
#include <py/runtime.h>
|
||||
}
|
||||
|
||||
// Invoke all (except one, see below) public API macros which initialize structs to make sure
|
||||
// they are C++-compatible, meaning they explicitly initialize all struct members.
|
||||
mp_obj_t f0();
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(f0_obj, f0);
|
||||
mp_obj_t f1(mp_obj_t);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(f1_obj, f1);
|
||||
mp_obj_t f2(mp_obj_t, mp_obj_t);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(f2_obj, f2);
|
||||
mp_obj_t f3(mp_obj_t, mp_obj_t, mp_obj_t);
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(f3_obj, f3);
|
||||
mp_obj_t fvar(size_t, const mp_obj_t *);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR(fvar_obj, 1, fvar);
|
||||
mp_obj_t fvarbetween(size_t, const mp_obj_t *);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fvarbetween_obj, 1, 2, fvarbetween);
|
||||
mp_obj_t fkw(size_t, const mp_obj_t *, mp_map_t *);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(fkw_obj, 1, fkw);
|
||||
|
||||
static const mp_rom_map_elem_t table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_f0), MP_ROM_PTR(&f0_obj) },
|
||||
};
|
||||
MP_DEFINE_CONST_MAP(map, table);
|
||||
MP_DEFINE_CONST_DICT(dict, table);
|
||||
|
||||
static const qstr attrtuple_fields[] = {
|
||||
MP_QSTR_f0,
|
||||
};
|
||||
MP_DEFINE_ATTRTUPLE(attrtuple, attrtuple_fields, 1, MP_ROM_PTR(&f0_obj));
|
||||
|
||||
void nlr_cb(void *);
|
||||
void nlr_cb(void *){
|
||||
}
|
||||
|
||||
// The MP_DEFINE_CONST_OBJ_TYPE macro is not C++-compatible because each of the
|
||||
// MP_DEFINE_CONST_OBJ_TYPE_NARGS_X macros only initializes some of _mp_obj_type_t's
|
||||
// .slot_index_xxx members but that cannot be fixed to be done in a deterministic way.
|
||||
|
||||
|
||||
#if defined(MICROPY_UNIX_COVERAGE)
|
||||
|
||||
// Just to test building of C++ code.
|
||||
static mp_obj_t extra_cpp_coverage_impl() {
|
||||
MP_DEFINE_NLR_JUMP_CALLBACK_FUNCTION_1(ctx, nlr_cb, (void *) nlr_cb);
|
||||
|
||||
// To avoid 'error: unused variable [-Werror,-Wunused-const-variable]'.
|
||||
(void) ctx;
|
||||
(void) f0_obj;
|
||||
(void) f1_obj;
|
||||
(void) f2_obj;
|
||||
(void) f3_obj;
|
||||
(void) fvar_obj;
|
||||
(void) fvarbetween_obj;
|
||||
(void) fkw_obj;
|
||||
(void) map;
|
||||
(void) dict;
|
||||
(void) attrtuple;
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue