dhylands wrote:Using extern C just satisfies the linker.
You need to make sure that once you're in MicroPython land, if you call ANY C++ code that it does not throw an exception, or it will totally mess up the MicroPython exception stack. As long as MicroPython doesn't call any C++ functions which may throw an exception you'll be fine.
As to your hang, then it sounds like perhaps your Python to C bindings are not quite setup properly.
Did you try something that's known to work, like the c_sample from here:
viewtopic.php?f=16&t=2861&p=19206#p19206
So here is what I have for setting up the Python to C binding. I don't see anything wrong with it.
Code: Select all
static mp_obj_t c_sample_set_callback(mp_obj_t callback_obj)
{
MP_STATE_PORT(c_sample_callback_obj) = callback_obj;
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(c_sample_set_callback_obj, c_sample_set_callback);
static mp_obj_t c_sample_call_callback(mp_obj_t mp_arg0, mp_obj_t mp_arg1, mp_obj_t mp_arg2);
static MP_DEFINE_CONST_FUN_OBJ_3(c_sample_call_callback_obj, c_sample_call_callback);
static const mp_map_elem_t c_sample_globals_table[] =
{
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_c_sample) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_callback), (mp_obj_t)&c_sample_set_callback_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_call_callback), (mp_obj_t)&c_sample_call_callback_obj },
};
static MP_DEFINE_CONST_DICT(mp_module_c_sample_globals, c_sample_globals_table);
const mp_obj_module_t mp_module_c_sample =
{
.base = { &mp_type_module },
.name = MP_QSTR_c_sample,
.globals = (mp_obj_dict_t*)&mp_module_c_sample_globals,
};
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);