Return value of rb_define_class (et al.) can't be stored and reused
-------------------------------------------------------------------

                 Key: JRUBY-6085
                 URL: https://jira.codehaus.org/browse/JRUBY-6085
             Project: JRuby
          Issue Type: Bug
          Components: C Extensions
    Affects Versions: JRuby 1.6
            Reporter: Mon ouïe
            Assignee: Thomas E Enebo
            Priority: Minor


In MRI and Rubinius, one can store the return value of rb_define_class (and 
similar functions) in a global variable and use it for type checks later.

    #include "ruby.h"
    #include <stdio.h>

    VALUE cFoo;

    VALUE is_foo(VALUE self, VALUE obj) {
      if (RTEST(rb_obj_is_kind_of(obj, cFoo))
        printf("it's a foo!\n");
    }

    void Init_foo() {
      cFoo = rb_define_class("Foo");
      rb_define_singleton_method(cFoo, is_foo, "is_foo?", 1);
    }

In JRuby, though, the VALUE will get invalidated after sometimes (causing some 
error messages I don't have right now). Users of the C API have to retrieve the 
constant manually every time to ensure it will work.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to