summaryrefslogtreecommitdiff
path: root/struct.c
AgeCommit message (Collapse)Author
2021-09-27Enhanced RDoc for Struct (#4895)Burdette Lamar
Revises introductory material. Adds section "What's Here". Adds previously missing documentation for method #deconstruct_keys. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-24Enhanced RDoc for Struct (#4891)Burdette Lamar
Treats: #values_at #select #== #hash #eql? #size #dig Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-24Enhanced RDoc for Struct (#4890)Burdette Lamar
Treated: #each #each_pair #inspect #to_a #to_h #[] #[]= Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-23Enhance RDoc for Struct (#4885)Burdette Lamar
Treats #members and ::new. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2021-09-15[DOC] Fix broken links [ci skip]Nobuyoshi Nakada
* As the "doc/" prefix is specified by the `--page-dir` option, remove from the rdoc references. * Refer to the original .rdoc instead of the converted .html.
2021-09-11Using SYMBOL_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/4798
2021-07-15Make Struct#keyword_init? return nil by default [Feature #18008]Nobuyoshi Nakada
2021-07-15Regularize keyword_init values not to hold the argument objectNobuyoshi Nakada
2021-07-15struct.c: Add keyword_init? singleton method for StructClass (#4609)hkdnet
Fixes [Feature #18008] Notes: Merged-By: nurse <naruse@airemix.jp>
2021-01-17Warn Struct#initialize with only keyword args (#4070)Takashi Kokubun
* Warn Struct#initialize with only keyword args A part of [Feature #16806] * Do not warn if `keyword_init: false` is explicitly specified * Add a NEWS entry * s/in/from/ * Make sure all fields are initialized Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2020-08-19RHASH_TBL: is now ext-only卜部昌平
It seems almost no internal codes use RHASH_TBL any longer. Why not just eliminate it entirely, so that the macro can be purely ext-only. Notes: Merged: https://github.com/ruby/ruby/pull/3426
2020-08-14Fix links to Dig Methods document (#3421)Burdette Lamar
* Fix links to Dig Methods document * Fix links to Dig Methods document Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-08-13Adding doc/dig_methods.rdoc and links to it (#3416)Burdette Lamar
Adds a full discussion of #dig, along with links from Array, Hash, Struct, and OpenStruct. CSV::Table and CSV::Row are over in ruby/csv. I'll get to them soon. The art to the thing is to figure out how much (or how little) to say at each #dig. Notes: Merged-By: BurdetteLamar <BurdetteLamar@Yahoo.com>
2020-07-13precalc invokebuiltin destinations卜部昌平
Noticed that struct rb_builtin_function is a purely compile-time constant. MJIT can eliminate some runtime calculations by statically generate dedicated C code generator for each builtin functions. Notes: Merged: https://github.com/ruby/ruby/pull/3305
2020-07-06Inline builtin struct arefTakashi Kokubun
We don't do this for aset because it might raise a FrozenError. ``` $ benchmark-driver -v --rbenv 'before;after;before --jit;after --jit' benchmark/mjit_struct_aref.yml --repeat-count=4 before: ruby 2.8.0dev (2020-07-06T01:47:11Z master d94ef7c6b6) [x86_64-linux] after: ruby 2.8.0dev (2020-07-06T07:11:51Z master 85425168f4) [x86_64-linux] last_commit=Inline builtin struct aref before --jit: ruby 2.8.0dev (2020-07-06T01:47:11Z master d94ef7c6b6) +JIT [x86_64-linux] after --jit: ruby 2.8.0dev (2020-07-06T07:11:51Z master 85425168f4) +JIT [x86_64-linux] last_commit=Inline builtin struct aref Calculating ------------------------------------- before after before --jit after --jit mjit_struct_aref(struct) 34.783M 34.810M 48.321M 58.378M i/s - 40.000M times in 1.149996s 1.149097s 0.827794s 0.685192s Comparison: mjit_struct_aref(struct) after --jit: 58377836.7 i/s before --jit: 48321205.7 i/s - 1.21x slower after: 34809935.5 i/s - 1.68x slower before: 34782736.5 i/s - 1.68x slower ```
2020-06-17Replaced accessors of `Struct` with `invokebuiltin`Nobuyoshi Nakada
2020-06-16Revert "Replaced accessors of `Struct` with `invokebuiltin`"Nobuyoshi Nakada
This reverts commit 19cabe8b09d92d033c244f32ff622b8e513375f1, which didn't support tool/lib/iseq_loader_checker.rb.
2020-06-16Replaced accessors of `Struct` with `invokebuiltin`Nobuyoshi Nakada
2020-05-08Added GC guard for splatted arrayNobuyoshi Nakada
2020-05-08Classes made from Struct should have default `new` singleton method.Marc-Andre Lafortune
[Bug #16465] [Bug #16801] [Fix GH-2795] [Fix GH-2944] [Fix GH-3045] [Fix GH-3093] Note: Backporting shouldn't modify object.h and instead can use struct_new_kw which is basically a duplicate implementation of rb_class_new_instance_pass_kw Co-authored-by: Yusuke Endoh <mame@ruby-lang.org> Co-authored-by: John Hawthorn <john@hawthorn.email> Co-authored-by: Adam Hess <HParker@github.com> Co-authored-by: Jose Cortinas <jacortinas@gmail.com> Co-authored-by: Jean Boussier <jean.boussier@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/3093
2020-03-16hash.c: Do not use the fast path (rb_yield_values) for lambda blocksYusuke Endoh
As a semantics, Hash#each yields a 2-element array (pairs of keys and values). So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception due to lambda's arity check. However, the optimization that avoids Array allocation by using rb_yield_values for blocks whose arity is more than 1 (introduced at b9d29603375d17c3d1d609d9662f50beaec61fa1 and some commits), seemed to overlook the lambda case, and wrongly allowed the code above to work. This change experimentally attempts to make it strict; now the code above raises an ArgumentError. This is an incompatible change; if the compatibility issue is bigger than our expectation, it may be reverted (until Ruby 3.0 release). [Bug #12706]
2019-12-26decouple 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). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-11-19Avoid needless object allocationKazuki Tsujimoto
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-08Define Struct#deconstruct_keysKazuki Tsujimoto
2019-10-31Allow only one argument for keyword_init structAlan Wu
``` irb(main):001:0> RUBY_VERSION => "2.6.5" irb(main):002:0> S = Struct.new(:foo, keyword_init: true) => S(keyword_init: true) irb(main):003:0> S.new({foo: 23424}, 234) # I don't think this is intentional => #<struct S foo=23424> irb(main):004:0> ``` Tightening this up should inform users when they are confused about whether a struct is `keyword_init`. Notes: Merged: https://github.com/ruby/ruby/pull/2634
2019-10-21Pass the called keyword arguments if `keyword_init`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/2582
2019-09-29Make direct calls to rb_{obj_instance,mod_module}_{eval,exec} not pass keywordsJeremy Evans
In general RB_PASS_CALLED_KEYWORDS should only be set if we are sure the arguments passed come directly from Ruby. For direct calls to these C functions, we should not assume that keywords are passed. Add static *_internal versions of these functions that Kernel#instance_{eval,exec} and Module#{class,module}_{eval,exec} call that set RB_PASS_CALLED_KEYWORDS. Also, change struct.c back to calling rb_mod_module_eval, now that the call is safe. Notes: Merged: https://github.com/ruby/ruby/pull/2505
2019-09-27Fix warning when doing Struct.new(:x, keyword_init: true){}Jeremy Evans
This is due to calling rb_mod_module_eval directly instead of using rb_funcall_passing_block. The problem with calling directly is it does not create a new VM frame, so rb_mod_module_eval was called with no arguments, but with the keyword given VM frame flag set, which causes problems internally. Notes: Merged: https://github.com/ruby/ruby/pull/2500
2019-09-03Do not turn on keyword_init for Struct subclass if keyword hash is emptyJeremy Evans
This was accidentally turned on because there was no checking for Qundef. Also, since only a single keyword is currently supported, simplify the rb_get_kwargs call. Notes: Merged: https://github.com/ruby/ruby/pull/2423 Merged-By: jeremyevans <code@jeremyevans.net>
2019-08-29Disallow use of attrset symbols as Struct membersJeremy Evans
Fixes [Bug #11326]
2019-04-17Define Struct#deconstructktsj
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-08struct.c: force hash values fixablenobu
* struct.c (rb_struct_hash): force hash values fixable on LLP64 environment. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67470 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-23Struct#to_h: Add doc for block form.marcandre
Patch by Shuji Kobayashi [doc] [ci skip] [#15454] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66505 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-05* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-05use `RSTRUCT_CONST_PTR` carefully.ko1
* struct.c: should not use `RSTRUCT_CONST_PTR` with method dispatch because pointers can be obsolete after method dispatch. `rb_equal()` and so on can dispatch Ruby's methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-04struct.c: [DOC] add docs for Struct#filterstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-01introduce USE_TRANSIENT_HEAP to enable/disable theap.ko1
* include/ruby/ruby.h: intrdocue `USE_TRANSIENT_HEAP` macro to enable/disable transient heap. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-30support theap for T_STRUCT.ko1
* struct.c: members memory can use theap. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-29* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-29use RARRAY_AREF() instead of RARRAY_CONST_PTR().ko1
* class.c (rb_keyword_error_new): use RARRAY_AREF() because RARRAY_CONST_PTR() can introduce additional overhead in a futre. Same fixes for other files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-04* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-04use RARRAY_AREF().ko1
* struct.c (setup_struct): no need to use Array raw ptr here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-20Enumerable#to_h with block and so onnobu
[Feature #15143] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-16Alias Struct#select as Struct#filter. Patch by Kenichi Kamiya.marcandre
[Fix GH-#1862] [#1784] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-24UNREACHABLE_RETURNnobu
* include/ruby/ruby.h (UNREACHABLE_RETURN): UNREACHABLE at the end of non-void functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05marshal.c: allow marshalling keyword_init structk0kubun
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
2017-12-14struct.c: [DOC] improve docs for Struct.newstomar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61232 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12struct.c: don't explain implementation detailsk0kubun
of keyword_init option. [DOC] [ci skip] It's implemented to take Hash, but it's just implementation detail and it's intended to behave in the same way as keyword arguments (for :keyword_init option too). Also I unified coding style of r61137 with other places. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-12struct.c: show `keyword_init: true` on inspectk0kubun
for debugging if it's specified for the Struct class. This follows up r61137. We don't provide a method to check it because I don't think of any use case, but showing this to inspect would be helpful for debugging if someone is debugging whether keyword_init is properly enabled or not. In this commit, I didn't show `keyword_init: false` because of backward compatibility. Ideally any application should not depend on the behavior of inspect, but I don't have strong motivation to break it too. [close GH-1773] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e