Skip to content

Commit b9a36b2

Browse files
committed
Expand Turso's custom-function slots from 32 to 64
Turso's sqlite3_create_function_v2 has 32 pre-generated bridge trampolines (MAX_CUSTOM_FUNCS). The driver registers 44 UDFs, so the last 12 silently fail registration; SQL calls to from_base64 etc. then fail with 'no such function'. Generate 32 more bridges.
1 parent 6031c5c commit b9a36b2

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,42 @@ jobs:
105105
print(f'patched {n} sqlite3_column_* functions')
106106
PY
107107
108+
# Turso's custom-function registry is capped at 32 pre-generated
109+
# bridge trampolines; the driver registers 44 UDFs, so the last 12
110+
# silently fail. Bump to 64 by adding 32 more func_bridge!/FUNC_BRIDGES
111+
# entries.
112+
python3 - <<'PY_FN_SLOTS'
113+
p = 'sqlite3/src/lib.rs'
114+
s = open(p).read()
115+
old_max = 'const MAX_CUSTOM_FUNCS: usize = 32;'
116+
new_max = 'const MAX_CUSTOM_FUNCS: usize = 64;'
117+
assert old_max in s, 'MAX_CUSTOM_FUNCS not found'
118+
s = s.replace(old_max, new_max, 1)
119+
120+
# Inject 32 more func_bridge! declarations after func_bridge_31.
121+
bridge_marker = 'func_bridge!(31, func_bridge_31);\n'
122+
assert bridge_marker in s
123+
extra_bridges = ''.join(
124+
f'func_bridge!({i}, func_bridge_{i});\n' for i in range(32, 64)
125+
)
126+
s = s.replace(bridge_marker, bridge_marker + extra_bridges, 1)
127+
128+
# Extend the FUNC_BRIDGES array: find the closing `];` of the
129+
# static and inject the extra entries before it.
130+
import re
131+
pat = re.compile(
132+
r'(static FUNC_BRIDGES: \[ScalarFunction; MAX_CUSTOM_FUNCS\] = \[\n'
133+
r'(?:\s*func_bridge_\d+,\n)+)(\];\n)'
134+
)
135+
m = pat.search(s)
136+
assert m is not None, 'FUNC_BRIDGES array not found'
137+
extra_entries = ''.join(f' func_bridge_{i},\n' for i in range(32, 64))
138+
s = s[:m.start(2)] + extra_entries + s[m.start(2):]
139+
140+
open(p, 'w').write(s)
141+
print('patched MAX_CUSTOM_FUNCS 32 -> 64')
142+
PY_FN_SLOTS
143+
108144
# SQLite looks up function names case-insensitively, but Turso's
109145
# extension registry stores names as-is and connection.rs looks
110146
# them up with HashMap::get directly. The driver's translator emits

0 commit comments

Comments
 (0)