[Haskell-cafe] How to deal with pointers to pointers in the FFI

Jefferson Heard jefferson.r.heard at gmail.com
Fri Oct 17 15:12:49 EDT 2008


I have the following functions in C:

OGRErr 	OGR_G_CreateFromWkb (unsigned char *, OGRSpatialReferenceH,
OGRGeometryH *, int)
OGRErr 	OGR_G_CreateFromWkt (char **, OGRSpatialReferenceH, OGRGeometryH *)
void 	OGR_G_DestroyGeometry (OGRGeometryH)
OGRGeometryH 	OGR_G_CreateGeometry (OGRwkbGeometryType)

The normal sequence of calls is

OGRGeometryH handle = OGR_G_CreateGeometry(SOME_TYPE);
// do stuff
OGR_G_DestroyGeometry(handle);

OR

OGR_G_CreateFromWkb(blob, ref, &handle, 0);
// do stuff
OGR_G_DestroyGeometry(handle);

As you can see, in one case, I have to pass in a pointer to the
returned handle, and not just the handle.  How can I accomplish this
feat using a single type?

I had

data OGRGeometryH
type Geometry = Ptr OGRGeometryH

but then can I declare that a function returns a

Ptr (Geometry)

?



-- 
I try to take things like a crow; war and chaos don't always ruin a
picnic, they just mean you have to be careful what you swallow.

-- Jessica Edwards


More information about the Haskell-Cafe mailing list