diff options
43 files changed, 484 insertions, 512 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index eb0d2b390d..4aa9b27192 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -224,14 +224,14 @@ GetVpValue(VALUE v, int must) #ifdef ENABLE_NUMERIC_STRING case T_STRING: SafeStringValue(v); - return VpCreateRbObject(strlen(RSTRING(v)->ptr) + VpBaseFig() + 1, - RSTRING(v)->ptr); + return VpCreateRbObject(strlen(RSTRING_PTR(v)) + VpBaseFig() + 1, + RSTRING_PTR(v)); #endif /* ENABLE_NUMERIC_STRING */ case T_BIGNUM: bg = rb_big2str(v, 10); - return VpCreateRbObject(strlen(RSTRING(bg)->ptr) + VpBaseFig() + 1, - RSTRING(bg)->ptr); + return VpCreateRbObject(strlen(RSTRING_PTR(bg)) + VpBaseFig() + 1, + RSTRING_PTR(bg)); default: goto SomeOneMayDoIt; } @@ -240,7 +240,7 @@ SomeOneMayDoIt: if(must) { rb_raise(rb_eTypeError, "%s can't be coerced into BigDecimal", rb_special_const_p(v)? - RSTRING(rb_inspect(v))->ptr: + RSTRING_PTR(rb_inspect(v)): rb_obj_classname(v) ); } @@ -332,7 +332,7 @@ BigDecimal_load(VALUE self, VALUE str) unsigned long m=0; SafeStringValue(str); - pch = RSTRING(str)->ptr; + pch = RSTRING_PTR(str); /* First get max prec */ while((*pch)!=(unsigned char)'\0' && (ch=*pch++)!=(unsigned char)':') { if(!ISDIGIT(ch)) { @@ -1510,7 +1510,7 @@ BigDecimal_to_s(int argc, VALUE *argv, VALUE self) if(rb_scan_args(argc,argv,"01",&f)==1) { if(TYPE(f)==T_STRING) { SafeStringValue(f); - psz = RSTRING(f)->ptr; + psz = RSTRING_PTR(f); if(*psz==' ') { fPlus = 1; psz++; } else if(*psz=='+') { @@ -1687,7 +1687,7 @@ BigDecimal_global_new(int argc, VALUE *argv, VALUE self) mf = GetPositiveInt(nFig); } SafeStringValue(iniValue); - GUARD_OBJ(pv,VpCreateRbObject(mf, RSTRING(iniValue)->ptr)); + GUARD_OBJ(pv,VpCreateRbObject(mf, RSTRING_PTR(iniValue))); return ToValue(pv); } @@ -1718,7 +1718,7 @@ BigDecimal_new(int argc, VALUE *argv, VALUE self) mf = GetPositiveInt(nFig); } SafeStringValue(iniValue); - GUARD_OBJ(pv,VpNewRbClass(mf, RSTRING(iniValue)->ptr,self)); + GUARD_OBJ(pv,VpNewRbClass(mf, RSTRING_PTR(iniValue),self)); return ToValue(pv); } diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c index 079905d4c2..3bc1a83103 100644 --- a/ext/dbm/dbm.c +++ b/ext/dbm/dbm.c @@ -114,24 +114,24 @@ fdbm_initialize(int argc, VALUE *argv, VALUE obj) if (flags & RUBY_DBM_RW_BIT) { flags &= ~RUBY_DBM_RW_BIT; - dbm = dbm_open(RSTRING(file)->ptr, flags, mode); + dbm = dbm_open(RSTRING_PTR(file), flags, mode); } else { dbm = 0; if (mode >= 0) { - dbm = dbm_open(RSTRING(file)->ptr, O_RDWR|O_CREAT, mode); + dbm = dbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT, mode); } if (!dbm) { - dbm = dbm_open(RSTRING(file)->ptr, O_RDWR, 0); + dbm = dbm_open(RSTRING_PTR(file), O_RDWR, 0); } if (!dbm) { - dbm = dbm_open(RSTRING(file)->ptr, O_RDONLY, 0); + dbm = dbm_open(RSTRING_PTR(file), O_RDONLY, 0); } } if (!dbm) { if (mode == -1) return Qnil; - rb_sys_fail(RSTRING(file)->ptr); + rb_sys_fail(RSTRING_PTR(file)); } dbmp = ALLOC(struct dbmdata); @@ -166,8 +166,8 @@ fdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone) DBM *dbm; StringValue(keystr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); GetDBM2(obj, dbmp, dbm); value = dbm_fetch(dbm, key); @@ -206,14 +206,14 @@ fdbm_index(VALUE obj, VALUE valstr) DBM *dbm; StringValue(valstr); - val.dptr = RSTRING(valstr)->ptr; - val.dsize = RSTRING(valstr)->len; + val.dptr = RSTRING_PTR(valstr); + val.dsize = RSTRING_LEN(valstr); GetDBM2(obj, dbmp, dbm); for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - if (val.dsize == RSTRING(valstr)->len && - memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0) { + if (val.dsize == RSTRING_LEN(valstr) && + memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0) { return rb_tainted_str_new(key.dptr, key.dsize); } } @@ -274,8 +274,8 @@ fdbm_delete(VALUE obj, VALUE keystr) fdbm_modify(obj); StringValue(keystr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); GetDBM2(obj, dbmp, dbm); @@ -348,8 +348,8 @@ fdbm_delete_if(VALUE obj) for (i = 0; i < RARRAY(ary)->len; i++) { keystr = RARRAY(ary)->ptr[i]; StringValue(keystr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); if (dbm_delete(dbm, key)) { rb_raise(rb_eDBMError, "dbm_delete failed"); } @@ -438,11 +438,11 @@ fdbm_store(VALUE obj, VALUE keystr, VALUE valstr) keystr = rb_obj_as_string(keystr); valstr = rb_obj_as_string(valstr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); - val.dptr = RSTRING(valstr)->ptr; - val.dsize = RSTRING(valstr)->len; + val.dptr = RSTRING_PTR(valstr); + val.dsize = RSTRING_LEN(valstr); GetDBM2(obj, dbmp, dbm); dbmp->di_size = -1; @@ -595,8 +595,8 @@ fdbm_has_key(VALUE obj, VALUE keystr) DBM *dbm; StringValue(keystr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); GetDBM2(obj, dbmp, dbm); val = dbm_fetch(dbm, key); @@ -612,14 +612,14 @@ fdbm_has_value(VALUE obj, VALUE valstr) DBM *dbm; StringValue(valstr); - val.dptr = RSTRING(valstr)->ptr; - val.dsize = RSTRING(valstr)->len; + val.dptr = RSTRING_PTR(valstr); + val.dsize = RSTRING_LEN(valstr); GetDBM2(obj, dbmp, dbm); for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { val = dbm_fetch(dbm, key); - if (val.dsize == RSTRING(valstr)->len && - memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0) + if (val.dsize == RSTRING_LEN(valstr) && + memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0) return Qtrue; } return Qfalse; diff --git a/ext/dbm/extconf.rb b/ext/dbm/extconf.rb index 19bfc1f6d3..41996c417c 100644 --- a/ext/dbm/extconf.rb +++ b/ext/dbm/extconf.rb @@ -34,6 +34,7 @@ def db_check(db) for hdr in $dbm_conf_headers.fetch(db, ["ndbm.h"]) if have_header(hdr.dup) and have_type("DBM", hdr.dup, hsearch) $defs << hsearch << '-DDBM_HDR="<'+hdr+'>"' + p $defs return true end end @@ -55,7 +56,7 @@ end have_header("cdefs.h") have_header("sys/cdefs.h") -if /DBM_HDR/ =~ $CFLAGS and have_func(db_prefix("dbm_open")) +if /DBM_HDR/ =~ $defs.join(" ") and have_func(db_prefix("dbm_open")) have_func(db_prefix("dbm_clearerr")) unless $dbm_conf_have_gdbm create_makefile("dbm") end diff --git a/ext/digest/digest.c b/ext/digest/digest.c index 906ea18b3b..9d3492ae40 100644 --- a/ext/digest/digest.c +++ b/ext/digest/digest.c @@ -72,10 +72,10 @@ rb_digest_base_s_digest(VALUE klass, VALUE str) Data_Get_Struct(obj, void, pctx); StringValue(str); - algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len); + algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str)); str = rb_str_new(0, algo->digest_len); - algo->final_func(RSTRING(str)->ptr, pctx); + algo->final_func(RSTRING_PTR(str), pctx); return str; } @@ -91,10 +91,10 @@ rb_digest_base_s_hexdigest(VALUE klass, VALUE str) Data_Get_Struct(obj, void, pctx); StringValue(str); - algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len); + algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str)); str = rb_str_new(0, algo->digest_len * 2); - algo->end_func(pctx, RSTRING(str)->ptr); + algo->end_func(pctx, RSTRING_PTR(str)); return str; } @@ -128,7 +128,7 @@ rb_digest_base_update(VALUE self, VALUE str) algo = get_digest_base_metadata(rb_obj_class(self)); Data_Get_Struct(self, void, pctx); - algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len); + algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str)); return self; } @@ -162,7 +162,7 @@ rb_digest_base_digest(VALUE self) pctx2 = xmalloc(len); memcpy(pctx2, pctx1, len); - algo->final_func(RSTRING(str)->ptr, pctx2); + algo->final_func(RSTRING_PTR(str), pctx2); free(pctx2); return str; @@ -185,7 +185,7 @@ rb_digest_base_hexdigest(VALUE self) pctx2 = xmalloc(len); memcpy(pctx2, pctx1, len); - algo->end_func(pctx2, RSTRING(str)->ptr); + algo->end_func(pctx2, RSTRING_PTR(str)); free(pctx2); return str; @@ -213,12 +213,12 @@ rb_digest_base_equal(VALUE self, VALUE other) StringValue(other); str2 = other; - if (RSTRING(str2)->len == algo->digest_len) + if (RSTRING_LEN(str2) == algo->digest_len) str1 = rb_digest_base_digest(self); else str1 = rb_digest_base_hexdigest(self); - if (RSTRING(str1)->len == RSTRING(str2)->len + if (RSTRING_LEN(str1) == RSTRING_LEN(str2) && rb_str_cmp(str1, str2) == 0) return Qtrue; diff --git a/ext/etc/etc.c b/ext/etc/etc.c index 06ae842d48..65a2963e74 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -153,8 +153,8 @@ etc_getpwnam(VALUE obj, VALUE nam) struct passwd *pwd; SafeStringValue(nam); - pwd = getpwnam(RSTRING(nam)->ptr); - if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING(nam)->ptr); + pwd = getpwnam(RSTRING_PTR(nam)); + if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING_PTR(nam)); return setup_passwd(pwd); #else return Qnil; @@ -351,8 +351,8 @@ etc_getgrnam(VALUE obj, VALUE nam) rb_secure(4); SafeStringValue(nam); - grp = getgrnam(RSTRING(nam)->ptr); - if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING(nam)->ptr); + grp = getgrnam(RSTRING_PTR(nam)); + if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING_PTR(nam)); return setup_group(grp); #else return Qnil; diff --git a/ext/extmk.rb b/ext/extmk.rb index dbc1c92e57..a9fad432bd 100644 --- a/ext/extmk.rb +++ b/ext/extmk.rb @@ -380,7 +380,7 @@ else end if $extout - RbConfig.expand(extout = "#$extout", RbConfig::CONFIG.merge("topdir"=>$topdir)) + RbConfig.expand(extout = "#{$extout}", RbConfig::CONFIG.merge("topdir"=>$topdir)) if $install dest = RbConfig.expand($rubylibdir.dup) unless $destdir.empty? diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c index 4857d386ee..8c9b5a72e5 100644 --- a/ext/gdbm/gdbm.c +++ b/ext/gdbm/gdbm.c @@ -114,19 +114,19 @@ fgdbm_initialize(int argc, VALUE *argv, VALUE obj) if (flags & RUBY_GDBM_RW_BIT) { flags &= ~RUBY_GDBM_RW_BIT; - dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE, + dbm = gdbm_open(RSTRING_PTR(file), MY_BLOCK_SIZE, flags, mode, MY_FATAL_FUNC); } else { dbm = 0; if (mode >= 0) - dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE, + dbm = gdbm_open(RSTRING_PTR(file), MY_BLOCK_SIZE, GDBM_WRCREAT|flags, mode, MY_FATAL_FUNC); if (!dbm) - dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE, + dbm = gdbm_open(RSTRING_PTR(file), MY_BLOCK_SIZE, GDBM_WRITER|flags, 0, MY_FATAL_FUNC); if (!dbm) - dbm = gdbm_open(RSTRING(file)->ptr, MY_BLOCK_SIZE, + dbm = gdbm_open(RSTRING_PTR(file), MY_BLOCK_SIZE, GDBM_READER|flags, 0, MY_FATAL_FUNC); } @@ -136,7 +136,7 @@ fgdbm_initialize(int argc, VALUE *argv, VALUE obj) if (gdbm_errno == GDBM_FILE_OPEN_ERROR || gdbm_errno == GDBM_CANT_BE_READER || gdbm_errno == GDBM_CANT_BE_WRITER) - rb_sys_fail(RSTRING(file)->ptr); + rb_sys_fail(RSTRING_PTR(file)); else rb_raise(rb_eGDBMError, "%s", gdbm_strerror(gdbm_errno)); } @@ -176,12 +176,8 @@ rb_gdbm_fetch(GDBM_FILE dbm, datum key) if (val.dptr == 0) return Qnil; - str = rb_obj_alloc(rb_cString); - RSTRING(str)->len = val.dsize; - RSTRING(str)->aux.capa = val.dsize; - RSTRING(str)->ptr = REALLOC_N(val.dptr,char,val.dsize+1); - RSTRING(str)->ptr[val.dsize] = '\0'; - + str = rb_str_new(val.dptr, val.dsize); + free(val.dptr); OBJ_TAINT(str); return (VALUE)str; } @@ -192,8 +188,8 @@ rb_gdbm_fetch2(GDBM_FILE dbm, VALUE keystr) datum key; StringValue(keystr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); return rb_gdbm_fetch(dbm, key); } @@ -218,12 +214,8 @@ rb_gdbm_firstkey(GDBM_FILE dbm) if (key.dptr == 0) return Qnil; - str = rb_obj_alloc(rb_cString); - RSTRING(str)->len = key.dsize; - RSTRING(str)->aux.capa = key.dsize; - RSTRING(str)->ptr = REALLOC_N(key.dptr,char,key.dsize+1); - RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; - + str = rb_str_new(key.dptr, key.dsize); + free(key.dptr); OBJ_TAINT(str); return str; } @@ -234,18 +226,13 @@ rb_gdbm_nextkey(GDBM_FILE dbm, VALUE keystr) datum key, key2; VALUE str; - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); key2 = gdbm_nextkey(dbm, key); if (key2.dptr == 0) return Qnil; - str = rb_obj_alloc(rb_cString); - RSTRING(str)->len = key2.dsize; - RSTRING(str)->aux.capa = key2.dsize; - RSTRING(str)->ptr = REALLOC_N(key2.dptr,char,key2.dsize+1); - RSTRING(str)->ptr[RSTRING(str)->len] = '\0'; - + str = rb_str_new(key2.dptr, key2.dsize); OBJ_TAINT(str); return str; } @@ -297,9 +284,9 @@ fgdbm_index(VALUE obj, VALUE valstr) valstr2 = rb_gdbm_fetch2(dbm, keystr); if (!NIL_P(valstr2) && - RSTRING(valstr)->len == RSTRING(valstr2)->len && - memcmp(RSTRING(valstr)->ptr, RSTRING(valstr2)->ptr, - RSTRING(valstr)->len) == 0) { + RSTRING_LEN(valstr) == RSTRING_LEN(valstr2) && + memcmp(RSTRING_PTR(valstr), RSTRING_PTR(valstr2), + RSTRING_LEN(valstr)) == 0) { return keystr; } } @@ -358,8 +345,8 @@ rb_gdbm_delete(VALUE obj, VALUE keystr) rb_gdbm_modify(obj); StringValue(keystr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); GetDBM2(obj, dbmp, dbm); if (!gdbm_exists(dbm, key)) { @@ -501,11 +488,11 @@ fgdbm_store(VALUE obj, VALUE keystr, VALUE valstr) StringValue(keystr); StringValue(valstr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); - val.dptr = RSTRING(valstr)->ptr; - val.dsize = RSTRING(valstr)->len; + val.dptr = RSTRING_PTR(valstr); + val.dsize = RSTRING_LEN(valstr); GetDBM2(obj, dbmp, dbm); dbmp->di_size = -1; @@ -685,8 +672,8 @@ fgdbm_has_key(VALUE obj, VALUE keystr) GDBM_FILE dbm; StringValue(keystr); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; + key.dptr = RSTRING_PTR(keystr); + key.dsize = RSTRING_LEN(keystr); GetDBM2(obj, dbmp, dbm); if (gdbm_exists(dbm, key)) @@ -709,9 +696,9 @@ fgdbm_has_value(VALUE obj, VALUE valstr) valstr2 = rb_gdbm_fetch2(dbm, keystr); if (!NIL_P(valstr2) && - RSTRING(valstr)->len == RSTRING(valstr2)->len && - memcmp(RSTRING(valstr)->ptr, RSTRING(valstr2)->ptr, - RSTRING(valstr)->len) == 0) { + RSTRING_LEN(valstr) == RSTRING_LEN(valstr2) && + memcmp(RSTRING_PTR(valstr), RSTRING_PTR(valstr2), + RSTRING_LEN(valstr)) == 0) { return Qtrue; } } diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 767896ed57..0c89c2ab17 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -167,13 +167,13 @@ iconv_create(VALUE to, VALUE from, struct rb_iconv_opt_t *opt) if (cd == (iconv_t)-1) { int inval = errno == EINVAL; const char *s = inval ? "invalid encoding " : "iconv"; - volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING(to)->len + - RSTRING(from)->len + 8); + volatile VALUE msg = rb_str_new(0, strlen(s) + RSTRING_LEN(to) + + RSTRING_LEN(from) + 8); - sprintf(RSTRING(msg)->ptr, "%s(\"%s\", \"%s\")", - s, RSTRING(to)->ptr, RSTRING(from)->ptr); - s = RSTRING(msg)->ptr; - RSTRING(msg)->len = strlen(s); + sprintf(RSTRING_PTR(msg), "%s(\"%s\", \"%s\")", + s, RSTRING_PTR(to), RSTRING_PTR(from)); + s = RSTRING_PTR(msg); + rb_str_set_len(msg, strlen(s)); if (!inval) rb_sys_fail(s); iconv_fail(rb_eIconvInvalidEncoding, Qnil, rb_ary_new3(2, to, from), NULL, s); @@ -284,7 +284,7 @@ iconv_fail(VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, co if (mesg && *mesg) { args[0] = rb_str_new2(mesg); } - else if (TYPE(failed) != T_STRING || RSTRING(failed)->len < FAILED_MAXLEN) { + else if (TYPE(failed) != T_STRING || RSTRING_LEN(failed) < FAILED_MAXLEN) { args[0] = rb_inspect(failed); } else { @@ -313,10 +313,10 @@ rb_str_derive(VALUE str, const char* ptr, int len) if (NIL_P(str)) return rb_str_new(ptr, len); - if (RSTRING(str)->ptr == ptr && RSTRING(str)->len == len) + if (RSTRING_PTR(str) == ptr && RSTRING_LEN(str) == len) return str; - if (RSTRING(str)->ptr + RSTRING(str)->len == ptr + len) - ret = rb_str_substr(str, ptr - RSTRING(str)->ptr, len); + if (RSTRING_PTR(str) + RSTRING_LEN(str) == ptr + len) + ret = rb_str_substr(str, ptr - RSTRING_PTR(str), len); else ret = rb_str_new(ptr, len); OBJ_INFECT(ret, str); @@ -368,8 +368,8 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* int slen; StringValue(str); - slen = RSTRING(str)->len; - inptr = RSTRING(str)->ptr; + slen = RSTRING_LEN(str); + inptr = RSTRING_PTR(str); if (start < 0 ? (start += slen) < 0 : start >= slen) length = 0; @@ -438,8 +438,8 @@ iconv_convert(iconv_t cd, VALUE str, int start, int length, struct iconv_env_t* rb_str_concat(ret, RARRAY(rescue)->ptr[0]); if (len > 1 && !NIL_P(str = RARRAY(rescue)->ptr[1])) { StringValue(str); - inlen = length = RSTRING(str)->len; - instart = inptr = RSTRING(str)->ptr; + inlen = length = RSTRING_LEN(str); + instart = inptr = RSTRING_PTR(str); continue; } } @@ -602,7 +602,7 @@ iconv_s_convert(struct iconv_env_t* env) if (!NIL_P(last)) { VALUE s = iconv_convert(env->cd, Qnil, 0, 0, env); - if (RSTRING(s)->len) + if (RSTRING_LEN(s)) env->append(env->ret, s); } @@ -816,13 +816,13 @@ iconv_conv(int argc, VALUE *argv, VALUE self) if (argc > 0) { do { s = iconv_convert(cd, *argv++, 0, -1, NULL); - if (RSTRING(s)->len) + if (RSTRING_LEN(s)) rb_str_buf_append(str, s); else str = s; } while (--argc); s = iconv_convert(cd, Qnil, 0, 0, NULL); - if (RSTRING(s)->len) + if (RSTRING_LEN(s)) rb_str_buf_append(str, s); else str = s; diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c index 723fa55b03..8a4bcfce64 100644 --- a/ext/nkf/nkf.c +++ b/ext/nkf/nkf.c @@ -62,7 +62,7 @@ rb_nkf_putchar(unsigned int c) o_len += incsize; rb_str_resize(result, o_len); incsize *= 2; - output = RSTRING(result)->ptr; + output = RSTRING_PTR(result); } output[output_ctr++] = c; @@ -147,30 +147,29 @@ rb_nkf_kconv(VALUE obj, VALUE opt, VALUE src) reinit(); StringValue(opt); - opt_ptr = RSTRING(opt)->ptr; - opt_end = opt_ptr + RSTRING(opt)->len; + opt_ptr = RSTRING_PTR(opt); + opt_end = opt_ptr + RSTRING_LEN(opt); nkf_split_options(opt_ptr); incsize = INCSIZE; input_ctr = 0; StringValue(src); - input = RSTRING(src)->ptr; - i_len = RSTRING(src)->len; + input = RSTRING_PTR(src); + i_len = RSTRING_LEN(src); result = rb_str_new(0, i_len*3 + 10); v = result; output_ctr = 0; - output = RSTRING(result)->ptr; - o_len = RSTRING(result)->len; + output = RSTRING_PTR(result); + o_len = RSTRING_LEN(result); *output = '\0'; if(x0201_f == WISH_TRUE) x0201_f = ((!iso2022jp_f)? TRUE : NO_X0201); kanji_convert(NULL); - RSTRING(result)->ptr[output_ctr] = '\0'; - RSTRING(result)->len = output_ctr; + rb_str_set_len(result, output_ctr); OBJ_INFECT(result, src); return result; @@ -209,8 +208,8 @@ rb_nkf_guess1(VALUE obj, VALUE src) int sequence_counter = 0; StringValue(src); - p = RSTRING(src)->ptr; - pend = p + RSTRING(src)->len; + p = RSTRING_PTR(src); + pend = p + RSTRING_LEN(src); if (p == pend) return INT2FIX(_UNKNOWN); #define INCR do {\ @@ -323,8 +322,8 @@ rb_nkf_guess2(VALUE obj, VALUE src) input_ctr = 0; StringValue(src); - input = RSTRING(src)->ptr; - i_len = RSTRING(src)->len; + input = RSTRING_PTR(src); + i_len = RSTRING_LEN(src); if(x0201_f == WISH_TRUE) x0201_f = ((!iso2022jp_f)? TRUE : NO_X0201); diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c index a98f2641cc..4000e8fc58 100644 --- a/ext/openssl/ossl.c +++ b/ext/openssl/ossl.c @@ -131,7 +131,7 @@ ossl_buf2str(char *buf, int len) int status = 0; str = rb_protect((VALUE(*)_((VALUE)))ossl_str_new, len, &status); - if(!NIL_P(str)) memcpy(RSTRING(str)->ptr, buf, len); + if(!NIL_P(str)) memcpy(RSTRING_PTR(str), buf, len); OPENSSL_free(buf); if(status) rb_jump_tag(status); @@ -170,7 +170,7 @@ ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd) rflag = flag ? Qtrue : Qfalse; pass = rb_protect(ossl_pem_passwd_cb0, rflag, &status); if (status) return -1; /* exception was raised. */ - len = RSTRING(pass)->len; + len = RSTRING_LEN(pass); if (len < 4) { /* 4 is OpenSSL hardcoded limit */ rb_warning("password must be longer than 4 bytes"); continue; @@ -179,7 +179,7 @@ ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd) rb_warning("password must be shorter then %d bytes", max_len-1); continue; } - memcpy(buf, RSTRING(pass)->ptr, len); + memcpy(buf, RSTRING_PTR(pass), len); break; } return len; diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h index 0366901a35..3be563005c 100644 --- a/ext/openssl/ossl.h +++ b/ext/openssl/ossl.h @@ -118,11 +118,10 @@ VALUE ossl_x509crl_sk2ary(STACK_OF(X509_CRL) *crl); VALUE ossl_buf2str(char *buf, int len); #define ossl_str_adjust(str, p) \ do{\ - int len = RSTRING(str)->len;\ - int newlen = (p) - (unsigned char*)RSTRING(str)->ptr;\ + int len = RSTRING_LEN(str);\ + int newlen = (p) - (unsigned char*)RSTRING_PTR(str);\ assert(newlen <= len);\ - RSTRING(str)->len = newlen;\ - RSTRING(str)->ptr[newlen] = 0;\ + rb_str_set_len(str, newlen);\ }while(0) /* diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c index c60cbc12a1..fe8a1e0c35 100644 --- a/ext/openssl/ossl_asn1.c +++ b/ext/openssl/ossl_asn1.c @@ -214,7 +214,7 @@ obj_to_asn1bstr(VALUE obj, long unused_bits) StringValue(obj); if(!(bstr = ASN1_BIT_STRING_new())) ossl_raise(eASN1Error, NULL); - ASN1_BIT_STRING_set(bstr, RSTRING(obj)->ptr, RSTRING(obj)->len); + ASN1_BIT_STRING_set(bstr, RSTRING_PTR(obj), RSTRING_LEN(obj)); bstr->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */ bstr->flags |= ASN1_STRING_FLAG_BITS_LEFT|(unused_bits&0x07); @@ -229,7 +229,7 @@ obj_to_asn1str(VALUE obj) StringValue(obj); if(!(str = ASN1_STRING_new())) ossl_raise(eASN1Error, NULL); - ASN1_STRING_set(str, RSTRING(obj)->ptr, RSTRING(obj)->len); + ASN1_STRING_set(str, RSTRING_PTR(obj), RSTRING_LEN(obj)); return str; } @@ -253,8 +253,8 @@ obj_to_asn1obj(VALUE obj) ASN1_OBJECT *a1obj; StringValue(obj); - a1obj = OBJ_txt2obj(RSTRING(obj)->ptr, 0); - if(!a1obj) a1obj = OBJ_txt2obj(RSTRING(obj)->ptr, 1); + a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 0); + if(!a1obj) a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 1); if(!a1obj) ossl_raise(eASN1Error, "invalid OBJECT ID"); return a1obj; @@ -295,7 +295,7 @@ obj_to_asn1derstr(VALUE obj) str = ossl_to_der(obj); if(!(a1str = ASN1_STRING_new())) ossl_raise(eASN1Error, NULL); - ASN1_STRING_set(a1str, RSTRING(str)->ptr, RSTRING(str)->len); + ASN1_STRING_set(a1str, RSTRING_PTR(str), RSTRING_LEN(str)); return a1str; } @@ -699,13 +699,13 @@ ossl_asn1data_to_der(VALUE self) tag = ossl_asn1_tag(self); tag_class = ossl_asn1_tag_class(self); - if((length = ASN1_object_size(1, RSTRING(value)->len, tag)) <= 0) + if((length = ASN1_object_size(1, RSTRING_LEN(value), tag)) <= 0) ossl_raise(eASN1Error, NULL); der = rb_str_new(0, length); - p = RSTRING(der)->ptr; - ASN1_put_object(&p, is_cons, RSTRING(value)->len, tag, tag_class); - memcpy(p, RSTRING(value)->ptr, RSTRING(value)->len); - p += RSTRING(value)->len; + p = RSTRING_PTR(der); + ASN1_put_object(&p, is_cons, RSTRING_LEN(value), tag, tag_class); + memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value)); + p += RSTRING_LEN(value); ossl_str_adjust(der, p); return der; @@ -824,8 +824,8 @@ ossl_asn1_traverse(VALUE self, VALUE obj) obj = ossl_to_der_if_possible(obj); tmp = rb_str_new4(StringValue(obj)); - p = RSTRING(tmp)->ptr; - ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 0, 1); + p = RSTRING_PTR(tmp); + ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 0, 1); return Qnil; } @@ -840,8 +840,8 @@ ossl_asn1_decode(VALUE self, VALUE obj) obj = ossl_to_der_if_possible(obj); tmp = rb_str_new4(StringValue(obj)); - p = RSTRING(tmp)->ptr; - ary = ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 1, 0); + p = RSTRING_PTR(tmp); + ary = ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 1, 0); ret = rb_ary_entry(ary, 0); return ret; @@ -857,8 +857,8 @@ ossl_asn1_decode_all(VALUE self, VALUE obj) obj = ossl_to_der_if_possible(obj); tmp = rb_str_new4(StringValue(obj)); - p = RSTRING(tmp)->ptr; - ret = ossl_asn1_decode0(&p, RSTRING(tmp)->len, &offset, 0, 0, 0); + p = RSTRING_PTR(tmp); + ret = ossl_asn1_decode0(&p, RSTRING_LEN(tmp), &offset, 0, 0, 0); return ret; } @@ -973,21 +973,21 @@ ossl_asn1cons_to_der(VALUE self) explicit = ossl_asn1_is_explicit(self); value = join_der(ossl_asn1_get_value(self)); - seq_len = ASN1_object_size(1, RSTRING(value)->len, tag); + seq_len = ASN1_object_size(1, RSTRING_LEN(value), tag); length = ASN1_object_size(1, seq_len, tn); str = rb_str_new(0, length); - p = RSTRING(str)->ptr; + p = RSTRING_PTR(str); if(tc == V_ASN1_UNIVERSAL) - ASN1_put_object(&p, 1, RSTRING(value)->len, tn, tc); + ASN1_put_object(&p, 1, RSTRING_LEN(value), tn, tc); else{ if(explicit){ ASN1_put_object(&p, 1, seq_len, tn, tc); - ASN1_put_object(&p, 1, RSTRING(value)->len, tag, V_ASN1_UNIVERSAL); + ASN1_put_object(&p, 1, RSTRING_LEN(value), tag, V_ASN1_UNIVERSAL); } - else ASN1_put_object(&p, 1, RSTRING(value)->len, tn, tc); + else ASN1_put_object(&p, 1, RSTRING_LEN(value), tn, tc); } - memcpy(p, RSTRING(value)->ptr, RSTRING(value)->len); - p += RSTRING(value)->len; + memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value)); + p += RSTRING_LEN(value); ossl_str_adjust(str, p); return str; @@ -1007,7 +1007,7 @@ ossl_asn1obj_s_register(VALUE self, VALUE oid, VALUE sn, VALUE ln) StringValue(sn); StringValue(ln); - if(!OBJ_create(RSTRING(oid)->ptr, RSTRING(sn)->ptr, RSTRING(ln)->ptr)) + if(!OBJ_create(RSTRING_PTR(oid), RSTRING_PTR(sn), RSTRING_PTR(ln))) ossl_raise(eASN1Error, NULL); return Qtrue; diff --git a/ext/openssl/ossl_bio.c b/ext/openssl/ossl_bio.c index 9f22c97919..aa0b99fe8c 100644 --- a/ |