Subject: | [PATCH] stdout clobbered with newlines |
I observed this problem with Math-Pari-2.01080604 and pari-2.3.5.
Math-Pari-2.01080604 worked fine with pari-2.1.7.
When Math::Pari passes a PARI error on as a Perl exception, a newline
strays to stdout from inside PARI. This might be owed to some error
handling "improvement" intended for GP only, and thus a PARI bug, but
Math::Pari could cope with it by not exposing stdout to PARI output at
all. This kind of encapsulation could also mitigate similar bugs in the
future.
My patch gives PARI a black hole to talk to while its output is not
wanted, and reestablishes this setting after PARI has dropped output
redirection as a part of its error recovery routine.
Test case:
perl -MMath::Pari -e '$x=PARI(0);$y=eval{$x/$x}||eval{$x**-1}'
This should print nothing but prints two empty lines on affected platforms.
-Martin
Subject: | clean_stdout.patch |
diff -ru Math-Pari-2.01080604.orig/Pari.xs Math-Pari-2.01080604/Pari.xs
--- Math-Pari-2.01080604.orig/Pari.xs 2010-03-03 22:53:32.000000000 +0100
+++ Math-Pari-2.01080604/Pari.xs 2011-04-20 23:52:35.000000000 +0200
@@ -719,6 +719,24 @@
/* EMPTY */
}
+static void
+null_putc(char c)
+{
+}
+
+static void
+null_puts(PUTS_CONST char* p)
+{
+}
+
+static void
+null_flush(void)
+{
+}
+
+static PariOUT nullOut={null_putc, null_puts, null_flush, NULL};
+
+
/* Support error messages of the form (calling PARI('O(det2($mat))')):
PARI: *** obsolete function: O(det2($mat))
^----------- */
@@ -748,6 +766,7 @@
STRLEN l;
char *s = SvPV(errSv,l);
char *nl = memchr(s,'\n',l);
+ pariOut = &nullOut;
sv_setpv(workErrsv,"");
sv_2mortal(errSv);
@@ -3761,6 +3780,7 @@
#endif /* PARI_VERSION_EXP >= 2003000 */
PariStack = (SV *) GENfirstOnStack;
workErrsv = newSVpv("",0);
+ pariOut = &nullOut;
pariErr = &perlErr;
foreignHandler = (void*)&callPerlFunction;
foreignAutoload = &autoloadPerlFunction;