[Vm-dev] [PATCH] added FilePlugin error code lookup function

Eliot Miranda eliot.miranda at gmail.com
Thu Mar 22 02:07:32 UTC 2018


Hi Ben, Hi Alistair, Hi Monty,

    I have thought for a long time that the way to go this is to generate a C program and compile it either to a shared object or, as Mariano and others suggested and implemented, have its output be the values needed.  See the Pharo dev thread "Can OSProcess functionality be implemented using FFI instead of plugin?".  The key idea is to maintain a per-host-type pool of constants, comprising error codes, ioctls, typedefs, etc, whatever one needs, and have the C be generated from the pool.  The C source is needed only at development time.  I think Mariano settled on STON as the C output format.  Anyway, I'm not reiterating here.  I will say that coming up with a different solution per plugin is a waste of effort when one can find up with a general scheme that will serve many needs and b extensible with very little effort.  The key idea is that one gets the system to generate a C program that is compiled and run on each host type and that compiled form or its output therefore faithfully reflects the values of error codes, types etc of the host.

_,,,^..^,,,_ (phone)

> On Mar 21, 2018, at 6:04 PM, Ben Coman <btc at openinworld.com> wrote:
> 
> 
> 
> On 21 March 2018 at 22:28, monty <monty2 at programmer.net> wrote:
> >
> >
> > The SQ_FILE_*_ERROR codes can be mapped directly to an expanded file exception hierarchy, so an appropriate exception class can be thrown (and caught) on failure. #primitiveFailForOSError: can be used for this. Or it can be used with the raw errno/GetLastError() codes, and a sqFileErrorCodeFromSystemErrorCode()-based primitive can be used after to map it.
> >
> > The exact values of the errno.h E* defines are technically unspecified,
> 
> By "unspecified" do you just mean that they are different between platforms.
> What about embedding  errno.h  in the compiled VM and let the Image side browse and parse it, so the error mapping/condensing can be done Image-side?
> I'm not sure of the difficulty to do this since I haven't done it before,
> but maybe something like...  https://stackoverflow.com/questions/410980/include-a-text-file-in-a-c-program-as-a-char
> 
> 
> > We need some way in-image to portably, correctly distinguish certain failure modes (like a file not existing) from others. (Code in the current Squeak image just guesses.)
> 
> This should(?) portably provide the exact C label for a numeric error.  
> The Image-side might need per-platform mapping/condensing, but still may be nicer to do it there.
> 
> cheers -ben
> 
>  
> >
> > and the perror()/strerror_r() messages are locale-specific: http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_03
> >
> > I would like to hear more ideas.
> >
> > > Sent: Wednesday, March 21, 2018 at 7:08 AM
> > > From: "Alistair Grant" <akgrant0710 at gmail.com>
> > > To: "Squeak Virtual Machine Development Discussion" <vm-dev at lists.squeakfoundation.org>
> > > Subject: Re: [Vm-dev] [PATCH] added FilePlugin error code lookup function
> > >
> > >
> > > Hi Monty,
> > >
> > > The VM has a primitive failure that allows the OS error to be
> > > returned: #primitiveFailForOSError:
> > >
> > > Why not simply return the OS error and allow the image to deal with it?
> > >
> > > Cheers,
> > > Alistair
> > >
> > >
> > >
> > > On 21 March 2018 at 07:52, monty <monty2 at programmer.net> wrote:
> > > >
> > > >
> > > > +enum {
> > > > +       SQ_FILE_ERROR,
> > > > +       SQ_FILE_PERMISSION_ERROR,
> > > > +       SQ_FILE_ALREADY_EXISTS_ERROR,
> > > > +       SQ_FILE_DOES_NOT_EXIST_ERROR,
> > > > +       SQ_FILE_RESOURCE_LIMIT_ERROR,
> > > > +       SQ_FILE_INVALID_OPERATION_ERROR,
> > > > +       SQ_FILE_IO_ERROR,
> > > > +       SQ_FILE_BAD_HANDLE_ERROR,
> > > > +       SQ_FILE_IS_DIRECTORY_ERROR,
> > > > +       SQ_FILE_IS_NOT_DIRECTORY_ERROR,
> > > > +       SQ_FILE_INVALID_NAME_ERROR,
> > > > +       SQ_FILE_IN_PROGRESS_ERROR
> > > > +};
> > > > 
> > > > +
> > > > +sqInt
> > > > +sqFileErrorCodeFromSystemErrorCode(sqInt errorCode)
> > > > +{
> > > > +       /* A switch statement is avoided, since some error codes, like EAGAIN/EWOULDBLOCK, can
> > > > +          overlap, and EINTR is not propagated as SQ_FILE_IN_PROGRESS_ERROR, since it should be
> > > > +          handled internally where possible and because only certain operations can be safely
> > > > +          reattempted after failing with EINTR
> > > > +       */
> > > > +       if (errorCode == EACCES
> > > > +               || errorCode == EPERM
> > > > +               || errorCode == EROFS)
> > > > +               return SQ_FILE_PERMISSION_ERROR;
> > > > +       else if (errorCode == EEXIST)
> > > > +               return SQ_FILE_ALREADY_EXISTS_ERROR;
> > > > +       else if (errorCode == ENOENT
> > > > +               || errorCode == ENODEV
> > > > +               || errorCode == ENXIO)
> > > > +               return SQ_FILE_DOES_NOT_EXIST_ERROR;
> > > > +       else if (errorCode == EDQUOT
> > > > +               || errorCode == EFBIG
> > > > +               || errorCode == EMFILE
> > > > +               || errorCode == EMLINK
> > > > +               || errorCode == ENFILE
> > > > +               || errorCode == ENOLCK
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20180321/987a2950/attachment-0001.html>


More information about the Vm-dev mailing list