[Win32utils-devel] Converting rb_protect + ruby_stop to pure Ruby

Heesob Park phasis at gmail.com
Mon May 1 20:29:38 EDT 2006


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



More information about the win32utils-devel mailing list