Skip to content

Commit 12f4488

Browse files
committed
merge revision(s) 40525,40526,40528,40530: [Backport ruby#8345]
proc.c: remove unnecessary static function * proc.c (proc_lambda): remove and use rb_block_lambda directly instead. * include/ruby/intern.h (rb_block_lambda): add declaration instead of deprecated rb_f_lambda. * proc.c (mproc, mlambda): use frozen core methods instead of plain global methods, so that methods cannot be overridden. [ruby-core:54687] [Bug ruby#8345] * vm.c (Init_VM): define proc and lambda on the frozen core object. * defs/id.def (predefined): add "idProc". * proc.c (mnew, mproc, mlambda): use predefined IDs. * vm.c (Init_VM): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@41394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent fff6788 commit 12f4488

File tree

7 files changed

+45
-21
lines changed

7 files changed

+45
-21
lines changed

ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Wed Jun 19 03:54:04 2013 Nobuyoshi Nakada <[email protected]>
2+
3+
* defs/id.def (predefined): add "idProc".
4+
5+
* proc.c (mnew, mproc, mlambda): use predefined IDs.
6+
7+
* vm.c (Init_VM): ditto.
8+
9+
Wed Jun 19 03:54:04 2013 Nobuyoshi Nakada <[email protected]>
10+
11+
* include/ruby/intern.h (rb_block_lambda): add declaration instead of
12+
deprecated rb_f_lambda.
13+
114
Wed Jun 19 03:24:07 2013 Kazuki Tsujimoto <[email protected]>
215

316
* include/ruby/ruby.h, vm_eval.c (rb_funcall_with_block):

defs/id.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ firstline, predefined = __LINE__+1, %[\
77
gets
88
succ
99
each
10+
proc
1011
lambda
1112
send
1213
__send__
@@ -48,7 +49,10 @@ const_ids = []
4849
class_ids = []
4950
names = {}
5051
predefined.split(/^/).each_with_index do |line, num|
51-
next if /^#/ =~ line or (name, token = line.split; !name)
52+
next if /^#/ =~ line
53+
line.sub!(/\s+#.*/, '')
54+
name, token = line.split
55+
next unless name
5256
token ||= name
5357
if /#/ =~ token
5458
token = "_#{token.gsub(/\W+/, '_')}"

include/ruby/intern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ VALUE rb_require_safe(VALUE, int);
382382
void rb_obj_call_init(VALUE, int, VALUE*);
383383
VALUE rb_class_new_instance(int, VALUE*, VALUE);
384384
VALUE rb_block_proc(void);
385-
VALUE rb_f_lambda(void);
385+
VALUE rb_block_lambda(void);
386386
VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE);
387387
VALUE rb_obj_is_proc(VALUE);
388388
VALUE rb_proc_call(VALUE, VALUE);

proc.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ rb_block_proc(void)
481481
return proc_new(rb_cProc, FALSE);
482482
}
483483

484+
/*
485+
* call-seq:
486+
* lambda { |...| block } -> a_proc
487+
*
488+
* Equivalent to <code>Proc.new</code>, except the resulting Proc objects
489+
* check the number of parameters passed when called.
490+
*/
491+
484492
VALUE
485493
rb_block_lambda(void)
486494
{
@@ -494,20 +502,6 @@ rb_f_lambda(void)
494502
return rb_block_lambda();
495503
}
496504

497-
/*
498-
* call-seq:
499-
* lambda { |...| block } -> a_proc
500-
*
501-
* Equivalent to <code>Proc.new</code>, except the resulting Proc objects
502-
* check the number of parameters passed when called.
503-
*/
504-
505-
static VALUE
506-
proc_lambda(void)
507-
{
508-
return rb_block_lambda();
509-
}
510-
511505
/* Document-method: ===
512506
*
513507
* call-seq:
@@ -952,7 +946,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
952946
again:
953947
me = rb_method_entry_without_refinements(klass, id, &defined_class);
954948
if (UNDEFINED_METHOD_ENTRY_P(me)) {
955-
ID rmiss = rb_intern("respond_to_missing?");
949+
ID rmiss = idRespond_to_missing;
956950
VALUE sym = ID2SYM(id);
957951

958952
if (obj != Qundef && !rb_method_basic_definition_p(klass, rmiss)) {
@@ -1993,13 +1987,13 @@ method_inspect(VALUE method)
19931987
static VALUE
19941988
mproc(VALUE method)
19951989
{
1996-
return rb_funcall(Qnil, rb_intern("proc"), 0);
1990+
return rb_funcall2(rb_mRubyVMFrozenCore, idProc, 0, 0);
19971991
}
19981992

19991993
static VALUE
20001994
mlambda(VALUE method)
20011995
{
2002-
return rb_funcall(Qnil, rb_intern("lambda"), 0);
1996+
return rb_funcall(rb_mRubyVMFrozenCore, idLambda, 0, 0);
20031997
}
20041998

20051999
static VALUE
@@ -2339,7 +2333,7 @@ Init_Proc(void)
23392333

23402334
/* utility functions */
23412335
rb_define_global_function("proc", rb_block_proc, 0);
2342-
rb_define_global_function("lambda", proc_lambda, 0);
2336+
rb_define_global_function("lambda", rb_block_lambda, 0);
23432337

23442338
/* Method */
23452339
rb_cMethod = rb_define_class("Method", rb_cObject);

test/ruby/test_proc.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'test/unit'
2+
require_relative 'envutil'
23

34
class TestProc < Test::Unit::TestCase
45
def setup
@@ -1196,4 +1197,14 @@ def foo
11961197
assert_equal('zot', o.method(:foo).to_proc.() {'zot'}, bug3792)
11971198
}
11981199
end
1200+
1201+
def test_overriden_lambda
1202+
bug8345 = '[ruby-core:54687] [Bug #8345]'
1203+
assert_normal_exit('def lambda; end; method(:puts).to_proc', bug8345)
1204+
end
1205+
1206+
def test_overriden_proc
1207+
bug8345 = '[ruby-core:54688] [Bug #8345]'
1208+
assert_normal_exit('def proc; end; ->{}.curry', bug8345)
1209+
end
11991210
end

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.0.0"
22
#define RUBY_RELEASE_DATE "2013-06-19"
3-
#define RUBY_PATCHLEVEL 231
3+
#define RUBY_PATCHLEVEL 232
44

55
#define RUBY_RELEASE_YEAR 2013
66
#define RUBY_RELEASE_MONTH 6

vm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,8 @@ Init_VM(void)
22602260
rb_define_method_id(klass, id_core_hash_merge_ary, m_core_hash_merge_ary, 2);
22612261
rb_define_method_id(klass, id_core_hash_merge_ptr, m_core_hash_merge_ptr, -1);
22622262
rb_define_method_id(klass, id_core_hash_merge_kwd, m_core_hash_merge_kwd, 2);
2263+
rb_define_method_id(klass, idProc, rb_block_proc, 0);
2264+
rb_define_method_id(klass, idLambda, rb_block_lambda, 0);
22632265
rb_obj_freeze(fcore);
22642266
rb_gc_register_mark_object(fcore);
22652267
rb_mRubyVMFrozenCore = fcore;

0 commit comments

Comments
 (0)