Subject: Re: [SWIPL] Querying PL from C, under Freebsd.

From: Jan Wielemaker <[email-masked]>
Date: Thu, 31 Jan 2002 10:49:01 +0100

> I am facing a problem that I really don't know how to solve 
> fast, may be one could help, it would be great thanks.
> I was calling PL from C, under freeBSD in a usual way 
> looking like this.
> 
> term_t a0;
> predicate_t p;
> qid_t q;
> 
> a0 = PL_new_term_ref();
> .....
> ....
> 
> when I tested my application, it stucks, and if I don't 
> stop it fast enougth, it makes my pager process complain 
> strongly, and them kill the app and core it.
> I found that the problem was coming from the term 
> allocation ( a0 = PL_new_term_ref() ), and when I checked 
> in SwiPL doc, I found this :
> "
> term_t PL_new_term_ref()
> Return a fresh reference to a term. The reference is 
> allocated on the local stack. Allocating a term-reference 
> may trigger a stack-shift on machines that cannot use 
> sparse-memory management for allocation the Prolog stacks. 
> The returned reference describes a variable. 
> "
> I though so that my freebsd (4.0) cannot use sparse memory 
> management...is there a way to solve this problem, or do I 
> have to implement a sparse memory management or forget 
> about working under BSD (very sad).

Even if you don't have sparce memory management, this should not be a
problem.  When calling PL_new_term_ref() in a loop you should use
the *foreign_frame() functions to discard created term-references,
but just a plain call should work nicely.  Any possibility to repeat
this here, or is it dependent on a very odd situation?

Any machine worth mentioning these days should support enough of mmap()
to make mapped stacks work.  Can you provide a login?

	Cheers --- Jan