From: Graham Menhennitt Date: 2012-11-22T10:54:05+09:00 Subject: Re: "undefined method `synchronize' for #" from embedded Ruby program This is a multi-part message in MIME format. --------------060408050205090802020601 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 21/11/2012 5:38 PM, Graham Menhennitt wrote: > The error is: > undefined method `synchronize' for # > If I search back over this list's archives, I can see a few other people > with the same problem (but no solution). > > #include > > int > main(int argc, char *argv[]) > { > RUBY_INIT_STACK; > ruby_init(); > ruby_init_loadpath(); > > rb_eval_string("$mutex = Mutex.new"); > rb_eval_string("$mutex.synchronize(){}"); > > return 0; > } > I've done a bit more investigation and found that it happens in all 1.9 releases of Ruby, but it does NOT happen in 1.8.7. The test program below produces: [:locked?, :try_lock, :lock, :unlock, :sleep, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] Whereas running "ruby -e 'p Mutex.new.methods'" produces: [:locked?, :try_lock, :lock, :unlock, :sleep, :synchronize, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__] Note that ":synchronize" is missing from the former. I've tried removing all gems in case one of them was doing something strange. I've searched the Ruby source code, but I can't see anything that might cause this. Anybody got any ideas? Should I take this to ruby.core? Thanks, Graham Test program: #include int main(int argc, char *argv[]) { RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); rb_eval_string("p Mutex.new.methods"); return 0; } --------------060408050205090802020601 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
On 21/11/2012 5:38 PM, Graham Menhennitt wrote:
The error is:
    undefined method `synchronize' for #<Mutex:0xa0f5adc>
If I search back over this list's archives, I can see a few other people
with the same problem (but no solution).

#include <ruby.h>

int
main(int argc, char *argv[])
{
    RUBY_INIT_STACK;
    ruby_init();
    ruby_init_loadpath();

    rb_eval_string("$mutex = Mutex.new");
    rb_eval_string("$mutex.synchronize(){}");

    return 0;
}

I've done a bit more investigation and found that it happens in all 1.9 releases of Ruby, but it does NOT happen in 1.8.7.

The test program below produces:
[:locked?, :try_lock, :lock, :unlock, :sleep, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]
Whereas running "ruby -e 'p Mutex.new.methods'" produces:
[:locked?, :try_lock, :lock, :unlock, :sleep, :synchronize, :nil?, :===, :=~, :!~, :eql?, :hash, :<=>, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :to_s, :inspect, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :object_id, :to_enum, :enum_for, :==, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__, :__id__]

Note that ":synchronize" is missing from the former.

I've tried removing all gems in case one of them was doing something strange. I've searched the Ruby source code, but I can't see anything that might cause this.

Anybody got any ideas? Should I take this to ruby.core?

Thanks,
    Graham

Test program:
#include <ruby.h>

int
main(int argc, char *argv[])
{
    RUBY_INIT_STACK;
    ruby_init();
    ruby_init_loadpath();

    rb_eval_string("p Mutex.new.methods");

    return 0;
}

--------------060408050205090802020601--