Skip to content

Commit 1b62a6c

Browse files
kesmit13claude
andcommitted
Guard WASI-incompatible POSIX APIs in accel.c with #ifndef __wasi__
The mmap_read, mmap_write, and recv_exact functions use poll.h, sys/mman.h, and sys/socket.h which are unavailable in WASI. Wrap these includes, function bodies, and PyMethodDef entries with #ifndef __wasi__ guards so the C extension compiles for wasm32-wasip2. The core call_function_accel optimization remains available. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c732dff commit 1b62a6c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

accel.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11

22
#include <math.h>
3+
#ifndef __wasi__
34
#include <poll.h>
5+
#endif
46
#include <stdint.h>
57
#include <stdlib.h>
68
#include <string.h>
9+
#ifndef __wasi__
710
#include <sys/mman.h>
811
#include <sys/socket.h>
12+
#endif
913
#include <unistd.h>
1014
#include <Python.h>
1115

@@ -5298,6 +5302,7 @@ static PyObject *call_function_accel(PyObject *self, PyObject *args, PyObject *k
52985302
goto exit;
52995303
}
53005304

5305+
#ifndef __wasi__
53015306
/*
53025307
* mmap_read(fd, length) -> bytes
53035308
*
@@ -5444,6 +5449,7 @@ static PyObject *accel_recv_exact(PyObject *self, PyObject *args) {
54445449
free(buf);
54455450
return result;
54465451
}
5452+
#endif /* !__wasi__ */
54475453

54485454
static PyMethodDef PyMySQLAccelMethods[] = {
54495455
{"read_rowdata_packet", (PyCFunction)read_rowdata_packet, METH_VARARGS | METH_KEYWORDS, "PyMySQL row data packet reader"},
@@ -5452,9 +5458,11 @@ static PyMethodDef PyMySQLAccelMethods[] = {
54525458
{"dump_rowdat_1_numpy", (PyCFunction)dump_rowdat_1_numpy, METH_VARARGS | METH_KEYWORDS, "ROWDAT_1 formatter for external functions which takes numpy.arrays"},
54535459
{"load_rowdat_1_numpy", (PyCFunction)load_rowdat_1_numpy, METH_VARARGS | METH_KEYWORDS, "ROWDAT_1 parser for external functions which creates numpy.arrays"},
54545460
{"call_function_accel", (PyCFunction)call_function_accel, METH_VARARGS | METH_KEYWORDS, "Combined load/call/dump for UDF function calls"},
5461+
#ifndef __wasi__
54555462
{"mmap_read", (PyCFunction)accel_mmap_read, METH_VARARGS, "mmap read: maps fd, copies data, unmaps"},
54565463
{"mmap_write", (PyCFunction)accel_mmap_write, METH_VARARGS, "mmap write: ftruncate+lseek+write in one call"},
54575464
{"recv_exact", (PyCFunction)accel_recv_exact, METH_VARARGS, "Receive exactly N bytes from a socket fd"},
5465+
#endif
54585466
{NULL, NULL, 0, NULL}
54595467
};
54605468

0 commit comments

Comments
 (0)