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]
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).
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.
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.
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.
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.
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
* 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.
* 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
* 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
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
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
* 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
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
* 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
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
* 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
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
* 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
* 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
* 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
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
* 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