Bill Allombert on Tue, 11 Sep 2018 22:46:28 +0200


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

Re: err_e_STACK should be a universal constant


On Tue, Sep 11, 2018 at 10:35:40AM +0200, Jeroen Demeyer wrote:
> Hello,
> 
> As far as I know, every GEN returned by the PARI library falls in one of
> these 3 cases:
> 
> * on PARI stack
> * clone
> * universal constant
> 
> The only exception is err_e_STACK which is effectively a universal constant
> but is_universal_constant() returns 0 for it. Is there a reason for that?
> 
> I am asking in the context of Python bindings for PARI. The existing cypari2
> package used to always copy everything. Now I'm trying to improve the memory
> management by keeping objects on the PARI stack for a longer time. To do
> this, I need to distinguish between the 3 cases I mentioned above and
> err_e_STACK is the only object (that I found so far) where this fails.

The attached patch should fix this.
However note that you should always special case e_STACK, because if it
happens this means that the stack is full so you need to recover
somehow.

Cheers,
Bill.
>From 26d8c8d76587d067ef9c10407bc0bee896012ead Mon Sep 17 00:00:00 2001
From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
Date: Tue, 11 Sep 2018 22:29:30 +0200
Subject: [PATCH] Merge readonly_err_STACK in readonly_constants

---
 src/language/init.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/language/init.c b/src/language/init.c
index 4b26ddf2e..3927a3304 100644
--- a/src/language/init.c
+++ b/src/language/init.c
@@ -77,14 +77,12 @@ static const ulong readonly_constants[] = {
   evaltyp(t_INT) | _evallg(3),  /* gen_m2 */
   evalsigne(-1) | evallgefint(3),
   2,
+  evaltyp(t_ERROR) | _evallg(2), /* err_e_STACK */
+  e_STACK,
   evaltyp(t_FRAC) | _evallg(3), /* ghalf */
   (ulong)(readonly_constants+4),
   (ulong)(readonly_constants+7)
 };
-static const ulong readonly_err_STACK[] = {
-  evaltyp(t_ERROR) | _evallg(2),
-  e_STACK
-};
 THREAD GEN bernzone, primetab;
 byteptr diffptr;
 FILE    *pari_outfile, *pari_errfile, *pari_logfile, *pari_infile;
@@ -506,8 +504,8 @@ init_universal_constants(void)
   gen_2  = (GEN)readonly_constants+7;
   gen_m1 = (GEN)readonly_constants+10;
   gen_m2 = (GEN)readonly_constants+13;
-  ghalf  = (GEN)readonly_constants+16;
-  err_e_STACK = (GEN)readonly_err_STACK;
+  err_e_STACK = (GEN)readonly_constants+16;
+  ghalf  = (GEN)readonly_constants+18;
 }
 
 static void
-- 
2.11.0