No subject

Fergus Henderson fjh at
Sun Nov 30 16:04:44 AEDT 1997

Return-Path: <pets at>
Received: from by with SMTP (5.83--+1.3.1+0.51)
	id AA26624; Thu, 27 Nov 1997 17:25:07 +1100 (from pets at
Received: from localhost (pets at localhost)
	by (8.8.7/8.8.7) with SMTP id RAA23406
	for <mercury-users at>; Thu, 27 Nov 1997 17:25:07 +1100 (EST)
Date: Thu, 27 Nov 1997 17:25:05 +1100 (EST)
From: Peter Schachte <pets at>
X-Sender: pets at
To: mercury-users at
Subject: Re: [mercury-users] Circular lists
In-Reply-To: <199711270428.PAA12766 at>
Message-Id: <Pine.GSO.3.95.971127170405.22549A-100000 at>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Status: RO
Content-Length: 1631
Lines: 33

On Thu, 27 Nov 1997, Richard A. O'Keefe wrote:

> 	I strongly suspect that with Quintus Prolog, just as with Mercury, 
> 	there were undocumented ways of accessing Prolog data structures
> 	from C.
> I just told you there weren't.  At the time I left, even *Quintus* couldn't
> write dynamically loaded foreign code that accessed (let alone tampered
> with) Prolog data structures.

Actually Richard, that's changed.  In QP 3.1, a raft of C functions were
added for accessing and creating Prolog terms from C.  These all preserve
the freedom of the Prolog system to move memory around by not using pointers
directly into the heap, but rather pointers into a special area that gets
fixed up whenever the stacks get shifted or garbage collected.  This area is
also part of the root set for the garbage collector.  The lifetime of these
indirect term references created by passing a term from Prolog to C, or
created by creating a Prolog term from C, is limited to a single call from
Prolog to C (or vice-versa), so C code can't hold onto these things, and so
terms passed to C don't become permanently un-GCable. 

BTW, Fergus' claim that C programs don't have access to non-atomic Mercury
term arguments (if I understood him right) isn't quite true.  The Mercury
reference manual specifies a few C functions/macros that allow Mercury lists
to be constructed/deconstructed.  It's only for lists, though. 

-Peter Schachte			| Politicians are the same all over. They
pets at		| promise to build a bridge even where there is	| no river. -- Nikita Krushchev 
PGP key available on request	| 

More information about the users mailing list