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

391 Коммитов

Автор SHA1 Сообщение Дата
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
shyouhei 3ca0948f68 INFINITY is float. That of double is HUGE_VAL.
It seems HUGE_VAL is already used. Why not eliminate INTINITY.
NAN is also float. That of double is called nan(). This is also
fixed.

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-19 01:45:36 +00:00
shyouhei 29b0b75beb long_toobig marked as NORETURN
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 09:44:39 +00:00
nobu fcb112a172 marshal.c: initialize keywords
* marshal.c (r_object0): initialize `keywords` and removed
  `keyword_init` flag, to get rid of maybe-uninitialized warning.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 01:27:45 +00:00
naruse 900bf7682e include ruby/ruby.h before ruby.io.h
It breaks AIX build:
https://rubyci.org/logs/rubyci.s3.amazonaws.com/aix71_ppc/ruby-trunk/log/20180117T113303Z.log.html.gz

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17 18:08:58 +00:00
kazu 51edb30042 Include ruby/{io,encoding}.h before internal.h
because of r61712 and r61713

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 12:35:12 +00:00
k0kubun 26df9588d6 marshal.c: allow marshalling keyword_init struct
struct.c: define rb_struct_s_keyword_init to shared with marshal.c

internal.h: add the declaration to be used by marshal.c

test/ruby/test_marshal.rb: add test for Bug#14314

[Feature #14314] [ruby-core:84629]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 11:44:31 +00:00
nobu 340fe20a3b hide internal data objects
* marshal.c (compat_allocator_table): hide the wrapper object of
  compat_allocator_tbl.

* process.c (rb_execarg_new): hide wrapper objects of struct
  rb_execarg.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61009 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-04 07:37:21 +00:00
glass 8875e0ca4a use rb_hash_new_with_size()
* hash.c: use rb_hash_new_with_size().

* marshal.c: ditto

* struct.c: ditto

* vm_args.c: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-01 04:26:25 +00:00
nobu d9ae8c0bc8 marshal.c: revert r57631 partially
* marshal.c (rb_marshal_dump_limited): do not free dump_arg, which
  may be dereferenced in check_dump_arg due to continuation, and
  get rid of dangling pointers.

* marshal.c (rb_marshal_load_with_proc): ditto for load_arg.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-15 08:38:01 +00:00
normal 9f20ee518d marshal.c: use hidden objects to allow recycling
Hidden objects (klass == 0) are not visible to Ruby code invoked
from other threads or signal handlers, so they can never be
accessed from other contexts.  This makes it safe to call
rb_gc_force_recycle on the object slot after releasing malloc
memory.

* marshal.c (rb_marshal_dump_limited): hide dump_arg and recycle when done
  (rb_marshal_load_with_proc): hide load_arg and recycle when done
  [ruby-core:79518]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-15 00:42:51 +00:00
nobu 9eb54f7fb4 ruby.h: RB_GC_GUARD stronger than gcc7
* include/ruby/ruby.h (RB_GC_GUARD): prevent guarded pointer from
  optimization by using as an input to inline asm.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-02-13 08:14:19 +00:00
naruse 7c1b30a602 Prevent GC by volatile [Bug #13150]
test/ruby/test_marshal.rb test_context_switch (load) and test_gc (dump)
are failed on FreeBSD 10.3 and gcc7 (FreeBSD Ports Collection) 7.0.0
20170115 (experimental); RB_GC_GUARD looks not worked well.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-23 16:58:27 +00:00
nobu e83c344645 marshal.c: fix infinite recursion
* marshal.c (check_userdump_arg): marshal_dump should not return
  an instance of the same class, otherwise it causes infinite
  recursion.  [ruby-core:78289] [Bug #12974]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-24 11:07:12 +00:00
nobu 88c3dcce6d marshal.c: negative limit
* marshal.c (w_object): should not decrement negative limit which
  means unlimited.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56893 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-24 10:59:35 +00:00
nobu 7bfeb1c2ae remove SIGN_EXTEND_CHAR macro
* marshal.c (r_long): cast to `signed char`, which is used
  already, instead of SIGN_EXTEND_CHAR.
* parse.y: SIGN_EXTEND_CHAR is no longer used.  [Fix GH-1302]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-23 02:44:54 +00:00
drbrain c9165d0644 * marshal.c (r_object0): raise ArgumentError when linking to undefined
object.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-16 22:18:12 +00:00
drbrain fa0e37646a * marshal.c (r_object0): Fix Marshal crash for corrupt extended object.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-14 18:36:14 +00:00
naruse 826f2ee306 * marshal.c (r_object0): honor Marshal.load post proc
value for TYPE_LINK.  by Hiroshi Nakamura <nahi@ruby-lang.org>
  https://github.com/ruby/ruby/pull/1204 fix GH-1204

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-21 08:36:01 +00:00
normal 328205c56e marshal.c: remove NULL checks for *_memsize
This follows r52986, NULL checks in rb_data_type_t.function.dsize
callbacks are unnecessary.

* marshal.c (memsize_dump_arg): remove NULL check
  (memsize_load_arg): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-09 21:34:01 +00:00
nobu 1fadd43881 marshal.c: skip internal names
* marshal.c (w_objivar): skip internal instance variables in
  T_OBJECT too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-08 05:20:41 +00:00
nobu 2a66cc554d encoding.c: defer finding encoding
* encoding.c (enc_m_loader): defer finding encoding object not to
  be infected by marshal source.  [ruby-core:71793] [Bug #11760]
* marshal.c (r_object0): enable compatible loader on USERDEF
  class.  the loader function is called with the class itself,
  instead of an allocated object, and the loaded data.
* marshal.c (compat_allocator_table): intialize
  compat_allocator_tbl on demand.
* object.c (rb_undefined_alloc): extract from rb_obj_alloc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-02 07:27:22 +00:00
nobu a497ed3733 marshal.c: lookup and remove
* marshal.c (r_fixup_compat): delete compatible object with
  lookup.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-02 06:50:41 +00:00