| 1 |
#include "ruby.h" |
| 2 |
|
| 3 |
VALUE rb_str_dup(VALUE str); |
| 4 |
|
| 5 |
static VALUE |
| 6 |
bug_rb_str_dup(VALUE self, VALUE str) |
| 7 |
{ |
| 8 |
rb_check_type(str, T_STRING); |
| 9 |
return rb_str_dup(str); |
| 10 |
} |
| 11 |
|
| 12 |
static VALUE |
| 13 |
bug_shared_string_p(VALUE self, VALUE str) |
| 14 |
{ |
| 15 |
rb_check_type(str, T_STRING); |
| 16 |
return RB_FL_TEST(str, RUBY_ELTS_SHARED) && RB_FL_TEST(str, RSTRING_NOEMBED) ? Qtrue : Qfalse; |
| 17 |
} |
| 18 |
|
| 19 |
static VALUE |
| 20 |
bug_sharing_with_shared_p(VALUE self, VALUE str) |
| 21 |
{ |
| 22 |
rb_check_type(str, T_STRING); |
| 23 |
if (bug_shared_string_p(self, str)) { |
| 24 |
return bug_shared_string_p(self, RSTRING(str)->as.heap.aux.shared); |
| 25 |
} |
| 26 |
return Qfalse; |
| 27 |
} |
| 28 |
|
| 29 |
void |
| 30 |
Init_string_rb_str_dup(VALUE klass) |
| 31 |
{ |
| 32 |
rb_define_singleton_method(klass, "rb_str_dup", bug_rb_str_dup, 1); |
| 33 |
rb_define_singleton_method(klass, "shared_string?", bug_shared_string_p, 1); |
| 34 |
rb_define_singleton_method(klass, "sharing_with_shared?", bug_sharing_with_shared_p, 1); |
| 35 |
} |