Skip to content

Commit c13ac4d

Browse files
committed
Assert the GVL is held when performing various rb_ functions.
[Feature #20877]
1 parent 4e970c5 commit c13ac4d

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

array.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "probes.h"
2828
#include "ruby/encoding.h"
2929
#include "ruby/st.h"
30+
#include "ruby/thread.h"
3031
#include "ruby/util.h"
3132
#include "vm_core.h"
3233
#include "builtin.h"
@@ -521,6 +522,8 @@ rb_ary_set_shared(VALUE ary, VALUE shared_root)
521522
static inline void
522523
rb_ary_modify_check(VALUE ary)
523524
{
525+
RUBY_ASSERT(ruby_thread_has_gvl_p());
526+
524527
rb_check_frozen(ary);
525528
ary_verify(ary);
526529
}
@@ -705,6 +708,8 @@ empty_ary_alloc(VALUE klass)
705708
static VALUE
706709
ary_new(VALUE klass, long capa)
707710
{
711+
RUBY_ASSERT(ruby_thread_has_gvl_p());
712+
708713
VALUE ary;
709714

710715
if (capa < 0) {

common.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,7 @@ array.$(OBJEXT): {$(VPATH)}rubyparser.h
22762276
array.$(OBJEXT): {$(VPATH)}shape.h
22772277
array.$(OBJEXT): {$(VPATH)}st.h
22782278
array.$(OBJEXT): {$(VPATH)}subst.h
2279+
array.$(OBJEXT): {$(VPATH)}thread.h
22792280
array.$(OBJEXT): {$(VPATH)}thread_$(THREAD_MODEL).h
22802281
array.$(OBJEXT): {$(VPATH)}thread_native.h
22812282
array.$(OBJEXT): {$(VPATH)}util.h
@@ -17547,6 +17548,7 @@ string.$(OBJEXT): {$(VPATH)}shape.h
1754717548
string.$(OBJEXT): {$(VPATH)}st.h
1754817549
string.$(OBJEXT): {$(VPATH)}string.c
1754917550
string.$(OBJEXT): {$(VPATH)}subst.h
17551+
string.$(OBJEXT): {$(VPATH)}thread.h
1755017552
string.$(OBJEXT): {$(VPATH)}thread_$(THREAD_MODEL).h
1755117553
string.$(OBJEXT): {$(VPATH)}thread_native.h
1755217554
string.$(OBJEXT): {$(VPATH)}util.h

string.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "probes.h"
4343
#include "ruby/encoding.h"
4444
#include "ruby/re.h"
45+
#include "ruby/thread.h"
4546
#include "ruby/util.h"
4647
#include "ruby_assert.h"
4748
#include "vm_sync.h"
@@ -2586,6 +2587,8 @@ rb_check_lockedtmp(VALUE str)
25862587
static inline void
25872588
str_modifiable(VALUE str)
25882589
{
2590+
RUBY_ASSERT(ruby_thread_has_gvl_p());
2591+
25892592
if (RB_UNLIKELY(FL_ANY_RAW(str, STR_UNMODIFIABLE_MASK))) {
25902593
if (CHILLED_STRING_P(str)) {
25912594
CHILLED_STRING_MUTATED(str);
@@ -2612,6 +2615,8 @@ str_dependent_p(VALUE str)
26122615
static inline int
26132616
str_independent(VALUE str)
26142617
{
2618+
RUBY_ASSERT(ruby_thread_has_gvl_p());
2619+
26152620
if (RB_UNLIKELY(FL_ANY_RAW(str, STR_DEPENDANT_MASK))) {
26162621
str_modifiable(str);
26172622
return !str_dependent_p(str);
@@ -2622,6 +2627,8 @@ str_independent(VALUE str)
26222627
static void
26232628
str_make_independent_expand(VALUE str, long len, long expand, const int termlen)
26242629
{
2630+
RUBY_ASSERT(ruby_thread_has_gvl_p());
2631+
26252632
char *ptr;
26262633
char *oldptr;
26272634
long capa = len + expand;
@@ -2664,6 +2671,8 @@ rb_str_modify(VALUE str)
26642671
void
26652672
rb_str_modify_expand(VALUE str, long expand)
26662673
{
2674+
RUBY_ASSERT(ruby_thread_has_gvl_p());
2675+
26672676
int termlen = TERM_LEN(str);
26682677
long len = RSTRING_LEN(str);
26692678

@@ -2727,6 +2736,8 @@ rb_must_asciicompat(VALUE str)
27272736
VALUE
27282737
rb_string_value(volatile VALUE *ptr)
27292738
{
2739+
RUBY_ASSERT(ruby_thread_has_gvl_p());
2740+
27302741
VALUE s = *ptr;
27312742
if (!RB_TYPE_P(s, T_STRING)) {
27322743
s = rb_str_to_str(s);
@@ -3286,6 +3297,8 @@ rb_str_locktmp_ensure(VALUE str, VALUE (*func)(VALUE), VALUE arg)
32863297
void
32873298
rb_str_set_len(VALUE str, long len)
32883299
{
3300+
RUBY_ASSERT(ruby_thread_has_gvl_p());
3301+
32893302
long capa;
32903303
const int termlen = TERM_LEN(str);
32913304

0 commit comments

Comments
 (0)