Propagating errno from c extensions

rubyists-

any strong opinions on handling errno from c extentions?

personally, it seems that one would want to raise an exception like

Errno::EACCESS

when errno == EACCESS

however i see many cases where functions simply return Qfalse, Qtrue, etc. for
broad catagories of errno values - leaving the user to guess as to the cause
of the error (eg. rb_file_flock). is there are way of getting at errno that i
am unaware of? if so perhaps this is o.k…

IMHO a VHLL like ruby should either

a) succeed

b) throw an error

and one should never explcitly need to check error codes.

-a

···

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

Hi,

any strong opinions on handling errno from c extentions?

rb_sys_fail()

however i see many cases where functions simply return Qfalse, Qtrue, etc. for
broad catagories of errno values - leaving the user to guess as to the cause
of the error (eg. rb_file_flock). is there are way of getting at errno that i
am unaware of? if so perhaps this is o.k…

rb_file_flock() raises SystemCallError except for the case it
would block.

···

At Fri, 5 Dec 2003 11:57:05 +0900, Ara.T.Howard wrote:


Nobu Nakada

Date: Fri, 5 Dec 2003 12:38:00 +0900
From: nobu.nokada@softhome.net
Newsgroups: comp.lang.ruby
Subject: Re: propagating errno from c extensions

Hi,

any strong opinions on handling errno from c extentions?

rb_sys_fail()

thanks. didn’t realize that’s what that did!

however i see many cases where functions simply return Qfalse, Qtrue, etc. for
broad catagories of errno values - leaving the user to guess as to the cause
of the error (eg. rb_file_flock). is there are way of getting at errno that i
am unaware of? if so perhaps this is o.k…

rb_file_flock() raises SystemCallError except for the case it
would block.

doesn’t this mean that, under certain return values (EACCES), flock would
simply return false?

file.c

···

On Fri, 5 Dec 2003 nobu.nokada@softhome.net wrote:

At Fri, 5 Dec 2003 11:57:05 +0900, > Ara.T.Howard wrote:
================

2092 retry:
2093 TRAP_BEG;
2094 ret = flock(fileno(fptr->f), NUM2INT(operation));
2095 TRAP_END;
2096 if (ret < 0) {
2097 switch (errno) {
2098 case EAGAIN:
2099 case EACCES:
2100 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
2101 case EWOULDBLOCK:
2102 #endif
2103 return Qfalse;
2104 case EINTR:
2105 #if defined(ERESTART)
2106 case ERESTART:
2107 #endif
2108 goto retry;
2109 }
2110 rb_sys_fail(fptr->path);
2111 }
2112 #endif
2113 return INT2FIX(0);
2114 }

-a

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

Hi,

···

At Fri, 5 Dec 2003 14:02:05 +0900, Ara.T.Howard wrote:

however i see many cases where functions simply return Qfalse, Qtrue, etc. for
broad catagories of errno values - leaving the user to guess as to the cause
of the error (eg. rb_file_flock). is there are way of getting at errno that i
am unaware of? if so perhaps this is o.k…

rb_file_flock() raises SystemCallError except for the case it
would block.

doesn’t this mean that, under certain return values (EACCES), flock would
simply return false?

On some systems, fcntl() fails with not EAGAIN but EACCES when the
file is locked already.


Nobu Nakada