Ilya Zakharevich on Wed, 15 May 2002 20:53:56 -0400 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
RESTORE_AVMA(oldvalue) |
As far as I understand, the only problem with interfacing PARI with other math-related libraries (e.g., to allow Groebner bases supported) is an absense of the type t_EXTERNAL_DATA. The minimal support for this type in the PARI core should be: cloning/uncloning, create/destroy and a couple of others; these operations should go through the dispatch table (the pointer to this table should be a part of the data structure associated to this type). However, the major obstacle for this to be done is the absense of refcounts for PARI objects: whatever is on stack at the time of "restoring the stack position" is just ignored (if it is not gerepile()d). This could lead to severe memory leaks. The following patch + edit one-liner make it easy to change the policy of "restoring the stack position" at run time: suppose that we have a linked list LL of object on the stack which need to be free()ed; the typical situation is LL == NULL. Then a change like #define RESTORE_AVMA(from) (LL ? hard_way_restore_avma(from) : (avma = (from)) will: a) have a very little overhead in absense of LL; b) allow hard_way_restore_avma() to obj_free() the objects which are in front of the LL chain up to the position from. Enjoy, Ilya P.S. pfind is available from http://www.ilyaz.org/software/perl/scripts --- ./src/headers/parigen.h-pre Wed May 15 20:20:04 2002 +++ ./src/headers/parigen.h Wed May 15 20:20:45 2002 @@ -156,3 +156,4 @@ typedef int (*QSCOMP)(const void *, cons #define setvarn(x,s) (((GEN)(x))[1]=\ (((GEN)(x))[1]&(~VARNBITS)) | evalvarn(s)) +#define RESTORE_AVMA(from) (avma = (from)) ======================================================= After applying this patch run pfind src '=~ s/((?:^|[{;:,]|\belse)\s*)avma\s*=\s*((?:\(\w+\))?\w+)(\s*[;),])/$1RESTORE_AVMA($2)$3/g' this replaces the bulk of assignments of the form "avma = from" to the corresponding macro. Around 70 assignments to avma remain unpatched, but this is easy to fix by hand after the bulk work is done. Enjoy, Ilya