Subject: Re: [SWIPL] PL_unify

From: Jan Wielemaker <[email-masked]>
Date: Thu, 27 Sep 2001 11:22:04 +0200

On Mon, 30 Jul 2001, Nissim Broudo wrote:
>
>I'm calling SWI-Prolog from C.  I need to use the bindings produced by one query in the input to a second query and I am encountering a problem.  I am using PL_unify.  The problem I am encountering is in a call like this:
>
>foreign_t my_query(term_t in) {
>
>int rval;
>term_t temp;
>char *st = "atom_string";
>PL_unify_atom_chars(temp, st);
>rval = PL_unify(temp,in);
>
>return rval; }
>
>Prolog reports an error:
>
>1 ?- my_query(X).
>
>ERROR: my_query/1: Caught signal 11 (segv)

temp is not initialised.  Use 

term_t temp = PL_new_term_ref();

None of these functions can be used on a not-initialised term_t
variable.  A term-reference is the address of a cell on the local
stack that holds the actual Prolog term.  This way Prolog knows
which terms are referenced by foreign code and should thus be
updated by the garbage collector.  I think the idea for this
originated at Quintus.  If you do a lot with foreign code make
sure you understand term-references.

	Regards --- Jan