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

594 Коммитов

Автор SHA1 Сообщение Дата
nobu 3bcf9fb53e hash.c: same hash values with Float#hash
* hash.c (rb_any_hash): use same hash values with Float#hash so
  that -0.0 and +0.0 will be identical.
  [ruby-core:68541] [Bug #10979]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-18 03:01:58 +00:00
gogotanaka 744a858bd2 * hash.c: [DOC] #delete method actually returns nil, if the key
is not found. [fix GH-844][ci skip] Patch by @ivdma

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-05 08:00:14 +00:00
nobu 802d71a57e [DOC] ENV keys must be strings [ci skip]
* hash.c (env_aset): state that ENV keys must be strings.

* process.c (rb_f_spawn): ditto.  [ruby-core:68146] [Bug #10859]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-18 02:42:58 +00:00
hsbt f6b9a0feaf * hash.c: Added docs to explain that #include? and #member? do not
check member equality
* lib/set.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-17 01:47:28 +00:00
nobu e567f351c2 marshal.c: indetity tables
* marshal.c (w_object, marshal_dump): use indetity tables for
  arbitrary VALUE keys, because of performance of FLONUM.
  [Bug #10761]
* marshal.c (obj_alloc_by_klass, marshal_load): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49389 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-23 11:01:02 +00:00
nobu 059ea6e4d8 hash.c: move Hash specific functions
* hash.c (rb_ident_hash): move compare_by_identity specific
  function from st.c.

* hash.c (rb_ident_hash_new): ditto from thread.c.

* st.c (st_numhash): remove ruby's Hash specific implementation.

* thread.c (recursive_list_access): use rb_ident_hash_new().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-23 02:36:50 +00:00
normal 6d56fd067e fix flonum hashing regression from r45384
* st.c (st_numhash): mix float value for flonum
* hash.c (rb_any_hash): ditto
* benchmark/bm_hash_aref_flo.rb: new benchmark
* benchmark/bm_hash_ident_flo.rb: ditto
  [Bug #10761]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-22 07:48:59 +00:00
ayumin 45ecc02716 * hash.c: fix docs for Hash#invert. [ruby-core:66917] [Bug #10612]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-01-03 15:00:31 +00:00
ko1 9c6eaad723 * hash.c (rb_hash_delete): return Qnil if there are no corresponding
entry. [Bug #10623]
* hash.c (rb_hash_delete_entry): try delete and return Qundef if there
  are no corresponding entry.
* internal.h: add rb_hash_delete_entry()'s declaration.
* symbol.c: use rb_hash_delete_entry().
* thread.c: use rb_hash_delete_entry().
* ext/-test-/hash/delete.c: use rb_hash_delete_entry().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-24 02:53:37 +00:00
nobu 62d43632ba hash.c: fix return value
* hash.c (hash_equal): prefer true than the result of implicit
  conversion from int returned by rb_eql() to VALUE.  [Fix GH-789]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48891 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-19 06:36:05 +00:00
akr 2b9191e557 * internal.h: Gather declarations in non-header files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-18 15:13:05 +00:00
akr 7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
ko1 5d5c95f28e * gc.c (gc_stat_internal): add compatible layer.
From Ruby 2.2, keys of GC.stat are changed [Feature #9924].
  To provide compatible layer, GC.stat add a default_proc
  (if default_proc of given Hash object is not set).
  At first use of this compatible layer of interpreter process,
  show a warning message like that:
  program: GC.stat[:total_allocated_object]
  warning message: "warning: GC.stat keys were changed from Ruby
  2.1. In this case,  you refer to obsolete `total_allocated_object'
  (new key is `total_allocated_objects').
  Please check <https://bugs.ruby-lang.org/issues/9924>
  for more information."
  Pleaes correct my English message :)
* hash.c (rb_hash_set_default_proc): export (in internal).
* internal.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-14 07:29:33 +00:00
ko1 fbebd502f9 * rewrite method/block parameter fitting logic to optimize
keyword arguments/parameters and a splat argument.
  [Feature #10440] (Details are described in this ticket)
  Most of complex part is moved to vm_args.c.
  Now, ISeq#to_a does not catch up new instruction format.
* vm_core.h: change iseq data structures.
  * introduce rb_call_info_kw_arg_t to represent keyword arguments.
  * add rb_call_info_t::kw_arg.
  * rename rb_iseq_t::arg_post_len to rb_iseq_t::arg_post_num.
  * rename rb_iseq_t::arg_keywords to arg_keyword_num.
  * rename rb_iseq_t::arg_keyword to rb_iseq_t::arg_keyword_bits.
    to represent keyword bitmap parameter index.
    This bitmap parameter shows that which keyword parameters are given
    or not given (0 for given).
    It is refered by `checkkeyword' instruction described bellow.
  * rename rb_iseq_t::arg_keyword_check to rb_iseq_t::arg_keyword_rest
    to represent keyword rest parameter index.
  * add rb_iseq_t::arg_keyword_default_values to represent default
    keyword values.
  * rename VM_CALL_ARGS_SKIP_SETUP to VM_CALL_ARGS_SIMPLE
    to represent
      (ci->flag & (SPLAT|BLOCKARG)) &&
      ci->blockiseq == NULL &&
      ci->kw_arg == NULL.
* vm_insnhelper.c, vm_args.c: rewrite with refactoring.
  * rewrite splat argument code.
  * rewrite keyword arguments/parameters code.
  * merge method and block parameter fitting code into one code base.
* vm.c, vm_eval.c: catch up these changes.
* compile.c (new_callinfo): callinfo requires kw_arg parameter.
* compile.c (compile_array_): check the last argument Hash object or
  not. If Hash object and all keys are Symbol literals, they are
  compiled to keyword arguments.
* insns.def (checkkeyword): add new instruction.
  This instruction check the availability of corresponding keyword.
  For example, a method "def foo k1: 'v1'; end" is cimpiled to the
  following instructions.
    0000 checkkeyword     2, 0  # check k1 is given.
    0003 branchif         9     # if given, jump to address #9
    0005 putstring        "v1"
    0007 setlocal_OP__WC__0 3   # k1 = 'v1'
    0009 trace            8
    0011 putnil
    0012 trace            16
    0014 leave
* insns.def (opt_send_simple): removed and add new instruction
  "opt_send_without_block".
* parse.y (new_args_tail_gen): reorder variables.
  Before this patch, a method "def foo(k1: 1, kr1:, k2: 2, **krest, &b)"
  has parameter variables "k1, kr1, k2, &b, internal_id, krest",
  but this patch reorders to "kr1, k1, k2, internal_id, krest, &b".
  (locate a block variable at last)
* parse.y (vtable_pop): added.
  This function remove latest `n' variables from vtable.
* iseq.c: catch up iseq data changes.
* proc.c: ditto.
* class.c (keyword_error): export as rb_keyword_error().
* common.mk: depend vm_args.c for vm.o.
* hash.c (rb_hash_has_key): export.
* internal.h: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-02 18:02:55 +00:00
nobu ca7835bec6 hash.c: rb_hash_delete does not call the block
* hash.c (rb_hash_delete): now does not call the block given to
  the current method.  [ruby-core:65861] [Bug #10413]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48114 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-23 12:42:57 +00:00
normal 3cb3966838 hash.c (rb_any_hash): remove unnecessary dsym check
gcc (Debian 4.7.2-5) 4.7.2 on x86 generates smaller code this
way, as it does not seem to be able to reuse the result of
SPECIAL_CONST_P.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47853 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-09 03:39:02 +00:00
nobu 28b9f11d5a protoize no-arguments functions
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47744 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-30 05:25:32 +00:00
nobu f3c9ffe094 hash.c: [DOC] fix for Hash#store docs
* hash.c (rb_hash_aset): fix misleading example which may suggest
  that Hash.store will return self instead of value - Hash#store
  is returning value and update itself, as well as Hash#[]=.
  [Fix GH-715]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-13 13:19:27 +00:00
ko1 123eeb1c1a * gc.c: add incremental GC algorithm. [Feature #10137]
Please refer this ticket for details.
  This change also introduces the following changes.
  * Remove RGENGC_AGE2_PROMOTION and introduce object age (0 to 3).
    Age can be count with FL_PROMOTE0 and FL_PROMOTE1 flags in
    RBasic::flags (2 bit). Age == 3 objects become old objects.
  * WB_PROTECTED flag in RBasic to WB_UNPROTECTED bitmap.
  * LONG_LIVED bitmap to represent living objects while minor GCs
    It specifies (1) Old objects and (2) remembered shady objects.
  * Introduce rb_objspace_t::marked_objects which counts marked
    objects in current marking phase. marking count is needed to
    introduce incremental marking.
  * rename mark related function and sweep related function to
    gc_(marks|sweep)_(start|finish|step|rest|continue).
  * rename rgengc_report() to gc_report().
  * Add obj_info() function to get cstr of object details.
  * Add MEASURE_LINE() macro to measure execution time of specific line.
  * and many small fixes.
* include/ruby/ruby.h: add flag USE_RINCGC.
  Now USE_RINCGC can be set only with USE_RGENGC.
* include/ruby/ruby.h: introduce FL_PROMOTED0 and add FL_PROMOTED1
  to count object age.
* include/ruby/ruby.h: rewrite write barriers for incremental marking.
* debug.c: catch up flag name changes.
* internal.h: add rb_gc_writebarrier_remember() instead of
  rb_gc_writebarrier_remember_promoted().
* array.c (ary_memcpy0): use rb_gc_writebarrier_remember().
* array.c (rb_ary_modify): ditto.
* hash.c (rb_hash_keys): ditto.
* hash.c (rb_hash_values): ditto.
* object.c (init_copy): use rb_copy_wb_protected_attribute() because
  FL_WB_PROTECTED is moved from RBasic::flags.
* test/objspace/test_objspace.rb: catch up ObjectSpace.dump() changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-09-08 04:11:00 +00:00
nobu d738e3e155 optimized any? methods
* array.c (rb_ary_any_p), hash.c (rb_hash_any_p): optimized
  versions.  these are bit faster than optimization in
  Enumerable#any?.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-18 13:16:48 +00:00
ngoto 90b1b2e607 * hash.c (ruby_setenv): Fix TestEnv#test_aset failure on Solaris 9.
When name contains '=', ruby_setenv raises Errno::EINVAL.
  That is the same behavior as Solaris 10.
  NULL check for malloc return value is also added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-10 15:22:07 +00:00
nobu 255adda52f hash.c: use rb_check_arity
* hash.c (rb_hash_initialize, rb_hash_fetch_m, rb_hash_default):
  use rb_check_arity over rb_scan_args.
  (env_fetch): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46660 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-02 08:25:21 +00:00
nobu 68bc5ba1b6 hash.c: fix memory leak
* hash.c (env_shift): fix memory leak on Windows, free environment
  strings block always.  [ruby-dev:48332] [Bug #9983]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-26 20:33:34 +00:00
nobu 78c763a25c hash.c: fix memory leak
* hash.c (env_select): fix memory leak and crash on Windows, make
  keys array first instead of iterating on envrion directly.
  [ruby-dev:48325] [Bug #9978]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-25 23:28:04 +00:00
nobu 7eeaf208b4 hash.c: fix dangling pointer
* hash.c (env_name): also store a coerced string to get rid of a
  dangling pointer.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-25 22:43:23 +00:00
nobu 4198f1473a hash.c: fix memory leak
* hash.c (ruby_setenv): fix memory leak on Windows, free
  environment strings block after check for the size.
  [ruby-dev:48323] [Bug #9977]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-25 13:31:34 +00:00
nobu e1884ec820 hash.c: env_name
* hash.c (get_env_ptr, env_name): extract check for bad
  environment variable name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-25 12:18:53 +00:00
nobu 51a1c68bc7 hash.c: prohibit tainted strings
* hash.c (env_aset, env_has_key, env_assoc, env_has_value),
  (env_rassoc, env_key): prohibit tainted strings if $SAFE is
  non-zero.  [Bug #9976]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-25 01:20:01 +00:00
nobu 20014eb3e0 hash.c: unused functions on non-Windows
* hash.c (invalid_envname, check_envname): not used on platforms
  other than Windows.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-24 18:24:24 +00:00
nobu c5255bdd03 hash.c: env_str_transcode
* hash.c (env_str_transcode): convert with replacing invalid/undef
  characters, on Windows.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-24 18:02:31 +00:00
nobu 9a6518abf7 hash.c: replace undef
* hash.c (env_str_new, env_path_str_new): replace invalid or
  undefined conversions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-24 02:19:09 +00:00
nobu 5c9bc9f8e1 hash.c: frozen PATH env
* hash.c (env_path_str_new): make PATH environment variable
  string, to be frozen.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46538 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-24 01:50:09 +00:00
shyouhei 8250aa2df0 * include/ruby/ruby.h (struct RHash): no longer. [Feature #9889]
* include/ruby/ruby.h (RHASH): ditto.

	* include/ruby/ruby.h (RHASH_ITER_LEV): deprecated.  Will be deleted later.

	* include/ruby/ruby.h (RHASH_IFNONE): ditto.

	* internal.h (struct RHash): moved here.

	* internal.h (RHASH): ditto.

	* hash.c (rb_hash_iter_lev): do not use this.

	* hash.c (rb_hash_ifnone): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-06-23 07:26:03 +00:00
nobu 7f3b12f05b use predefined IDs
* array.c (rb_ary_equal), hash.c (hash_equal): use predefined IDs,
  `to_ary` and `to_hash` respectively.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-20 08:28:31 +00:00
nobu 5bec2d8ccd hash.c: make rb_hash_keys extern
* hash.c (rb_hash_keys): make an internal public function.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-07 04:26:53 +00:00
nobu 10cf7c5b2a hash.c: use ID_SCOPE_SHIFT
* hash.c (rb_any_hash): use ID_SCOPE_SHIFT instead of magic number.
  [Feature #9425]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45386 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-23 01:10:12 +00:00
normal ef59670a44 st.c: use power-of-two sizes to avoid slow modulo ops
* st.c (hash_pos): use bitwise AND to avoid slow modulo op
  (new_size): power-of-two sizes for hash_pos change
  (st_numhash): adjust for common keys due to lack of prime modulo
  [Feature #9425]
* hash.c (rb_any_hash): right shift for symbols
* benchmark/bm_hash_aref_miss.rb: added to show improvement
* benchmark/bm_hash_aref_sym_long.rb: ditto
* benchmark/bm_hash_aref_str.rb: ditto
* benchmark/bm_hash_aref_sym.rb: ditto
* benchmark/bm_hash_ident_num.rb: added to prevent regression
* benchmark/bm_hash_ident_obj.rb: ditto
* benchmark/bm_hash_ident_str.rb: ditto
* benchmark/bm_hash_ident_sym.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-22 23:34:21 +00:00
nobu fc23374f06 [DOC] add links to `Object#hash`
add links to `Object#hash` to each #`hash` methods rdocs.
[Fixes GH-567]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-14 01:27:43 +00:00
nobu 1f29e8e2ba class.c: do nothing if copying self
* class.c (rb_mod_init_copy): do nothing if copying self.
  [ruby-dev:47989] [Bug #9535]
* hash.c (rb_hash_initialize_copy): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-21 11:42:03 +00:00
glass 13834fb3cb * hash.c (rb_hash_flatten): fix behavior of flatten(0).
[ruby-dev:47988] [Bug #9533]

* test/ruby/test_array.rb: test for above. patch is from
  Takeshi Sasaki.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-20 03:09:13 +00:00
glass f138018e9e * hash.c (rb_hash_flatten): fix behavior of flatten(-1).
[ruby-dev:47988] [Bug #9533]

* test/ruby/test_array.rb: test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45057 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-20 02:27:30 +00:00
tmm1 58f800a278 insns.def: add opt path for Hash#[] and Hash#[]= used with str literal keys
* insns.def (opt_aref_with): new instruction to optimize Hash#[],
  removing any allocation overhead when used with a string literal
  key. Patch by normalperson (Eric Wong). [ruby-core:59640] [Bug #9382]
* insns.def (opt_aset_with): new instruction to optimize Hash#[]=
* compile.c (iseq_compile_each): compiler shortcuts for new
  instructions
* hash.c (static VALUE rb_hash_compare_by_id_p): fix documentation for
  Hash#compare_by_identity to reflect frozen string sharing
* test/ruby/test_hash.rb (class TestHash): test for new behavior

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-10 04:54:08 +00:00
usa ac2864a871 * hash.c (rb_objid_hash): should return `long'. brushup r44534.
* object.c (rb_obj_hash): follow above change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-09 11:34:17 +00:00
usa 8abc55bc54 * hash.c (rb_any_hash): should treat the return value of rb_objid_hash()
as `long', because ruby assumes the object id of an object is `long'.
  this fixes test failures on mswin64 introduced at r44525.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-09 08:42:42 +00:00
nobu ab6efa5be2 object.c: hash value from objid with salt
* hash.c (rb_objid_hash): return hash value from object ID with a
  salt, extract from rb_any_hash().
* object.c (rb_obj_hash): return same value as rb_any_hash().
  fix r44125.  [ruby-core:59638] [Bug #9381]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-08 06:55:24 +00:00
glass 2c11bda8b9 * hash.c (rb_hash_keys): make rb_hash_keys() static.
it is no longer used from array.c since r43969.
  the patch is from normalperson (Eric Wong).
  [ruby-core:59449] [Feature #9336]

* internal.h: remove definition of rb_hash_keys().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-01 15:19:23 +00:00
nobu 4ce4f43f91 hash.c: remove dead code
* hash.c (rb_hash_reject): remove dead code for the deprecated
  behavior.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-26 05:28:24 +00:00
nobu 3a247f6489 hash.c: no extra states copy
* hash.c (HASH_REJECT_COPY_EXTRA_STATES): turn off the old
  behavior, copying extra states by accident.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-26 05:25:08 +00:00
nobu af17af1faa hash.c: extra states
* hash.c (rb_hash_reject): use words "extra states".


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-24 01:13:40 +00:00
nobu bc159ec502 hash.c: fix infinite loop
* hash.c (has_extra_methods): traverse ancestors, and fix infinite
  loop.  [Bug #9275]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 09:01:05 +00:00
nobu cb62186b07 hash.c: fix commit miss
* hash.c (HAS_EXTRA_STATES): remove extra parenthesis.
  [Bug #9275]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 07:00:01 +00:00
nobu c25c84777c hash.c: reduce warning
* hash.c (HAS_EXTRA_STATES): warn extra states only when something
  differ.  [ruby-core:59254] [Bug #9275]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 06:53:51 +00:00
nobu 21e74f5481 hash.c: reword
* hash.c (HAS_EXTRA_STATES, rb_hash_reject): use words
  "extra states".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44358 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-23 06:53:17 +00:00
ko1 c702005a7b * include/ruby/ruby.h: rename OBJ_WRITE and OBJ_WRITTEN into
RB_OBJ_WRITE and RB_OBJ_WRITTEN.
* array.c, class.c, compile.c, hash.c, internal.h, iseq.c,
  proc.c, process.c, re.c, string.c, variable.c, vm.c,
  vm_eval.c, vm_insnhelper.c, vm_insnhelper.h,
  vm_method.c: catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-20 08:07:47 +00:00
nobu 571955c13f hash.c: revert
* hash.c (rb_hash_reject): revert to deprecated behavior, with
  warnings, due to compatibility for HashWithDifferentAccess.
  [ruby-core:59154] [Bug #9223]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-17 11:15:00 +00:00
nobu cf460c34f7 hash.c: add warnings
* hash.c (rb_hash_reject): warn attributes in detail more.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-17 11:01:37 +00:00
nobu 26e425e6f4 hash.c: typo
* hash.c (rb_hash_reject): fix typo in macro name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-16 14:36:14 +00:00
nobu 0988148782 hash.c: warnings in rb_hash_reject
* hash.c (rb_hash_dup_empty): split from rb_hash_dup.

* hash.c (rb_hash_reject): add warnings (currently suppressed).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-16 13:40:04 +00:00
nobu 6cd0d06bae hash.c: refactor loop
* hash.c (rb_hash): rewrite with while instead of goto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-16 13:40:02 +00:00
nobu 740535f843 hash.c: reject should return a plain hash
* hash.c (rb_hash_reject): return a plain hash, without copying
  the class, default value, instance variables, and taintedness.
  they had been copied just by accident.
  [ruby-core:59045] [Bug #9223]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-11 07:01:29 +00:00
nobu 037a9d0655 array.c, hash.c: add salt
* array.c (rb_ary_hash): add salt to differentiate false and empty
  array.  [ruby-core:58993] [Bug #9231]
* hash.c (rb_any_hash, rb_hash_hash): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-10 14:44:51 +00:00
tmm1 a111923062 hash.c: fix segv in Hash#replace
* hash.c (rb_hash_replace): fix segv on `{}.replace({})` introduced
  in r44060 [Bug #9230] [ruby-core:58991]
* test/ruby/test_hash.rb: regression test for above

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44096 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-09 10:06:49 +00:00
nobu cf85aaf83e hash.c: reject shoult infect
* hash.c (rb_hash_reject): result should be infected by the
  receiver.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 11:25:06 +00:00
tmm1 3dd248f13d hash.c: fix WB miss issue in Hash#replace
* hash.c (rb_hash_replace): add a write barrier to fix GC mark miss on
  hashes using Hash#replace [Bug #9226] [ruby-core:58948]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 03:03:42 +00:00
tmm1 779ae78995 hash.c: revert r43870 and add alternative parser patch for literal keys
* hash.c (hash_aset_str): revert r43870 due to performance issue
  [Bug #9188] [ruby-core:58730]
* parse.y (assoc): convert literal string hash keys to fstrings
* test/ruby/test_hash.rb (class TestHash): expand test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-08 01:52:28 +00:00
nobu 7416073cde hash.c: rb_hash_reject without dup
* hash.c (rb_hash_reject): copy unrejected elements only to new hash,
  so that the change on the original receiver can affect.
  [ruby-core:58914] [Bug #9223]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-07 02:16:04 +00:00
nobu 1bbc52dee1 hash.c: bail out to the outermost frame
* hash.c (rb_hash): revert r43981 and bail out to the outermost frame
  when recursion is detected.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-05 05:40:43 +00:00
nobu 218d1f5e1e hash.c: same hash value for similar constructs
* hash.c (rb_hash_recursive): make similar (recursive) constructs
  return same hash value.  execute recursively, and rewind to the
  topmost frame with an object which .eql? to the recursive
  object, if recursion is detected.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 13:32:24 +00:00
nobu 6f2efe84fb hash.c: detect recursion for all
* hash.c (rb_hash): detect recursion for all `hash' methods.  each
  `hash' methods no longer need to use rb_exec_recursive().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 13:18:30 +00:00
glass 437b8bc53b * array.c (rb_hash_rehash): use hash_alloc() instead of rb_hash_new().
[Bug #9187]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 11:19:06 +00:00
nobu d7de38ff62 * hash.c (w32_getenv): should be static.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-03 03:18:46 +00:00
usa ff9f9c6d84 * hash.c (getenv): fixed test failures introduced by r43950.
[ruby-core:58774] [Bug #9195] reported by phasis68 (Heesob Park).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-02 13:31:14 +00:00
glass ead0c5d356 * hash.c (rb_hash_rehash): make temporary st_table under the control
of GC. [Bug #9187]

* test/ruby/test_hash.rb: add a test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-02 12:59:31 +00:00
usa 6b1a58b9e6 * hash.c (getenv): use ANSI codepage version of getenv() for miniruby
on Windows.
  [ruby-core:58732] [Bug #9189] reported by phasis68 (Heesob Park).


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43950 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-01 15:55:56 +00:00
glass 8efbe96231 * hash.c (rb_hash_to_a): specify array capa.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-01 05:39:38 +00:00
glass bfbe1b9b31 * hash.c (rb_hash_rehash): fix to free new st_table when exception
is raised in do_hash(). [Bug #9187]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-12-01 05:28:54 +00:00
glass 79e6336495 * st.c: add st_values() and st_values_check().
* include/ruby/st.h: add prototypes for above.

* hash.c (rb_hash_values): use st_values_check() for performance
 improvement if VALUE and st_data_t are compatible.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43895 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-28 08:39:16 +00:00
glass 78cfcbc657 * st.c (st_keys): fix not to use Qundef in st.c.
* include/ruby/st.h: define modified prototype.

* hash.c (rb_hash_keys): use modified st_keys().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43894 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-28 08:15:26 +00:00
glass 8c91dfb91b * st.c (st_keys): fix to use st_index_t for size of hash.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 16:36:44 +00:00
glass b426e1b1fa * st.c (st_keys): define st_keys(). it writes each key to buffer.
* hash.c (rb_hash_keys): use st_keys() for performance improvement
  if st_data_t and VALUE are compatible.

* st.h: define macro ST_DATA_COMPATIBLE_P() to predicate whether
  st_data_t and passed type are compatible.

* configure.in: check existence of builtin function to use in
  ST_DATA_COMPATIBLE_P().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 16:07:10 +00:00
tmm1 23178d1044 * gc.c (gc_page_sweep): Fix compile warning from last commit.
* hash.c (hash_aset_str): Re-use existing variable to avoid
  unnecessary pointer dereferencing.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 06:24:37 +00:00
tmm1 0c3b3e9237 * hash.c (hash_aset_str): Use rb_fstring() to de-duplicate hash string
keys. Patch by Eric Wong. [Bug #8998] [ruby-core:57727]
* test/ruby/test_hash.rb (class TestHash): test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-27 05:28:55 +00:00
nobu 94f01c55df should not ignore the rest of recursive constructs
* array.c (rb_ary_hash): should not ignore the rest of recursive
  constructs.
* hash.c (rb_hash_hash): ditto.
* range.c (range_hash): ditto.
* struct.c (rb_struct_hash): ditto.
* test/-ext-/test_recursion.rb (TestRecursion): separate from
  test/ruby/test_thread.rb.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-26 17:20:16 +00:00
nobu d503381ce8 hash.c: cut off if recursion
* hash.c (rb_hash): cut off if recursion detected to get rid of stack
  overflow.  [ruby-core:58567] [Bug #9151]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-26 13:43:40 +00:00
nobu abdada2d85 hash.c: static internal functions
* hash.c (NOINSERT_UPDATE_CALLBACK): make both of noinsert and insert
  internal functions static.  and put semicolons for etags to find the
  following functions properly.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-17 14:34:27 +00:00
tarui 28a1c4f33e * cont.c : Introdule ensure rollback mechanism. Please see below.
* internal.h (ruby_register_rollback_func_for_ensure): catch up above change.
	  Add rollback mechanism API.

	* vm_core.h (typedef struct rb_vm_struct): catch up above change.
	  Introdule ensure-rollback relation table.

	* vm_core.h (typedef struct rb_thread_struct): catch up above change.
	  Introdule ensure stack.

	* eval.c (rb_ensure): catch up above change.
	  Introdule ensure stack.

	* hash.c : New function for rollback ensure, and register it to
	  ensure-rollback relation table. [ruby-dev:47803] [Bug #9105]

	Ensure Rollback Mechanism:
	A rollback's function is a function to rollback a state before ensure's
	function execution.
	When the jump of callcc is across the scope of rb_ensure,
	ensure's functions and rollback's functions are executed appropriately
	for keeping consistency.

	Current API is unstable, and only internal use.

	ruby_register_rollback_func_for_ensure(ensure_func,rollback_func)
	This API create relation ensure's function to rollback's function.
	By registered rollback's function, it is executed When jumpping into
	corresponding rb_ensure scope.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-15 17:15:31 +00:00
tarui 9e96b1edea revert r43675 and r43683 without tests for applying rollback patch.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43687 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-15 17:08:52 +00:00
nobu e7d29c6cda hash.c: iteration level with reentering
* hash.c (hash_foreach_iter, hash_foreach_ensure, rb_hash_foreach):
  deal with iteration level when reentering by callcc.  temporary
  measure until rollback of ensure is introduced.  [ruby-dev:47807]
  [Bug #9105]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-15 13:21:38 +00:00
nobu 04c7fa0f3b hash.c: restore iter_lev
* hash.c (hash_foreach_ensure): restore iter_lev to the previous
  value, not just decrement.  [ruby-dev:47803] [Bug #9105]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-14 02:35:40 +00:00
nobu b0af0592fd hash.c, st.c: fix for ST_CHECK
* hash.c (foreach_safe_i, hash_foreach_iter): deal with error detected
  by ST_CHECK.
* st.c (st_foreach_check): call with non-error argument in normal case.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-14 02:33:50 +00:00
zzak 078ae7dd80 * hash.c: [DOC] Adds an example for Hash#store
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-13 01:43:49 +00:00
tmm1 8f3934261a * internal.h: move common string/hash flags to include file.
* ext/objspace/objspace_dump.c: remove flags shared above.
* hash.c: ditto.
* string.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-11 09:39:13 +00:00
nobu b28ce966c7 st.c: revert st_keys
* st.c: revert st_keys() at r43238.  VALUE cannot be in st.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 16:28:56 +00:00
glass 026955e375 * st.c (st_keys): define st_keys() for performance improvement of
Hash#keys and Array#uniq.

* st.h: ditto.

* hash.c (rb_hash_keys): use st_keys().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-10 12:06:01 +00:00
nobu 9c6ea2f200 array.c: use rb_hash_values
* array.c (rb_ary_uniq): use rb_hash_values(), as well as the case no
  block is given.
* internal.h: define rb_hash_values() as internal API.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-08 07:11:15 +00:00
glass 41eb48b88d * array.c (rb_ary_uniq): use rb_hash_keys().
* internal.h: define rb_hash_keys() as internal API.

* hash.c (rb_hash_keys): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43194 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-08 04:56:50 +00:00
charliesome 0b991b6579 * hash.c (env_update): [DOC] fix expected output, should be 0 instead
of 10. Patch by @yakko. [GH-411]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-03 00:43:01 +00:00
glass 7eaee5b5e2 * hash.c (env_each_pair): do not call rb_assoc_new() if
it isn't needed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-23 03:17:38 +00:00
nobu 85995e88d4 hash.c: utility functions from ruby_setenv
* hash.c (invalid_envname, check_envname): extract utility functions
  from ruby_setenv().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-13 07:28:25 +00:00
ktsj 04f0de74dd * error.c, file.c, gc.c, hash.c, thread.c, variable.c, vm_eval.c, bin/erb:
$SAFE=4 is obsolete.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-18 10:36:51 +00:00
zzak 7c5dc219d0 * hash.c (rb_hash_aset): [DOC] Document key dup patch by @kachick
[Fixes GH-382] https://github.com/ruby/ruby/pull/382


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-14 17:34:40 +00:00
glass 3118deb3ee * hash.c (rb_hash_compare_by_id): add function prototype.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-29 13:06:34 +00:00
glass cff03715ff * hash.c (rb_hash_compare_by_id): don't call rb_hash_rehash()
if self.compare_by_identity? == true.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-29 12:57:40 +00:00
glass eb8f91866e * hash.c (rb_hash_assoc): performance improvement by replacing
compare function in RHASH(hash)->ntbl->type temporarily like r42224.
  it falls back to rb_hash_foreach() if st_lookup() doesn't find the key.

* test/ruby/test_hash.rb: add a test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-29 12:39:21 +00:00
glass ef01a5a649 * hash.c (rb_hash_assoc): revert r42224. table->type->compare is
called only if hashes are matched.

* test/ruby/test_hash.rb: add a test to check using #== to compare.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-29 11:24:08 +00:00
nobu be24b385ff ChangeLog: commit miss
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-29 07:51:23 +00:00
glass 3f8e82b421 * hash.c (rb_hash_assoc): performance improvement by replacing
compare function in RHASH(hash)->ntbl->type temporarily.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-29 05:58:36 +00:00
naruse f262909cba * hash.c (rb_hash_flatten): use NUM2INT to raise TypeError on 32bit
platform. it's introduced by r42039

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-20 20:44:49 +00:00
glass 852caed8a3 * hash.c (rb_hash_flatten): performance improvement by not using
rb_hash_to_a() to avoid array creation with rb_assoc_new().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-18 08:48:12 +00:00
glass b30eb0fa04 * hash.c (delete_if_i): use ST_DELETE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-17 13:59:53 +00:00
glass 7c1a2f6192 * hash.c (rb_hash_replace): performance improvement by using
st_copy().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-17 13:17:01 +00:00
nobu c9118e2a86 hash.c: key name in error message
* hash.c (env_fetch): Add key name to message on ENV.fetch KeyError,
  as well as Hash#fetch.  [ruby-core:56062] [Feature #8649]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-17 08:12:25 +00:00
glass b9d2960337 * hash.c (rb_hash_each_pair): performance improvement by using
rb_block_arity().

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 04:38:50 +00:00
glass bc241235ac * hash.c (rb_hash_reject_bang): do not call rb_hash_foreach() if RHash
has ntbl and it is empty.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-12 02:35:16 +00:00
glass b9a9a02409 * hash.c (recursive_hash): use RHASH_SIZE() to check hash size.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-12 02:22:01 +00:00
glass 7a171aa8d1 * hash.c (rb_hash_size): use RHASH_SIZE().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41927 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-11 15:25:31 +00:00
glass 76a400ff71 * hash.c (rb_hash_values): set array capa to RHASH_SIZE().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-11 15:09:56 +00:00
glass c459495c77 * hash.c (rb_hash_keys): set array capa to RHASH_SIZE().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-11 15:06:18 +00:00
nobu 5e2f227d21 intern.h: define rb_enumerator_size_func
* include/ruby/intern.h (rb_enumerator_size_func): define strict
  function declaration for rb_enumeratorize_with_size().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-26 13:43:22 +00:00
charliesome fff3589899 * compile.c (make_name_for_block): use PRIsVALUE in format string
instead of %s and RSTRING_PTR to protect objects from being garbage
  collected too soon
* encoding.c (str_to_encindex): ditto
* hash.c (rb_hash_fetch_m): ditto
* io.c (rb_io_reopen): ditto
* parse.y (reg_fragment_check_gen): ditto
* parse.y (reg_compile_gen): ditto
* parse.y (ripper_assert_Qundef): ditto
* re.c (rb_reg_raise): ditto
* ruby.c (set_option_encoding_once): ditto
* vm_eval.c (rb_throw_obj): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-24 11:31:21 +00:00
ko1 982fee4fcc * include/ruby/ruby.h, gc.c: rename macros and functions:
OBJ_WB_GIVEUP() -> OBJ_WB_UNPROTECT(),
  rb_obj_wb_giveup() -> rb_obj_wb_unprotect(),
  rb_gc_giveup_promoted_writebarrier() ->
  rb_gc_writebarrier_unprotect_promoted(),
* class.c, eval.c, hash.c: use OBJ_WB_UNPROTECT().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-22 21:54:10 +00:00
ko1 4223f00713 * include/ruby/ruby.h (OBJ_WRITE): cast to (VALUE *) for second
parameter `slot'. You don't need to write a cast (VALUE *) any more.
* class.c, compile.c, hash.c, iseq.c, proc.c, re.c, variable.c,
  vm.c, vm_method.c: remove cast expressions for OBJ_WRITE().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-21 19:52:40 +00:00
nobu 79031be880 hash.c: refine error message
* hash.c (ruby_setenv): refine error message so include the variable
  name.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-21 05:31:41 +00:00
ko1 0f1df31bdf * hash.c: `st_update()' also has same issue of last fix.
write barriers at callback function are too early.
  All write barriers are executed after `st_update()'



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41398 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-18 21:29:30 +00:00
shugo 1f828497d1 * safe.c (rb_set_safe_level, safe_setter): raise an ArgumentError
when $SAFE is set to 4.  $SAFE=4 is now obsolete.
  [ruby-core:55222] [Feature #8468]

* object.c (rb_obj_untrusted, rb_obj_untrust, rb_obj_trust):
  Kernel#untrusted?, untrust, and trust are now deprecated.
  Their behavior is same as tainted?, taint, and untaint,
  respectively.

* include/ruby/ruby.h (OBJ_UNTRUSTED, OBJ_UNTRUST): OBJ_UNTRUSTED()
  and OBJ_UNTRUST() are aliases of OBJ_TAINTED() and OBJ_TAINT(),
  respectively.

* array.c, class.c, debug.c, dir.c, encoding.c, error.c, eval.c,
  ext/curses/curses.c, ext/dbm/dbm.c, ext/dl/cfunc.c,
  ext/dl/cptr.c, ext/dl/dl.c, ext/etc/etc.c, ext/fiddle/fiddle.c,
  ext/fiddle/pointer.c, ext/gdbm/gdbm.c, ext/readline/readline.c,
  ext/sdbm/init.c, ext/socket/ancdata.c, ext/socket/basicsocket.c,
  ext/socket/socket.c, ext/socket/udpsocket.c,
  ext/stringio/stringio.c, ext/syslog/syslog.c, ext/tk/tcltklib.c,
  ext/win32ole/win32ole.c, file.c, gc.c, hash.c, io.c, iseq.c,
  load.c, marshal.c, object.c, proc.c, process.c, random.c, re.c,
  safe.c, string.c, thread.c, transcode.c, variable.c,
  vm_insnhelper.c, vm_method.c, vm_trace.c: remove code for
  $SAFE=4.

* test/dl/test_dl2.rb, test/erb/test_erb.rb,
  test/readline/test_readline.rb,
  test/readline/test_readline_history.rb, test/ruby/test_alias.rb,
  test/ruby/test_array.rb, test/ruby/test_dir.rb,
  test/ruby/test_encoding.rb, test/ruby/test_env.rb,
  test/ruby/test_eval.rb, test/ruby/test_exception.rb,
  test/ruby/test_file_exhaustive.rb, test/ruby/test_hash.rb,
  test/ruby/test_io.rb, test/ruby/test_method.rb,
  test/ruby/test_module.rb, test/ruby/test_object.rb,
  test/ruby/test_pack.rb, test/ruby/test_rand.rb,
  test/ruby/test_regexp.rb, test/ruby/test_settracefunc.rb,
  test/ruby/test_struct.rb, test/ruby/test_thread.rb,
  test/ruby/test_time.rb: remove tests for $SAFE=4.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-12 14:20:51 +00:00
akr b23d9a8a63 * bignum.c (validate_integer_pack_format): Don't require a word order
flag if numwords is 1 or less.
  (absint_numwords_generic): Don't specify a word order for
  rb_integer_pack.

* hash.c (rb_hash): Ditto.

* time.c (v2w_bignum): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-11 14:40:16 +00:00
akr 0e8caa7d0f * bignum.c (rb_integer_pack): Returns sign instead of words.
(absint_numwords_generic): Follow the above change.
  (big2str_base_powerof2): Follow the above change.

* internal.h: Ditto.

* hash.c (rb_hash): Ditto.

* pack.c (pack_pack): Ditto.

* random.c (int_pair_to_real_inclusive): Ditto.
  (rand_init): Ditto.
  (random_load): Ditto.
  (limited_big_rand): Ditto.

* time.c (v2w_bignum): Ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-10 10:37:39 +00:00
akr 837392b452 * bignum.c (rb_integer_pack): numwords_allocated argument removed.
* internal.h (rb_integer_pack): Follow the above change.

* hash.c (rb_hash): Ditto.

* time.c (v2w_bignum): Ditto.

* pack.c (pack_pack): Ditto.

* random.c (int_pair_to_real_inclusive): Ditto.
  (rand_init): Ditto.
  (random_load): Ditto.
  (limited_big_rand): Ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41195 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-09 05:53:00 +00:00
akr e3bc7eec5f * hash.c (rb_hash): Use rb_integer_pack to obtain least significant
long integer.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-08 16:00:16 +00:00
nobu 6db56c86c9 fill rdocs
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41027 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-02 03:12:04 +00:00
ko1 68f96f6c3c * hash.c: fix WB bug.
(1) Hash's key also needs WB.
  (2) callback parameter *key and *value of st_update() is not a
  storage of st_table itself (only local variable). So that
  OBJ_WRITE() is not suitable, especially for `!exsinting'.
  OBJ_WRITTEN() is used instead of OBJ_WRITE().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-29 01:38:52 +00:00
ko1 c4c821a7d7 * hash.c (rb_hash_tbl_raw), internal.h: added.
Returns st_table without shading hash.
* array.c: use rb_hash_tbl_raw() for read-only purpose.
* compile.c (iseq_compile_each): ditto.
* gc.c (count_objects): ditto.
* insns.def: ditto.
* process.c: ditto.
* thread.c (clear_coverage): ditto.
* vm_insnhelper.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-26 16:19:04 +00:00
ko1 a20a14727f * hash.c, include/ruby/ruby.h: support WB protected hash.
* constify RHash::ifnone and make new macro RHASH_SET_IFNONE().
* insert write barrier for st_update().
* include/ruby/intern.h: declare rb_hash_set_ifnone(hash, ifnone).
* marshal.c (r_object0): use RHASH_SET_IFNONE().
* ext/openssl/ossl_x509name.c (Init_ossl_x509name): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-26 12:37:11 +00:00
ko1 83aba04862 * include/ruby/ruby.h: constify RBasic::klass and add
RBASIC_CLASS(obj) macro which returns a class of `obj'.
  This change is a part of RGENGC branch [ruby-trunk - Feature #8339].
* object.c: add new function rb_obj_reveal().
  This function reveal interal (hidden) object by rb_obj_hide().
  Note that do not change class before and after hiding.
  Only permitted example is:
  klass = RBASIC_CLASS(obj);
  rb_obj_hide(obj);
  ....
  rb_obj_reveal(obj, klass);
  TODO: API design. rb_obj_reveal() should be replaced with others.
  TODO: modify constified variables using cast may be harmful for
  compiler's analysis and optimizaton.
  Any idea to prohibt inserting RBasic::klass directly?
  If rename RBasic::klass and force to use RBASIC_CLASS(obj),
  then all codes such as `RBASIC(obj)->klass' will be
  compilation error. Is it acceptable? (We have similar
  experience at Ruby 1.9,
  for example "RARRAY(ary)->ptr" to "RARRAY_PTR(ary)".
* internal.h: add some macros.
* RBASIC_CLEAR_CLASS(obj) clear RBasic::klass to make it internal
  object.
* RBASIC_SET_CLASS(obj, cls) set RBasic::klass.
* RBASIC_SET_CLASS_RAW(obj, cls) same as RBASIC_SET_CLASS
  without write barrier (planned).
* RCLASS_SET_SUPER(a, b) set super class of a.
* array.c, class.c, compile.c, encoding.c, enum.c, error.c, eval.c,
  file.c, gc.c, hash.c, io.c, iseq.c, marshal.c, object.c,
  parse.y, proc.c, process.c, random.c, ruby.c, sprintf.c,
  string.c, thread.c, transcode.c, vm.c, vm_eval.c, win32/file.c:
  Use above macros and functions to access RBasic::klass.
* ext/coverage/coverage.c, ext/readline/readline.c,
  ext/socket/ancdata.c, ext/socket/init.c,
* ext/zlib/zlib.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 10:49:11 +00:00
ko1 aacd771046 * *.c, parse.y, insns.def: use RARRAY_AREF/ASET macro
instead of using RARRAY_PTR().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 09:56:22 +00:00
zzak 0dc6dcfb6a * hash.c: Hash[] and {} are not equivalent by @eam [Fixes GH-301]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13 01:31:27 +00:00
charliesome 5d7b5481ca * benchmark/bm_hash_shift.rb: add benchmark for Hash#shift
* hash.c (rb_hash_shift): use st_shift if hash is not being iterated to
  delete element without iterating the whole hash.

* hash.c (shift_i): remove function

* include/ruby/st.h (st_shift): add st_shift function

* st.c (st_shift): ditto

[Bug #8312] [ruby-core:54524] Patch by funny-falcon

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-25 05:03:30 +00:00
hsbt da91385f2c fix ENV.to_a rdoc example by @benolee [fix GH-288]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40322 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-16 06:28:35 +00:00
marcandre a6d08b450c * array.c: Fix rdoc for flatten!
* hash.c: Correct rdoc for reject!

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-23 20:17:20 +00:00
charliesome e45e06410d * hash.c (env_reject_bang): hide keys array from ObjectSpace
* hash.c (env_select_bang): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-06 13:46:26 +00:00
drbrain 0051369ba3 * hash.c (rb_env_size): Restored documentation for ENV.size
* lib/drb/drb.rb:  Documented DRb::DRb#run.

* lib/erb.rb (class ERB):  Improved documentation of ERb.

* transcode.c:  Documented Encoding::Converter constants.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-26 03:58:33 +00:00
zzak 663613a993 * hash.c (rb_hash_update): Revert documentation from r38672
See: https://github.com/ruby/ruby/pull/228#issuecomment-11791013


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-01 17:28:47 +00:00
zzak 1290747cfb * hash.c (rb_hash_update): Documentation for Hash#merge and shallow
copies Patch by Yorick Peterse [Fixes Github #228]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-01 17:17:28 +00:00
nobu be7bf5aa0c adjust style
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-29 12:22:04 +00:00
charliesome af35f2a61d * configure.in: check for the whether crt_externs.h is present when compiling
for darwin (this header is missing in the iOS SDK)
* eval_intern.h: check HAVE_CRT_EXTERNS_H before including crt_externs.h, if
  not defined, include missing/crt_externs.h instead
* hash.c: ditto
* missing/setproctitle.c: ditto
* missing/crt_externs.h: declare _NSGetEnviron() function and define environ
  for iOS

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-28 14:23:25 +00:00
nobu 66fd9d44d8 adjust style.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-01 15:25:28 +00:00
tenderlove 4c740bae97 * probes.d: add DTrace probe declarations. [ruby-core:27448]
* array.c (empty_ary_alloc, ary_new): added array create DTrace probe.

* compile.c (rb_insns_name): allowing DTrace probes to access
  instruction sequence name.

* Makefile.in: translate probes.d file to appropriate header file.

* common.mk: declare dependencies on the DTrace header.

* configure.in: add a test for existence of DTrace.

* eval.c (setup_exception): add a probe for when an exception is
  raised.

* gc.c: Add DTrace probes for mark begin and end, and sweep begin and
  end.

* hash.c (empty_hash_alloc): Add a probe for hash allocation.

* insns.def: Add probes for function entry and return.

* internal.h: function declaration for compile.c change.

* load.c (rb_f_load): add probes for `load` entry and exit, require
  entry and exit, and wrapping search_required for load path search.

* object.c (rb_obj_alloc): added a probe for general object creation.

* parse.y (yycompile0): added a probe around parse and compile phase.

* string.c (empty_str_alloc, str_new): DTrace probes for string
  allocation.

* test/dtrace/*: tests for DTrace probes.

* vm.c (vm_invoke_proc): add probes for function return on exception
  raise, hash create, and instruction sequence execution.

* vm_core.h: add probe declarations for function entry and exit.

* vm_dump.c: add probes header file.

* vm_eval.c (vm_call0_cfunc, vm_call0_cfunc_with_frame): add probe on
  function entry and return.

* vm_exec.c: expose instruction number to instruction name function.

* vm_insnshelper.c: add function entry and exit probes for cfunc
  methods.

* vm_insnhelper.h: vm usage information is always collected, so
  uncomment the functions.

12 19:14:50 2012  Akinori MUSHA  <knu@iDaemons.org>

* configure.in (isinf, isnan): isinf() and isnan() are macros on
  DragonFly which cannot be found by AC_REPLACE_FUNCS().  This
  workaround enforces the fact that they exist on DragonFly.

12 15:59:38 2012  Shugo Maeda  <shugo@ruby-lang.org>

* vm_core.h (rb_call_info_t::refinements), compile.c (new_callinfo),
  vm_insnhelper.c (vm_search_method): revert r37616 because it's too
  slow.  [ruby-dev:46477]

* test/ruby/test_refinement.rb (test_inline_method_cache): skip
  the test until the bug is fixed efficiently.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37631 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-12 21:52:12 +00:00
nobu 5051186a0b hash.c: warn for wrong elements
* hash.c (rb_hash_s_create): just warn for wrong elements now.
  [ruby-dev:46440] [Bug #7300]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-11 06:39:08 +00:00
nobu 5a5a86cc52 hash.c: refine error messages
* hash.c (rb_hash_s_create): refine error messages.
* error.c (rb_builtin_class_name): share for above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-11 06:38:17 +00:00
marcandre 17c0aff0d6 * hash.c: Support for enumerators created by ENV:
each, each_value, ...
  [Feature #6636]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-06 17:13:48 +00:00