From jan@swi.psy.uva.nl Thu Jan 31 10:49:01 2002
Received: from gollem.swi.psy.uva.nl (root@gollem.swi.psy.uva.nl [145.18.152.30])
	by swi.psy.uva.nl (8.11.6/8.11.2) with ESMTP id g0V9n1L08295;
	Thu, 31 Jan 2002 10:49:01 +0100 (MET)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.11.6/8.11.6/SuSE Linux 0.5) id g0V9n1C12047;
	Thu, 31 Jan 2002 10:49:01 +0100
Date: Thu, 31 Jan 2002 10:49:01 +0100
Message-Id: <200201310949.g0V9n1C12047@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: [SWIPL] Querying PL from C, under Freebsd.
To: Yan Guiborat <yan.guiborat@caramail.com>, prolog@swi.psy.uva.nl
In-Reply-To: Yan Guiborat's message of Thu, 31 Jan 2002 10:33:08 GMT+1
Phone: +31 - 20 - 525 6121

> 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


