When a block registered with `Database#define_function` raised an
exception, the connection was left holding sqlite's per-connection
mutex. Any other thread that subsequently used the connection blocked
forever while holding the GVL, wedging the entire process.
The scalar function callback will now invoke the block under
`rb_protect`, following the pattern established by the aggregate
handlers in `aggregator.c`: a raise will be converted into
`sqlite3_result_error` so that sqlite unwinds and releases its mutex
normally, and `Statement#step` will re-raise the original exception to
the caller.
When a block registered with Database#define_function raised an exception, the connection was left holding sqlite's per-connection mutex. Any other thread that subsequently used the connection blocked forever while holding the GVL, wedging the entire process.
The scalar function callback now invokes the block under rb_protect, following the pattern established by the aggregate handlers in aggregator.c: a raise is converted into sqlite3_result_error so that sqlite unwinds and releases its mutex normally, and Statement#step re-raises the original exception to the caller.