Bill Allombert on Wed, 10 Mar 2004 23:37:47 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

reporting the GP name of functions in error message


Hello PARI-dev,

I tried to implement reporting of the GP name of the function called
where an error occur in the new parser, but I found it could be done
the same way with the current parser, so here a patch.

It is for evaluation purpose, it could be perfected.

With this patch, we get for example:
? cotan(0)
  *** cotan: division by zero in R/R

instead of
? cotan(0)
  ***   division by zero in R/R

or
? for(i=2,100,factormod(x^4+1,i))
  *** factormod: composite modulus in mpsqrtmod: 9.

instead of

? for(i=2,100,factormod(x^4+1,i))
  ***   composite modulus in mpsqrtmod: 9.

which is less confusing when it appear inside a large GP routine.

Cheers,
Bill.

Index: src/language/anal.c
===================================================================
RCS file: /home/cvs/pari/src/language/anal.c,v
retrieving revision 1.157
diff -u -r1.157 anal.c
--- src/language/anal.c	26 Jan 2004 09:25:09 -0000	1.157
+++ src/language/anal.c	10 Mar 2004 22:20:21 -0000
@@ -31,6 +31,7 @@
 typedef GEN (*F1GEN)(GEN);
 
 extern void killsubblocs(GEN x);
+char *gp_function_name=NULL;
 
 static GEN    constante();
 static GEN    expr();
@@ -2011,11 +2012,14 @@
         err(talker2, "can't derive this", mark.identifier, mark.start);
       res = num_deriv(call, argvec);
     }
-    else switch (ret)
+    else
     {
+      gp_function_name=ep->name;
+      switch (ret)
+      {
       default: /* case RET_GEN: */
-	res = ((PFGEN)call)(_ARGS_);
-	break;
+        res = ((PFGEN)call)(_ARGS_);
+        break;
 
       case RET_INT:
 	m = (long)((int (*)(ANYARG))call)(_ARGS_);
@@ -2028,6 +2032,8 @@
       case RET_VOID:
 	((void (*)(ANYARG))call)(_ARGS_);
 	res = gnil; break;
+      }
+      gp_function_name=NULL;
     }
     if (has_pointer) check_pointers(has_pointer,init);
     if (!noparen) match(')');
Index: src/language/init.c
===================================================================
RCS file: /home/cvs/pari/src/language/init.c,v
retrieving revision 1.215
diff -u -r1.215 init.c
--- src/language/init.c	10 Mar 2004 17:24:56 -0000	1.215
+++ src/language/init.c	10 Mar 2004 22:20:25 -0000
@@ -1049,6 +1049,8 @@
   longjmp(GP_DATA? GP_DATA->env: environnement, numerr);
 }
 
+extern char *gp_function_name;
+
 void
 err(long numerr, ...)
 {
@@ -1123,7 +1125,13 @@
   }
   else
   {
-    pariputsf("  ***   %s", errmessage[numerr]);
+    if (gp_function_name)
+    {
+      pariputsf("  *** %s: %s", gp_function_name, errmessage[numerr]);
+      gp_function_name=NULL;
+    }
+    else
+      pariputsf("  ***   %s", errmessage[numerr]);
     switch (numerr)
     {
       case talker: case siginter: case invmoder: