<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div>Hi,</div><div><br></div><div>We run s7 (11.9, 21-Sep-2026; the code is unchanged in the 2-Oct-2026</div><div>tarball) inside GNU TeXmacs compiled to WebAssembly with Emscripten&nbsp;</div><div>(<a href="https://mgubi.github.io/texmacs/">https://mgubi.github.io/texmacs/</a>), and hit a "function signature mismatch”&nbsp;</div><div>trap. The cause is a direct function</div><div>installed with one signature and called with another.</div><div><br></div><div>In the tree rewriting of fx_c_si_direct into fx_c_ti_direct (around line</div><div>61674 of the 2-Oct s7.c), the p_pi case does</div><div><br></div><div>&nbsp; &nbsp; if ((opt3_direct(cdr(expr)) == (s7_pointer)string_ref_p_pi) &amp;&amp; (integer(caddr(expr)) == 0))</div><div>&nbsp; &nbsp; &nbsp; set_opt3_direct(cdr(expr), string_ref_p_p0);</div><div>&nbsp; &nbsp; return(with_fx(tree, ... fx_c_ti_direct));</div><div><br></div><div>but string_ref_p_p0 is a p_pp function (sc, str, unused_index), while</div><div>fx_c_ti_direct calls opt3_direct as s7_p_pi_t (sc, p, s7_int). Natively the</div><div>extra s7_int is harmless, which is presumably why it never showed up; in</div><div>WebAssembly, call_indirect checks the exact signature and traps. The two</div><div>other places that install string_ref_p_p0 are p_pp contexts and are fine.</div><div><br></div><div>Reproducer (traps in a WebAssembly build of s7 run under node):</div><div><br></div><div>&nbsp; &nbsp; (define (f a b) (string-ref a 0))</div><div>&nbsp; &nbsp; (define (g x) (f x (+ 1 2)))</div><div>&nbsp; &nbsp; (g "abc")</div><div><br></div><div>Natively, clang's -fsanitize=function also reports it:</div><div><br></div><div>&nbsp; &nbsp; s7.c:58048:74: runtime error: call to function string_ref_p_p0 through</div><div>&nbsp; &nbsp; &nbsp; pointer to incorrect function type 'struct s7_cell *(*)(struct s7_scheme *,</div><div>&nbsp; &nbsp; &nbsp; struct s7_cell *, long long)'</div><div>&nbsp; &nbsp; &nbsp; &nbsp; #0 fx_c_ti_direct s7.c:58048</div><div>&nbsp; &nbsp; &nbsp; &nbsp; #1 fx_c_aa s7.c:59701</div><div>&nbsp; &nbsp; &nbsp; &nbsp; #2 op_tc_or_a_and_a_la s7.c:92257</div><div><br></div><div>The attached patch just keeps string_ref_p_pi in that case. With it, s7test.scm</div><div>under clang 21 -fsanitize=function (with the block and libc tests, without</div><div>gsl) reports no mismatched call, and the reproducer runs in WebAssembly. It</div><div>might be worth adding the reproducer to s7test.scm, since nothing there has</div><div>that shape (a two-argument closure whose body is (string-ref &lt;first arg&gt; 0),</div><div>called with two expressions).</div><div><br></div><div>Thanks for s7!</div><div><br></div><div>Massimiliano Gubinelli</div><div><br></div><div>--- patch (against the 2-Oct-2026 s7.c) ---</div><div>--- a/s7.c</div><div>+++ b/s7.c</div><div>@@ -61671,8 +61671,7 @@</div><div>&nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div>&nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;if (opt3_direct(cdr(expr)) == (s7_pointer)vector_ref_p_pi)</div><div>&nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;return(with_fx(tree, fx_vector_ref_tc));</div><div>-<span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;if ((opt3_direct(cdr(expr)) == (s7_pointer)string_ref_p_pi) &amp;&amp; (integer(caddr(expr)) == 0))</div><div>-<span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;set_opt3_direct(cdr(expr), string_ref_p_p0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;/* not string_ref_p_p0 here: it is p_pp, but fx_c_ti_direct calls opt3_direct as p_pi */</div><div>&nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;return(with_fx(tree, (opt3_direct(cdr(expr)) == (s7_pointer)remainder_p_pi) ? fx_c_ti_remainder : fx_c_ti_direct));</div><div>&nbsp;<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>&nbsp; &nbsp; &nbsp; &nbsp;if (pfunc == fx_is_eq_sc) &nbsp; &nbsp;return(with_fx(tree, fx_is_eq_tc));</div><div><br></div></body></html>