summaryrefslogtreecommitdiff
path: root/pkgs/development/perl-modules/Math-Pari-darwin-callback-abi.patch
blob: ff5fe4984dfb6defc424d96ed48c36e83fe2b3f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--- a/Pari.xs
+++ b/Pari.xs
@@ -1518,21 +1518,63 @@
 }
 
 GEN
-callPerlFunction(PerlFunctionArg1 long_ep, ...)
-{
-    GEN res;
+callPerlFunction_args(PerlFunctionArg1 long_ep, GEN *args)
+{
     entree *ep = toEntreeP(long_ep);
-    va_list args;
     SV *cv = (SV*) ep->elt_CV;
     int numargs = CV_NUMARGS_get(cv);
-
-    va_start(args, long_ep);
-/*    warn("calling with numargs=%d", numargs); */
-    res = callPerlFunction_va_list(G_SCALAR, numargs, cv, args);
-/*    warn("ending call"); */
-    va_end(args);
-/*    warn("ended call"); */
+    GEN res;
+    int i;
+    dSP;
+    int count;
+    pari_sp oldavma = avma;
+    SV *oPariStack = PariStack;
+    SV *sv;
+
+    ENTER;
+    SAVETMPS;
+    SAVEINT(sentinel);
+    sentinel = avma;
+    PUSHMARK(sp);
+    EXTEND(sp, numargs + 1);
+    for (i = 0; i < numargs; i++)
+	PUSHs(pari2mortalsv(args[i], oldavma));
+    PUTBACK;
+    count = perl_call_sv(cv, G_SCALAR);
+
+    SPAGAIN;
+    if (count != 1)
+	croak("Perl function exported into PARI returns unexpected number %d of values (need 1)", count);
+
+    sv = SvREFCNT_inc(POPs);
+
+    PUTBACK;
+    FREETMPS;
+    LEAVE;
+
+    if (PariStack != oPariStack)
+	moveoffstack_newer_than(oPariStack);
+    res = sv2pari(sv);
+    res = myforcecopy(res);
+    SvREFCNT_dec(sv);
+
     return res;
+}
+
+GEN
+callPerlFunction(PerlFunctionArg1 long_ep, GEN arg0, GEN arg1, GEN arg2, GEN arg3, GEN arg4, GEN arg5, GEN arg6, GEN arg7)
+{
+    GEN args[8];
+
+    args[0] = arg0;
+    args[1] = arg1;
+    args[2] = arg2;
+    args[3] = arg3;
+    args[4] = arg4;
+    args[5] = arg5;
+    args[6] = arg6;
+    args[7] = arg7;
+    return callPerlFunction_args(long_ep, args);
 }
 
 entree *