summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-02 05:48:29 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-02 05:48:29 +0000
commitbb504213816e4598f1961b99e115f8ba59bef71f (patch)
treeff451d7ff4f58697fb5aff4779c4d8d9740481ad /string.c
parent499b5a9197f68e14873e641b737aea40a0f8bc5a (diff)
* string.c (sym_to_proc, sym_call): A Proc created by Symbol#to_proc
should close over the current refinements. [ruby-dev:46345] [Bug #7261] * vm_eval.c (rb_call0, rb_search_method_entry, rb_funcall_passing_block_with_refinements): add a new argument `refinements' for the above changes. * test/ruby/test_refinement.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37418 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/string.c b/string.c
index 9c79b2104c..ae9af6c85d 100644
--- a/string.c
+++ b/string.c
@@ -14,6 +14,8 @@
#include "ruby/ruby.h"
#include "ruby/re.h"
#include "ruby/encoding.h"
+#include "node.h"
+#include "eval_intern.h"
#include "internal.h"
#include <assert.h>
@@ -7605,15 +7607,18 @@ sym_to_sym(VALUE sym)
}
static VALUE
-sym_call(VALUE args, VALUE sym, int argc, VALUE *argv)
+sym_call(VALUE args, VALUE p, int argc, VALUE *argv)
{
VALUE obj;
+ NODE *memo = RNODE(p);
if (argc < 1) {
rb_raise(rb_eArgError, "no receiver given");
}
obj = argv[0];
- return rb_funcall_passing_block(obj, (ID)sym, argc - 1, argv + 1);
+ return rb_funcall_passing_block_with_refinements(obj, (ID) memo->u1.id,
+ argc - 1, argv + 1,
+ memo->u2.value);
}
/*
@@ -7633,25 +7638,32 @@ sym_to_proc(VALUE sym)
VALUE proc;
long id, index;
VALUE *aryp;
-
- if (!sym_proc_cache) {
- sym_proc_cache = rb_ary_tmp_new(SYM_PROC_CACHE_SIZE * 2);
- rb_gc_register_mark_object(sym_proc_cache);
- rb_ary_store(sym_proc_cache, SYM_PROC_CACHE_SIZE*2 - 1, Qnil);
- }
+ const NODE *cref = rb_vm_cref();
id = SYM2ID(sym);
- index = (id % SYM_PROC_CACHE_SIZE) << 1;
+ if (NIL_P(cref->nd_refinements)) {
+ if (!sym_proc_cache) {
+ sym_proc_cache = rb_ary_tmp_new(SYM_PROC_CACHE_SIZE * 2);
+ rb_gc_register_mark_object(sym_proc_cache);
+ rb_ary_store(sym_proc_cache, SYM_PROC_CACHE_SIZE*2 - 1, Qnil);
+ }
- aryp = RARRAY_PTR(sym_proc_cache);
- if (aryp[index] == sym) {
- return aryp[index + 1];
+ index = (id % SYM_PROC_CACHE_SIZE) << 1;
+ aryp = RARRAY_PTR(sym_proc_cache);
+ if (aryp[index] == sym) {
+ return aryp[index + 1];
+ }
+ else {
+ proc = rb_proc_new(sym_call,
+ (VALUE) NEW_MEMO(id, Qnil, 0));
+ aryp[index] = sym;
+ aryp[index + 1] = proc;
+ return proc;
+ }
}
else {
- proc = rb_proc_new(sym_call, (VALUE)id);
- aryp[index] = sym;
- aryp[index + 1] = proc;
- return proc;
+ return rb_proc_new(sym_call,
+ (VALUE) NEW_MEMO(id, cref->nd_refinements, 0));
}
}