spatialdude / usqlite

μSQLite library module for MicroPython
MIT License
87 stars 18 forks source link

Update to build with latest MicroPython version #14

Closed dpgeorge closed 1 year ago

dpgeorge commented 1 year ago

This allows this module to be compiled into the latest (as at v1.19.1-736) version of MicroPython.

Note: I have not tested these changes! Are there any tests that can be used to verify things work?

spatialdude commented 1 year ago

Thanks @dpgeorge. I'm finally getting to this! I do have some basic tests which I run on various devices; I probably should add them to the repo🤔 I'll test things out locally and merge the PR if it all works. Thanks again.

spatialdude commented 1 year ago

@dpgeorge I've merged the changes.

The only change I found I needed to make was to revise usqlite_lookup to not use mp_load_method_maybe() directly - https://github.com/spatialdude/usqlite/blob/2c91f8fdf2c1eba681029214196ab56beb6babba/usqlite_utils.c#L103

The problem I found is that because usqlite_lookup is called int the _attr function, it causes recursion and then eventually a stack overflow. This is due to the call in https://github.com/micropython/micropython/blob/699477d12d1aa1cb57ff6cfc3f5dc5e97524dbe6/py/runtime.c#L1178

So, the simplest solution I could see was to more or less copy what mp_load_method_maybe() does without the attr get slot call.

dpgeorge commented 1 year ago

Thanks for merging!

It's a shame you can't use mp_load_method_maybe() directly, but after a very quick look at it, I can't see a good solution.