Daniel Berger
2006-May-02 00:17 UTC
[Win32utils-devel] Converting rb_protect + ruby_stop to pure Ruby
Hi, Within process.c, in the fork method, there''s this bit of code: if(rb_block_given_p()){ int status; rb_protect(rb_yield, Qundef, &status); ruby_stop(status); } I translated that as this: if block_given? status = 0 begin yield rescue Exception status = -1 # Any non-zero result is failure end exit(status) end Is there a way to get the actual status? The $? global isn''t set at this point so that doesn''t seem to be an option. Or is this a reasonable default? This isn''t crucial but I thought I''d ask. Thanks, Dan
Heesob Park
2006-May-02 00:29 UTC
[Win32utils-devel] Converting rb_protect + ruby_stop to pure Ruby
Hi, On 5/2/06, Daniel Berger <djberg96 at gmail.com> wrote:> Hi, > > Within process.c, in the fork method, there''s this bit of code: > > if(rb_block_given_p()){ > int status; > rb_protect(rb_yield, Qundef, &status); > ruby_stop(status); > } > > > I translated that as this: > > if block_given? > status = 0 > begin > yield > rescue Exception > status = -1 # Any non-zero result is failure > end > exit(status) > end > > Is there a way to get the actual status? The $? global isn''t set at this > point so that doesn''t seem to be an option. Or is this a reasonable > default? > > This isn''t crucial but I thought I''d ask. >Here is rb_protect for ruby def rb_protect begin yield ensure return end end rb_protect { return } puts ''return stopped'' rb_protect { exit(1) } puts ''exit stopped'' rb_protect { raise "STOP ME!" } puts ''raise stopped'' rb_protect { throw(:jump) } puts ''throw stopped'' Regards, Park Heesob