summaryrefslogtreecommitdiff
path: root/proc.c
AgeCommit message (Collapse)Author
2019-11-25Fix the docs for Proc#>>.Paweł Przeniczny
The docs are wrong about the behaviour of `#>>` (looks like it was copied from `#<<`) In `(prc >> g).call(n)` _prc_ is called first (with _n_), *then* _g_ is called with the result. Code examples are OK. Notes: Merged: https://github.com/ruby/ruby/pull/2691
2019-11-21Refined inspection of argument forwardingNobuyoshi Nakada
2019-11-20Update representation (discussed on ruby tracker)zverok
Notes: Merged: https://github.com/ruby/ruby/pull/2618
2019-11-20Method parameters inspectzverok
Example: def m(a, b=nil, *c, d:, e: nil, **rest, &block) end p method(:m) #=> #<Method: m(a, b=<default>, *c, d:, e: <default>, **rest, &block) ...> Notes: Merged: https://github.com/ruby/ruby/pull/2618
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-14delete unused functions卜部昌平
Looking at the list of symbols inside of libruby-static.a, I found hundreds of functions that are defined, but used from nowhere. There can be reasons for each of them (e.g. some functions are specific to some platform, some are useful when debugging, etc). However it seems the functions deleted here exist for no reason. This changeset reduces the size of ruby binary from 26,671,456 bytes to 26,592,864 bytes on my machine. Notes: Merged: https://github.com/ruby/ruby/pull/2677
2019-11-12Show the name `Kernel#proc` in the warning messageNobuyoshi Nakada
2019-10-26Documentation improvements for Ruby corezverok
* Top-level `return`; * Documentation for comments syntax; * `rescue` inside blocks; * Enhance `Object#to_enum` docs; * Make `chomp:` option more obvious for `String#each_line` and `#lines`; * Enhance `Proc#>>` and `#<<` docs; * Enhance `Processs` class docs. Notes: Merged: https://github.com/ruby/ruby/pull/2612
2019-10-25check T_ICLASS for Method#inspect.Koichi Sasada
METHOD::klass can contain T_ICLASS so inspect should respect it.
2019-10-11Module#define_method: Add UnboundMethod to expected classesksss
Notes: Merged: https://github.com/ruby/ruby/pull/1465
2019-10-03Revert https://github.com/ruby/ruby/pull/2486卜部昌平
This reverts commits: 10d6a3aca7 8ba48c1b85 fba8627dc1 dd883de5ba 6c6a25feca 167e6b48f1 7cb96d41a5 3207979278 595b3c4fdd 1521f7cf89 c11c5e69ac cf33608203 3632a812c0 f56506be0d 86427a3219 . The reason for the revert is that we observe ABA problem around inline method cache. When a cache misshits, we search for a method entry. And if the entry is identical to what was cached before, we reuse the cache. But the commits we are reverting here introduced situations where a method entry is freed, then the identical memory region is used for another method entry. An inline method cache cannot detect that ABA. Here is a code that reproduce such situation: ```ruby require 'prime' class << Integer alias org_sqrt sqrt def sqrt(n) raise end GC.stress = true Prime.each(7*37){} rescue nil # <- Here we populate CC class << Object.new; end # These adjacent remove-then-alias maneuver # frees a method entry, then immediately # reuses it for another. remove_method :sqrt alias sqrt org_sqrt end Prime.each(7*37).to_a # <- SEGV ```
2019-09-30refactor constify most of rb_method_entry_t卜部昌平
Now that we have eliminated most destructive operations over the rb_method_entry_t / rb_callable_method_entry_t, let's make them mostly immutabe and mark them const. One exception is rb_export_method(), which destructively modifies visibilities of method entries. I have left that operation as is because I suspect that destructiveness is the nature of that function. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor add rb_method_entry_from_template卜部昌平
Tired of rb_method_entry_create(..., rb_method_definition_create( ..., &(rb_method_foo_t) {...})) maneuver. Provide a function that does the thing to reduce copy&paste. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor delete rb_method_entry_copy卜部昌平
The deleted function was to destructively overwrite existing method entries, which is now considered to be a bad idea. Delete it, and assign a newly created method entry instead. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor rb_method_definition_create take opts卜部昌平
Before this changeset rb_method_definition_create only allocated a memory region and we had to destructively initialize it later. That is not a good design so we change the API to return a complete struct instead. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor constify most of rb_method_definition_t卜部昌平
Most (if not all) of the fields of rb_method_definition_t are never meant to be modified once after they are stored. Marking them const makes it possible for compilers to warn on unintended modifications. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-29Remove VM_NO_KEYWORDS, replace with RB_NO_KEYWORDSJeremy Evans
VM_NO_KEYWORDS was introduced first in vm_core.h, but it is best to only use a single definition for this.
2019-09-26Fix more keyword separation issuesJeremy Evans
This fixes instance_exec and similar methods. It also fixes Enumerator::Yielder#yield, rb_yield_block, and a couple of cases with Proc#{<<,>>}. This support requires the addition of rb_yield_values_kw, similar to rb_yield_values2, for passing the keyword flag. Unlike earlier attempts at this, this does not modify the rb_block_call_func type or add a separate function type. The functions of type rb_block_call_func are called by Ruby with a separate VM frame, and we can get the keyword flag information from the VM frame flags, so it doesn't need to be passed as a function argument. These changes require the following VM functions accept a keyword flag: * vm_yield_with_cref * vm_yield * vm_yield_with_block Notes: Merged: https://github.com/ruby/ruby/pull/2493
2019-09-26Fix keyword argument separation issues in Enumerator::Generator#eachJeremy Evans
This requires adding rb_proc_call_kw to pass the keyword flag. Notes: Merged: https://github.com/ruby/ruby/pull/2491
2019-09-26Add rb_adjust_argv_kw_splat to internal.hJeremy Evans
We are calling this in a few other files, it is better to have it in a header than adding prototypes to the other files. Notes: Merged: https://github.com/ruby/ruby/pull/2491
2019-09-26Fix keyword argument separation issues in Proc#{<<,>>}Jeremy Evans
This requires adding rb_proc_call_with_block_kw. Notes: Merged: https://github.com/ruby/ruby/pull/2484
2019-09-14Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from RubyJeremy Evans
It is not safe to set this in C functions that can be called from other C functions, as in the non argument-delegation case, you can end up calling a Ruby method with a flag indicating keywords are set without passing keywords. Introduce some new *_kw functions that take a kw_splat flag and use these functions to set RB_PASS_CALLED_KEYWORDS in places where we know we are delegating methods (e.g. Class#new, Method#call)
2019-09-13Consolidate empty keyword handlingJeremy Evans
Remove rb_add_empty_keyword, and instead of calling that every place you need to add empty keyword hashes, run that code in a single static function in vm_eval.c. Add 4 defines to include/ruby/ruby.h, these are to be used as int kw_splat values when calling the various rb_*_kw functions: RB_NO_KEYWORDS :: Do not pass keywords RB_PASS_KEYWORDS :: Pass final argument (which should be hash) as keywords RB_PASS_EMPTY_KEYWORDS :: Add an empty hash to arguments and pass as keywords RB_PASS_CALLED_KEYWORDS :: Passes same keyword type as current method was called with (for method delegation) rb_empty_keyword_given_p needs to stay. It is required if argument delegation is done but delayed to a later point, which Enumerator does. Use RB_PASS_CALLED_KEYWORDS in rb_call_super to correctly delegate keyword arguments to super method.
2019-09-06Convert keyword argument to required positional hash argument for Class#new, ↵Jeremy Evans
Method#call, UnboundMethod#bind_call Also add keyword argument separation warnings for Class#new and Method#call. To allow for keyword argument to required positional hash converstion in cfuncs, add a vm frame flag indicating the cfunc was called with an empty keyword hash (which was removed before calling the cfunc). The cfunc can check this frame flag and add back an empty hash if it is passing its arguments to another Ruby method. Add rb_empty_keyword_given_p function for checking if called with an empty keyword hash, and rb_add_empty_keyword for adding back an empty hash to argv. All of this empty keyword argument support is only for 2.7. It will be removed in 3.0 as Ruby 3 will not convert empty keyword arguments to required positional hash arguments. Comment all of the relevent code to make it obvious this is expected to be removed. Add rb_funcallv_kw as an public C-API function, just like rb_funcallv but with a keyword flag. This is used by rb_obj_call_init (internals of Class#new). This also required expected call_type enum with CALL_FCALL_KW, similar to the recent addition of CALL_PUBLIC_KW. Add rb_vm_call_kw as a internal function, used by call_method_data (internals of Method#call and UnboundMethod#bind_call). Add tests for UnboundMethod#bind_call keyword handling. Notes: Merged: https://github.com/ruby/ruby/pull/2432
2019-09-05Add VM_NO_KEYWORDSJeremy Evans
I think this is easier to read than using literal 0 with comments in every case where it is used.
2019-09-05Propagate kw_splat informationYusuke Endoh
The kw_splat flag is whether the original call passes keyword or not. Some types of methods (e.g., bmethod and sym_proc) drops the information. This change tries to propagate the flag to the final callee, as far as I can.
2019-08-30Add rb_iseq_locationJeremy Evans
This wraps iseq_location and should fix the leaked global test.
2019-08-30Use more accurate source location in keyword argument separation warningsJeremy Evans
This shows locations in places it didn't before, such as for proc calls, and fixes the location for super calls. This requires making iseq_location non-static and MJIT exported, which I hope will not cause problems.
2019-08-30Separate keyword arguments from positional argumentsYusuke Endoh
And, allow non-symbol keys as a keyword arugment Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-08-30[DOC] Return obj may be different from 1st argument [ci skip]Kazuhiro NISHIYAMA
2019-08-30proc.c: Add UnboundMethod#bind_callYusuke Endoh
`umethod.bind_call(obj, ...)` is semantically equivalent to `umethod.bind(obj).call(...)`. This idiom is used in some libraries to call a method that is overridden. The added method does the same without allocation of intermediate Method object. [Feature #15955] ``` class Foo def add_1(x) x + 1 end end class Bar < Foo def add_1(x) # override x + 2 end end obj = Bar.new p obj.add_1(1) #=> 3 p Foo.instance_method(:add_1).bind(obj).call(1) #=> 2 p Foo.instance_method(:add_1).bind_call(obj, 1) #=> 2 ```
2019-08-29move docs around [ci skip]卜部昌平
To properly generate documents.
2019-08-29drop-in type check for rb_define_global_function卜部昌平
We can check the function pointer passed to rb_define_global_function like we do so in rb_define_method. It turns out that almost anybody is misunderstanding the API.
2019-08-27rb_proc_new / rb_fiber_new now free from ANYARGS卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_proc_new / rb_fiber_new, and applies RB_BLOCK_CALL_FUNC_ARGLIST wherever necessary.
2019-08-27decouple compile.c usage of imemo_ifunc卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from struct vm_ifunc, but in doing so we also have to decouple the usage of this struct in compile.c, which (I think) is an abuse of ANYARGS.
2019-08-16Add details about parameters to define_method doc (#2165)OKURA Masafumi
When we use `define_method` and `define_singleton_method`, if we supply block parameters to a block then a generated method has corresponding parameters. However, the doc doesn't mention it, so this info has been added.
2019-08-14* expand tabs.git
2019-08-14change Proc#to_s format ('@...' -> ' ...') (#2362)Koichi Sasada
Now Proc#to_s returns "#<Proc:0x00000237a0f5f170@t.rb:1>". However, it is convenient to select a file name by (double-)clicking on some terminals by separating ' ' instead of '@' like "#<Proc:0x00000237a0f5f170 t.rb:1>" [Feature #16101]
2019-08-12Rename rb_gc_mark_no_pin -> rb_gc_mark_movableAaron Patterson
Renaming this function. "No pin" leaks some implementation details. We just want users to know that if they mark this object, the reference may move and they'll need to update the reference accordingly.
2019-07-14fix typos.Tanaka Akira
2019-07-14Method#inspect with source location.Koichi Sasada
Method#inspect shows with source location. [Feature #14145]
2019-07-14Describe lambda-ness of Proc more.Tanaka Akira
2019-06-12* expand tabs.git
2019-06-11Add compaction support for more types.Aaron Patterson
This commit adds compaction support for: * Fibers * Continuations * Autoload Constants
2019-06-03Unpin objects that `proc` referencesAaron Patterson
This commit adds compaction support to method and proc objects. It just unpins references and implements the "compact" callback and updates references.
2019-04-27Add class ref to `UnboundMethod#owner` docokuramasafumi
It refers to `Method#receiver` in the doc, but there's no class reference in current doc. Some tools automatically make it a link so it's useful. Closes: https://github.com/ruby/ruby/pull/2156
2019-04-22Adds a reference to `TracePoint` to `binding` docsKazuhiro NISHIYAMA
This change adds an explicit reference to `TracePoint` in the documentation for `binding`. Currently it only refers to the now deprecated `Kernel#set_trace_func`. This reference is left alone for continuity in the documentation. [Fix GH-2079] Co-authored-by: Brandon Weaver <baweaver@squareup.com>
2019-04-13* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-13Proc.new: change deprecation warning for clarity (issue #15539)marcandre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e