Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Need help understanding exceptions handling from C extensions

Reply
Thread Tools

Need help understanding exceptions handling from C extensions

 
 
Jacob Repp
Guest
Posts: n/a
 
      02-21-2006
I'm working on the test cases for my AIO extension library on windows
and I have been running into this error consistently on one of my
tests:

test_addr_lookup_name_async(ClientTest):
ArgumentError: NULL pointer given
tc_client.rb:129:in `to_s'
tc_client.rb:129:in `test_addr_lookup_name_async'

The offending line is in the rescue block:

begin
q =3D AIOQueue.new
a =3D AIOAddr.new(q)
c =3D Callback.new
n =3D 0

assert(a.is_attached?, "should be attached")
a.lookup("www.google.com", c, :lookup_complete)

5.times { n +=3D q.process(100) }

assert(c.lookups =3D=3D 1, "didn't receive lookup callback")
assert(n =3D=3D 1, "not enough contexts processed")
rescue Exception =3D> ex
puts "caught #{ex}"
end

The exception is raised from q.process which hooks directly to a C
functions and makes another function call to an internal API I
defined. In this code I have my async context handler:

case CTX_ADDR_LOOKUP:
rb_funcall(
pctx->recvr,
pctx->symbid,
1,
=20
UINT2NUM(((Address*)(pctx->pbase))->addr.sin_addr.s_addr));

I believe this is 'raising' an exception. I see in other extensions
the usage of rb_protect() etc. I am under the impression that setjmp,
longjmp is being used to simulate exceptions in ruby, of which I'm
unfortunately not an expert in the usage.

I would like to be able to call out to ruby code without losing my
instruction pointer so that I may deliver the error to a registered
async error facility.

If someone could smack me over the head with a clue-by-four right now
that would be most appreciated

Of course I will continue learning and experimenting but I thouht this
would be a good time to solicit the knowledge of ruby-talk.


 
Reply With Quote
 
 
 
 
Jacob Repp
Guest
Posts: n/a
 
      02-21-2006
I caught the exception using rb_protect() but there is still a problem:

rbaio.c(1279): ruby error: NoMethodError: ???
rbaio.c(1292): from tc_client.rb:125:in `process'
rbaio.c(1292): from tc_client.rb:125:in `test_addr_lookup_name_async'

The class name I can interpret okay but when I take $! and call the
to_s method on it I get another exception because of the NULL issue. I
don't yet know why that is the case.

lasterr =3D rb_gv_get("$!");

// class and message
klass =3D rb_class_path(CLASS_OF(lasterr));
//message =3D rb_obj_as_string(lasterr);
DBG2("ruby error: %s: %s", RSTRING(klass)->ptr,
"???");//RSTRING(message)->ptr);

Uncommenting the conversion to string results in the NULL error.

On 2/20/06, Jacob Repp <(E-Mail Removed)> wrote:
> I'm working on the test cases for my AIO extension library on windows
> and I have been running into this error consistently on one of my
> tests:
>
> test_addr_lookup_name_async(ClientTest):
> ArgumentError: NULL pointer given
> tc_client.rb:129:in `to_s'
> tc_client.rb:129:in `test_addr_lookup_name_async'
>
> The offending line is in the rescue block:
>
> begin
> q =3D AIOQueue.new
> a =3D AIOAddr.new(q)
> c =3D Callback.new
> n =3D 0
>
> assert(a.is_attached?, "should be attached")
> a.lookup("www.google.com", c, :lookup_complete)
>
> 5.times { n +=3D q.process(100) }
>
> assert(c.lookups =3D=3D 1, "didn't receive lookup callback")
> assert(n =3D=3D 1, "not enough contexts processed")
> rescue Exception =3D> ex
> puts "caught #{ex}"
> end
>
> The exception is raised from q.process which hooks directly to a C
> functions and makes another function call to an internal API I
> defined. In this code I have my async context handler:
>
> case CTX_ADDR_LOOKUP:
> rb_funcall(
> pctx->recvr,
> pctx->symbid,
> 1,
>
> UINT2NUM(((Address*)(pctx->pbase))->addr.sin_addr.s_addr));
>
> I believe this is 'raising' an exception. I see in other extensions
> the usage of rb_protect() etc. I am under the impression that setjmp,
> longjmp is being used to simulate exceptions in ruby, of which I'm
> unfortunately not an expert in the usage.
>
> I would like to be able to call out to ruby code without losing my
> instruction pointer so that I may deliver the error to a registered
> async error facility.
>
> If someone could smack me over the head with a clue-by-four right now
> that would be most appreciated
>
> Of course I will continue learning and experimenting but I thouht this
> would be a good time to solicit the knowledge of ruby-talk.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding Assert and Exceptions mailforpr@googlemail.com C++ 29 10-17-2006 02:12 PM
Understanding and Using Exceptions Anonieko ASP .Net 1 06-15-2006 02:11 PM
Unable to access extensions menu or add extensions (I've tried past suggestions) nospam@spam.com Firefox 8 12-01-2005 01:33 AM
Checked exceptions vs unchecked exceptions Ahmed Moustafa Java 5 07-14-2004 01:46 PM
Custom exceptions -- inherit from exceptions.Exception? Paul Miller Python 3 11-12-2003 09:24 AM



Advertisments