Defining allocate is deprecated; use rb_define_alloc_func instead

Hello, I’m trying to upgrade RR to Ruby 1.9.2.

I’m getting the following warning:

warning: defining StrongSpecFixture.allocate is deprecated; use
rb_define_alloc_func()

Is there a way to redefine allocate in Ruby in a way that works across
all of the different Ruby implementations (JRuby, Rubinius, etc)?

Thank you,
Brian

On Sat, Oct 30, 2010 at 6:07 PM, Brian T. [email protected]
wrote:

Hello, I’m trying to upgrade RR to Ruby 1.9.2.

I’m getting the following warning:

warning: defining StrongSpecFixture.allocate is deprecated; use
rb_define_alloc_func()

Is there a way to redefine allocate in Ruby in a way that works across
all of the different Ruby implementations (JRuby, Rubinius, etc)?

Not really. Most impls, including MRI and JRuby, don’t actually
dispatch to allocate when constructing a new object, so there’s no way
to replace it at runtime. This is done partially for performance
reasons, and partially (at least in JRuby’s case) because allocate
initializes impossible-to-initialize-any-other-way internal state for
the object, so replacing it would be a bad thing.

JRuby 1.6 does provide a solid start on a compatible C API, though, so
if it’s native-level allocate binding you need, that’s an option. And
of course there’s impl-specific ways to do this entirely from Ruby
code in JRuby and probably others.

  • Charlie