correct way to expose pari internal functions?

[email protected] Mon, 17 Nov 2025 17:03:15 +0100
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
I stumbled through pari source code looking for "qfsolve()" and found 
this nearby in "src/basemath/qfsolve.c":

/* p a prime number, G 3x3 symmetric. Finds X!=0 such that X^t G X = 0 
mod p.
  * Allow returning a shorter X: to be completed with 0s. */
static GEN
qfsolvemodp(GEN G, GEN p)


I wanted to play with, but since it is static it cannot be just used 
with GP "install()" command.

I saw that "qfsolve()" implementation is oneliner calling static 
"qfsolve_i()".

I copied that and renamed:

GEN
qfsolvemodp_(GEN G, GEN p)
{ pari_sp av = avma; return gerepilecopy(av, qfsolvemodp(G, p)); }


Then I added this to "src/headers/paridecl.h":

GEN     qfsolvemodp_(GEN G, GEN p);


After "make all" and starting gp new function works:

hermann@j4105:~/pari-2.17.2$ ./gp -q
? install("qfsolvemodp_","GG")
? qfsolvemodp_(matdiagonal([1,1,1]),13)
[5, 1, 0]~
? abs(qfsolve(matdiagonal([1,1,1,-13]))[1..3])
[3, 2, 0]~
?


Is this the correct way to expose internal functions for playing with?

I once passed non-prime as 2nd argument and got segmentation fault — 
which is my fault because I did not follow the requirement for 2nd arg 
to be prime.


Regards,

Hermann.