summaryrefslogtreecommitdiff
path: root/include/ruby/internal
AgeCommit message (Collapse)Author
2025-05-08Move `object_id` in object fields.Jean Boussier
And get rid of the `obj_to_id_tbl` It's no longer needed, the `object_id` is now stored inline in the object alongside instance variables. We still need the inverse table in case `_id2ref` is invoked, but we lazily build it by walking the heap if that happens. The `object_id` concern is also no longer a GC implementation concern, but a generic implementation. Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com> Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-08Rename `ivptr` -> `fields`, `next_iv_index` -> `next_field_index`Jean Boussier
Ivars will longer be the only thing stored inline via shapes, so keeping the `iv_index` and `ivptr` names would be confusing. Instance variables won't be the only thing stored inline via shapes, so keeping the `ivptr` name would be confusing. `field` encompass anything that can be stored in a VALUE array. Similarly, `gen_ivtbl` becomes `gen_fields_tbl`. Notes: Merged: https://github.com/ruby/ruby/pull/13159
2025-05-05Add `RBIMPL_ATTR_NONSTRING_ARRAY()` macro for GCC 15Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/13256
2025-05-05Save one VALUE per embedded RTypedDataJeremy Evans
This halves the amount of memory used for embedded RTypedData if they are one VALUE (8 bytes on 64-bit platforms) over the slot size limit. For Set, on 64-bit it uses an embedded 56-byte struct. With the previous implementation, the embedded structs starts at offset 32, resulting in a total size of 88. Since that is over the 80 byte limit, it goes to the next highest bucket, 160 bytes, wasting 72 bytes. This allows it to fit in a 80 byte bucket, which reduces the total size for small sets of from 224 bytes (160 bytes embedded, 64 bytes malloc, 72 bytes wasted in embedding) to 144 bytes (80 bytes embedded, 64 bytes malloc, 0 bytes wasted in embedding). Any other embedded RTypedData will see similar advantages if they are currently one VALUE over the limit. To implement this, remove the typed_flag from struct RTypedData. Embed the typed_flag information in the type member, which is now a tagged pointer using VALUE type, using the bottom low 2 bits as flags (1 bit for typed flag, the other for the embedded flag). To get the actual pointer, RTYPEDDATA_TYPE masks out the low 2 bits and then casts. That moves the RTypedData data pointer from offset 32 to offset 24 (on 64-bit). Vast amount of code in the internals (and probably external C extensions) expects the following code to work for both RData and non-embedded RTypedData: ```c DATA_PTR(obj) = some_pointer; ``` Allow this to work by moving the data pointer in RData between the dmark and dfree pointers, so it is at the same offset (24 on 64-bit). Other than these changes to the include files, the only changes needed were to gc.c, to account for the new struct layouts, handle setting the low bits in the type member, and to use RTYPEDDATA_TYPE(obj) instead of RTYPEDDATA(obj)->type. Notes: Merged: https://github.com/ruby/ruby/pull/13190
2025-04-30Suppress gcc 15 unterminated-string-initialization warningsNobuyoshi Nakada
2025-04-30Fix C23 (GCC 15) WIN32 compatibility for rb_define_* functionsAlan Wu
Fixes [Bug #21286] Notes: Merged: https://github.com/ruby/ruby/pull/13202
2025-04-30RUBY_T_{TRUE,FALSE} comments were reversedMatt Valentine-House
[ci skip] Notes: Merged: https://github.com/ruby/ruby/pull/13207
2025-03-18Suppress sign-conversion warning [ci skip]Nobuyoshi Nakada
2025-02-28[DOC] Fix the comment for RUBY_CONST_ID and rb_internNobuyoshi Nakada
RUBY_CONST_ID has never been deprecated; `rb_intern` is handy but it is using non-standard GCC extensions and does not cache the ID with other compilers.
2025-02-12Remove dead iv_index_tbl field in RObjectPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12739
2025-01-14[Bug #21024] <cstdbool> header has been uselessNobuyoshi Nakada
And finally deprecated at C++-17. Patched by jprokop (Jarek Prokop). Notes: Merged: https://github.com/ruby/ruby/pull/12573
2025-01-14Mark `rb_path_check` as internal onlyNobuyoshi Nakada
2025-01-13Move the declaration of `rb_path_check`Nobuyoshi Nakada
Although this function is unrelated to hash, it was defined in hash.c to check PATH environment variable originally. Then the definition was moeved to file.c but the declaration was left in the hash.c block. Notes: Merged: https://github.com/ruby/ruby/pull/12564
2025-01-12[DOC] Fix the description of `rb_path_check`Nobuyoshi Nakada
c.f. #20971
2025-01-11[Bug #21024] <cstdbool> header is deprecated in C++17Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12551
2025-01-02Move rbimpl_size_add_overflow from gc.c to memory.hPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12459
2024-12-25Development of 3.5.0 started.Yukihiro "Matz" Matsumoto
2024-12-18use RBIMPL_ATTR_MAYBE_UNUSEDNaohisa Goto
The macro MAYBE_UNUSED, prepared by ./configure, may not be defined in some environments such as Oracle Developer Studio 12.5 on Solaris 10. This fixes [Bug #20963]
2024-12-17[DOC] rb_id2name(): Note truncation danger (+minor copyediting)Alan Wu
Thanks, nobu!
2024-12-17[DOC] Add note to rb_id2name about GC compactionPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/12376
2024-12-17Win32: Fix `rbimpl_size_mul_overflow` on arm64Nobuyoshi Nakada
`_umul128` is specific to x86_64 platform, see higher words by `__umulh` on arm64. Notes: Merged: https://github.com/ruby/ruby/pull/12367
2024-12-13[DOC] Update `rb_strlen_lit`Nobuyoshi Nakada
It is not "in bytes" for wide char literal.
2024-12-04Fix typos in public headers [ci skip]Alan Wu
2024-11-29[DOC] Rewrite docs for rb_sym2str()Alan Wu
Explaining this by reference to rb_id2str() obscures a few important details because IDs and symbols don't map to each other perfectly (you can have a dynamic symbol without an ID!) Also, it used to take 2 redirections to get to concrete information, and I think being more direct is friendlier.
2024-11-29[DOC] Mention that rb_id2str() returns a frozen stringAlan Wu
2024-11-13Mark strings returned by Symbol#to_s as chilled (#12065)Jean byroot Boussier
* Use FL_USER0 for ELTS_SHARED This makes space in RString for two bits for chilled strings. * Mark strings returned by `Symbol#to_s` as chilled [Feature #20350] `STR_CHILLED` now spans on two user flags. If one bit is set it marks a chilled string literal, if it's the other it marks a `Symbol#to_s` chilled string. Since it's not possible, and doesn't make much sense to include debug info when `--debug-frozen-string-literal` is set, we can't include allocation source, but we can safely include the symbol name in the warning message, making it much easier to find the source of the issue. Co-Authored-By: Étienne Barrié <etienne.barrie@gmail.com> --------- Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com> Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-11-12Add missing macros for `__has_builtin`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12060
2024-11-10rb_strlen_lit: support wide string literalsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12046
2024-11-10Fix sign-conversion warnings on IL32 platformsNobuyoshi Nakada
If `long` and `int` are the same size, `unsigned int` max would exceed `signed long` range. It is guaranteed by `RB_POSFIXABLE` that `v` can be casted to `long` safely here. Notes: Merged: https://github.com/ruby/ruby/pull/12045
2024-11-06`Warning[:strict_unused_block]`Koichi Sasada
to show unused block warning strictly. ```ruby class C def f = nil end class D def f = yield end [C.new, D.new].each{|obj| obj.f{}} ``` In this case, `D#f` accepts a block. However `C#f` doesn't accept a block. There are some cases passing a block with `obj.f{}` where `obj` is `C` or `D`. To avoid warnings on such cases, "unused block warning" will be warned only if there is not same name which accepts a block. On the above example, `C.new.f{}` doesn't show any warnings because there is a same name `D#f` which accepts a block. We call this default behavior as "relax mode". `strict_unused_block` new warning category changes from "relax mode" to "strict mode", we don't check same name methods and `C.new.f{}` will be warned. [Feature #15554] Notes: Merged: https://github.com/ruby/ruby/pull/12005
2024-10-23Fix false warning by gcc 14 for aarch64Nobuyoshi Nakada
gcc 14 for aarch64 with `-O3` may emit a false positive warning for a pointer access of `RB_BUILTIN_TYPE` called from `RB_TYPE_P`. `Qfalse` shouldn't get there because of `RB_SPECIAL_CONST_P`, but the optimizer seems to ignore this condition in some cases (`ASSUME` just before the access doesn't seem to have any effect either). Only by reversing the order in `RB_SPECIAL_CONST_P` to compare with 0 first does the warning seem to go away. Notes: Merged: https://github.com/ruby/ruby/pull/11928
2024-10-08Cast via `uintptr_t` function pointer between object pointerNobuyoshi Nakada
- ISO C forbids conversion of function pointer to object pointer type - ISO C forbids conversion of object pointer to function pointer type
2024-09-24fix rb_memsearch() documentNAITOH Jun
## Why? The explanation of x and y is reversed. https://github.com/ruby/ruby/blob/ddbd64400199fd408d23c85f9fb0d7f742ecf9e1/re.c#L251-L256 ``` long rb_memsearch(const void *x0, long m, const void *y0, long n, rb_encoding *enc) { const unsigned char *x = x0, *y = y0; if (m > n) return -1; ``` Notes: Merged: https://github.com/ruby/ruby/pull/11625
2024-08-28[DOC] Mention rb_io_fdopen() takes ownership of the FDAlan Wu
2024-08-11Fix sign-conversion warningNobuyoshi Nakada
``` ../../.././include/ruby/internal/special_consts.h:349:36: error: conversion to ‘VALUE’ {aka ‘long unsigned int’} from ‘int’ may change the sign of the result [-Werror=sign-conversion] 349 | return RB_SPECIAL_CONST_P(obj) * RUBY_Qtrue; | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~ ```
2024-07-19Make rb_check_frozen_inline() static inline againAlan Wu
Since 730e3b2ce01915c4a98b79bb281b2c38a9ff1131 ("Stop exposing `rb_str_chilled_p`"), we noticed a speed loss on a few benchmarks that are string operations heavy. This is partially due to routines no longer having the options to inline rb_check_frozen_inline() in non-LTO builds. Make it an inlining candidate again to recover speed. Testing this patch on my machine, the fannkuchredux benchmark gets a 1.15 speed-up with YJIT and 1.03 without YJIT. Notes: Merged: https://github.com/ruby/ruby/pull/11211
2024-07-17[DOC] Note that rb_obj_freeze_inline() can raise NoMemoryErrorAlan Wu
And move it back to a public header because Doxygen might not be scanning the .c files. [Feature #18776] Notes: Merged: https://github.com/ruby/ruby/pull/11179
2024-07-17[DOC] No more is rb_ary_freeze() an alias of rb_obj_freeze()Alan Wu
[Feature #20589] Notes: Merged: https://github.com/ruby/ruby/pull/11179
2024-07-12give up USE_GC_MALLOC_OBJ_INFO_DETAILS卜部昌平
This feature is no longer possible under current design; now that our GC is pluggable, we cannot assume what was achieved by this compiler flag is always possble by the dynamically-loaded GC implementation.
2024-07-10Add rb_block_call2, a flexible variant of rb_block_callYusuke Endoh
This function accepts flags: RB_NO_KEYWORDS, RB_PASS_KEYWORDS, RB_PASS_CALLED_KEYWORDS: Works as the same as rb_block_call_kw. RB_BLOCK_NO_USE_PACKED_ARGS: The given block ("bl_proc") does not use "yielded_arg" of rb_block_call_func_t. Instead, the block accesses the yielded arguments via "argc" and "argv". This flag allows the called method to yield arguments without allocating an Array.
2024-06-21Show more in `RBIMPL_ASSERT_TYPE`Nobuyoshi Nakada
2024-06-13Crash instead of raising with Check_Type() in RBIMPL_ASSERT_TYPE() in debug ↵Alan Wu
builds Previously, RBIMPL_ASSERT_TYPE() used Check_Type() only in RUBY_DEBUG builds. It raised TypeError, but only in debug builds. For people testing type mismatch using debug builds looking for a Ruby exception, this can be misleading -- the code could be missing a type check in non-debug builds if it is relying on for example RSTRING_LEN() to raise. Also, Check_Type() can obscure the true cause of error in debug mode. When type check fails because the object is corrupt, instead of crashing with a clear type assertion message, it can crash while trying to construct an exception object to raise. You can see this for example in <https://github.com/ruby/ruby/actions/runs/9489999591/job/26152506434?pr=10985>, where RB_ENCODING_GET() is used on a corrupt object, but the crash happens later and says "Assertion Failed: ../src/vm_method.c:1477:callable_method_entry_or_negative". RBIMPL_ASSERT_TYPE() should assert right away. RBIMPL_ASSERT_OR_ASSUME() asserts when RUBY_DEBUG and assumes in release builds, as desired. This should help investigate flaky CI failures that show up as TypeError from `Kernel#require`, e.g. "'Kernel#require': wrong argument type false (expected String) (TypeError)". Same CI failure examples: - https://github.com/ruby/ruby/actions/runs/9034787861/job/24828147431 - https://github.com/ruby/ruby/actions/runs/9418303667/job/25945492440 - https://github.com/ruby/ruby/actions/runs/9505650952/job/26201031314 The failure occurs with and without use of YJIT.
2024-06-06Mark old Data API as deprecatedJean Boussier
[Feature #19998]
2024-06-02Stop exposing `rb_str_chilled_p`Jean Boussier
[Feature #20205] Now that chilled strings no longer appear as frozen, there is no need to offer an API to check for chilled strings. We however need to change `rb_check_frozen_internal` to no longer be a macro, as it needs to check for chilled strings.
2024-05-28Make value_type.h compatible with -WconversionJean Boussier
[Feature #20507] This was missed from the initial commit. ``` ../../.././include/ruby/internal/value_type.h:446:27: error: implicit conversion changes signedness: 'enum ruby_value_type' to 'int' [-Werror,-Wsign-conversion] rb_unexpected_type(v, t); ~~~~~~~~~~~~~~~~~~ ^ ```
2024-05-28Allow compilation of C extensions with `-Wconversion`Mike Dalessio
C extension maintainers can now compile with this warning option and the Ruby header files will generate no warnings. [Feature #20507]
2024-05-28Stop marking chilled strings as frozenÉtienne Barrié
They were initially made frozen to avoid false positives for cases such as: str = str.dup if str.frozen? But this may cause bugs and is generally confusing for users. [Feature #20205] Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-04-29suppress -Wold-style-cast warnings卜部昌平
2024-04-29workaround C++ compile error卜部昌平
We observe compiler error on FreeBSD. Their stdckdint.h does not understand C++. This shall be addressed on their side. Unti then we resport to our own version. https://rubyci.s3.amazonaws.com/freebsd14/ruby-master/log/20240427T143002Z.log.html.gz
2024-04-27use of stdckdint.h卜部昌平
C23 is going to have this header. The industry is already moving towards accepting it; OSes and compilers started to implement theirs. Why not detect its presence and if any, prefer over other ways. See also: - https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2683.pdf - https://reviews.freebsd.org/D41734 - https://reviews.llvm.org/D157331 - https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8441841a1b985d68245954af1ff023db121b0635