Assert the GVL is held when performing various rb_ functions.

[Feature #20877]
This commit is contained in:
Samuel Williams 2024-11-01 15:45:43 +13:00
parent 4e970c5d5a
commit c13ac4d615
Notes: git 2025-04-14 09:28:26 +00:00
3 changed files with 20 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include "probes.h"
#include "ruby/encoding.h"
#include "ruby/st.h"
#include "ruby/thread.h"
#include "ruby/util.h"
#include "vm_core.h"
#include "builtin.h"
@ -521,6 +522,8 @@ rb_ary_set_shared(VALUE ary, VALUE shared_root)
static inline void
rb_ary_modify_check(VALUE ary)
{
RUBY_ASSERT(ruby_thread_has_gvl_p());
rb_check_frozen(ary);
ary_verify(ary);
}
@ -705,6 +708,8 @@ empty_ary_alloc(VALUE klass)
static VALUE
ary_new(VALUE klass, long capa)
{
RUBY_ASSERT(ruby_thread_has_gvl_p());
VALUE ary;
if (capa < 0) {

View File

@ -2276,6 +2276,7 @@ array.$(OBJEXT): {$(VPATH)}rubyparser.h
array.$(OBJEXT): {$(VPATH)}shape.h
array.$(OBJEXT): {$(VPATH)}st.h
array.$(OBJEXT): {$(VPATH)}subst.h
array.$(OBJEXT): {$(VPATH)}thread.h
array.$(OBJEXT): {$(VPATH)}thread_$(THREAD_MODEL).h
array.$(OBJEXT): {$(VPATH)}thread_native.h
array.$(OBJEXT): {$(VPATH)}util.h
@ -17547,6 +17548,7 @@ string.$(OBJEXT): {$(VPATH)}shape.h
string.$(OBJEXT): {$(VPATH)}st.h
string.$(OBJEXT): {$(VPATH)}string.c
string.$(OBJEXT): {$(VPATH)}subst.h
string.$(OBJEXT): {$(VPATH)}thread.h
string.$(OBJEXT): {$(VPATH)}thread_$(THREAD_MODEL).h
string.$(OBJEXT): {$(VPATH)}thread_native.h
string.$(OBJEXT): {$(VPATH)}util.h

View File

@ -42,6 +42,7 @@
#include "probes.h"
#include "ruby/encoding.h"
#include "ruby/re.h"
#include "ruby/thread.h"
#include "ruby/util.h"
#include "ruby_assert.h"
#include "vm_sync.h"
@ -2586,6 +2587,8 @@ rb_check_lockedtmp(VALUE str)
static inline void
str_modifiable(VALUE str)
{
RUBY_ASSERT(ruby_thread_has_gvl_p());
if (RB_UNLIKELY(FL_ANY_RAW(str, STR_UNMODIFIABLE_MASK))) {
if (CHILLED_STRING_P(str)) {
CHILLED_STRING_MUTATED(str);
@ -2612,6 +2615,8 @@ str_dependent_p(VALUE str)
static inline int
str_independent(VALUE str)
{
RUBY_ASSERT(ruby_thread_has_gvl_p());
if (RB_UNLIKELY(FL_ANY_RAW(str, STR_DEPENDANT_MASK))) {
str_modifiable(str);
return !str_dependent_p(str);
@ -2622,6 +2627,8 @@ str_independent(VALUE str)
static void
str_make_independent_expand(VALUE str, long len, long expand, const int termlen)
{
RUBY_ASSERT(ruby_thread_has_gvl_p());
char *ptr;
char *oldptr;
long capa = len + expand;
@ -2664,6 +2671,8 @@ rb_str_modify(VALUE str)
void
rb_str_modify_expand(VALUE str, long expand)
{
RUBY_ASSERT(ruby_thread_has_gvl_p());
int termlen = TERM_LEN(str);
long len = RSTRING_LEN(str);
@ -2727,6 +2736,8 @@ rb_must_asciicompat(VALUE str)
VALUE
rb_string_value(volatile VALUE *ptr)
{
RUBY_ASSERT(ruby_thread_has_gvl_p());
VALUE s = *ptr;
if (!RB_TYPE_P(s, T_STRING)) {
s = rb_str_to_str(s);
@ -3286,6 +3297,8 @@ rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg)
void
rb_str_set_len(VALUE str, long len)
{
RUBY_ASSERT(ruby_thread_has_gvl_p());
long capa;
const int termlen = TERM_LEN(str);