
Hi there,
since we have decided that PPL 0.4 must be shipped with a reasonably complete YAP interface, we have investigated a bit more the problems we are experiencing. These can be split in two: the first one has to do with the fact that PPL uses GMP and YAP also uses, by default, GMP. That results in a segmentation fault at the very first memory allocation of a GMP object that the PPL performs. But let us proceed with order. The machines we use are Athlon machines running RedHat GNU/Linux 7.2 and 7.3 with all the updates applied. We use GCC 3.0.4.
$ uname -a Linux xyzzy 2.4.18 #2 Thu Feb 28 07:12:54 CET 2002 i686 unknown $ gcc -v Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs Configured with: ../gcc-3.0.4/configure --prefix=/usr/local Thread model: single gcc version 3.0.4 $
We use a CVS version of yap that is up-to-date at the time of writing. This has been configured with
--enable-debug-yap --prefix=/usr/local
With this configuration we cannot even load the PPL-YAP interface due to a segmentation fault in AllocBigNumSpace (size=4) at C/bignum.c:96. The complete log of a gdb session is below the signature (I am sure Vitor will immediately see where the problem is).
To expose the other problems we have (I will do that in a following message) we must therefore add --disable-gmp to the configuration options of YAP. Will be back later
Roberto

The problem seems to be that Yap defines its own allocation functions for gmp objects:
#ifdef USE_GMP /* YAP style memory allocation */ mp_set_memory_functions( AllocBigNumSpace, ReAllocBigNumSpace, FreeBigNumSpace); #endif
This allows Yap to work with such objects in its own stacks. Unfortunately, these functions require for another function, PreAllocBigNum to have been called before. In general, using them is a bit dangerous, because they assume they have control over the global stack.
I suppose Yap is polluting the application space, so the correct solution would be for Yap to reset these functions before entering user code. But this would make the interface slower for any application that doesn't use GMP.
A compromise might be for me to provide two interface functions (YapResetGMPFunctions() and YapSet GMPFunctions()) and for you to call them before you started manipulating GMP objects.
Cheers,
Vitor

Vitor Santos Costa wrote:
The problem seems to be that Yap defines its own allocation functions for gmp objects:
#ifdef USE_GMP /* YAP style memory allocation */ mp_set_memory_functions( AllocBigNumSpace, ReAllocBigNumSpace, FreeBigNumSpace); #endif
This allows Yap to work with such objects in its own stacks. Unfortunately, these functions require for another function, PreAllocBigNum to have been called before. In general, using them is a bit dangerous, because they assume they have control over the global stack.
I suppose Yap is polluting the application space, so the correct solution would be for Yap to reset these functions before entering user code. But this would make the interface slower for any application that doesn't use GMP.
A compromise might be for me to provide two interface functions (YapResetGMPFunctions() and YapSet GMPFunctions()) and for you to call them before you started manipulating GMP objects.
Why is not Yap calling PreAllocBigNum first? I mean, initializing things so that AllocBigNumSpace and friends work correctly would seem something to be done in the first lines of Yap's main function. Wouldn't this solve all the problems? The PPL does not really care where GMP takes the memory from: if it comes from Yap's stacks that is fine. In other words, PPL just uses the GMP's entry point without making any further assumption. All the best
Roberto

Vitor Santos Costa wrote:
The problem seems to be that Yap defines its own allocation functions for gmp objects:
#ifdef USE_GMP /* YAP style memory allocation */ mp_set_memory_functions( AllocBigNumSpace, ReAllocBigNumSpace, FreeBigNumSpace); #endif
This allows Yap to work with such objects in its own stacks. Unfortunately, these functions require for another function, PreAllocBigNum to have been called before. In general, using them is a bit dangerous, because they assume they have control over the global stack.
I suppose Yap is polluting the application space, so the correct solution would be for Yap to reset these functions before entering user code. But this would make the interface slower for any application that doesn't use GMP.
A compromise might be for me to provide two interface functions (YapResetGMPFunctions() and YapSet GMPFunctions()) and for you to call them before you started manipulating GMP objects.
Hi Vitor,
I believe that calling mp_set_memory_functions repeatedly would mean that we must abandon all the guarantees provided by GMP's interface. In fact, the following paragraph is taken from GMP's manual:
@strong{Be sure to call @code{mp_set_memory_functions} only when there are no active GMP objects allocated using the previous memory functions! Usually that means calling it before any other GMP function.}
Ciao
Roberto

Hi Roberto,
I believe that calling mp_set_memory_functions repeatedly would mean that we must abandon all the guarantees provided by GMP's interface. In fact, the following paragraph is taken from GMP's manual:
@strong{Be sure to call @code{mp_set_memory_functions} only when there are no active GMP objects allocated using the previous memory functions! Usually that means calling it before any other GMP function.}
I have to think a bit about this. The functions are really not ok to be exported right now. On the other hand what you want to do is quite legitimate. It's a bit of the minefield, let me consider the best alternative.
Cheers
Vitor

Hi Vitor,
I believe that calling mp_set_memory_functions repeatedly would mean that we must abandon all the guarantees provided by GMP's interface. In fact, the following paragraph is taken from GMP's manual:
@strong{Be sure to call @code{mp_set_memory_functions} only when there are no active GMP objects allocated using the previous memory functions! Usually that means calling it before any other GMP function.}
Ciao
Roberto
Hi Roberto,
I changed the Yap GMP allocation routines to fall back to malloc/realloc/free if outside context. I think that is the best solution for two reasons:
- It is the most general: external processes might not want their objects to disappear during backtracking. - It avoids nasty interactions with the garbage collector: even I disallow gc of these objects, is application is not prepared for the gc barging in and shifting objects around?
I haven't actually tested it outside Yap, do you mind trying it and telling me it works?
Thanks
Vitor

Vitor Santos Costa wrote:
I changed the Yap GMP allocation routines to fall back to
malloc/realloc/free if outside context. I think that is the best solution for two reasons:
- It is the most general: external processes might not want their objects to disappear during backtracking.
- It avoids nasty interactions with the garbage collector: even I disallow gc of these objects, is application is not prepared for the gc barging in and shifting objects around?
I haven't actually tested it outside Yap, do you mind trying it and telling me it works?
Hi Vitor,
I can confirm I am no longer observing the problem we had with GLP. (I am observing other problems, but more debugging work is needed to properly identify them.) Thanks a lot
Roberto

Vitor Santos Costa wrote:
I changed the Yap GMP allocation routines to fall back to malloc/realloc/free if outside context. I think that is the best solution for two reasons:
- It is the most general: external processes might not want their objects to disappear during backtracking.
- It avoids nasty interactions with the garbage collector: even I disallow gc of these objects, is application is not prepared for the gc barging in and shifting objects around?
I haven't actually tested it outside Yap, do you mind trying it and telling me it works?
Dear Vitor,
with your change I have succeeded, after fixing a couple of bugs on my part, at producing a working YAP interface for the Parma Polyhedra Library. This will be part of the next PPL release. BTW, finding these bugs has been exceptionally difficult due to the fact that Term, Functor and Atom are all typedef'd to be CELL: this means you can do all sorts of mistakes without any help from the C compiler. Thanks again for you help. All the best
Roberto

Hi Roberto,
with your change I have succeeded, after fixing a couple of bugs on my part, at producing a working YAP interface for the Parma Polyhedra Library. This will be part of the next PPL release.
Great.
BTW, finding these bugs has been exceptionally difficult due to the fact that Term, Functor and Atom are all typedef'd to be CELL: this means you can do all sorts of mistakes without any help from the C compiler.
Yes, actually it is possible to have them being different types.
Thanks again for you help.
Thanks for your work, great news!
Cheers,
Vitor

Dear Roberto,
with your change I have succeeded, after fixing a couple of bugs on my part, at producing a working YAP interface for the Parma Polyhedra Library. This will be part of the next PPL release. BTW, finding these bugs has been exceptionally difficult due to the fact that Term, Functor and Atom are all typedef'd to be CELL: this means you can do all sorts of mistakes without any help from the C compiler.
That is quite a reasonable complaint, they actually have different types in Yap itself. I fixed it.
Cheers,
Vitor
participants (2)
-
Roberto Bagnara
-
Vitor Santos Costa