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

181 Коммитов

Автор SHA1 Сообщение Дата
normal 099e6e7817 struct.c: cache member definition in a subclass
Since getting Qnil is already error, it is safe to use rb_attr_get.

* struct.c (struct_ivar_get): cache member definition in a subclass
  Thanks to Sokolov Yura aka funny_falcon <funny.falcon@gmail.com>
  in https://bugs.ruby-lang.org/issues/10585

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-22 21:50:31 +00:00
ko1 18bbd05709 * method.h: split rb_method_definition_t::flag to several flags.
`flag' contains several categories of attributes and it makes us
  confusion (at least, I had confused).
  * rb_method_visibility_t (flags::visi)
    * NOEX_UNDEF     -> METHOD_VISI_UNDEF     = 0
    * NOEX_PUBLIC    -> METHOD_VISI_PUBLIC    = 1
    * NOEX_PRIVATE   -> METHOD_VISI_PRIVATE   = 2
    * NOEX_PROTECTED -> METHOD_VISI_PROTECTED = 3
  * NOEX_SAFE(flag)) -> safe (flags::safe, 2 bits)
  * NOEX_BASIC       -> basic (flags::basic, 1 bit)
  * NOEX_MODFUNC     -> rb_scope_visibility_t in CREF
  * NOEX_SUPER       -> MISSING_SUPER (enum missing_reason)
  * NOEX_VCALL       -> MISSING_VCALL (enum missing_reason)
  * NOEX_RESPONDS    -> BOUND_RESPONDS (macro)
  Now, NOEX_NOREDEF is not supported (I'm not sure it is needed).
  Background:
    I did not know what "NOEX" stands for.
    I asked Matz (who made this name) and his answer was "Nothing".
    "At first, it meant NO EXport (private), but the original
    meaning was gone."
    This is why I remove the mysterious word "NOEX" from MRI.
* vm_core.h: introduce `enum missing_reason' to represent
  method_missing (NoMethodError) reason.
* eval_intern.h: introduce rb_scope_visibility_t to represent
  scope visibility.
  It has 3 method visibilities (public/private/protected)
  and `module_function`.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-03 01:39:16 +00:00
ko1 57b817f4c5 * method.h: make rb_method_entry_t a VALUE.
Motivation and new data structure are described in [Bug #11203].
  This patch also solve the following issues.
  * [Bug #11200] Memory leak of method entries
  * [Bug #11046] __callee__ returns incorrect method name in orphan
                 proc
* test/ruby/test_method.rb: add a test for [Bug #11046].
* vm_core.h: remvoe rb_control_frame_t::me. me is located at value
  stack.
* vm_core.h, gc.c, vm_method.c: remove unlinked_method... codes
  because method entries are simple VALUEs.
* method.h:  Now, all method entries has own independent method
  definititons. Strictly speaking, this change is not essential,
  but for future changes.
  * rb_method_entry_t::flag is move to rb_method_definition_t::flag.
  * rb_method_definition_t::alias_count is now
    rb_method_definition_t::alias_count_ptr, a pointer to the counter.
* vm_core.h, vm_insnhelper.c (rb_vm_frame_method_entry) added to
  search the current method entry from value stack.
* vm_insnhelper.c (VM_CHECK_MODE): introduced to enable/disable
  assertions.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-02 04:20:30 +00:00
ko1 cd909b553f * class.c: remove needless include pragmra for method.h.
* struct.c: ditto.
* vm_method.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-06-01 06:44:16 +00:00
ko1 d84f9b1694 * fix namespace issue on singleton class expressions. [Bug #10943]
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored
  to rb_method_definition_t::body.iseq_body.cref.
* vm_insnhelper.c: modify SVAR usage.
  When calling ISEQ type method, push CREF information onto method
  frame, SVAR located place. Before this fix, SVAR is simply nil.
  After this patch, CREF (or NULL == Qfalse for not iseq methods)
  is stored at the method invocation.
  When SVAR is requierd, then put NODE_IF onto SVAR location,
  and NDOE_IF::nd_reserved points CREF itself.
* vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added.
* vm_insnhelper.c (vm_push_frame): accept CREF.
* method.h, vm_method.c (rb_add_method_iseq): added. This function
  accepts iseq and CREF.
* class.c (clone_method): use rb_add_method_iseq().
* gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref.
* iseq.c: remove CREF related codes.
* insns.def (getinlinecache/setinlinecache): CREF should be cache key
  because a different CREF has a different namespace.
* node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR.
* proc.c: catch up changes.
* struct.c: ditto.
* insns.def: ditto.
* vm_args.c (raise_argument_error): ditto.
* vm_eval.c: ditto.
* test/ruby/test_class.rb: add a test.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-06 12:24:58 +00:00
nobu e4717eaa4c iseq.c: struct accessors
* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset): call
  accessor functions directly, not to be affected by [] and []=
  methods.  [ruby-core:66846] [Bug #10601]
* struct.c (define_aref_method, define_aset_method): ditto.
* vm_insnhelper.c (rb_vm_opt_struct_aref, rb_vm_opt_struct_aset):
  direct accessors of Struct.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-16 06:18:25 +00:00
nobu 8efe878d11 struct.c: use iseqval
* struct.c (define_aref_method, define_aset_method): use iseq
  VALUE instead of rb_iseq_t to prevent from GC, as RB_GC_GUARD
  makes sense only for local variables.  [Feature #10575]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 04:39:29 +00:00
normal 65651b34b1 struct: avoid all O(n) behavior on access
This avoids O(n) on lookups with structs over 10 members.
This also avoids O(n) behavior on all assignments on Struct members.
Members 0..9 still use existing C methods to read in O(1) time

Benchmark results:

vm2_struct_big_aref_hi*	1.305
vm2_struct_big_aref_lo*	1.157
vm2_struct_big_aset*	3.306
vm2_struct_small_aref*	1.015
vm2_struct_small_aset*	3.273

Note: I chose use loading instructions from an array instead of writing
directly to linked-lists in compile.c for ease-of-maintainability.  We
may move the method definitions to prelude.rb-like files in the future.

I have also tested this patch with the following patch to disable
the C ref_func methods and ensured the test suite and rubyspec works

	--- a/struct.c
	+++ b/struct.c
	@@ -209,7 +209,7 @@ setup_struct(VALUE nstr, VALUE members)
		ID id = SYM2ID(ptr_members[i]);
		VALUE off = LONG2NUM(i);

	-	if (i < N_REF_FUNC) {
	+	if (0 && i < N_REF_FUNC) {
		    rb_define_method_id(nstr, id, ref_func[i], 0);
		}
		else {

* iseq.c (rb_method_for_self_aref, rb_method_for_self_aset):
  new methods to generate bytecode for struct.c
  [Feature #10575]
* struct.c (rb_struct_ref, rb_struct_set): remove
  (define_aref_method, define_aset_method): new functions
  (setup_struct): use new functions
* test/ruby/test_struct.rb: add test for struct >10 members
* benchmark/bm_vm2_struct_big_aref_hi.rb: new benchmark
* benchmark/bm_vm2_struct_big_aref_lo.rb: ditto
* benchmark/bm_vm2_struct_big_aset.rb: ditto
* benchmark/bm_vm2_struct_small_aref.rb: ditto
* benchmark/bm_vm2_struct_small_aset.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-09 15:43:49 +00:00
nobu 07bb8b4cce struct.c: trivial optimization
* struct.c (rb_struct_set): get rid of calling rb_frame_this_func
  twice.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-08 04:18:01 +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
nobu dafeb23e99 struct.c: no rb_class_real twice
* struct.c (inspect_struct): as rb_obj_class() returns real class
  name, so rb_class_name is not needed.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-21 04:39:28 +00:00
ko1 76a929a7fc * parse.y: change Symbol <-> ID relationship to avoid
exposing IDs from collectable symbols.
  [Bug #10014]
  Now, rb_check_id() returns 0 if corresponding symbol is
  pinned dynamic symbol.
  There is remaining intern_cstr_without_pindown(), it can return
  IDs from collectable symbols. We must be careful to use it
  (only used in parse.y).  I think it should be removed if
  it does not have impact for performance.
* parse.y:
  add:
  * STATIC_SYM2ID()
  * STATIC_ID2SYM()
  rename:
  * rb_pin_dynamic_symbol() -> dsymbol_pindown()
* internal.h:
  remove:
  * rb_check_id_without_pindown()
  * rb_sym2id_without_pindown()
  add:
  * rb_check_symbol()
  * rb_check_symbol_cstr()
* load.c: use rb_check_id() or rb_check_id_cstr().
* object.c: ditto.
* struct.c: ditto.
* thread.c: ditto.
* vm_method.c: ditto.
* string.c (sym_find): use only rb_check_symbol().
* sprintf.c (rb_str_format): use rb_check_symbol_cstr().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-09 06:14:41 +00:00
nobu 876bfc6b4e Init functions don't need ID caches
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46663 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-03 03:38:10 +00:00
nobu 1d223a3bdf struct.c: avoid pinning down
* struct.c (rb_struct_set, rb_struct_aref, rb_struct_aset): get
  rid of pinning down dynamic symbols by SYM2ID.

* struct.c (rb_struct_aref_sym, rb_struct_aset_sym): use Symbol
  instead of ID.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-28 12:36:27 +00:00
nobu 4a46362239 struct.c: encoding of member name
* struct.c (not_a_member): preserve encoding of member name in
  error messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-28 10:32:36 +00:00
nobu afb4bcbfd6 struct.c: not_a_member message
* struct.c (not_a_member): extract name error and use same error
  messages.  based on the patch by Marcus Stollsteimer <sto.mar AT
  web.de> at [ruby-core:61721].  [Bug #9684]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-28 10:32:16 +00:00
nari 90b7073842 * parse.y: support Symbol GC. [ruby-trunk Feature #9634]
See this ticket about Symbol GC.

* include/ruby/ruby.h:
  Declare few functions.
  * rb_sym2id: almost same as old SYM2ID but support dynamic symbols.
  * rb_id2sym: almost same as old ID2SYM but support dynamic symbols.
  * rb_sym2str: almost same as `rb_id2str(SYM2ID(sym))` but not
    pin down a dynamic symbol.
  Declare a new struct.
  * struct RSymbol: represents a dynamic symbol as object in
    Ruby's heaps.
  Add few macros.
  * STATIC_SYM_P: check a static symbol.
  * DYNAMIC_SYM_P: check a dynamic symbol.
  * RSYMBOL: cast to RSymbol

* gc.c: declare RSymbol. support T_SYMBOL.

* internal.h: Declare few functions.
  * rb_gc_free_dsymbol: free up a dynamic symbol. GC call this
    function at a sweep phase.
  * rb_str_dynamic_intern: convert a string to a dynamic symbol.
  * rb_check_id_without_pindown: not pinning function.
  * rb_sym2id_without_pindown: ditto.
  * rb_check_id_cstr_without_pindown: ditto.

* string.c (Init_String): String#intern and String#to_sym use
  rb_str_dynamic_intern.

* template/id.h.tmpl: use LSB of ID as a flag for determining a
  static symbol, so we shift left other ruby_id_types.

* string.c: use rb_sym2str instead `rb_id2str(SYM2ID(sym))` to
  avoid pinning.

* load.c: use xx_without_pindown function at creating temporary ID
  to avoid pinning.

* object.c: ditto.

* sprintf.c: ditto.

* struct.c: ditto.

* thread.c: ditto.

* variable.c: ditto.

* vm_method.c: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-26 04:57:47 +00:00
ko1 c813697d97 * struct.c (rb_struct_alloc): use RARRAY_CONST_PTR() instead of
RARRAY_PTR().



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-03-20 04:06:27 +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
akr 6f8b0e9bb0 * include/ruby/intern.h,
include/ruby/io.h,
  include/ruby/ruby.h,
  include/ruby/win32.h,
  include/ruby/backward/rubysig.h,
  bignum.c,
  gc.c,
  io.c,
  process.c,
  safe.c,
  struct.c,
  thread.c,
  ext/socket/rubysocket.h,
  ext/-test-/old_thread_select: Remove deprecated definitions
  [ruby-core:60581] [Feature #9502]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-02-14 15:16:31 +00:00
charliesome 306c154c2d * struct.c (rb_struct_set): return assigned value from setter method
rather than struct object. [Bug #9353] [ruby-core:59509]

* test/ruby/test_struct.rb (test_setter_method_returns_value): add test

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-01-04 13:44:34 +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
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
glass 5c54eb4045 * dir.c, pack.c, ruby.c, struct.c, vm_eval.c: use RARRAY_CONST_PTR().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43580 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-11-08 02:37:47 +00:00
nobu ab453f901d struct.c: fix warning message
* struct.c (new_struct): fix warning message, class name and encoding.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-10-27 15:52:39 +00:00
zzak ddb04eba87 * struct.c: [DOC] grammar of ArgumentError in Struct.new [Bug #8936]
Patch by Prathamesh Sonpatki


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-26 15:41:02 +00:00
ko1 dc626dbab3 * include/ruby/ruby.h: rename RARRAY_RAWPTR() to RARRAY_CONST_PTR().
RARRAY_RAWPTR(ary) returns (const VALUE *) type pointer and
  usecase of this macro is not acquire raw pointer, but acquire
  read-only pointer. So we rename to better name.
  RSTRUCT_RAWPTR() is also renamed to RSTRUCT_CONST_PTR()
  (I expect that nobody use it).
* array.c, compile.c, cont.c, enumerator.c, gc.c, proc.c, random.c,
  string.c, struct.c, thread.c, vm_eval.c, vm_insnhelper.c:
  catch up this change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-25 08:24:34 +00:00
ko1 5da55dfcb4 * struct.c (rb_struct_define_without_accessor_under): added.
This function is similar to rb_define_class_under() against
  rb_define_class().
* include/ruby/intern.h: add a declaration of this function.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-29 09:12:25 +00:00
ko1 ad0ef29da7 * array.c (rb_ary_splice): use RARRAY_PTR_USE() without WB because
there are not new relations.
* enum.c (enum_sort_by): ditto.
* struct.c (setup_struct): use RARRAY_RAWPTR().
* vm_eval.c (yield_under): ditto.
* ext/pathname/pathname.c (path_entries): use RARRAY_AREF().
* ext/pathname/pathname.c (path_s_glob): ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-26 05:47:27 +00:00
nobu 042e5013a3 struct.c: rb_struct_define_under
* struct.c (rb_struct_define_under): new function to define Struct
  under the given namespace, not under Struct.  [Feature #8264]
* ext/etc/etc.c: use rb_struct_define_under.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-08-03 00:31:02 +00:00
glass d738fed4eb * struct.c (rb_struct_each_pair): use rb_yield_values(2, key, value)
instead of rb_yield(rb_assoc_new(key, value)) if rb_block_arity()
  is greater than 1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-15 05:20:11 +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
ko1 6a1101f23e * include/ruby/ruby.h: support write barrier protection for T_STRUCT.
Introduce the following C APIs:
  * RSTRUCT_RAWPTR(st) returns pointer (do WB on your risk).
    The type of returned pointer is (const VALUE *).
  * RSTRUCT_GET(st, idx) returns idx-th value of struct.
  * RSTRUCT_SET(st, idx, v) set idx-th value by v with WB.
  And
  * RSTRUCT_PTR(st) returns pointer with shady operation.
    The type of returned pointer is (VALUE *).
* struct.c, re.c, gc.c, marshal.c: rewrite with above APIs.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-21 11:22:18 +00:00
drbrain 28d975a633 * struct.c: Improve documentation: replace "instance variable" with
"member", recommend the use of a block to customize structs, note
  that member accessors are created, general cleanup.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-11 22:17:02 +00:00
akr bd15d4ca78 * internal.h (numberof): Gathered from various files.
* array.c, math.c, thread_pthread.c, iseq.c, enum.c, string.c, io.c,
  load.c, compile.c, struct.c, eval.c, gc.c, parse.y, process.c,
  error.c, ruby.c: Remove the definitions of numberof.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-06-07 10:01:19 +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
nobu a69c74be72 struct.c: hide member names
* struct.c (rb_struct_define_without_accessor, rb_struct_define),
  (rb_struct_s_def): hide member names array.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-13 01:20:39 +00:00
nobu 5e5690781c struct.c: split make_struct
* struct.c (anonymous_struct, new_struct, setup_struct): split
  make_struct() for each purpose.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-13 01:20:34 +00:00
nobu 112a3b1fca struct.c: avoid inadvertent symbol creation
* struct.c (make_struct): avoid inadvertent symbol creation.
  (rb_struct_aref): ditto.
  (rb_struct_aset): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40101 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-04 07:55:11 +00:00
zzak eed593eba6 * struct.c (Struct.new): Document Struct.new with block
Patch by Hiroyuki Iwatsuki [Bug #7674]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-01-19 02:37:01 +00:00
glass f9e621372d * struct.c (make_struct): remove junk ID check to allow members who
have junk name like "foo\000".
* test/ruby/test_struct.rb: Test for above.
  [Bug #7575] [ruby-dev:46750]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-22 02:52:48 +00:00
nobu 92cef134b5 struct.c: fix typo
* struct.c (rb_struct_each_pair): fix typo.  [Bug #7382]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 07:54:53 +00:00
nobu 7588c674d5 struct.c: yield assoc in each_pair
* struct.c (rb_struct_each_pair): yield associated pairs so that
  an unsplat argument can get both, for consistency with Hash,
  OpenStruct, and etc.  [ruby-dev:46533] [Bug #7382]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37721 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19 07:31:05 +00:00
marcandre ce0bf9f43d * struct.c: Support for Struct's enumerators #size
[Feature #6636]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-06 17:14:02 +00:00
ktsj 493d253300 * struct.c: fix typo.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37342 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-27 11:06:46 +00:00
nari c3a46d6aca * include/ruby/ruby.h: add C APIs.
VALUE rb_newobj_of(VALUE klass, VALUE flags)
  #define NEWOBJ_OF(obj,type,klass,flags)
  These allow to change a allocation strategy depending on klass
  or flags.

* gc.c: ditto

* array.c: use new C API.
* bignum.c: ditto
* class.c: ditto
* complex.c: ditto
* ext/socket/ancdata.c: ditto
* ext/socket/option.c: ditto
* hash.c: ditto
* io.c: ditto
* marshal.c: ditto
* numeric.c: ditto
* object.c: ditto
* random.c: ditto
* range.c: ditto
* rational.c: ditto
* re.c: ditto
* string.c: ditto
* struct.c: ditto
  [Feature #7177][Feature #7047]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-20 06:57:51 +00:00
nobu 2073258a7d obj_init_copy
* object.c (rb_obj_init_copy): should check if trusted too.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-05 11:13:18 +00:00
mame f9217681c5 * struct.c (rb_struct_members): Refactoring. As Struct#members had
returned an array of String, the old code was needed to convert
  Symbols to Strings.  But it is almost unnecessary because the
  method now returns an array of Symbols.  A patch by Masaki
  Matsushita <glass.saga at gmail dot com>  [Feature #6218]
  [ruby-dev:45451]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-05-21 15:47:03 +00:00
nobu 770ddcdfe0 * hash.c, object.c, struct.c, lib/ostruct.rb: add to_h methods.
[Feature #6276]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-24 03:46:55 +00:00
naruse 62c9ecfa12 Revert r35339-35343 because of no tests.
* hash.c: Alias ENV.to_h to ENV.to_hash [ref #6276]

* lib/ostruct.rb: Add OpenStruct#to_h [Feature #6276]

* struct.c: Add Struct#to_h [Feature #6276]

* object.c: Add NilClass#to_h [Feature #6276]

* hash.c: Add Hash#to_h [Feature #6276]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-04-18 03:59:15 +00:00