[mercury-users] map and c_pointer
Tyson Dowd
trd at cs.mu.OZ.AU
Mon Apr 15 11:11:07 AEST 2002
On 11-Apr-2002, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> On 11-Apr-2002, Michael Day <mikeday at bigpond.net.au> wrote:
> > If I have a map(string, foo), where foo ---> foo(c_pointer), should I
> > expect a segfault when I attempt to insert a value into the map?
>
> Why? Unification and comparison of c_pointers is handled by address
> comparison, so map(foo, string) would also work. The Mercury code
> won't even care whether the pointers are valid. You have to really
> be trying to get a segfault in Mercury.
Just as a side note, address comparison doesn't work for backends with
garbage collectors which move pointers. In general it is not a good idea
to do things this way -- you should use a stable name for this kind
of code. We don't have a general stable name system yet.
See:
@inproceedings{ jones99stretching,
author = "Simon L. Peyton Jones and Simon Marlow and Conal Elliott",
title = "Stretching the Storage Manager: Weak Pointers and Stable Names in Haskell",
booktitle = "Implementation of Functional Languages",
pages = "37-58",
year = "1999",
url = "citeseer.nj.nec.com/peytonjones99stretching.html"
}
for how this can be done and why.
There was code that did this on startup of the Mercury runtime system
(sorted a map on c_pointers) which causes quite a lot of trouble with both
the accurate GC and .NET backend.
Any code that interfaces to C and passes C pointers around is not pure
Mercury code anyway, so you don't have to try that *hard* to get a
segfault.
--
Tyson Dowd #
# Surreal humour isn't everyone's cup of fur.
trd at cs.mu.oz.au #
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list