Граф коммитов

483 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans c257303ae7 Deprecate rb_eval_cmd, add rb_eval_cmd_kw
rb_eval_cmd takes a safe level, and now that $SAFE is deprecated,
it should be deprecated as well.

Replace with rb_eval_cmd_kw, which takes a keyword flag.  Switch
the two callers to this function.
2019-11-18 01:00:25 +02:00
Jeremy Evans ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
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.
2019-11-18 01:00:25 +02:00
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
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.
2019-11-18 01:00:25 +02:00
卜部昌平 c9ffe751d1 delete 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.
2019-11-14 20:35:48 +09:00
Ben Woosley bb71a128eb Prefer st_is_member over st_lookup with 0
The st_is_member DEFINE has simpler semantics, for more readable code.
2019-10-09 23:46:50 +09:00
Jean Boussier 9d0866c7d7 [EXPERIMENTAL] Make Module#name return a frozen String
* Always the same frozen String for a given Module or Class.
    * Avoids extra allocations whenever calling Module#name.
    * See [Feature #16150]
2019-09-26 13:25:23 +02:00
Yusuke Endoh 28eefb33c8 variable.c: Rename rb_st_copy to rb_iv_tbl_copy
This function was created as a variant of st_copy with firing write
barrier.
It should have more explicit name, such as st_copy_with_write_barrier.
But because it is used only for copying iv_tbl, so I rename it to
rb_iv_tbl_copy now.  If we face other use case than iv_tbl, we may want
to rename it to more general name.
2019-09-22 16:21:26 +09:00
Jeremy Evans 7470f96565 Fix Module#class_variables for singleton classes of classes/modules
Module#class_variables should reflect class variable lookup. For
singleton classes of classes/modules, this means the lookup should
be:

* Singleton Class
* Class
* All Ancestors of Class

Note that this doesn't include modules included in the singleton
class, because class variable lookup doesn't include those.

Singleton classes of other objects do not have this behavior and
always just search all ancestors of the singleton class, so do not
change the behavior for them.

Fixes [Bug #8297]
2019-09-21 16:10:18 -07:00
Kazuki Tsujimoto ea84a68075
Export rb_const_source_location_at for MJIT 2019-09-01 16:25:01 +09:00
卜部昌平 0766f67168 move docs around [ci skip]
To properly generate documents.
2019-08-29 18:34:09 +09:00
卜部昌平 79d280a5e8 rb_ivar_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit adds a function
prototype for rb_ivar_foreach.  Luckily this change revealed no
problematic usage of the function.
2019-08-27 15:52:26 +09:00
卜部昌平 ae2dc3f217 rb_define_hooked_variable now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit uses rb_gvar_getter_t /
rb_gvar_setter_t for rb_define_hooked_variable /
rb_define_virtual_variable which revealed lots of function prototype
inconsistencies.  Some of them were literally decades old, going back
to dda5dc00cf.
2019-08-27 15:52:26 +09:00
卜部昌平 703783324c rb_ensure now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
rb_ensure, which also revealed many arity / type mismatches.
2019-08-27 15:52:26 +09:00
Alan Wu c8f97596b7 Don't accidentally name anonymous module/class
b00f280d4b introduced
an accidental behavior change in that defining a module/class under
`m` gives `m` a name when `m` is anonymous.

`ruby -ve 'Module.new { class self::A; end; p name }'` outputs a name
similar to `Module#inspect` when it should output `nil` like in Ruby
2.6.x.

 * variable.c: Use `make_temporary_path` instead of `save_temporary_path`
   when getting the name of the parent module.

 * variable.c (rb_set_class_path): Delegate to `rb_set_class_path_string`
   instead of duplicating the logic.

[Bug #16097]
2019-08-14 17:13:28 +09:00
Aaron Patterson aac4d9d6c7
Rename rb_gc_mark_no_pin -> rb_gc_mark_movable
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-08-12 16:44:54 -04:00
Koichi Sasada ebd398ac5a remove RHash::iter_lev.
iter_lev is used to detect the hash is iterating or not.
Usually, iter_lev should be very small number (1 or 2) so
`int` is overkill.

This patch introduce iter_lev in flags (7 bits, FL13 to FL19)
and if iter_lev exceeds this range, save it in hidden attribute.
We can get 1 word in RHash.

We can't modify frozen objects. Therefore I added new internal API
`rb_ivar_set_internal()` which allows us to set an attribute
even if the target object is frozen
if the name is hidden ivar (the name without `@` prefix).
2019-07-31 09:44:23 +09:00
Nobuyoshi Nakada bdddaa9f56
Use rb_ident_hash_new instead of rb_hash_new_compare_by_id
The latter is same as the former, removed the duplicate function.
2019-07-03 02:09:01 +09:00
git 77a073239c * expand tabs. 2019-07-01 14:00:37 +09:00
Nobuyoshi Nakada 99dc885974
Fixed inadvertent ID creation in rb_iv_get 2019-07-01 13:56:55 +09:00
Nobuyoshi Nakada aa2f505825
Make autoloading_const_entry static 2019-06-23 02:49:39 +09:00
git c5c3486340 * expand tabs. 2019-06-23 01:47:40 +09:00
Nobuyoshi Nakada 9384383019
Module#constant_source_location [Feature #10771] 2019-06-23 01:46:38 +09:00
Nobuyoshi Nakada 5084233b88
Split global search for module 2019-06-23 01:26:48 +09:00
Nobuyoshi Nakada 151843b981
Hoisted out autoloading_const_entry 2019-06-23 01:26:42 +09:00
git c997f7daaa * expand tabs. 2019-06-21 17:29:08 +09:00
Nobuyoshi Nakada 5b7cc63d11
Turned `recur` into `int` [Feature #15777] 2019-06-21 17:28:37 +09:00
Jean Boussier fb85a42860
Add an optional `inherit` argument to Module#autoload?
[Feature #15777]

Closes: https://github.com/ruby/ruby/pull/2173
2019-06-21 17:28:37 +09:00
Aaron Patterson 6db2d6d852
Add compaction support for more types.
This commit adds compaction support for:

* Fibers
* Continuations
* Autoload Constants
2019-06-11 09:16:14 -07:00
Nobuyoshi Nakada c1e5299787
Fix FrozenError when assigning frozen class to constant
* variable.c (set_namespace_path): modules/classes can get named
  by assignment to constant, even if frozen.  [Bug #15891]
2019-06-01 02:41:14 +09:00
Nobuyoshi Nakada 48f3dc3cce
Set namespace tree
* variable.c (set_namespace_path): set path to the whole namespace
  tree.  [Feature #15765]
2019-05-22 15:47:00 +09:00
Alan Wu 1b20d6a6c6
Extract build_const_pathname
* variable.c (build_const_pathname): build constant path from
  name as a string.  [Feature #15765]
2019-05-22 15:47:00 +09:00
Alan Wu b00f280d4b
Eagerly name modules and classes
* variable.c: make the hidden ivars `classpath` and `tmp_classpath` the source
  of truth for module and constant names. Assign to them when modules are bind
  to constants.

* variable.c: remove references to module name cache, as what used to be the cache
  is now the source of truth. Remove rb_class_path_no_cache().

* variable.c: remove the hidden ivar `classid`. This existed for the purposes of
  module name search, which is now replaced. Also, remove the associated
  rb_name_class().

* class.c: use rb_set_class_path_string to set the name of Object during boot.
  Must use a fstring as this runs before rb_cString is initialized and
  creating a normal string leads to a VALUE without a class.

* spec/ruby/core/module/name_spec.rb: add a few specs to specify what happens
  to Module#name across multiple operations. These specs pass without other
  code changes in this commit.

[Feature #15765]
2019-05-22 15:46:47 +09:00
Aaron Patterson 154a67f140
Rename rb_gc_new_location to rb_gc_location
The function will return new or existing locations depending on whether
or not the object actually moved, so give it a more appropriate name.
2019-05-18 12:24:28 +03:00
Urabe, Shyouhei aa190abe20 newptr should not be NULL
obj_ivar_heap_alloc already handles that situation.
2019-04-26 15:59:40 +09:00
Urabe, Shyouhei f02760fc0a avoid reading uninitialized variable
autoload_reset() can read this state.result.  Because autoload_reset
is a function passed to rb_ensure, there is a chance when an
execption raises before actually filling this memory region.

test/ruby/test_defined.rb:test_autoload_noload is one of such case.

Found using memory sanitizer.

==54014==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x557a683f3e5a in autoload_reset variable.c:2372:9
    #1 0x557a6707a93b in rb_ensure eval.c:1084:5
    #2 0x557a683efbf5 in rb_autoload_load variable.c:2475:14
    #3 0x557a685fc460 in vm_get_ev_const vm_insnhelper.c:938:4
    #4 0x557a68448e0a in vm_exec_core insns.def:267:11
2019-04-26 15:59:40 +09:00
tenderlove 91793b8967 Add `GC.compact` again.
🙏

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20 01:19:47 +00:00
tenderlove 744e5df715 Reverting compaction for now
For some reason symbols (or classes) are being overridden in trunk

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 09:41:41 +00:00
tenderlove 3c55b643ae Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17 03:17:25 +00:00
kazu 25c1fd3b90 Reverting all commits from r67479 to r67496 because of CI failures
Because hard to specify commits related to r67479 only.
So please commit again.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10 09:15:21 +00:00
tenderlove 3ef4db15e9 Adding `GC.compact` and compacting GC support.
This commit adds the new method `GC.compact` and compacting GC support.
Please see this issue for caveats:

  https://bugs.ruby-lang.org/issues/15626

[Feature #15626]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-09 20:32:04 +00:00
nobu 978290515e [DOC] Fix method references to Method instance methods
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-28 03:33:36 +00:00
nobu de0ef1a9df [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-28 03:33:35 +00:00
svn 28f619e301 * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-09 00:12:53 +00:00
nobu 5aecf03ec3 variable.c: hoisted out rb_namespace_p
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-09 00:12:52 +00:00
svn b0d24baf8a * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-28 10:33:04 +00:00
nobu d54a86d49d Hoisted out undefined_constant
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-28 10:33:02 +00:00
nobu 98e65d9d92 Prefer rb_check_arity when 0 or 1 arguments
Especially over checking argc then calling rb_scan_args just to
raise an ArgumentError.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 07:49:24 +00:00
nobu 98f8baf944 No new entry when getting undefined global variable
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-25 04:05:09 +00:00
nobu 7ac1ff5fb7 Prefer ALLOCV over ALLOCA
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-25 03:36:10 +00:00
ko1 c39797e872 introduce USE_TRANSIENT_HEAP to enable/disable theap.
* include/ruby/ruby.h: intrdocue `USE_TRANSIENT_HEAP` macro
  to enable/disable transient heap.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-01 08:53:44 +00:00