Subject: bug#69573: Eager macro-expansion failure: (wrong-type-argument integer-or-marker-p nil)

From: Andrea Corallo <[email-masked]>
Date: Sat, 09 Mar 2024 16:41:02 -0500

Stefan Monnier <[email-masked]> writes:

>>> (defalias 're-search-forward-ifpmod (symbol-function 're-search-forward) ...)
> [...]
>> Stefan, can you help maybe?  Gabriele then does this:
> [...]
>> and we have found that this causes weird errors because at least some
>> definitions, like `forward-paragraph', call `re-search-forward-ifpmod'
>> afterwards.  This seems to happen only when using a native compiled
>
> Sounds like a problem in the code that installs trampolines.
>
> Andrea?
>
> If we look at `fset`, the C code does:
>
>     if (!NILP (Vnative_comp_enable_subr_trampolines)
>         && SUBRP (function)
>         && !SUBR_NATIVE_COMPILEDP (function))
>       CALLN (Ffuncall, Qcomp_subr_trampoline_install, symbol);
>
> so indeed if the SUBR_NATIVE_COMPILEDP function is stored in another
> symbol, we will still call Qcomp_subr_trampoline_install, even tho it's
> a case where it should not be necessary, and I suspect this can lead to
> the kind of problems mentioned above, if we do something like
>
>     (defalias 'foo (symbol-function 'bar))
>     (fset 'foo <something-else>)
>
> where native calls to `bar` could end up redirected to the definition of
> `foo` :-(

Here I'm,

mmmhh, I'm really not sure why calling Qcomp_subr_trampoline_install
should be problematic.  I'll look at it, but this week I'm on holiday so
might take a bit more :)

Bests

  Andrea