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

413 Коммитов

Автор SHA1 Сообщение Дата
Kazuhiro NISHIYAMA 04f07713d1
Fix typos [ci skip] 2021-12-25 10:33:49 +09:00
Jean Boussier afcbb501ac marshal.c Marshal.load accepts a freeze: true option.
Fixes [Feature #18148]

When set, all the loaded objects are returned as frozen.

If a proc is provided, it is called with the objects already frozen.
2021-10-05 18:34:56 +02:00
S.H dc9112cf10
Using NIL_P macro instead of `== Qnil` 2021-10-03 22:34:45 +09:00
Nobuyoshi Nakada d087214658 Restore Hash#compare_by_identity mode [Bug #18171] 2021-10-02 11:43:35 +09:00
Jean byroot Boussier 529fc204af
marshal.c: don't call the proc with partially initialized objects. (#4866)
For cyclic objects, it requires to keep a st_table of the partially
initialized objects.
2021-09-30 16:50:31 +02:00
Nobuyoshi Nakada 8226c33bb5
Add symname_equal_lit for comparison with a string literal 2021-09-23 22:07:52 +09:00
Nobuyoshi Nakada 49af9012a2
Prohibit invalid encoding symbols [Bug #18184] 2021-09-23 16:02:44 +09:00
Nobuyoshi Nakada 7cec727612
Check instance variable count overflow 2021-09-23 14:01:08 +09:00
Nobuyoshi Nakada 64bdad5991
Extract ruby2_keywords predicate and setter 2021-09-23 13:59:45 +09:00
Nobuyoshi Nakada 842a4cb915
Turned to_be_skipped_id to an inline function 2021-09-23 10:55:49 +09:00
Nobuyoshi Nakada 552728a23a
Check the encoding of `ruby2_keywords_flag` [Bug #18184] 2021-09-23 00:07:17 +09:00
Nobuyoshi Nakada 7c0230b05d
Check the entire name as `ruby2_keywords_flag` [Bug #18184] 2021-09-22 19:04:55 +09:00
Jean Boussier 89242279e6 Marshal.load: do not call the proc until strings have their encoding
Ref: https://bugs.ruby-lang.org/issues/18141
2021-09-15 08:00:18 +09:00
S.H 71ba09632b
Remove unneeded declarations 2021-03-20 21:00:29 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Nobuyoshi Nakada 5c49bb5486
Removed useless casts 2020-09-05 17:34:12 +09:00
卜部昌平 ff30358d13 RARRAY_AREF: convert into an inline function
RARRAY_AREF has been a macro for reasons.  We might not be able to
change that for public APIs, but why not relax the situation internally
to make it an inline function.
2020-08-15 12:09:26 +09:00
卜部昌平 41703fcfab r_object0: 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.
2020-06-29 11:05:41 +09:00
Jeremy Evans 98286e9850 Ensure origins for all included, prepended, and refined modules
This fixes various issues when a module is included in or prepended
to a module or class, and then refined, or refined and then included
or prepended to a module or class.

Implement by renaming ensure_origin to rb_ensure_origin, making it
non-static, and calling it when refining a module.

Fix Module#initialize_copy to handle origins correctly.  Previously,
Module#initialize_copy did not handle origins correctly.  For example,
this code:

```ruby
module B; end
class A
  def b; 2 end
  prepend B
end
a = A.dup.new
class A
  def b; 1 end
end
p a.b
```

Printed 1 instead of 2.  This is because the super chain for
a.singleton_class was:

```
a.singleton_class
A.dup
B(iclass)
B(iclass origin)
A(origin) # not A.dup(origin)
```

The B iclasses would not be modified, so the includer entry would be
still be set to A and not A.dup.

This modifies things so that if the class/module has an origin,
all iclasses between the class/module and the origin are duplicated
and have the correct includer entry set, and the correct origin
is created.

This requires other changes to make sure all tests still pass:

* rb_undef_methods_from doesn't automatically handle classes with
  origins, so pass it the origin for Comparable when undefing
  methods in Complex. This fixed a failure in the Complex tests.

* When adding a method, the method cache was not cleared
  correctly if klass has an origin.  Clear the method cache for
  the klass before switching to the origin of klass.  This fixed
  failures in the autoload tests related to overridding require,
  without breaking the optimization tests.  Also clear the method
  cache for both the module and origin when removing a method.

* Module#include? is fixed to skip origin iclasses.

* Refinements are fixed to use the origin class of the module that
  has an origin.

* RCLASS_REFINED_BY_ANY is removed as it was only used in a single
  place and is no longer needed.

* Marshal#dump is fixed to skip iclass origins.

* rb_method_entry_make is fixed to handled overridden optimized
  methods for modules that have origins.

Fixes [Bug #16852]
2020-06-03 09:50:37 -07:00
卜部昌平 9e41a75255 sed -i 's|ruby/impl|ruby/internal|'
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平 d7f4d732c1 sed -i s|ruby/3|ruby/impl|g
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
卜部昌平 9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
2020-04-08 13:28:13 +09:00
Yusuke Endoh b23fd59cbb marshal.c: Support dump and load of a Hash with the ruby2_keywords flag
It is useful for a program that dumps and load arguments (like drb).
In future, they should deal with both positional arguments and keyword
ones explicitly, but until ruby2_keywords is deprecated, it is good to
support the flag in marshal.

The implementation is similar to String's encoding; it is dumped as a
hidden instance variable.

[Feature #16501]
2020-01-17 17:20:19 +09:00
Nobuyoshi Nakada 012f297311
Get rid of use of magic number 'E' 2020-01-11 20:19:58 +09:00
卜部昌平 5e22f873ed decouple 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).
2019-12-26 20:45:12 +09: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
卜部昌平 7b6fde4258 drop-in type check for rb_define_module_function
We can check the function pointer passed to rb_define_module_function
like how we do so in rb_define_method.  The difference is that this
changeset reveales lots of atiry mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平 50f5a0a8d6 rb_hash_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit adds function prototypes
for rb_hash_foreach / st_foreach_safe.  Also fixes some prototype
mismatches.
2019-08-27 15:52:26 +09:00
卜部昌平 6dd60cf114 st_foreach now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit deletes ANYARGS from
st_foreach.  I strongly believe that this commit should have had come
with b0af0592fd, which added extra
parameter to st_foreach callbacks.
2019-08-27 15:52:26 +09:00
Nobuyoshi Nakada ffdef3674a
Warn instance variable `E`
It is not dumped, as it is a short alias for `:encoding`.
2019-08-10 13:18:41 +09:00
git 3c3783ac88 * expand tabs. 2019-08-10 11:43:07 +09:00
Nobuyoshi Nakada ab31693af1
Share caches for short encoding ivar name. 2019-08-10 11:38:49 +09:00
git e315f3a134 * expand tabs. 2019-07-31 10:22:47 +09:00
Koichi Sasada 72825c35b0 Use 1 byte hint for ar_table [Feature #15602]
On ar_table, Do not keep a full-length hash value (FLHV, 8 bytes)
but keep a 1 byte hint from a FLHV (lowest byte of FLHV).
An ar_table only contains at least 8 entries, so hints consumes
8 bytes at most. We can store hints in RHash::ar_hint.

On 32bit CPU, we use 4 entries ar_table.

The advantages:
* We don't need to keep FLHV so ar_table only consumes
  16 bytes (VALUEs of key and value) * 8 entries = 128 bytes.
* We don't need to scan ar_table, but only need to check hints
  in many cases. Especially we don't need to access ar_table
  if there is no match entries (in many cases).
  It will increase memory cache locality.

The disadvantages:
* This technique can increase `#eql?` time because hints can
  conflicts (in theory, it conflicts once in 256 times).
  It can introduce incompatibility if there is a object x where
  x.eql? returns true even if hash values are different.
  I believe we don't need to care such irregular case.
* We need to re-calculate FLHV if we need to switch from ar_table
  to st_table (e.g. exceeds 8 entries).
  It also can introduce incompatibility, on mutating key objects.
  I believe we don't need to care such irregular case too.

Add new debug counters to measure the performance:
* artable_hint_hit - hint is matched and eql?#=>true
* artable_hint_miss - hint is not matched but eql?#=>false
* artable_hint_notfound - lookup counts
2019-07-31 09:52:03 +09:00
git ff5b149435 * expand tabs. 2019-07-14 14:04:34 +09:00
Yusuke Endoh ba94404f70 Add /* fall through */ comments
to suppress some Coverity Scan warnings
2019-07-14 14:04:19 +09:00
git 70dcf5b368 * expand tabs. 2019-07-01 16:25:56 +09:00
Nobuyoshi Nakada 78ee2c2453
marshal.c: check instance variable count
* marshal.c (w_ivar_each): ensure that no instance variable was
  removed while dumping other instance variables.  [Bug #15968]
2019-07-01 16:20:03 +09:00
Nobuyoshi Nakada 0b1e26398e
Hoisted out w_ivar_each 2019-07-01 16:18:51 +09:00
Nobuyoshi Nakada c9423b016c
marshal.c: check instance variable count
* marshal.c (w_obj_each): ensure that no instance variable was
  added while dumping other instance variables.  [Bug #15968]
2019-07-01 15:02:27 +09:00
Nobuyoshi Nakada e690df1f1e
Marshal distant past/future
[Feature #15160]
2019-06-19 15:26:53 +09:00
Nobuyoshi Nakada c8b001858e
Revert "marshal.c: new functions for extensions"
This reverts a commit miss, 24a96a0228.
2019-06-04 19:06:19 +09:00
Nobuyoshi Nakada 24a96a0228
marshal.c: new functions for extensions
* marshal.c (rb_marshal_dump_limited): new function for extension
  libraries to dump object with limited nest level.

* marshal.c (rb_marshal_load_with_proc): new function for extension
  libraries to load object with hook proc.
2019-06-04 18:59:03 +09:00
shyouhei 3a083985a4 avoid division by zero
* cvt(): use signbit() instead of 1/d < 0
* w_float(): ditto
* ruby_float_step_size(): unit==0 check shall be prior to divisions
* arith_seq_float_step_size(): ditto
* rb_big_divide(): same as r65642
* fix_divide(): ditto
* rb_big_fdiv_double(): ditto
* fix_fdiv_double(): ditto


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-16 01:52:39 +00:00
shyouhei 86d1fc8863 suppress integer overflow warnings
* util.c: annotate as NO_SANITIZE
* bignum.c: avoid (size_t)--
* marshal.c: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-15 07:34:01 +00:00
svn d4f1187d31 * remove trailing spaces, expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:12:12 +00:00
ko1 8f675cdd00 support theap for T_HASH. [Feature #14989]
* hash.c, internal.h: support theap for small Hash.
  Introduce RHASH_ARRAY (li_table) besides st_table and small Hash
  (<=8 entries) are managed by an array data structure.
  This array data can be managed by theap.
  If st_table is needed, then converting array data to st_table data.

  For st_table using code, we prepare "stlike" APIs which accepts hash value
  and are very similar to st_ APIs.

  This work is based on the GSoC achievement
  by tacinight <tacingiht@gmail.com> and refined by ko1.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30 22:11:51 +00:00
shyouhei 55702df221 move GCC version check from marshal.c to configure.ac
I think it should be done in configure


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-27 04:33:11 +00:00
ko1 d0fb73a0f0 check enc_capable.
* encoding.c (rb_enc_capable): make it extern to check enc_capable.
  enc_index can be set to limited types such as T_STRING, T_REGEX
  and so on. This function check an object is this kind of types.

* include/ruby/encoding.h: ditto.

* encoding.c (enc_set_index): check a given object is enc_capable.

* include/ruby/encoding.h (PUREFUNC):

* marshal.c (encoding_name): check `rb_enc_capable` first.

* marshal.c (r_ivar): ditto. If it is not enc_capable, it should be
  malformed data.

* spec/ruby/optional/capi/encoding_spec.rb: remove tests depending
  on the wrong feature: all objects can set enc_index.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-28 08:35:48 +00:00
shyouhei 782236e3bd add missing/nan.c
instead of scattering #ifdef HAVE_NANF here and there define our
own nan() unless defined elsewhere.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-20 03:16:59 +00:00