summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-24 23:57:28 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-24 23:57:28 +0900
commit14d154076876a6566b273f0eb3c4a56c681a6b13 (patch)
tree25e50d3f3469be81e36bf6aa4a16f3668c05d067 /include
parent1780ad37483592d7752d314fbdb3bfd01966c229 (diff)
RString NULL ptr check only when RUBY_DEBUG
Since edf01d4e82d8e44ee30ec41fbcb7f802bc8b8c5d, fake string treats NULL as an empty string.
Diffstat (limited to 'include')
-rw-r--r--include/ruby/internal/core/rstring.h10
1 files changed, 3 insertions, 7 deletions
diff --git a/include/ruby/internal/core/rstring.h b/include/ruby/internal/core/rstring.h
index a03ad5b2ec..0bca74e688 100644
--- a/include/ruby/internal/core/rstring.h
+++ b/include/ruby/internal/core/rstring.h
@@ -417,13 +417,9 @@ RSTRING_PTR(VALUE str)
{
char *ptr = rbimpl_rstring_getmem(str).as.heap.ptr;
- if (RB_UNLIKELY(! ptr)) {
+ if (RUBY_DEBUG && RB_UNLIKELY(! ptr)) {
/* :BEWARE: @shyouhei thinks that currently, there are rooms for this
- * function to return NULL. In the 20th century that was a pointless
- * concern. However struct RString can hold fake strings nowadays. It
- * seems no check against NULL are exercised around handling of them
- * (one of such usages is located in marshal.c, which scares
- * @shyouhei). Better check here for maximum safety.
+ * function to return NULL. Better check here for maximum safety.
*
* Also, this is not rb_warn() because RSTRING_PTR() can be called
* during GC (see what obj_info() does). rb_warn() needs to allocate
@@ -447,7 +443,7 @@ RSTRING_END(VALUE str)
{
struct RString buf = rbimpl_rstring_getmem(str);
- if (RB_UNLIKELY(! buf.as.heap.ptr)) {
+ if (RUBY_DEBUG && RB_UNLIKELY(! buf.as.heap.ptr)) {
/* Ditto. */
rb_debug_rstring_null_ptr("RSTRING_END");
}