716 Commits
Author SHA1 Message Date
Hiroshi SHIBATA 18e7b33cf4 [Bug #22284] Let NUM2INT handle Fixnum arity of curry
NUM2INT already takes the Fixnum path by itself.
2026-10-09 16:07:20 -07:00
YO4 1328590e45 [Bug #22284] Fix curry with a non-Fixnum arity on LLP64
FIX2INT does not call to_int where int and long have the same size, so `method(:puts).curry(1r)` waited for a garbage number of arguments on Windows. Convert the arity once and keep the result as a Fixnum, which also limits the to_int call to one.
2026-10-09 16:07:20 -07:00
Peter Zhu 555611e109 Fix Method#inspect when klass is iclass
[Bug #22321]

In the following script, the klass of the Method object is an iclass, which
will raise an error "NoMethodError: undefined method 'inspect' for an instance of M":

    module M
      def foo = 1
    end

    class C
      include M
    end

    obj = C.new
    meth = obj.method(:foo).unbind.bind(obj)
    puts meth.inspect
2026-10-09 16:06:13 -07:00
John Hawthorn 4d2a5af522 Use write barrier version for rb_proc_call_kw 2026-05-05 13:27:43 -07:00
Mike Dalessio 0768f08caf Fix UnboundMethod#== for methods from included/extended modules [Backport #21873]
Method#unbind clones the method entry, preserving its defined_class.
For methods mixed in via include/extend, defined_class is an ICLASS,
causing UnboundMethod#== to return false when comparing against the
same method obtained via Module#instance_method.

Resolve ICLASS defined_class in method_eq.

[Bug #21873]
2026-02-10 10:32:51 -08:00
Peter Zhu d517e04806 [DOC] Combine docs for Method#call aliases
RDoc does not parse the documentation for the Method#call aliases, so we
should combine the aliases into one documentation.
2025-12-23 09:00:04 -05:00
Peter Zhu 6a2cd630d5 [DOC] Improve call-seq of Proc#call 2025-12-22 09:12:54 -05:00
Peter Zhu cfb324e9d1 [DOC] Improve docs for Method#>> 2025-12-21 14:08:00 -05:00
Peter Zhu 9f8231b7f8 [DOC] Update call-seq for Method#>> 2025-12-21 14:08:00 -05:00
Peter Zhu 759187b560 [DOC] Improve docs for Method#<< 2025-12-21 14:08:00 -05:00
Peter Zhu 76441060f2 [DOC] Update call-seq for Method#<< 2025-12-21 14:08:00 -05:00
Nobuyoshi Nakada 85ff21c9e5 RBOOL is unnecessary in C boolean context
Fix a `-Wint-in-bool-context` warning.

```
proc.c:688:33: warning: '?:' using integer constants in boolean context [-Wint-in-bool-context]
  688 |     if (RBOOL(get_local_variable_ptr(&env, idItImplicit, FALSE))) {
```
2025-12-18 16:42:20 +09:00
Peter Zhu f483484fc6 [DOC] Fix call-seq of Method#box 2025-12-16 21:03:57 -05:00
Nobuyoshi Nakada 065c48cdf1 Revert "[Feature #6012] Extend source_location for end position
and columns"

This reverts commit 073c4e1cc7.

https://bugs.ruby-lang.org/issues/6012#note-31
> we will cancel this feature in 4.0 because of design ambiguities
> such as whether to return column positions in bytes or characters as
> in [#21783].

[#21783]: https://bugs.ruby-lang.org/issues/21783
2025-12-16 16:13:07 +09:00
tomoya ishida b8ba9cebb9 Fix binding.implicit_parameters_get/defined segfault when wrong name string is passed (#15530) 2025-12-13 01:40:49 +09:00
Yusuke Endoh 04422384dd Add docs to Binding#numbered_parameters, etc. 2025-12-12 23:24:50 +09:00
Yusuke Endoh 129d74c96b Binding#implicit_parameters, etc. support the implicit "it" parameter
[Bug #21049]
2025-12-12 23:24:50 +09:00
Yusuke Endoh fa7cddc969 Add Binding#implicit_parameters, etc.
This changeset introduces:

* `Binding#implicit_parameters`
* `Binding#implicit_parameter_get`
* `Binding#implicit_parameter_defined?`

[Bug #21049]
2025-12-12 23:24:50 +09:00
Yusuke Endoh 1794cfe12f Binding#local_variable_defined? raises a NameError for numbered params.
[Bug #21776]
2025-12-12 15:21:29 +09:00
Yusuke Endoh 04494d9e40 Binding#local_variable_defined? must not handle numbered parameters
[Bug #21776]
2025-12-12 13:16:52 +09:00
Koichi Sasada 4c893e2ff1 Method and UnboundMethod can be sharable
with `RUBY_TYPED_FROZEN_SHAREABLE_NO_REC`,
if the receiver object is shareable on Method objects.
2025-12-05 02:28:30 +09:00
Satoshi Tagomori d2a587c791 renaming internal data structures and functions from namespace to box 2025-11-07 13:14:54 +09:00
Satoshi Tagomori 4f47327287 Update current namespace management by using control frames and lexical contexts
to fix inconsistent and wrong current namespace detections.

This includes:
* Moving load_path and related things from rb_vm_t to rb_namespace_t to simplify
  accessing those values via namespace (instead of accessing either vm or ns)
* Initializing root_namespace earlier and consolidate builtin_namespace into root_namespace
* Adding VM_FRAME_FLAG_NS_REQUIRE for checkpoints to detect a namespace to load/require files
* Removing implicit refinements in the root namespace which was used to determine
  the namespace to be loaded (replaced by VM_FRAME_FLAG_NS_REQUIRE)
* Removing namespaces from rb_proc_t because its namespace can be identified by lexical context
* Starting to use ep[VM_ENV_DATA_INDEX_SPECVAL] to store the current namespace when
  the frame type is MAGIC_TOP or MAGIC_CLASS (block handlers don't exist in this case)
2025-09-29 01:15:38 +09:00
Peter Zhu 21d76b423c Fix out-of-bounds read in Method#inspect for unnamed parameters
For parameters without names, accessing the name in array index 1 would
be an out-of-bounds read.
2025-09-11 08:14:25 -04:00
Jeremy Evans acb29f7fa1 Do not respect ruby2_keywords on method/proc with post arguments
Previously, ruby2_keywords could be used on a method or proc with
post arguments, but I don't think the behavior is desired:

```ruby
def a(*c, **kw) [c, kw] end
def b(*a, b) a(*a, b) end
ruby2_keywords(:b)

b({foo: 1}, bar: 1)
```

This changes ruby2_keywords to emit a warning and not set the
flag on a method/proc with post arguments.

While here, fix the ruby2_keywords specs for warnings, since they
weren't testing what they should be testing.  They all warned
because the method didn't accept a rest argument, not because it
accepted a keyword or keyword rest argument.
2025-08-22 00:46:57 +09:00
John Hawthorn 9fedae9976 Add missing writebarrier to rb_func_proc_dup
Because TypedData_Make_Struct both allocates an object and after
xmallocs memory, all added references must always be writebarrier
protected.
2025-08-18 21:36:30 -07:00
Nobuyoshi Nakada 6179cc0118 [DOC] Fill undocumented documents 2025-08-04 02:23:43 +09:00
Nobuyoshi Nakada a60bf9e693 * adjust indent 2025-06-17 12:30:18 +09:00
Jean Boussier 0cc41d3d39 proc.c: saves Binding#clone on copying ivars twice 2025-06-06 11:30:23 +02:00
Richard Böhme 9a41d76b83 Fix one-by-one error of numbered parameter ID 2025-05-21 22:12:34 +09:00
Jean Boussier 0964593e5d Shrink sym_proc_cache by half
There is no need to store the symbol and the proc given the
proc has a reference to the symbol.

This makes the cache half as small, now fitting in an object
slot, but also make it easier to allow that cache to be
used by ractors, assuming we'd make `Symbol#to_proc`
return a shareable proc.
2025-05-21 09:29:27 +02:00
Luke Gruber f6cbf499bc Fix Symbol#to_proc (rb_sym_to_proc) to be ractor safe
In non-main ractors, don't use `sym_proc_cache`. It is not thread-safe
to add to this array without a lock and also it leaks procs from one
ractor to another. Instead, we create a new proc each time. If this
results in poor performance we can come up with a solution later.

Fixes [Bug #21354]
2025-05-21 08:12:18 +02:00
Daisuke Aritomo edff523407 [DOC] Describe new return value of source_location
Proc#source_location, Method#source_location and
UnboundMethod#source_location carry more information since
073c4e1cc7.

https://bugs.ruby-lang.org/issues/6012
https://github.com/ruby/ruby/pull/12539
2025-05-20 15:51:42 +09:00
Yusuke Endoh cf3e2bbad2 Prevent a compile error of clang's -Wformat-pedantic
```
  /github/workspace/src/proc.c:2023:65: error: format specifies type 'void *' but the argument has type 'const rb_namespace_t *' (aka 'const struct rb_namespace_struct *') [-Werror,-Wformat-pedantic]
   2023 |     rb_bug("Unexpected namespace on the method definition: %p", ns);
        |                                                            ~~   ^~
```
2025-05-11 23:32:50 +09:00
Satoshi Tagomori 382645d440 namespace on read 2025-05-11 23:32:50 +09:00
Nobuyoshi Nakada 1dddc6c78b Remove no longer used union
IMEMO_NEW takes just one memo value, min/max argc are assigned
directly and packed argc is not used.
2025-04-03 16:56:24 +09:00
Nobuyoshi Nakada f23146f09f Fix enums in comparisons 2025-03-16 12:27:56 +09:00
Yusuke Endoh 7605d68062 Revert "refactor: make get_local_variable_ptr accept "rb_env_t *""
This reverts commit 6d75599a1a.

Updating env was actually needed in local_variable_set.
Alan Wu pointed this out to me.
2025-02-20 10:20:06 +09:00
Yusuke Endoh 993fd96ce6 reject numbered parameters from Binding#local_variables
Also, Binding#local_variable_get and #local_variable_set rejects an
access to numbered parameters.

[Bug #20965] [Bug #21049]
2025-02-18 16:23:24 +09:00
Yusuke Endoh 6d75599a1a refactor: make get_local_variable_ptr accept "rb_env_t *"
... instead of "rb_env_t **" because no one uses the updated env.
2025-02-18 16:23:24 +09:00
Nobuyoshi Nakada db02a6b3ab [Bug #21103] Fix local variable index calculation with forwarding
Forwarding argument is optimized not to packed when no other arguments
and an internal object refers values before it.  This size is decided
at called time, calculate the local variable index from the fixed end
point.
2025-02-01 22:03:47 +09:00
Peter Zhu 5a448a87fc Remove dead function rb_func_proc_new 2025-01-20 10:31:36 -05:00
Alan Wu 6637aa4682 Proc#parameters: Show anonymous optionals as [:opt]
Have this for lead parameters as well as parameters after rest ("post").

[Bug #20974]
2025-01-13 12:58:59 -05:00
Nobuyoshi Nakada 073c4e1cc7 [Feature #6012] Extend source_location for end position and columns 2025-01-09 20:21:41 +09:00
Junichi Ito c8e3d745fa Use a single quote instead of a backtick for error messages
Fix https://bugs.ruby-lang.org/issues/20977
2025-01-05 20:50:53 -05:00
Nobuyoshi Nakada b4ec22fe6c [DOC] Exclude 'Method' from RDoc's autolinking 2025-01-02 12:23:49 +09:00
Victor Shepelev 173ae93e56 Document 'it' and update numbered parameters docs (#12375) 2024-12-18 21:38:40 +02:00
Peter Zhu 92dd9734a9 Fix use-after-free in ep in Proc#dup for ifunc procs
[Bug #20950]

ifunc proc has the ep allocated in the cfunc_proc_t which is the data of
the TypedData object. If an ifunc proc is duplicated, the ep points to
the ep of the source object. If the source object is freed, then the ep
of the duplicated object now points to a freed memory region. If we try
to use the ep we could crash.

For example, the following script crashes:

    p = { a: 1 }.to_proc
    100.times do
      p = p.dup
      GC.start
      p.call
    rescue ArgumentError
    end

This commit changes ifunc proc to also duplicate the ep when it is duplicated.
2024-12-13 10:10:03 -05:00
Peter Zhu 29c480dd6f [Bug #20853] Fix Proc#hash to not change after compaction
The hash value of a Proc must remain constant after a compaction, otherwise
it may not work as the key in a hash table.
2024-11-01 10:49:50 -04:00
Jeremy Evans 9986a7c393 Make Object#singleton_method return methods in modules included in or prepended to singleton class
To simplify the implementation, this makes Object#singleton_method
call the same method called by Object#method (rb_obj_method), then
check that the returned Method is defined before the superclass of the
object's singleton class.  To keep the same error messages, it rescues
exceptions raised by rb_obj_method, and then raises its own exception.

Fixes [Bug #20620]
2024-10-03 07:27:01 -07:00