summaryrefslogtreecommitdiff
path: root/proc.c
AgeCommit message (Collapse)Author
2020-06-29add UNREACHABLE_RETURN卜部昌平
Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29proc_binding: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_obj_singleton_method: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29rb_method_name_error: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29bind_local_variable_get: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-20Removed space linesNobuyoshi Nakada
2020-06-20Remove unused variablesKazuki Tsujimoto
2020-06-19Implement Proc#== and #eql?Jeremy Evans
Previously, these were not implemented, and Object#== and #eql? were used. This tries to check the proc internals to make sure that procs created from separate blocks are treated as not equal, but procs created from the same block are treated as equal, even when the lazy proc allocation optimization is used. Implements [Feature #14267] Notes: Merged: https://github.com/ruby/ruby/pull/3174
2020-06-17rb_method_name_error: delete unused code卜部昌平
If you look at the code flow (break -> goto), this assignment never makes any sense. Should just remove. I _guess_ this behaviour is unintended. Original code at commit 4dc1a2180946ab793adee5eb235fc4ee8fa4cefe did something. It might be the code flow that is buggy. However rubyspec already includes this particular edge case at ruby/core/module/undef_method_spec.rb. I don't think we can change the way it is any longer.
2020-06-11Warn when passing a non-literal block to Kernel#lambdaJeremy Evans
Implements [Feature #15973] Notes: Merged: https://github.com/ruby/ruby/pull/3209
2020-06-10Make proc/Proc.new without block an error instead of warningJeremy Evans
The warning for these was added in 2.7. Notes: Merged: https://github.com/ruby/ruby/pull/3208
2020-06-09Work around infinite loop when overriding method visibility in prepended ↵Jeremy Evans
module (#3201) For ZSUPER methods with no defined class for the method entry, start the next lookup at the superclass of the origin class of the method owner, instead of the superclass of the method owner. Fixes [Bug #16942] Notes: Merged-By: jeremyevans <code@jeremyevans.net>
2020-04-24[DOC] Separated Method#[] from Method#call [Bug #16813] [ci skip]Nobuyoshi Nakada
2020-04-24[DOC] Fixed explanation for Method#>> [Bug #16813] [ci skip]Nobuyoshi Nakada
2020-04-08Suppress -Wswitch warningsNobuyoshi Nakada
2020-03-22Merge pull request #2721 from jeremyevans/method-inspect-chain-alias-11188Jeremy Evans
Correctly show defined class for aliases of aliases Notes: Merged-By: jeremyevans <code@jeremyevans.net>
2020-03-16`Proc` made by `Hash#to_proc` should be a lambda [Bug #12671]Yusuke Endoh
Like `Symbol#to_proc` (f0b815dc670b61eba1daaa67a8613ac431d32b16)
2020-03-16hash.c: Do not use the fast path (rb_yield_values) for lambda blocksYusuke Endoh
As a semantics, Hash#each yields a 2-element array (pairs of keys and values). So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception due to lambda's arity check. However, the optimization that avoids Array allocation by using rb_yield_values for blocks whose arity is more than 1 (introduced at b9d29603375d17c3d1d609d9662f50beaec61fa1 and some commits), seemed to overlook the lambda case, and wrongly allowed the code above to work. This change experimentally attempts to make it strict; now the code above raises an ArgumentError. This is an incompatible change; if the compatibility issue is bigger than our expectation, it may be reverted (until Ruby 3.0 release). [Bug #12706]
2020-03-16proc.c: Remove non-sense /* fall through */Yusuke Endoh
2020-03-09Don't display singleton class in Method#inspect unless method defined thereJeremy Evans
Previously, if an object has a singleton class, and you call Object#method on the object, the resulting string would include the object's singleton class, even though the method was not defined in the singleton class. Change this so the we only show the singleton class if the method is defined in the singleton class. Fixes [Bug #15608] Notes: Merged: https://github.com/ruby/ruby/pull/2949 Merged-By: jeremyevans <code@jeremyevans.net>
2020-02-22Proc from Symbol needs a receiverNobuyoshi Nakada
So its arity should be -2 instead of -1. [Bug #16640] https://bugs.ruby-lang.org/issues/16640#change-84337
2020-02-22`Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]Nobuyoshi Nakada
With refinements, too.
2020-02-19`Proc` made by `Symbol#to_proc` should be a lambda [Bug #16260]Nobuyoshi Nakada
2020-02-09Check if bindable against the refined target [Bug #16617]Nobuyoshi Nakada
2020-01-30Fix wrong return value in proc documentation.Florian Heinle
Notes: Merged: https://github.com/ruby/ruby/pull/2868
2020-01-23Rename RUBY_MARK_NO_PIN_UNLESS_NULL to RUBY_MARK_MOVABLE_UNLESS_NULL0x005c
Notes: Merged: https://github.com/ruby/ruby/pull/2823
2020-01-02Fully separate positional arguments and keyword argumentsJeremy Evans
This removes the warnings added in 2.7, and changes the behavior so that a final positional hash is not treated as keywords or vice-versa. To handle the arg_setup_block splat case correctly with keyword arguments, we need to check if we are taking a keyword hash. That case didn't have a test, but it affects real-world code, so add a test for it. This removes rb_empty_keyword_given_p() and related code, as that is not needed in Ruby 3. The empty keyword case is the same as the no keyword case in Ruby 3. This changes rb_scan_args to implement keyword argument separation for C functions when the : character is used. For backwards compatibility, it returns a duped hash. This is a bad idea for performance, but not duping the hash breaks at least Enumerator::ArithmeticSequence#inspect. Instead of having RB_PASS_CALLED_KEYWORDS be a number, simplify the code by just making it be rb_keyword_given_p(). Notes: Merged: https://github.com/ruby/ruby/pull/2794
2019-12-30Decide lambdaness of (f << g) using g (#2729)Alan Wu
* Deciding lambdaness of (f << g) using g * Use version guards for spec changes Notes: Merged-By: XrXr
2019-12-26decouple internal.h headers卜部昌平
Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26internal/imemo.h rework卜部昌平
Arrange contents and eliminate macros, to make them readable. Macro IFUNC_NEW was deleted because there was only one usage. Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-22Adjust sentence in doc [ci skip]Alan Wu
Notes: Merged: https://github.com/ruby/ruby/pull/2773 Merged-By: XrXr
2019-12-22Actualize Method#inspect docszverok
Notes: Merged: https://github.com/ruby/ruby/pull/2768
2019-12-22Document numbered block parameterszverok
Notes: Merged: https://github.com/ruby/ruby/pull/2767
2019-12-21Kernel#lambda: return forwarded block as non-lambda procAlan Wu
Before this commit, Kernel#lambda can't tell the difference between a directly passed literal block and one passed with an ampersand. A block passed with an ampersand is semantically speaking already a non-lambda proc. When Kernel#lambda receives a non-lambda proc, it should simply return it. Implementation wise, when the VM calls a method with a literal block, it places the code for the block on the calling control frame and passes a pointer (block handler) to the callee. Before this commit, the VM forwards block arguments by simply forwarding the block handler, which leaves the slot for block code unused when a control frame forwards its block argument. I use the vacant space to indicate that a frame has forwarded its block argument and inspect that in Kernel#lambda to detect forwarded blocks. This is a very ad-hoc solution and relies *heavily* on the way block passing works in the VM. However, it's the most self-contained solution I have. [Bug #15620] Notes: Merged: https://github.com/ruby/ruby/pull/2289
2019-12-19Added rb_warn_deprecatedNobuyoshi Nakada
2019-12-09Add Proc#ruby2_keywordsJeremy Evans
This allows passing keywords through a normal argument splat in a Proc. While needing ruby2_keywords support for methods is more common, there is code that delegates keywords through normal argument splats in procs, including code in Rails. For that reason, it makes sense to expose this for procs as well. Internally, ruby2_keywords is not tied to methods, but iseqs, so this just allows for setting the ruby2_keywords for the iseq related to the proc. Notes: Merged: https://github.com/ruby/ruby/pull/2728
2019-12-04Make {Method,UnboundMethod}#super_method handle clone/bind/unbindJeremy Evans
This wasn't working previously because the iclass entry wasn't being copied, and without an iclass entry, super_method returns nil. Fixes [Bug #15629] Notes: Merged: https://github.com/ruby/ruby/pull/2723
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