propagating errno from c extensions

A

Ara.T.Howard

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 :: http://www.ngdc.noaa.gov/stp/
| 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'
===============================================================================
 
N

nobu.nokada

Hi,

At Fri, 5 Dec 2003 11:57:05 +0900,
Ara.T.Howard said:
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.
 
A

Ara.T.Howard

Date: Fri, 5 Dec 2003 12:38:00 +0900
From: (e-mail address removed)
Newsgroups: comp.lang.ruby
Subject: Re: propagating errno from c extensions

Hi,

At Fri, 5 Dec 2003 11:57:05 +0900,


rb_sys_fail()

thanks. didn't realize that's what that did!
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
================
....
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 :: http://www.ngdc.noaa.gov/stp/
| 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'
===============================================================================
 
N

nobu.nokada

Hi,

At Fri, 5 Dec 2003 14:02:05 +0900,
Ara.T.Howard said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[RCR] Kernel#hostname 0
puts(derived_from_array) 0
make MISSING=flock.o 0
tk file dialog and directories 3
io/nonblock 4
ruby advocacy 3
flock vs fcntl and nfs 0
TkRoot.new :width => 4, :height => 2 1

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top