From: "Ara.T.Howard" Date: 2003-12-05T14:02:05+09:00 Subject: Re: propagating errno from c extensions On Fri, 5 Dec 2003 nobu.nokada@softhome.net wrote: > 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, > > At Fri, 5 Dec 2003 11:57:05 +0900, > Ara.T.Howard wrote: > > 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 ================ .... 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' ===============================================================================