[m-rev.] for review: library changes for `mmc --make' on Windows
Simon Taylor
stayl at cs.mu.OZ.AU
Thu Jul 24 04:38:46 AEST 2003
On 24-Jul-2003, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 15-Jun-2003, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> ...
> > +% Can we retrieve inodes on this system.
> > +:- type file_id
> > + ---> file_id(device :: int, inode :: int).
> > +:- pred io__file_id_2(string, int, string, int, int,
> > + io__state, io__state).
> > +:- mode io__file_id_2(in, out, out, out, out, di, uo) is det.
> > +
> > +:- pragma foreign_proc("C",
> > + io__file_id_2(FileName::in, Status::out, Msg::out,
> > + Device::out, Inode::out, IO0::di, IO::uo),
> > + [will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
> > +"{
> > +#ifdef MR_HAVE_STAT
> > + struct stat s;
> > + if (stat(FileName, &s) == 0) {
> > + Device = s.st_dev;
> > + Inode = s.st_ino;
>
> This code assumes that a dev_t and an ino_t are integral types
> that will fit into a Mercury int. This assumption is false,
> and results in a compilation error on mars with lcc, where
> dev_t is a struct type (because it is 64 bits and lcc has no
> 64-bit integral type).
That dev_t is a struct is a bug in glibc, because according to POSIX
dev_t is meant to be an integral type. (There's no portable way to
compare structs for equality, and equality test is the only operation
that makes sense for dev_t). So, basically, code which uses glibc's
dev_t can only be compiled with gcc, unless you include lots
of system-specific hackery.
> Probably the best fix is to use a foreign_type instead.
> The foreign type would have to be defined carefully using appropriate
> #ifdefs, because on non-Posix systems dev_t and ino_t might not exist.
That needs to be done, but what's the best way to define the
unification predicate, given the above?
Simon.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list