[mercury-users] announced: libtiff foreign interface (caveats)

Peter Wang wangp at students.csse.unimelb.edu.au
Wed Feb 7 13:30:18 AEDT 2007


On 2007-02-06, doug.auclair at logicaltypes.com <doug.auclair at logicaltypes.com> wrote:
> Dear all, Peter wrote:
> 
> >The mutex only protects a single foreign_proc at a time.  It doesn't
> >prevent two instances of read_to_matrix or write_as_tiff from executing
> >at the same time, for example.  You'd need to get rid of the two globals
> >in libtiff_io.c and pass them around as parameters.
> 
> *sigh!* And that was exactly why I wrote the warning as I did!  Change #2
> on its way.  Good catch, Peter!
> 
> Two questions: does this change make the library thread safe?

If the libtiff functions are thread-safe, then I think it should be okay.

> The cast it complains about is converting a c_pointer type to an external C pointer
> type!  Can this warning be eliminated?

Use pragma foreign_type, e.g.

    :- type image.
    :- pragma foreign_type("C", image, "struct image *").

BTW, you really should make some of your predicates take I/O states and
return error codes.

Peter

--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list