Adding External C Modules with external functions to mp as a library
Re: Adding External C Modules with external functions to mp as a library
For some values, mp_obj_new_int_from_uint will do a heap allocation, so your heap might not be initialized properly.
Re: Adding External C Modules with external functions to mp as a library
We are using the lib in a project that already had mp. We haven't changed any of the initialization code, this code has been working since 2016.
Re: Adding External C Modules with external functions to mp as a library
It's also possible that the corruption is occuring elsewhere in your code and its just the call to mp_obj_new_int_from_uint that's tripping up after the corruption.
Try creating an empty function that just calls mp_obj_new_int_from_uint and returns a similar value to your C code.
It could also be stack overflow, of the C code is allocating large objects on the stack. This can then cause heap corruption. The stack is typically located at the high end of RAM and the heap normally ends just before the stack.
Try creating an empty function that just calls mp_obj_new_int_from_uint and returns a similar value to your C code.
It could also be stack overflow, of the C code is allocating large objects on the stack. This can then cause heap corruption. The stack is typically located at the high end of RAM and the heap normally ends just before the stack.
Re: Adding External C Modules with external functions to mp as a library
I found the problem. MP's UART code was conflicting with our firmware. Simple fix.
Which brings back an old question I've had, can the CLI be easily removed, along with the entire hardware layer? Basically have mp run scripts and let my module do all the work. In the process making mp even smaller and more portable.
Which brings back an old question I've had, can the CLI be easily removed, along with the entire hardware layer? Basically have mp run scripts and let my module do all the work. In the process making mp even smaller and more portable.
Re: Adding External C Modules with external functions to mp as a library
If it's not one thing it's another lol.
So the library along with my c module is sort of working now, however, when calling mp_obj_get_int() there seems to be an overflow problem when using values >= 0x40000000. Values <= 0x3FFFFFFF don't have a problem. Basically it's having issues with numbers greater than 30 bits.
So the library along with my c module is sort of working now, however, when calling mp_obj_get_int() there seems to be an overflow problem when using values >= 0x40000000. Values <= 0x3FFFFFFF don't have a problem. Basically it's having issues with numbers greater than 30 bits.
Re: Adding External C Modules with external functions to mp as a library
This is the "some values" that dhylands referred to earlier in "For some values, mp_obj_new_int_from_uint will do a heap allocation..."cduran wrote: ↑Thu Mar 12, 2020 6:01 pmSo the library along with my c module is sort of working now, however, when calling mp_obj_get_int() there seems to be an overflow problem when using values >= 0x40000000. Values <= 0x3FFFFFFF don't have a problem. Basically it's having issues with numbers greater than 30 bits.
"Small ints" are stored inline in the mp_obj_t value. "Long ints" depend on the implementation that's enabled. Most ports use the MPZ implementation.
When you access an int value, you need to know whether it's actually a long int.