Skip to content

Commit b66653a

Browse files
kesmit13claude
andcommitted
Add WASI stubs for mmap_read/mmap_write/recv_exact and fix accel logging
The _singlestoredb_accel C extension ifdef'd out the mmap and socket functions for __wasi__ builds, but registry.py imports all four symbols (call_function_accel, mmap_read, mmap_write, recv_exact) in a single try block. The missing exports caused the entire import to fail, silently falling back to the pure Python call_function loop. Add #else stubs that raise NotImplementedError if called, so the symbols are importable and call_function_accel works in WASM. Also capture the accel import error and log it in initialize() for future diagnostics. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c65793a commit b66653a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

accel.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5449,6 +5449,23 @@ static PyObject *accel_recv_exact(PyObject *self, PyObject *args) {
54495449
free(buf);
54505450
return result;
54515451
}
5452+
#else /* __wasi__ stubs — importable but raise NotImplementedError if called */
5453+
5454+
static PyObject *accel_mmap_read(PyObject *self, PyObject *args) {
5455+
PyErr_SetString(PyExc_NotImplementedError, "mmap_read is not available in WASM");
5456+
return NULL;
5457+
}
5458+
5459+
static PyObject *accel_mmap_write(PyObject *self, PyObject *args) {
5460+
PyErr_SetString(PyExc_NotImplementedError, "mmap_write is not available in WASM");
5461+
return NULL;
5462+
}
5463+
5464+
static PyObject *accel_recv_exact(PyObject *self, PyObject *args) {
5465+
PyErr_SetString(PyExc_NotImplementedError, "recv_exact is not available in WASM");
5466+
return NULL;
5467+
}
5468+
54525469
#endif /* !__wasi__ */
54535470

54545471
static PyMethodDef PyMySQLAccelMethods[] = {
@@ -5458,11 +5475,9 @@ static PyMethodDef PyMySQLAccelMethods[] = {
54585475
{"dump_rowdat_1_numpy", (PyCFunction)dump_rowdat_1_numpy, METH_VARARGS | METH_KEYWORDS, "ROWDAT_1 formatter for external functions which takes numpy.arrays"},
54595476
{"load_rowdat_1_numpy", (PyCFunction)load_rowdat_1_numpy, METH_VARARGS | METH_KEYWORDS, "ROWDAT_1 parser for external functions which creates numpy.arrays"},
54605477
{"call_function_accel", (PyCFunction)call_function_accel, METH_VARARGS | METH_KEYWORDS, "Combined load/call/dump for UDF function calls"},
5461-
#ifndef __wasi__
54625478
{"mmap_read", (PyCFunction)accel_mmap_read, METH_VARARGS, "mmap read: maps fd, copies data, unmaps"},
54635479
{"mmap_write", (PyCFunction)accel_mmap_write, METH_VARARGS, "mmap write: ftruncate+lseek+write in one call"},
54645480
{"recv_exact", (PyCFunction)accel_recv_exact, METH_VARARGS, "Receive exactly N bytes from a socket fd"},
5465-
#endif
54665481
{NULL, NULL, 0, NULL}
54675482
};
54685483

singlestoredb/functions/ext/collocated/registry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from singlestoredb.functions.signature import get_signature
2828
from singlestoredb.mysql.constants import FIELD_TYPE as ft
2929

30+
_accel_error: Optional[str] = None
3031
try:
3132
from _singlestoredb_accel import call_function_accel as _call_function_accel
3233
from _singlestoredb_accel import mmap_read as _mmap_read
@@ -36,6 +37,7 @@
3637
logging.getLogger(__name__).info('_singlestoredb_accel loaded successfully')
3738
except Exception as e:
3839
_has_accel = False
40+
_accel_error = str(e)
3941
_mmap_read = None
4042
_mmap_write = None
4143
_recv_exact = None

singlestoredb/functions/ext/collocated/wasm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import logging
99
import traceback
1010

11+
from .registry import _accel_error
1112
from .registry import _has_accel
1213
from .registry import call_function
1314
from .registry import describe_functions_json
@@ -30,6 +31,11 @@ def initialize(self) -> None:
3031
logger.info('Using accelerated C call_function_accel loop')
3132
else:
3233
logger.info('Using pure Python call_function loop')
34+
if _accel_error:
35+
logger.warning(
36+
'_singlestoredb_accel failed to load: %s',
37+
_accel_error,
38+
)
3339
_registry.initialize()
3440

3541
def call_function(self, name: str, input_data: bytes) -> bytes:

0 commit comments

Comments
 (0)