summaryrefslogtreecommitdiff
path: root/include/ruby
AgeCommit message (Collapse)Author
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é <[email protected]> --------- Co-authored-by: Étienne Barrié <[email protected]> Co-authored-by: Jean Boussier <[email protected]>
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-06Revert "Introduce Fiber Scheduler `blocking_region` hook. (#11963)" (#12013)Samuel Williams
This reverts some of commit 87fb44dff6409a19d12052cf0fc07ba80a4c45ac. We will rename and propose a slightly different interface. Notes: Merged-By: ioquatix <[email protected]>
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-11-02Include windows.h for `LONG` and `Interlocked` functionsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/11985
2024-10-31Introduce Fiber Scheduler `blocking_region` hook. (#11963)Samuel Williams
Notes: Merged-By: ioquatix <[email protected]>
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-10-04Better handling of timeout in `rb_io_maybe_wait_*`. (#9531)Samuel Williams
Notes: Merged-By: ioquatix <[email protected]>
2024-10-04Clarify `rb_io_maybe_wait` behaviour. (#9527)Samuel Williams
Notes: Merged-By: ioquatix <[email protected]>
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-25Fix memory leak in Regexp capture group when timeoutPeter Zhu
[Bug #20650] The capture group allocates memory that is leaked when it times out. For example: re = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001) str = "a" * 1000000 + "x" 10.times do 100.times do re =~ str rescue Regexp::TimeoutError end puts `ps -o rss= -p #{$$}` end Before: 34688 56416 78288 100368 120784 140704 161904 183568 204320 224800 After: 16288 16288 16880 16896 16912 16928 16944 17184 17184 17200 Notes: Merged: https://github.com/ruby/ruby/pull/11238
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-21Delegate from `RBIMPL_ASSERT_OR_ASSUME` to `RUBY_ASSERT_ALWAYS`Nobuyoshi Nakada
Get rid of expansion of the argument which often contains complicated macros, and simplify the failure message.
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-07Cast `RUBY_ATOMIC_PTR_CAS` argumentsNobuyoshi Nakada
As well as `RUBY_ATOMIC_PTR_EXCHANGE` and `RUBY_ATOMIC_PTR_LOAD`.
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 <[email protected]>
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
2024-04-19Refer autoconfigured endian macro (#10572)Nobuyoshi Nakada
Remove the case `RB_IO_BUFFER_HOST_ENDIAN` is not defined.
2024-04-18Include coderange.h in encoding.hPeter Zhu
ruby_coderange_type is defined in ruby/internal/encoding/coderange.h so we need to include it.
2024-04-16RB_OBJ_FREEZE_RAW: Set the object shapeJean Boussier
2024-04-11put empty `rb_gc_force_recycle()`Koichi Sasada
and declare it will be removed soon. ddtrace is still referes the API and build was failed. See https://github.com/DataDog/dd-trace-rb/pull/3578 Maybe threre are only few users of this C-API now so we can remove it soon.
2024-04-08Add builtin type assertionNobuyoshi Nakada
2024-04-05Remove deprecated function rb_gc_force_recyclePeter Zhu
This function has been deprecated since Ruby 3.1, so we should remove it for Ruby 3.4.
2024-03-27[DOC] remove repetitive words in commentscrazeteam
Signed-off-by: crazeteam <[email protected]>
2024-03-26Expose rb_str_chilled_pÉtienne Barrié
Some extensions (like stringio) may need to differentiate between chilled strings and frozen strings. They can now use rb_str_chilled_p but must check for its presence since the function will be removed when chilled strings are removed. [Bug #20389] [Feature #20205] Co-authored-by: Jean Boussier <[email protected]>
2024-03-23[DOC] Small edits in rbasic.hXavier Noria
2024-03-22Revert "Hide public implementation of `rb_io`. (#9568)" (#10283)Samuel Williams
This reverts commit 9ab1fa3bf570bf19b0d6808adf12e965aacc6d83.
2024-03-19Implement chilled stringsÉtienne Barrié
[Feature #20205] As a path toward enabling frozen string literals by default in the future, this commit introduce "chilled strings". From a user perspective chilled strings pretend to be frozen, but on the first attempt to mutate them, they lose their frozen status and emit a warning rather than to raise a `FrozenError`. Implementation wise, `rb_compile_option_struct.frozen_string_literal` is no longer a boolean but a tri-state of `enabled/disabled/unset`. When code is compiled with frozen string literals neither explictly enabled or disabled, string literals are compiled with a new `putchilledstring` instruction. This instruction is identical to `putstring` except it marks the String with the `STR_CHILLED (FL_USER3)` and `FL_FREEZE` flags. Chilled strings have the `FL_FREEZE` flag as to minimize the need to check for chilled strings across the codebase, and to improve compatibility with C extensions. Notes: - `String#freeze`: clears the chilled flag. - `String#-@`: acts as if the string was mutable. - `String#+@`: acts as if the string was mutable. - `String#clone`: copies the chilled flag. Co-authored-by: Jean Boussier <[email protected]>
2024-03-14[Feature #20265] Remove rb_newobj_of and RB_NEWOBJ_OFPeter Zhu
2024-03-14[Feature #20265] Remove rb_newobj and RB_NEWOBJPeter Zhu
2024-03-14[Feature #20306] Implement ruby_free_at_exit_pPeter Zhu
ruby_free_at_exit_p is a way for extensions to determine whether they should free all memory at shutdown.
2024-03-06Move FL_SINGLETON to FL_USER1Jean Boussier
This frees FL_USER0 on both T_MODULE and T_CLASS. Note: prior to this, FL_SINGLETON was never set on T_MODULE, so checking for `FL_SINGLETON` without first checking that `FL_TYPE` was `T_CLASS` was valid. That's no longer the case.
2024-03-06Hide public implementation of `rb_io`. (#9568)Samuel Williams
Remove `struct rb_io {...}`.
2024-03-05[DOC] fix some commentscui fliter
Signed-off-by: cui fliter <[email protected]>