Skip to content

Commit 3553a86

Browse files
committed
ext: use RARRAY_CONST_PTR
* ext/bigdecimal/bigdecimal.c: use RARRAY_CONST_PTR just fore reference instead of RARRAY_PTR, to keep the array WB-protected. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 52912db commit 3553a86

File tree

20 files changed

+123
-106
lines changed

20 files changed

+123
-106
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ BigDecimal_to_i(VALUE self)
699699
}
700700
else {
701701
VALUE a = BigDecimal_split(self);
702-
VALUE digits = RARRAY_PTR(a)[1];
702+
VALUE digits = RARRAY_CONST_PTR(a)[1];
703703
VALUE numerator = rb_funcall(digits, rb_intern("to_i"), 0);
704704
VALUE ret;
705705
ssize_t dpower = e - (ssize_t)RSTRING_LEN(digits);
@@ -788,7 +788,7 @@ BigDecimal_to_r(VALUE self)
788788
sign = VpGetSign(p);
789789
power = VpExponent10(p);
790790
a = BigDecimal_split(self);
791-
digits = RARRAY_PTR(a)[1];
791+
digits = RARRAY_CONST_PTR(a)[1];
792792
denomi_power = power - RSTRING_LEN(digits);
793793
numerator = rb_funcall(digits, rb_intern("to_i"), 0);
794794

ext/date/date_core.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3826,14 +3826,14 @@ rt_complete_frags(VALUE klass, VALUE hash)
38263826
for (i = 0; i < RARRAY_LEN(tab); i++) {
38273827
VALUE x, a;
38283828

3829-
x = RARRAY_PTR(tab)[i];
3830-
a = RARRAY_PTR(x)[1];
3829+
x = RARRAY_CONST_PTR(tab)[i];
3830+
a = RARRAY_CONST_PTR(x)[1];
38313831

38323832
{
38333833
long j, n = 0;
38343834

38353835
for (j = 0; j < RARRAY_LEN(a); j++)
3836-
if (!NIL_P(ref_hash0(RARRAY_PTR(a)[j])))
3836+
if (!NIL_P(ref_hash0(RARRAY_CONST_PTR(a)[j])))
38373837
n++;
38383838
if (n > eno) {
38393839
eno = n;
@@ -3845,8 +3845,8 @@ rt_complete_frags(VALUE klass, VALUE hash)
38453845
g = 0;
38463846
else {
38473847
g = 1;
3848-
k = RARRAY_PTR(RARRAY_PTR(tab)[idx])[0];
3849-
a = RARRAY_PTR(RARRAY_PTR(tab)[idx])[1];
3848+
k = RARRAY_CONST_PTR(RARRAY_CONST_PTR(tab)[idx])[0];
3849+
a = RARRAY_CONST_PTR(RARRAY_CONST_PTR(tab)[idx])[1];
38503850
e = eno;
38513851
}
38523852
}
@@ -3867,7 +3867,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
38673867
long i;
38683868

38693869
for (i = 0; i < RARRAY_LEN(a); i++) {
3870-
VALUE e = RARRAY_PTR(a)[i];
3870+
VALUE e = RARRAY_CONST_PTR(a)[i];
38713871

38723872
if (!NIL_P(ref_hash0(e)))
38733873
break;
@@ -3884,7 +3884,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
38843884
long i;
38853885

38863886
for (i = 0; i < RARRAY_LEN(a); i++) {
3887-
VALUE e = RARRAY_PTR(a)[i];
3887+
VALUE e = RARRAY_CONST_PTR(a)[i];
38883888

38893889
if (!NIL_P(ref_hash0(e)))
38903890
break;
@@ -3908,7 +3908,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
39083908
long i;
39093909

39103910
for (i = 0; i < RARRAY_LEN(a); i++) {
3911-
VALUE e = RARRAY_PTR(a)[i];
3911+
VALUE e = RARRAY_CONST_PTR(a)[i];
39123912

39133913
if (!NIL_P(ref_hash0(e)))
39143914
break;
@@ -3925,7 +3925,7 @@ rt_complete_frags(VALUE klass, VALUE hash)
39253925
long i;
39263926

39273927
for (i = 0; i < RARRAY_LEN(a); i++) {
3928-
VALUE e = RARRAY_PTR(a)[i];
3928+
VALUE e = RARRAY_CONST_PTR(a)[i];
39293929

39303930
if (!NIL_P(ref_hash0(e)))
39313931
break;
@@ -7085,16 +7085,16 @@ d_lite_marshal_load(VALUE self, VALUE a)
70857085

70867086

70877087
if (RARRAY_LEN(a) == 2) {
7088-
ajd = f_sub(RARRAY_PTR(a)[0], half_days_in_day);
7088+
ajd = f_sub(RARRAY_CONST_PTR(a)[0], half_days_in_day);
70897089
of = INT2FIX(0);
7090-
sg = RARRAY_PTR(a)[1];
7090+
sg = RARRAY_CONST_PTR(a)[1];
70917091
if (!k_numeric_p(sg))
70927092
sg = DBL2NUM(RTEST(sg) ? GREGORIAN : JULIAN);
70937093
}
70947094
else {
7095-
ajd = RARRAY_PTR(a)[0];
7096-
of = RARRAY_PTR(a)[1];
7097-
sg = RARRAY_PTR(a)[2];
7095+
ajd = RARRAY_CONST_PTR(a)[0];
7096+
of = RARRAY_CONST_PTR(a)[1];
7097+
sg = RARRAY_CONST_PTR(a)[2];
70987098
}
70997099

71007100
old_to_new(ajd, of, sg,
@@ -7119,12 +7119,12 @@ d_lite_marshal_load(VALUE self, VALUE a)
71197119
int jd, df, of;
71207120
double sg;
71217121

7122-
nth = RARRAY_PTR(a)[0];
7123-
jd = NUM2INT(RARRAY_PTR(a)[1]);
7124-
df = NUM2INT(RARRAY_PTR(a)[2]);
7125-
sf = RARRAY_PTR(a)[3];
7126-
of = NUM2INT(RARRAY_PTR(a)[4]);
7127-
sg = NUM2DBL(RARRAY_PTR(a)[5]);
7122+
nth = RARRAY_CONST_PTR(a)[0];
7123+
jd = NUM2INT(RARRAY_CONST_PTR(a)[1]);
7124+
df = NUM2INT(RARRAY_CONST_PTR(a)[2]);
7125+
sf = RARRAY_CONST_PTR(a)[3];
7126+
of = NUM2INT(RARRAY_CONST_PTR(a)[4]);
7127+
sg = NUM2DBL(RARRAY_CONST_PTR(a)[5]);
71287128
if (!df && f_zero_p(sf) && !of) {
71297129
set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD);
71307130
} else {

ext/dbm/dbm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ fdbm_delete_if(VALUE obj)
528528
}
529529

530530
for (i = 0; i < RARRAY_LEN(ary); i++) {
531-
keystr = RARRAY_PTR(ary)[i];
531+
keystr = RARRAY_CONST_PTR(ary)[i];
532532
key.dptr = RSTRING_PTR(keystr);
533533
key.dsize = (DSIZE_TYPE)RSTRING_LEN(keystr);
534534
if (dbm_delete(dbm, key)) {
@@ -599,11 +599,13 @@ static VALUE fdbm_store(VALUE,VALUE,VALUE);
599599
static VALUE
600600
update_i(RB_BLOCK_CALL_FUNC_ARGLIST(pair, dbm))
601601
{
602+
const VALUE *ptr;
602603
Check_Type(pair, T_ARRAY);
603604
if (RARRAY_LEN(pair) < 2) {
604605
rb_raise(rb_eArgError, "pair must be [key, value]");
605606
}
606-
fdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
607+
ptr = RARRAY_CONST_PTR(pair);
608+
fdbm_store(dbm, ptr[0], ptr[1]);
607609
return Qnil;
608610
}
609611

ext/fiddle/closure.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
7070
cPointer = rb_const_get(mFiddle, rb_intern("Pointer"));
7171

7272
for (i = 0; i < argc; i++) {
73-
type = NUM2INT(RARRAY_PTR(rbargs)[i]);
73+
type = NUM2INT(RARRAY_CONST_PTR(rbargs)[i]);
7474
switch (type) {
7575
case TYPE_VOID:
7676
argc = 0;
@@ -123,7 +123,7 @@ callback(ffi_cif *cif, void *resp, void **args, void *ctx)
123123
}
124124
}
125125

126-
ret = rb_funcall2(self, rb_intern("call"), argc, RARRAY_PTR(params));
126+
ret = rb_funcall2(self, rb_intern("call"), argc, RARRAY_CONST_PTR(params));
127127
RB_GC_GUARD(params);
128128

129129
type = NUM2INT(ctype);
@@ -210,7 +210,7 @@ initialize(int rbargc, VALUE argv[], VALUE self)
210210
cl->argv = (ffi_type **)xcalloc(argc + 1, sizeof(ffi_type *));
211211

212212
for (i = 0; i < argc; i++) {
213-
int type = NUM2INT(RARRAY_PTR(args)[i]);
213+
int type = NUM2INT(RARRAY_CONST_PTR(args)[i]);
214214
cl->argv[i] = INT2FFI_TYPE(type);
215215
}
216216
cl->argv[argc] = NULL;

ext/fiddle/function.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ initialize(int argc, VALUE argv[], VALUE self)
110110
arg_types = xcalloc(RARRAY_LEN(args) + 1, sizeof(ffi_type *));
111111

112112
for (i = 0; i < RARRAY_LEN(args); i++) {
113-
int type = NUM2INT(RARRAY_PTR(args)[i]);
113+
int type = NUM2INT(RARRAY_CONST_PTR(args)[i]);
114114
arg_types[i] = INT2FFI_TYPE(type);
115115
}
116116
arg_types[RARRAY_LEN(args)] = NULL;
@@ -164,7 +164,7 @@ function_call(int argc, VALUE argv[], VALUE self)
164164
values = (void **)((char *)generic_args + (size_t)argc * sizeof(fiddle_generic));
165165

166166
for (i = 0; i < argc; i++) {
167-
VALUE type = RARRAY_PTR(types)[i];
167+
VALUE type = RARRAY_CONST_PTR(types)[i];
168168
VALUE src = argv[i];
169169

170170
if(NUM2INT(type) == TYPE_VOIDP) {

ext/gdbm/gdbm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ fgdbm_delete_if(VALUE obj)
634634
}
635635

636636
for (i = 0; i < RARRAY_LEN(ary); i++)
637-
rb_gdbm_delete(obj, RARRAY_PTR(ary)[i]);
637+
rb_gdbm_delete(obj, RARRAY_CONST_PTR(ary)[i]);
638638
if (status) rb_jump_tag(status);
639639
if (n > 0) dbmp->di_size = n - (int)RARRAY_LEN(ary);
640640
rb_ary_clear(ary);
@@ -747,11 +747,13 @@ fgdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
747747
static VALUE
748748
update_i(RB_BLOCK_CALL_FUNC_ARGLIST(pair, dbm))
749749
{
750+
const VALUE *ptr;
750751
Check_Type(pair, T_ARRAY);
751752
if (RARRAY_LEN(pair) < 2) {
752753
rb_raise(rb_eArgError, "pair must be [key, value]");
753754
}
754-
fgdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
755+
ptr = RARRAY_CONST_PTR(pair);
756+
fgdbm_store(dbm, ptr[0], ptr[1]);
755757
return Qnil;
756758
}
757759

ext/io/console/console.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,14 @@ console_set_winsize(VALUE io, VALUE size)
521521
int newrow, newcol;
522522
#endif
523523
VALUE row, col, xpixel, ypixel;
524+
const VALUE *sz;
524525
int fd;
525526

526527
GetOpenFile(io, fptr);
527528
size = rb_Array(size);
528-
rb_scan_args((int)RARRAY_LEN(size), RARRAY_PTR(size), "22",
529-
&row, &col, &xpixel, &ypixel);
529+
rb_check_arity(RARRAY_LENINT(size), 2, 4);
530+
sz = RARRAY_CONST_PTR(size);
531+
row = sz[0], col = sz[1], xpixel = sz[2], ypixel = sz[3];
530532
fd = GetWriteFD(fptr);
531533
#if defined TIOCSWINSZ
532534
ws.ws_row = ws.ws_col = ws.ws_xpixel = ws.ws_ypixel = 0;

ext/openssl/ossl_ocsp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
682682
/* All ary's members should be X509Extension */
683683
Check_Type(ext, T_ARRAY);
684684
for (i = 0; i < RARRAY_LEN(ext); i++)
685-
OSSL_Check_Kind(RARRAY_PTR(ext)[i], cX509Ext);
685+
OSSL_Check_Kind(RARRAY_CONST_PTR(ext)[i], cX509Ext);
686686
}
687687

688688
error = 0;
@@ -711,7 +711,7 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
711711
sk_X509_EXTENSION_pop_free(single->singleExtensions, X509_EXTENSION_free);
712712
single->singleExtensions = NULL;
713713
for(i = 0; i < RARRAY_LEN(ext); i++){
714-
x509ext = DupX509ExtPtr(RARRAY_PTR(ext)[i]);
714+
x509ext = DupX509ExtPtr(RARRAY_CONST_PTR(ext)[i]);
715715
if(!OCSP_SINGLERESP_add_ext(single, x509ext, -1)){
716716
X509_EXTENSION_free(x509ext);
717717
error = 1;

ext/openssl/ossl_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ ossl_sslctx_setup(VALUE self)
759759
if(!NIL_P(val)){
760760
if (RB_TYPE_P(val, T_ARRAY)) {
761761
for(i = 0; i < RARRAY_LEN(val); i++){
762-
client_ca = GetX509CertPtr(RARRAY_PTR(val)[i]);
762+
client_ca = GetX509CertPtr(RARRAY_CONST_PTR(val)[i]);
763763
if (!SSL_CTX_add_client_CA(ctx, client_ca)){
764764
/* Copies X509_NAME => FREE it. */
765765
ossl_raise(eSSLError, "SSL_CTX_add_client_CA");

ext/openssl/ossl_x509cert.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,13 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
668668
Check_Type(ary, T_ARRAY);
669669
/* All ary's members should be X509Extension */
670670
for (i=0; i<RARRAY_LEN(ary); i++) {
671-
OSSL_Check_Kind(RARRAY_PTR(ary)[i], cX509Ext);
671+
OSSL_Check_Kind(RARRAY_CONST_PTR(ary)[i], cX509Ext);
672672
}
673673
GetX509(self, x509);
674674
sk_X509_EXTENSION_pop_free(x509->cert_info->extensions, X509_EXTENSION_free);
675675
x509->cert_info->extensions = NULL;
676676
for (i=0; i<RARRAY_LEN(ary); i++) {
677-
ext = DupX509ExtPtr(RARRAY_PTR(ary)[i]);
677+
ext = DupX509ExtPtr(RARRAY_CONST_PTR(ary)[i]);
678678

679679
if (!X509_add_ext(x509, ext, -1)) { /* DUPs ext - FREE it */
680680
X509_EXTENSION_free(ext);

0 commit comments

Comments
 (0)