summaryrefslogtreecommitdiff
path: root/symbol.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge gc.h and internal/gc.hMatt Valentine-House2023-02-091-1/+0
| | | | [Feature #19425]
* Rewrite Symbol#to_sym and #intern in Ruby (#6683)Takashi Kokubun2022-11-151-0/+2
|
* Implement optimize send in yjit (#6488)Jimmy Miller2022-10-111-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Implement optimize send in yjit This successfully makes all our benchmarks exit way less for optimize send reasons. It makes some benchmarks faster, but not by as much as I'd like. I think this implementation works, but there are definitely more optimial arrangements. For example, what if we compiled send to a jump table? That seems like perhaps the most optimal we could do, but not obvious (to me) how to implement give our current setup. Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> * Attempt at fixing the issues raised by @XrXr * fix allowlist * returns 0 instead of nil when not found * remove comment about encoding exception * Fix up c changes * Update assert Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> * get rid of unneeded code and fix the flags * Apply suggestions from code review Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> * rename and fix typo Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
* Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu2022-07-261-2/+2
| | | | | | rb_ary_tmp_new suggests that the array is temporary in some way, but that's not true, it just creates an array that's hidden and not on the transient heap. This commit renames it to rb_ary_hidden_new.
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-168/+168
| | | | [Misc #18891]
* Ensure _id2ref finds symbols with the correct typeDaniel Colson2022-07-201-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit it was possible to call `ObjectSpace._id2ref` with an offset static symbol object_id and get back a new, incorrectly tagged symbol: ``` > sensible_sym = ObjectSpace._id2ref(:a.object_id) => :a > nonsense_sym = ObjectSpace._id2ref(:a.object_id + 40) => :a > sensible_sym == nonsense_sym => false ``` `nonsense_sym` ends up tagged with `RUBY_ID_INSTANCE` instead of `RB_ID_LOCAL`. That means we can do silly things like: ``` > foo = Object.new > foo.instance_variable_set(:a, 123) (irb):2:in `instance_variable_set': `a' is not allowed as an instance variable name (NameError) > foo.instance_variable_set(ObjectSpace._id2ref(:a.object_id + 40), 123) => 123 > foo.instance_variables => [:a] ``` This was happening because `get_id_entry` ignores the tag bits when looking up the symbol. So `rb_id2str(symid)` would return a value and then we'd continue on with the nonsense `symid`. This commit prevents the situation by checking that the `symid` actually matches what we get back from `get_id_entry`. Now we get a `RangeError` for the nonsense id: ``` > ObjectSpace._id2ref(:a.object_id) => :a > ObjectSpace._id2ref(:a.object_id + 40) (irb):1:in `_id2ref': 0x000000000013f408 is not symbol id value (RangeError) ``` Co-authored-by: John Hawthorn <jhawthorn@github.com>
* [Bug #18905] Check symbol name types more strictlyNobuyoshi Nakada2022-07-201-1/+1
|
* [DOC] Move the documentations of moved Symbol methodsNobuyoshi Nakada2022-04-141-0/+11
|
* Assign temporary ID to anonymous ID [Bug #18250]Nobuyoshi Nakada2021-11-231-0/+11
| | | | | | | | Dumped iseq binary can not have unnamed symbols/IDs, and ID 0 is stored instead. As `struct rb_id_table` disallows ID 0, also for the distinction, re-assign a new temporary ID based on the local variable table index when loading from the binary, as well as the parser.
* rb_id_serial_to_id: return unregistered ID as an internal IDNobuyoshi Nakada2021-11-071-1/+2
| | | | | | | | | | | | | | | | ```ruby def foo(*); ->{ super }; end ``` This code makes anonymous parameters which is not registered as an ID. The problem is that when Ractors try to scan `getlocal` instructions, it puts the Symbol corresponding to the parameter in to a hash. Since it is not registered, we end up with a strange exception. This commit wraps the unregistered ID in an internal ID so that we get the same exception for `...` as `*`. Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: John Hawthorn <john@hawthorn.email>
* Fix STATIC_SYM2ID for large ID on IL32LLP64 platformsNobuyoshi Nakada2021-10-141-1/+1
|
* `rb_id_serial_to_id` is used in `key2id` since 4c2d014e9216Nobuyoshi Nakada2021-10-131-3/+0
|
* include/ruby/internal/symbol.h: add doxygen卜部昌平2021-09-101-23/+0
| | | | Must not be a bad idea to improve documents. [ci skip]
* rb_enc_symname_type: indent卜部昌平2021-03-051-21/+21
|
* rb_enc_symname_type: refactor reduce goto卜部昌平2021-03-051-5/+4
| | | | A bit readable to me.
* sync ruby_global_symbolsKoichi Sasada2020-09-181-103/+196
| | | | | ruby_global_symbols can be accessed with multiple ractors so that the accesses should be synchronized.
* `rb_encoding` is defined as `const`Nobuyoshi Nakada2020-08-011-1/+1
| | | | Duplicate type qualifier is not needed.
* rb_enc_symname_type: refactor split卜部昌平2020-06-291-44/+93
| | | | Reduce goto by splitting the function.
* indent [ci skip]卜部昌平2020-06-291-22/+22
|
* rb_enc_synmane_type: do not goto into a branch卜部昌平2020-06-291-4/+8
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* [DOC] Added document for rb_check_symbol() [ci skip]Nobuyoshi Nakada2020-05-241-0/+12
|
* decouple internal.h headers卜部昌平2019-12-261-3/+12
| | | | | | | | | | | | | | | | | | 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).
* delete unused functions卜部昌平2019-11-141-102/+0
| | | | | | | | | | | | Looking at the list of symbols inside of libruby-static.a, I found hundreds of functions that are defined, but used from nowhere. There can be reasons for each of them (e.g. some functions are specific to some platform, some are useful when debugging, etc). However it seems the functions deleted here exist for no reason. This changeset reduces the size of ruby binary from 26,671,456 bytes to 26,592,864 bytes on my machine.
* Fix a use-after-free bug by avoiding rb_str_new_frozenYusuke Endoh2019-09-061-1/+2
| | | | | | | | | | | | | | `str2 = rb_str_new_frozen(str1)` seems to make str1 a shared string that refers to str2, but str2 is not marked as STR_IS_SHARED_M nor STR_NOFREE. `rb_fstring(str2)` frees str2's ptr because it is not marked, and the free'ed pointer is the same as str1's ptr. After that, accessing str1 may cause use-after-free memory corruption. I guess this is a bug of rb_str_new_frozen, but I'm completely unsure what it should be; the string states and flags are not documented. So, this is a workaround for [Bug #16136]. I confirmed that rspec of activeadmin runs gracefully.
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-16/+0
| | | | | | We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
* Prefix global_symbols with `ruby_`Nobuyoshi Nakada2019-05-161-1/+2
|
* Hide internal IDsNobuyoshi Nakada2019-04-261-6/+30
| | | | | | | | * parse.y (internal_id): number the ID serial for internal use by counting down from the neary maximum value, not to accidentally match permanent IDs. [Bug #15768]
* Add `GC.compact` again.tenderlove2019-04-201-6/+1
| | | | | | 🙏 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Reverting compaction for nowtenderlove2019-04-171-1/+6
| | | | | | For some reason symbols (or classes) are being overridden in trunk git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Adding `GC.compact` and compacting GC support.tenderlove2019-04-171-6/+1
| | | | | | | | | | | This commit adds the new method `GC.compact` and compacting GC support. Please see this issue for caveats: https://bugs.ruby-lang.org/issues/15626 [Feature #15626] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Reverting all commits from r67479 to r67496 because of CI failureskazu2019-04-101-1/+6
| | | | | | | | Because hard to specify commits related to r67479 only. So please commit again. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Adding `GC.compact` and compacting GC support.tenderlove2019-04-091-6/+1
| | | | | | | | | | | This commit adds the new method `GC.compact` and compacting GC support. Please see this issue for caveats: https://bugs.ruby-lang.org/issues/15626 [Feature #15626] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* [DOC] fix markups [ci skip]nobu2019-03-281-2/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y: ignore constant name capturesnobu2018-12-201-1/+1
| | | | | | | | * parse.y (reg_named_capture_assign_iter): ignore non-local name captures, including non-ASCII constant names. [ruby-dev:50719] [Bug #15437] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: dsymbol initial encodingnobu2018-06-281-1/+1
| | | | | | | * symbol.c (dsymbol_alloc): set encoding directly. no need to check existing encoding in rb_enc_associate. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: non-ASCII constant namesnobu2018-04-101-1/+37
| | | | | | | | | | * symbol.c (rb_sym_constant_char_p): support for non-ASCII constant names. [Feature #13770] * object.c (rb_mod_const_get, rb_mod_const_defined): support for non-ASCII constant names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h: remove dependecy on ruby/encoding.hnobu2018-01-091-1/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* common conversion functionsnobu2017-10-261-0/+6
| | | | | | | | | | | | | * array.c (rb_to_array_type): make public to share common code internally. * hash.c (rb_to_hash_type): make public to share common code internally. * symbol.c (rb_to_symbol_type): make public to share common code internally. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* .gdbinit: print_id in rp_id [ci skip]nobu2017-10-061-1/+1
| | | | | | | | | * .gdbinit (rp_id): use print_id instead of calling lookup_id_str() in a debugger context. * symbol.c (ID_ENTRY_UNIT): made visible to debuggers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c (rb_id2str): eliminate branch to set classnormal2017-02-031-9/+1
| | | | | | | | | | | Since the fstring table encompasses all strings in the symbol table, we may reuse the fstring table walk to set the class and eliminate the branch in rb_id2str. * string.c (Init_String): use rb_cString immediately after definition * symbol.c (rb_id2str): eliminate branch to set class git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * symbol.c (is_identchar): use ISDIGIT instead of rb_enc_isalnum.naruse2016-05-261-5/+5
| | | | | | | | | | | Though rb_enc_isalnum is encoding aware function, its argument here is *m, which is a single byte. Therefore ISDIGIT is faster. * symbol.c (is_special_global_name): ditto. * symbol.c (rb_enc_symname_type): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: more informative error messagenobu2016-01-251-1/+2
| | | | | | | | * symbol.c (sym_check_asciionly): more informative error message with the encoding name and the inspected content. [ruby-core:73398] [Feature #12016] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: rb_sym_internnobu2015-11-301-1/+30
| | | | | | | * symbol.c (rb_sym_intern): rename from rb_cstr_intern and add variants. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: not freeze the receivernobu2015-11-201-7/+8
| | | | | | | * symbol.c (rb_str_intern): should not freeze the receiver itself unexpectedly. [ruby-core:71611] [Bug #11721] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: rb_cstr_internnobu2015-11-081-0/+8
| | | | | | | | * symbol.c (rb_cstr_intern): new function to make Symbol object like as rb_str_intern() but from pointer to the name, its length and its encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* id.def: token_opsnobu2015-11-051-49/+0
| | | | | | | * defs/id.def (token_ops): gather associations between IDs, operators, and parser tokens. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* RUBY_DTRACE_CREATE_HOOKnobu2015-10-291-6/+2
| | | | | | | | | | * internal.h (RUBY_DTRACE_CREATE_HOOK): macro to call hook at object creation. * vm.c (rb_source_location, rb_source_loc): retrieve source path and line number at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: dotq in rippernobu2015-10-251-0/+2
| | | | | | * symbol.c (op_tbl): add DOTQ for ripper. [Feature #11537] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52276 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* symbol.c: suppress warningsnobu2015-08-261-0/+3
| | | | | | | * symbol.c (rb_id_serial_to_id): suppress unused-function warnings where ID_TABLE_IMPL is 0, 1, or 11. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51684 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * ext/objspace/objspace.c: add a new method ObjectSpace.count_symbols.ko12015-08-211-0/+6
| | | | | | | | | | | | [Feature #11158] * symbol.c (rb_sym_immortal_count): added to count immortal symbols. * symbol.h: ditto. * test/objspace/test_objspace.rb: add a test for this method. * NEWS: describe about this method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e