[M3devel] unix - unknown qualification
Rodney M. Bates
rodney_bates at lcwb.coop
Fri Jul 13 14:54:37 CEST 2012
Sounds like a good idea to me. IT moves the M3/C boundary back just
enough to pick up all the #ifdef stuff, etc.
but not the application-specific code.
On 07/13/2012 04:33 AM, Jay K wrote:
> Hey, how about I just provide copying wrappers here, like we do for stat?
> Where we define an idealized portable struct flock and copy it back and forth in C to the real struct flock?
>
> It is a little strange -- the wrapper is fnctl.
> It must check the first parameter, and know/assume its meaning.
>
>
> - Jay
>
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--
> From: jay.krell at cornell.edu
> To: pgoltzsch at gmail.com; m3devel at elegosoft.com
> Date: Thu, 12 Jul 2012 22:12:49 +0000
> Subject: Re: [M3devel] unix - unknown qualification
>
> Unix.i3 has always been a maintenance and portability problem.
> As such, it has been dramatically reduced.
> This stuff was probably removed, esp. struct_flock.
> The constants can exposed easily enough, portably, but aren't useful without the struct, prpbably.
>
>
> You REALLY REALLY REALLY want to write this in C.
> Writing it in Modula-3 has many downsides. You lose safety. You losestatic checking. You loseportability.
> You gain infinitely small efficiency.
> Something like:
>
>
> jbook2:libm3 jay$ pwd
> /dev2/cm3/m3-libs/libm3
> jbook2:libm3 jay$ find . | xargs grep flock
> ./src/os/POSIX/FilePosixC.c:saves us from having to declare struct flock, which is gnarled up in #ifdefs.
> ./src/os/POSIX/FilePosixC.c: struct flock lock;
> ./src/os/POSIX/FilePosixC.c: struct flock lock;
> ./tests/os/src/locktest.c: struct flock param;
>
>
> ./src/os/POSIX/FilePosixC.c:
>
> /* Copyright (C) 1993, Digital Equipment Corporation */
> /* All rights reserved. */
> /* See the file COPYRIGHT for a full description. */
>
> /*
> Writing part of libm3/os/POSIX/FilePosix.m3/RegularFileLock, RegularFileUnlock in C
> saves us from having to declare struct flock, which is gnarled up in #ifdefs.
>
> see http://www.opengroup.org/onlinepubs/009695399/functions/fcntl.html
> */
>
> #include "m3core.h"
> #include <string.h>
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> #define FALSE 0
> #define TRUE 1
>
> INTEGER FilePosixC__RegularFileLock(int fd)
> {
> struct flock lock;
> int err;
>
> ZeroMemory(&lock, sizeof(lock));
> lock.l_type = F_WRLCK;
> lock.l_whence = SEEK_SET;
>
> if (fcntl(fd, F_SETLK, &lock) < 0)
> {
> err = errno;
> if (err == EACCES || err == EAGAIN)
> return FALSE;
> return -1;
> }
> return TRUE;
> }
>
> INTEGER FilePosixC__RegularFileUnlock(int fd)
> {
> struct flock lock;
>
> ZeroMemory(&lock, sizeof(lock));
> lock.l_type = F_UNLCK;
> lock.l_whence = SEEK_SET;
>
> return fcntl(fd, F_SETLK, &lock);
> }
>
> #ifdef __cplusplus
> } /* extern "C" */
> #endif
>
>
>
> We can add this to libm3 probably.
>
>
> - Jay
>
>
> > Date: Thu, 12 Jul 2012 14:58:11 +0200
> > From: pgoltzsch at gmail.com
> > To: m3devel at elegosoft.com
> > Subject: Re: [M3devel] unix - unknown qualification
> >
> > >>>>> Rodney M. Bates wrote:
> >
> > > I think we need to see some source code for ClsShare.m3.
> > > particularly to see what is before the dot on these lines. I
> > > don't see any of the failing qualifications in Unix.i3 in my
> > > cm3 directory.
> >
> > The first errors are caused by the following procedure,
> > which seems to copied from old DEC example code as I found
> > out while looking for a solution:
> >
> > PROCEDURE FilePartLock( h : INTEGER; start, len : INTEGER ) : BOOLEAN RAISES {OSError.E} =
> > VAR flock := Unix.struct_flock {
> > l_type := Unix.F_WRLCK,
> > l_whence := Unix.L_SET,
> > l_start := 0,
> > l_len := 0, (* i.e., whole file *)
> > l_pid := 0 }; (* don't care *)
> > BEGIN
> > flock.l_start := start;
> > flock.l_len := len;
> > IF Unix.fcntl( h, Unix.F_SETLK, LOOPHOLE( ADR( flock ), Ctypes.long ) ) < 0
> > THEN
> > IF Uerror.errno = Uerror.EACCES OR
> > Uerror.errno = Uerror.EAGAIN THEN
> > RETURN FALSE
> > END;
> > OSErrorPosix.Raise()
> > END;
> > RETURN TRUE
> > END FilePartLock;
> >
> >
> >
> > Regards,
> >
> > Patrick
More information about the M3devel
mailing list