1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ruby.h (struct RString): embed small strings.

(RSTRING_LEN): defined for accessing string members.
  (RSTRING_PTR): ditto.

* string.c: use RSTRING_LEN and RSTRING_PTR.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10809 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-08-31 10:30:33 +00:00
parent 22f249ebd7
commit 25c50cd193
43 changed files with 484 additions and 512 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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?

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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)
/*

View file

@ -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;

View file

@ -39,7 +39,7 @@ ossl_obj2bio(VALUE obj)
}
else {
StringValue(obj);
bio = BIO_new_mem_buf(RSTRING(obj)->ptr, RSTRING(obj)->len);
bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LEN(obj));
if (!bio) ossl_raise(eOSSLError, NULL);
}

View file

@ -124,22 +124,22 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
switch (base) {
case 0:
if (!BN_mpi2bn(RSTRING(str)->ptr, RSTRING(str)->len, bn)) {
if (!BN_mpi2bn(RSTRING_PTR(str), RSTRING_LEN(str), bn)) {
ossl_raise(eBNError, NULL);
}
break;
case 2:
if (!BN_bin2bn(RSTRING(str)->ptr, RSTRING(str)->len, bn)) {
if (!BN_bin2bn(RSTRING_PTR(str), RSTRING_LEN(str), bn)) {
ossl_raise(eBNError, NULL);
}
break;
case 10:
if (!BN_dec2bn(&bn, RSTRING(str)->ptr)) {
if (!BN_dec2bn(&bn, RSTRING_PTR(str))) {
ossl_raise(eBNError, NULL);
}
break;
case 16:
if (!BN_hex2bn(&bn, RSTRING(str)->ptr)) {
if (!BN_hex2bn(&bn, RSTRING_PTR(str))) {
ossl_raise(eBNError, NULL);
}
break;
@ -165,13 +165,13 @@ ossl_bn_to_s(int argc, VALUE *argv, VALUE self)
case 0:
len = BN_bn2mpi(bn, NULL);
str = rb_str_new(0, len);
if (BN_bn2mpi(bn, RSTRING(str)->ptr) != len)
if (BN_bn2mpi(bn, RSTRING_PTR(str)) != len)
ossl_raise(eBNError, NULL);
break;
case 2:
len = BN_num_bytes(bn);
str = rb_str_new(0, len);
if (BN_bn2bin(bn, RSTRING(str)->ptr) != len)
if (BN_bn2bin(bn, RSTRING_PTR(str)) != len)
ossl_raise(eBNError, NULL);
break;
case 10:

View file

@ -176,14 +176,14 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
if (NIL_P(init_v)) memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
else{
StringValue(init_v);
if (EVP_MAX_IV_LENGTH > RSTRING(init_v)->len) {
if (EVP_MAX_IV_LENGTH > RSTRING_LEN(init_v)) {
memset(iv, 0, EVP_MAX_IV_LENGTH);
memcpy(iv, RSTRING(init_v)->ptr, RSTRING(init_v)->len);
memcpy(iv, RSTRING_PTR(init_v), RSTRING_LEN(init_v));
}
else memcpy(iv, RSTRING(init_v)->ptr, sizeof(iv));
else memcpy(iv, RSTRING_PTR(init_v), sizeof(iv));
}
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), EVP_md5(), iv,
RSTRING(pass)->ptr, RSTRING(pass)->len, 1, key, NULL);
RSTRING_PTR(pass), RSTRING_LEN(pass), 1, key, NULL);
p_key = key;
p_iv = iv;
}
@ -222,15 +222,15 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
StringValue(vpass);
if(!NIL_P(vsalt)){
StringValue(vsalt);
if(RSTRING(vsalt)->len != PKCS5_SALT_LEN)
if(RSTRING_LEN(vsalt) != PKCS5_SALT_LEN)
rb_raise(eCipherError, "salt must be an 8-octet string");
salt = RSTRING(vsalt)->ptr;
salt = RSTRING_PTR(vsalt);
}
iter = NIL_P(viter) ? 2048 : NUM2INT(viter);
digest = NIL_P(vdigest) ? EVP_md5() : GetDigestPtr(vdigest);
GetCipher(self, ctx);
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt,
RSTRING(vpass)->ptr, RSTRING(vpass)->len, iter, key, iv);
RSTRING_PTR(vpass), RSTRING_LEN(vpass), iter, key, iv);
if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, -1) != 1)
ossl_raise(eCipherError, NULL);
OPENSSL_cleanse(key, sizeof key);
@ -248,16 +248,15 @@ ossl_cipher_update(VALUE self, VALUE data)
VALUE str;
StringValue(data);
in = RSTRING(data)->ptr;
if ((in_len = RSTRING(data)->len) == 0)
in = RSTRING_PTR(data);
if ((in_len = RSTRING_LEN(data)) == 0)
rb_raise(rb_eArgError, "data must not be empty");
GetCipher(self, ctx);
str = rb_str_new(0, in_len+EVP_CIPHER_CTX_block_size(ctx));
if (!EVP_CipherUpdate(ctx, RSTRING(str)->ptr, &out_len, in, in_len))
if (!EVP_CipherUpdate(ctx, RSTRING_PTR(str), &out_len, in, in_len))
ossl_raise(eCipherError, NULL);
assert(out_len < RSTRING(str)->len);
RSTRING(str)->len = out_len;
RSTRING(str)->ptr[out_len] = 0;
assert(out_len < RSTRING_LEN(str));
rb_str_set_len(str, out_len);
return str;
}
@ -271,11 +270,10 @@ ossl_cipher_final(VALUE self)
GetCipher(self, ctx);
str = rb_str_new(0, EVP_CIPHER_CTX_block_size(ctx));
if (!EVP_CipherFinal_ex(ctx, RSTRING(str)->ptr, &out_len))
if (!EVP_CipherFinal_ex(ctx, RSTRING_PTR(str), &out_len))
ossl_raise(eCipherError, NULL);
assert(out_len <= RSTRING(str)->len);
RSTRING(str)->len = out_len;
RSTRING(str)->ptr[out_len] = 0;
assert(out_len <= RSTRING_LEN(str));
rb_str_set_len(str, out_len);
return str;
}
@ -298,10 +296,10 @@ ossl_cipher_set_key(VALUE self, VALUE key)
StringValue(key);
GetCipher(self, ctx);
if (RSTRING(key)->len < EVP_CIPHER_CTX_key_length(ctx))
if (RSTRING_LEN(key) < EVP_CIPHER_CTX_key_length(ctx))
ossl_raise(eCipherError, "key length too short");
if (EVP_CipherInit_ex(ctx, NULL, NULL, RSTRING(key)->ptr, NULL, -1) != 1)
if (EVP_CipherInit_ex(ctx, NULL, NULL, RSTRING_PTR(key), NULL, -1) != 1)
ossl_raise(eCipherError, NULL);
return key;
@ -315,10 +313,10 @@ ossl_cipher_set_iv(VALUE self, VALUE iv)
StringValue(iv);
GetCipher(self, ctx);
if (RSTRING(iv)->len < EVP_CIPHER_CTX_iv_length(ctx))
if (RSTRING_LEN(iv) < EVP_CIPHER_CTX_iv_length(ctx))
ossl_raise(eCipherError, "iv length too short");
if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, RSTRING(iv)->ptr, -1) != 1)
if (EVP_CipherInit_ex(ctx, NULL, NULL, NULL, RSTRING_PTR(iv), -1) != 1)
ossl_raise(eCipherError, NULL);
return iv;

View file

@ -171,16 +171,16 @@ ossl_config_add_value(VALUE self, VALUE section, VALUE name, VALUE value)
StringValue(name);
StringValue(value);
GetConfig(self, conf);
if(!(sv = _CONF_get_section(conf, RSTRING(section)->ptr))){
if(!(sv = _CONF_new_section(conf, RSTRING(section)->ptr))){
if(!(sv = _CONF_get_section(conf, RSTRING_PTR(section)))){
if(!(sv = _CONF_new_section(conf, RSTRING_PTR(section)))){
ossl_raise(eConfigError, NULL);
}
}
if(!(cv = OPENSSL_malloc(sizeof(CONF_VALUE)))){
ossl_raise(eConfigError, NULL);
}
cv->name = BUF_strdup(RSTRING(name)->ptr);
cv->value = BUF_strdup(RSTRING(value)->ptr);
cv->name = BUF_strdup(RSTRING_PTR(name));
cv->value = BUF_strdup(RSTRING_PTR(value));
if(!cv->name || !cv->value || !_CONF_add_string(conf, sv, cv)){
OPENSSL_free(cv->name);
OPENSSL_free(cv->value);
@ -201,7 +201,7 @@ ossl_config_get_value(VALUE self, VALUE section, VALUE name)
StringValue(section);
StringValue(name);
GetConfig(self, conf);
str = NCONF_get_string(conf, RSTRING(section)->ptr, RSTRING(name)->ptr);
str = NCONF_get_string(conf, RSTRING_PTR(section), RSTRING_PTR(name));
if(!str){
ERR_clear_error();
return Qnil;

View file

@ -136,7 +136,7 @@ ossl_digest_update(VALUE self, VALUE data)
StringValue(data);
GetDigest(self, ctx);
EVP_DigestUpdate(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
EVP_DigestUpdate(ctx, RSTRING_PTR(data), RSTRING_LEN(data));
return self;
}
@ -225,12 +225,12 @@ ossl_digest_equal(VALUE self, VALUE other)
str2 = other;
}
GetDigest(self, ctx);
if (RSTRING(str2)->len == EVP_MD_CTX_size(ctx)) {
if (RSTRING_LEN(str2) == EVP_MD_CTX_size(ctx)) {
str1 = ossl_digest_digest(self);
} else {
str1 = ossl_digest_hexdigest(self);
}
if (RSTRING(str1)->len == RSTRING(str2)->len
if (RSTRING_LEN(str1) == RSTRING_LEN(str2)
&& rb_str_cmp(str1, str2) == 0) {
return Qtrue;
}

View file

@ -40,7 +40,7 @@ VALUE eEngineError;
*/
#define OSSL_ENGINE_LOAD_IF_MATCH(x) \
do{\
if(!strcmp(#x, RSTRING(name)->ptr)){\
if(!strcmp(#x, RSTRING_PTR(name))){\
ENGINE_load_##x();\
return Qtrue;\
}\
@ -75,7 +75,7 @@ ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto);
#endif
OSSL_ENGINE_LOAD_IF_MATCH(openssl);
rb_warning("no such builtin loader for `%s'", RSTRING(name)->ptr);
rb_warning("no such builtin loader for `%s'", RSTRING_PTR(name));
return Qnil;
#endif /* HAVE_ENGINE_LOAD_BUILTIN_ENGINES */
}
@ -112,7 +112,7 @@ ossl_engine_s_by_id(VALUE klass, VALUE id)
StringValue(id);
ossl_engine_s_load(1, &id, klass);
if(!(e = ENGINE_by_id(RSTRING(id)->ptr)))
if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
ossl_raise(eEngineError, NULL);
WrapEngine(klass, obj, e);
if(rb_block_given_p()) rb_yield(obj);
@ -281,8 +281,8 @@ ossl_engine_ctrl_cmd(int argc, VALUE *argv, VALUE self)
rb_scan_args(argc, argv, "11", &cmd, &val);
StringValue(cmd);
if (!NIL_P(val)) StringValue(val);
ret = ENGINE_ctrl_cmd_string(e, RSTRING(cmd)->ptr,
NIL_P(val) ? NULL : RSTRING(val)->ptr, 0);
ret = ENGINE_ctrl_cmd_string(e, RSTRING_PTR(cmd),
NIL_P(val) ? NULL : RSTRING_PTR(val), 0);
if (!ret) ossl_raise(eEngineError, NULL);
return self;

View file

@ -64,7 +64,7 @@ ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
StringValue(key);
GetHMAC(self, ctx);
HMAC_Init_ex(ctx, RSTRING(key)->ptr, RSTRING(key)->len,
HMAC_Init_ex(ctx, RSTRING_PTR(key), RSTRING_LEN(key),
GetDigestPtr(digest), NULL);
return self;
@ -94,7 +94,7 @@ ossl_hmac_update(VALUE self, VALUE data)
StringValue(data);
GetHMAC(self, ctx);
HMAC_Update(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
HMAC_Update(ctx, RSTRING_PTR(data), RSTRING_LEN(data));
return self;
}
@ -159,8 +159,8 @@ ossl_hmac_s_digest(VALUE klass, VALUE digest, VALUE key, VALUE data)
StringValue(key);
StringValue(data);
buf = HMAC(GetDigestPtr(digest), RSTRING(key)->ptr, RSTRING(key)->len,
RSTRING(data)->ptr, RSTRING(data)->len, NULL, &buf_len);
buf = HMAC(GetDigestPtr(digest), RSTRING_PTR(key), RSTRING_LEN(key),
RSTRING_PTR(data), RSTRING_LEN(data), NULL, &buf_len);
return rb_str_new(buf, buf_len);
}
@ -175,8 +175,8 @@ ossl_hmac_s_hexdigest(VALUE klass, VALUE digest, VALUE key, VALUE data)
StringValue(key);
StringValue(data);
buf = HMAC(GetDigestPtr(digest), RSTRING(key)->ptr, RSTRING(key)->len,
RSTRING(data)->ptr, RSTRING(data)->len, NULL, &buf_len);
buf = HMAC(GetDigestPtr(digest), RSTRING_PTR(key), RSTRING_LEN(key),
RSTRING_PTR(data), RSTRING_LEN(data), NULL, &buf_len);
if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * buf_len) {
ossl_raise(eHMACError, "Cannot convert buf to hexbuf");
}

View file

@ -62,9 +62,9 @@ ossl_spki_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
StringValue(buffer);
if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING(buffer)->ptr, -1))) {
p = RSTRING(buffer)->ptr;
if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING(buffer)->len))) {
if (!(spki = NETSCAPE_SPKI_b64_decode(RSTRING_PTR(buffer), -1))) {
p = RSTRING_PTR(buffer);
if (!(spki = d2i_NETSCAPE_SPKI(NULL, &p, RSTRING_LEN(buffer)))) {
ossl_raise(eSPKIError, NULL);
}
}
@ -86,7 +86,7 @@ ossl_spki_to_der(VALUE self)
if ((len = i2d_NETSCAPE_SPKI(spki, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if (i2d_NETSCAPE_SPKI(spki, &p) <= 0)
ossl_raise(eX509CertError, NULL);
ossl_str_adjust(str, p);
@ -182,8 +182,8 @@ ossl_spki_set_challenge(VALUE self, VALUE str)
StringValue(str);
GetSPKI(self, spki);
if (!ASN1_STRING_set(spki->spkac->challenge, RSTRING(str)->ptr,
RSTRING(str)->len)) {
if (!ASN1_STRING_set(spki->spkac->challenge, RSTRING_PTR(str),
RSTRING_LEN(str))) {
ossl_raise(eSPKIError, NULL);
}

View file

@ -109,9 +109,9 @@ ossl_ocspreq_initialize(int argc, VALUE *argv, VALUE self)
if(!NIL_P(arg)){
arg = ossl_to_der_if_possible(arg);
StringValue(arg);
p = (unsigned char*)RSTRING(arg)->ptr;
p = (unsigned char*)RSTRING_PTR(arg);
if(!d2i_OCSP_REQUEST((OCSP_REQUEST**)&DATA_PTR(self), &p,
RSTRING(arg)->len)){
RSTRING_LEN(arg))){
ossl_raise(eOCSPError, "cannot load DER encoded request");
}
}
@ -134,7 +134,7 @@ ossl_ocspreq_add_nonce(int argc, VALUE *argv, VALUE self)
else{
StringValue(val);
GetOCSPReq(self, req);
ret = OCSP_request_add1_nonce(req, RSTRING(val)->ptr, RSTRING(val)->len);
ret = OCSP_request_add1_nonce(req, RSTRING_PTR(val), RSTRING_LEN(val));
}
if(!ret) ossl_raise(eOCSPError, NULL);
@ -265,7 +265,7 @@ ossl_ocspreq_to_der(VALUE self)
if((len = i2d_OCSP_REQUEST(req, NULL)) <= 0)
ossl_raise(eOCSPError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_OCSP_REQUEST(req, &p) <= 0)
ossl_raise(eOCSPError, NULL);
ossl_str_adjust(str, p);
@ -316,9 +316,9 @@ ossl_ocspres_initialize(int argc, VALUE *argv, VALUE self)
if(!NIL_P(arg)){
arg = ossl_to_der_if_possible(arg);
StringValue(arg);
p = RSTRING(arg)->ptr;
p = RSTRING_PTR(arg);
if(!d2i_OCSP_RESPONSE((OCSP_RESPONSE**)&DATA_PTR(self), &p,
RSTRING(arg)->len)){
RSTRING_LEN(arg))){
ossl_raise(eOCSPError, "cannot load DER encoded response");
}
}
@ -377,7 +377,7 @@ ossl_ocspres_to_der(VALUE self)
if((len = i2d_OCSP_RESPONSE(res, NULL)) <= 0)
ossl_raise(eOCSPError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_OCSP_RESPONSE(res, NULL) <= 0)
ossl_raise(eOCSPError, NULL);
ossl_str_adjust(str, p);
@ -436,7 +436,7 @@ ossl_ocspbres_add_nonce(int argc, VALUE *argv, VALUE self)
else{
StringValue(val);
GetOCSPBasicRes(self, bs);
ret = OCSP_basic_add1_nonce(bs, RSTRING(val)->ptr, RSTRING(val)->len);
ret = OCSP_basic_add1_nonce(bs, RSTRING_PTR(val), RSTRING_LEN(val));
}
if(!ret) ossl_raise(eOCSPError, NULL);

View file

@ -129,7 +129,7 @@ ossl_pkcs12_to_der(VALUE self)
if((len = i2d_PKCS12(p12, NULL)) <= 0)
ossl_raise(ePKCS12Error, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_PKCS12(p12, &p) <= 0)
ossl_raise(ePKCS12Error, NULL);
ossl_str_adjust(str, p);

View file

@ -749,7 +749,7 @@ ossl_pkcs7_to_der(VALUE self)
if((len = i2d_PKCS7(pkcs7, NULL)) <= 0)
ossl_raise(ePKCS7Error, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_PKCS7(pkcs7, &p) <= 0)
ossl_raise(ePKCS7Error, NULL);
ossl_str_adjust(str, p);

View file

@ -68,7 +68,7 @@ ossl_pkey_new_from_file(VALUE filename)
EVP_PKEY *pkey;
SafeStringValue(filename);
if (!(fp = fopen(RSTRING(filename)->ptr, "r"))) {
if (!(fp = fopen(RSTRING_PTR(filename), "r"))) {
ossl_raise(ePKeyError, "%s", strerror(errno));
}
@ -169,13 +169,12 @@ ossl_pkey_sign(VALUE self, VALUE digest, VALUE data)
GetPKey(self, pkey);
EVP_SignInit(&ctx, GetDigestPtr(digest));
StringValue(data);
EVP_SignUpdate(&ctx, RSTRING(data)->ptr, RSTRING(data)->len);
EVP_SignUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data));
str = rb_str_new(0, EVP_PKEY_size(pkey)+16);
if (!EVP_SignFinal(&ctx, RSTRING(str)->ptr, &buf_len, pkey))
if (!EVP_SignFinal(&ctx, RSTRING_PTR(str), &buf_len, pkey))
ossl_raise(ePKeyError, NULL);
assert(buf_len <= RSTRING(str)->len);
RSTRING(str)->len = buf_len;
RSTRING(str)->ptr[buf_len] = 0;
assert(buf_len <= RSTRING_LEN(str));
rb_str_set_len(str, buf_len);
return str;
}
@ -190,8 +189,8 @@ ossl_pkey_verify(VALUE self, VALUE digest, VALUE sig, VALUE data)
EVP_VerifyInit(&ctx, GetDigestPtr(digest));
StringValue(sig);
StringValue(data);
EVP_VerifyUpdate(&ctx, RSTRING(data)->ptr, RSTRING(data)->len);
switch (EVP_VerifyFinal(&ctx, RSTRING(sig)->ptr, RSTRING(sig)->len, pkey)) {
EVP_VerifyUpdate(&ctx, RSTRING_PTR(data), RSTRING_LEN(data));
switch (EVP_VerifyFinal(&ctx, RSTRING_PTR(sig), RSTRING_LEN(sig), pkey)) {
case 0:
return Qfalse;
case 1:

View file

@ -213,7 +213,7 @@ ossl_dh_to_der(VALUE self)
if((len = i2d_DHparams(pkey->pkey.dh, NULL)) <= 0)
ossl_raise(eDHError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_DHparams(pkey->pkey.dh, &p) < 0)
ossl_raise(eDHError, NULL);
ossl_str_adjust(str, p);
@ -335,11 +335,10 @@ ossl_dh_compute_key(VALUE self, VALUE pub)
pub_key = GetBNPtr(pub);
len = DH_size(dh);
str = rb_str_new(0, len);
if ((len = DH_compute_key(RSTRING(str)->ptr, pub_key, dh)) < 0) {
if ((len = DH_compute_key(RSTRING_PTR(str), pub_key, dh)) < 0) {
ossl_raise(eDHError, NULL);
}
RSTRING(str)->len = len;
RSTRING(str)->ptr[len] = 0;
rb_str_set_len(str, len);
return str;
}

View file

@ -241,7 +241,7 @@ ossl_dsa_to_der(VALUE self)
if((len = i2d_func(pkey->pkey.dsa, NULL)) <= 0)
ossl_raise(eDSAError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_func(pkey->pkey.dsa, &p) < 0)
ossl_raise(eDSAError, NULL);
ossl_str_adjust(str, p);
@ -334,12 +334,11 @@ ossl_dsa_sign(VALUE self, VALUE data)
ossl_raise(eDSAError, "Private DSA key needed!");
}
str = rb_str_new(0, ossl_dsa_buf_size(pkey));
if (!DSA_sign(0, RSTRING(data)->ptr, RSTRING(data)->len, RSTRING(str)->ptr,
if (!DSA_sign(0, RSTRING_PTR(data), RSTRING_LEN(data), RSTRING_PTR(str),
&buf_len, pkey->pkey.dsa)) { /* type is ignored (0) */
ossl_raise(eDSAError, NULL);
}
RSTRING(str)->len = buf_len;
RSTRING(str)->ptr[buf_len] = 0;
rb_str_set_len(str, buf_len);
return str;
}
@ -354,8 +353,8 @@ ossl_dsa_verify(VALUE self, VALUE digest, VALUE sig)
StringValue(digest);
StringValue(sig);
/* type is ignored (0) */
ret = DSA_verify(0, RSTRING(digest)->ptr, RSTRING(digest)->len,
RSTRING(sig)->ptr, RSTRING(sig)->len, pkey->pkey.dsa);
ret = DSA_verify(0, RSTRING_PTR(digest), RSTRING_LEN(digest),
RSTRING_PTR(sig), RSTRING_LEN(sig), pkey->pkey.dsa);
if (ret < 0) {
ossl_raise(eDSAError, NULL);
}

View file

@ -236,7 +236,7 @@ ossl_rsa_to_der(VALUE self)
if((len = i2d_func(pkey->pkey.rsa, NULL)) <= 0)
ossl_raise(eRSAError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_func(pkey->pkey.rsa, &p) < 0)
ossl_raise(eRSAError, NULL);
ossl_str_adjust(str, p);
@ -258,12 +258,11 @@ ossl_rsa_public_encrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
buf_len = RSA_public_encrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
RSTRING(str)->ptr, pkey->pkey.rsa,
buf_len = RSA_public_encrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
RSTRING_PTR(str), pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
RSTRING(str)->len = buf_len;
RSTRING(str)->ptr[buf_len] = 0;
rb_str_set_len(str, buf_len);
return str;
}
@ -280,12 +279,11 @@ ossl_rsa_public_decrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
buf_len = RSA_public_decrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
RSTRING(str)->ptr, pkey->pkey.rsa,
buf_len = RSA_public_decrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
RSTRING_PTR(str), pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
RSTRING(str)->len = buf_len;
RSTRING(str)->ptr[buf_len] = 0;
rb_str_set_len(str, buf_len);
return str;
}
@ -305,12 +303,11 @@ ossl_rsa_private_encrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
buf_len = RSA_private_encrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
RSTRING(str)->ptr, pkey->pkey.rsa,
buf_len = RSA_private_encrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
RSTRING_PTR(str), pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
RSTRING(str)->len = buf_len;
RSTRING(str)->ptr[buf_len] = 0;
rb_str_set_len(str, buf_len);
return str;
}
@ -330,12 +327,11 @@ ossl_rsa_private_decrypt(int argc, VALUE *argv, VALUE self)
pad = (argc == 1) ? RSA_PKCS1_PADDING : NUM2INT(padding);
StringValue(buffer);
str = rb_str_new(0, ossl_rsa_buf_size(pkey));
buf_len = RSA_private_decrypt(RSTRING(buffer)->len, RSTRING(buffer)->ptr,
RSTRING(str)->ptr, pkey->pkey.rsa,
buf_len = RSA_private_decrypt(RSTRING_LEN(buffer), RSTRING_PTR(buffer),
RSTRING_PTR(str), pkey->pkey.rsa,
pad);
if (buf_len < 0) ossl_raise(eRSAError, NULL);
RSTRING(str)->len = buf_len;
RSTRING(str)->ptr[buf_len] = 0;
rb_str_set_len(str, buf_len);
return str;
}

View file

@ -31,7 +31,7 @@ static VALUE
ossl_rand_seed(VALUE self, VALUE str)
{
StringValue(str);
RAND_seed(RSTRING(str)->ptr, RSTRING(str)->len);
RAND_seed(RSTRING_PTR(str), RSTRING_LEN(str));
return str;
}
@ -41,7 +41,7 @@ ossl_rand_load_file(VALUE self, VALUE filename)
{
SafeStringValue(filename);
if(!RAND_load_file(RSTRING(filename)->ptr, -1)) {
if(!RAND_load_file(RSTRING_PTR(filename), -1)) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@ -51,7 +51,7 @@ static VALUE
ossl_rand_write_file(VALUE self, VALUE filename)
{
SafeStringValue(filename);
if (RAND_write_file(RSTRING(filename)->ptr) == -1) {
if (RAND_write_file(RSTRING_PTR(filename)) == -1) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@ -63,7 +63,7 @@ ossl_rand_bytes(VALUE self, VALUE len)
VALUE str;
str = rb_str_new(0, FIX2INT(len));
if (!RAND_bytes(RSTRING(str)->ptr, FIX2INT(len))) {
if (!RAND_bytes(RSTRING_PTR(str), FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
@ -76,7 +76,7 @@ ossl_rand_pseudo_bytes(VALUE self, VALUE len)
VALUE str;
str = rb_str_new(0, FIX2INT(len));
if (!RAND_pseudo_bytes(RSTRING(str)->ptr, FIX2INT(len))) {
if (!RAND_pseudo_bytes(RSTRING_PTR(str), FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
@ -88,7 +88,7 @@ ossl_rand_egd(VALUE self, VALUE filename)
{
SafeStringValue(filename);
if(!RAND_egd(RSTRING(filename)->ptr)) {
if(!RAND_egd(RSTRING_PTR(filename))) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@ -99,7 +99,7 @@ ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
{
SafeStringValue(filename);
if (!RAND_egd_bytes(RSTRING(filename)->ptr, FIX2INT(len))) {
if (!RAND_egd_bytes(RSTRING_PTR(filename), FIX2INT(len))) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;

View file

@ -394,8 +394,8 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_sess_id_ctx(self);
if (!NIL_P(val)){
StringValue(val);
if (!SSL_CTX_set_session_id_context(ctx, RSTRING(val)->ptr,
RSTRING(val)->len)){
if (!SSL_CTX_set_session_id_context(ctx, RSTRING_PTR(val),
RSTRING_LEN(val))){
ossl_raise(eSSLError, "SSL_CTX_set_session_id_context:");
}
}
@ -476,7 +476,7 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
ossl_raise(eSSLError, "SSL_CTX is not initialized.");
return Qnil;
}
if (!SSL_CTX_set_cipher_list(ctx, RSTRING(str)->ptr)) {
if (!SSL_CTX_set_cipher_list(ctx, RSTRING_PTR(str))) {
ossl_raise(eSSLError, "SSL_CTX_set_cipher_list:");
}
@ -635,7 +635,7 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
if(SSL_pending(ssl) <= 0)
rb_thread_wait_fd(fptr->fd);
for (;;){
nread = SSL_read(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
nread = SSL_read(ssl, RSTRING_PTR(str), RSTRING_LEN(str));
switch(ssl_get_error(ssl, nread)){
case SSL_ERROR_NONE:
goto end;
@ -662,8 +662,7 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
}
end:
RSTRING(str)->len = nread;
RSTRING(str)->ptr[nread] = 0;
rb_str_set_len(str, nread);
OBJ_TAINT(str);
return str;
@ -682,7 +681,7 @@ ossl_ssl_write(VALUE self, VALUE str)
if (ssl) {
for (;;){
nwrite = SSL_write(ssl, RSTRING(str)->ptr, RSTRING(str)->len);
nwrite = SSL_write(ssl, RSTRING_PTR(str), RSTRING_LEN(str));
switch(ssl_get_error(ssl, nwrite)){
case SSL_ERROR_NONE:
goto end;

View file

@ -95,9 +95,9 @@ ossl_x509attr_initialize(int argc, VALUE *argv, VALUE self)
if(rb_scan_args(argc, argv, "11", &oid, &value) == 1){
oid = ossl_to_der_if_possible(oid);
StringValue(oid);
p = RSTRING(oid)->ptr;
p = RSTRING_PTR(oid);
if(!d2i_X509_ATTRIBUTE((X509_ATTRIBUTE**)&DATA_PTR(self),
&p, RSTRING(oid)->len)){
&p, RSTRING_LEN(oid))){
ossl_raise(eX509AttrError, NULL);
}
return self;
@ -192,7 +192,7 @@ ossl_x509attr_get_value(VALUE self)
if(OSSL_X509ATTR_IS_SINGLE(attr)){
length = i2d_ASN1_TYPE(attr->value.single, NULL);
str = rb_str_new(0, length);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
i2d_ASN1_TYPE(attr->value.single, &p);
ossl_str_adjust(str, p);
}
@ -200,7 +200,7 @@ ossl_x509attr_get_value(VALUE self)
length = i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, NULL,
i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0);
str = rb_str_new(0, length);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, &p,
i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0);
ossl_str_adjust(str, p);
@ -222,10 +222,10 @@ ossl_x509attr_to_der(VALUE self)
if((len = i2d_X509_ATTRIBUTE(attr, NULL)) <= 0)
ossl_raise(eX509AttrError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_X509_ATTRIBUTE(attr, &p) <= 0)
ossl_raise(eX509AttrError, NULL);
RSTRING(str)->len = p - (unsigned char*)RSTRING(str)->ptr;
rb_str_set_len(str, p - (unsigned char*)RSTRING_PTR(str));
return str;
}

View file

@ -63,7 +63,7 @@ ossl_x509_new_from_file(VALUE filename)
VALUE obj;
SafeStringValue(filename);
if (!(fp = fopen(RSTRING(filename)->ptr, "r"))) {
if (!(fp = fopen(RSTRING_PTR(filename), "r"))) {
ossl_raise(eX509CertError, "%s", strerror(errno));
}
x509 = PEM_read_X509(fp, NULL, NULL, NULL);
@ -181,7 +181,7 @@ ossl_x509_to_der(VALUE self)
if ((len = i2d_X509(x509, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if (i2d_X509(x509, &p) <= 0)
ossl_raise(eX509CertError, NULL);
ossl_str_adjust(str, p);

View file

@ -229,23 +229,23 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
StringValue(value);
if(NIL_P(critical)) critical = Qfalse;
nid = OBJ_ln2nid(RSTRING(oid)->ptr);
if(!nid) nid = OBJ_sn2nid(RSTRING(oid)->ptr);
if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING(oid)->ptr);
nid = OBJ_ln2nid(RSTRING_PTR(oid));
if(!nid) nid = OBJ_sn2nid(RSTRING_PTR(oid));
if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING_PTR(oid));
valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
rb_str_append(valstr, value);
GetX509ExtFactory(self, ctx);
#ifdef HAVE_X509V3_EXT_NCONF_NID
rconf = rb_iv_get(self, "@config");
conf = NIL_P(rconf) ? NULL : GetConfigPtr(rconf);
ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING(valstr)->ptr);
ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));
#else
if (!empty_lhash) empty_lhash = lh_new(NULL, NULL);
ext = X509V3_EXT_conf_nid(empty_lhash, ctx, nid, RSTRING(valstr)->ptr);
#endif
if (!ext){
ossl_raise(eX509ExtError, "%s = %s",
RSTRING(oid)->ptr, RSTRING(value)->ptr);
RSTRING_PTR(oid), RSTRING_PTR(value));
}
WrapX509Ext(cX509Ext, obj, ext);
@ -280,9 +280,9 @@ ossl_x509ext_initialize(int argc, VALUE *argv, VALUE self)
if(rb_scan_args(argc, argv, "12", &oid, &value, &critical) == 1){
oid = ossl_to_der_if_possible(oid);
StringValue(oid);
p = RSTRING(oid)->ptr;
p = RSTRING_PTR(oid);
if(!d2i_X509_EXTENSION((X509_EXTENSION**)&DATA_PTR(self),
&p, RSTRING(oid)->len))
&p, RSTRING_LEN(oid)))
ossl_raise(eX509ExtError, NULL);
return self;
}
@ -319,14 +319,14 @@ ossl_x509ext_set_value(VALUE self, VALUE data)
data = ossl_to_der_if_possible(data);
StringValue(data);
if(!(s = OPENSSL_malloc(RSTRING(data)->len)))
if(!(s = OPENSSL_malloc(RSTRING_LEN(data))))
ossl_raise(eX509ExtError, "malloc error");
memcpy(s, RSTRING(data)->ptr, RSTRING(data)->len);
memcpy(s, RSTRING_PTR(data), RSTRING_LEN(data));
if(!(asn1s = ASN1_OCTET_STRING_new())){
free(s);
ossl_raise(eX509ExtError, NULL);
}
if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING(data)->len)){
if(!M_ASN1_OCTET_STRING_set(asn1s, s, RSTRING_LEN(data))){
free(s);
ASN1_OCTET_STRING_free(asn1s);
ossl_raise(eX509ExtError, NULL);
@ -409,7 +409,7 @@ ossl_x509ext_to_der(VALUE obj)
if((len = i2d_X509_EXTENSION(ext, NULL)) <= 0)
ossl_raise(eX509ExtError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_X509_EXTENSION(ext, &p) < 0)
ossl_raise(eX509ExtError, NULL);
ossl_str_adjust(str, p);

View file

@ -131,8 +131,8 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
unsigned char *p;
VALUE str = ossl_to_der_if_possible(arg);
StringValue(str);
p = RSTRING(str)->ptr;
if(!d2i_X509_NAME((X509_NAME**)&DATA_PTR(self), &p, RSTRING(str)->len)){
p = RSTRING_PTR(str);
if(!d2i_X509_NAME((X509_NAME**)&DATA_PTR(self), &p, RSTRING_LEN(str))){
ossl_raise(eX509NameError, NULL);
}
}
@ -152,8 +152,8 @@ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
StringValue(value);
if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
GetX509Name(self, name);
if (!X509_NAME_add_entry_by_txt(name, RSTRING(oid)->ptr, NUM2INT(type),
RSTRING(value)->ptr, RSTRING(value)->len, -1, 0)) {
if (!X509_NAME_add_entry_by_txt(name, RSTRING_PTR(oid), NUM2INT(type),
RSTRING_PTR(value), RSTRING_LEN(value), -1, 0)) {
ossl_raise(eX509NameError, NULL);
}
@ -291,7 +291,7 @@ ossl_x509name_to_der(VALUE self)
if((len = i2d_X509_NAME(name, NULL)) <= 0)
ossl_raise(eX509NameError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if(i2d_X509_NAME(name, &p) <= 0)
ossl_raise(eX509NameError, NULL);
ossl_str_adjust(str, p);

View file

@ -171,7 +171,7 @@ ossl_x509req_to_der(VALUE self)
if ((len = i2d_X509_REQ(req, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
str = rb_str_new(0, len);
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
if (i2d_X509_REQ(req, &p) <= 0)
ossl_raise(eX509ReqError, NULL);
ossl_str_adjust(str, p);

View file

@ -206,7 +206,7 @@ ossl_x509store_add_file(VALUE self, VALUE file)
if(file != Qnil){
Check_SafeStr(file);
path = RSTRING(file)->ptr;
path = RSTRING_PTR(file);
}
GetX509Store(self, store);
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
@ -227,7 +227,7 @@ ossl_x509store_add_path(VALUE self, VALUE dir)
if(dir != Qnil){
Check_SafeStr(dir);
path = RSTRING(dir)->ptr;
path = RSTRING_PTR(dir);
}
GetX509Store(self, store);
lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());

View file

@ -65,7 +65,7 @@ readline_readline(int argc, VALUE *argv, VALUE self)
rb_secure(4);
if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
SafeStringValue(tmp);
prompt = RSTRING(tmp)->ptr;
prompt = RSTRING_PTR(tmp);
}
if (!isatty(0) && errno == EBADF) rb_raise(rb_eIOError, "stdin closed");
@ -176,8 +176,8 @@ readline_attempted_completion_function(const char *text, int start, int end)
result = ALLOC_N(char *, matches + 2);
for (i = 0; i < matches; i++) {
temp = rb_obj_as_string(RARRAY(ary)->ptr[i]);
result[i + 1] = ALLOC_N(char, RSTRING(temp)->len + 1);
strcpy(result[i + 1], RSTRING(temp)->ptr);
result[i + 1] = ALLOC_N(char, RSTRING_LEN(temp) + 1);
strcpy(result[i + 1], RSTRING_PTR(temp));
}
result[matches + 1] = NULL;
@ -252,10 +252,10 @@ readline_s_set_completion_append_character(VALUE self, VALUE str)
}
else {
SafeStringValue(str);
if (RSTRING(str)->len == 0) {
if (RSTRING_LEN(str) == 0) {
rl_completion_append_character = '\0';
} else {
rl_completion_append_character = RSTRING(str)->ptr[0];
rl_completion_append_character = RSTRING_PTR(str)[0];
}
}
return self;
@ -276,7 +276,7 @@ readline_s_get_completion_append_character(VALUE self)
return Qnil;
str = rb_str_new("", 1);
RSTRING(str)->ptr[0] = rl_completion_append_character;
RSTRING_PTR(str)[0] = rl_completion_append_character;
return str;
#else
rb_notimplement();
@ -294,14 +294,14 @@ readline_s_set_basic_word_break_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (basic_word_break_characters == NULL) {
basic_word_break_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(basic_word_break_characters, char, RSTRING(str)->len + 1);
REALLOC_N(basic_word_break_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(basic_word_break_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
basic_word_break_characters[RSTRING(str)->len] = '\0';
RSTRING_PTR(str), RSTRING_LEN(str));
basic_word_break_characters[RSTRING_LEN(str)] = '\0';
rl_basic_word_break_characters = basic_word_break_characters;
return self;
#else
@ -334,14 +334,14 @@ readline_s_set_completer_word_break_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (completer_word_break_characters == NULL) {
completer_word_break_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(completer_word_break_characters, char, RSTRING(str)->len + 1);
REALLOC_N(completer_word_break_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(completer_word_break_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
completer_word_break_characters[RSTRING(str)->len] = '\0';
RSTRING_PTR(str), RSTRING_LEN(str));
completer_word_break_characters[RSTRING_LEN(str)] = '\0';
rl_completer_word_break_characters = completer_word_break_characters;
return self;
#else
@ -374,14 +374,14 @@ readline_s_set_basic_quote_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (basic_quote_characters == NULL) {
basic_quote_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(basic_quote_characters, char, RSTRING(str)->len + 1);
REALLOC_N(basic_quote_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(basic_quote_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
basic_quote_characters[RSTRING(str)->len] = '\0';
RSTRING_PTR(str), RSTRING_LEN(str));
basic_quote_characters[RSTRING_LEN(str)] = '\0';
rl_basic_quote_characters = basic_quote_characters;
return self;
@ -415,14 +415,13 @@ readline_s_set_completer_quote_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (completer_quote_characters == NULL) {
completer_quote_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(completer_quote_characters, char, RSTRING(str)->len + 1);
REALLOC_N(completer_quote_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(completer_quote_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
completer_quote_characters[RSTRING(str)->len] = '\0';
strncpy(completer_quote_characters, RSTRING_PTR(str), RSTRING_LEN(str));
completer_quote_characters[RSTRING_LEN(str)] = '\0';
rl_completer_quote_characters = completer_quote_characters;
return self;
@ -456,14 +455,13 @@ readline_s_set_filename_quote_characters(VALUE self, VALUE str)
SafeStringValue(str);
if (filename_quote_characters == NULL) {
filename_quote_characters =
ALLOC_N(char, RSTRING(str)->len + 1);
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(filename_quote_characters, char, RSTRING(str)->len + 1);
REALLOC_N(filename_quote_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(filename_quote_characters,
RSTRING(str)->ptr, RSTRING(str)->len);
filename_quote_characters[RSTRING(str)->len] = '\0';
strncpy(filename_quote_characters, RSTRING_PTR(str), RSTRING_LEN(str));
filename_quote_characters[RSTRING_LEN(str)] = '\0';
rl_filename_quote_characters = filename_quote_characters;
return self;
@ -524,7 +522,7 @@ hist_set(VALUE self, VALUE index, VALUE str)
if (i < 0) {
i += history_length;
}
entry = replace_history_entry(i, RSTRING(str)->ptr, NULL);
entry = replace_history_entry(i, RSTRING_PTR(str), NULL);
if (entry == NULL) {
rb_raise(rb_eIndexError, "invalid index");
}
@ -540,7 +538,7 @@ hist_push(VALUE self, VALUE str)
{
rb_secure(4);
SafeStringValue(str);
add_history(RSTRING(str)->ptr);
add_history(RSTRING_PTR(str));
return self;
}
@ -553,7 +551,7 @@ hist_push_method(int argc, VALUE *argv, VALUE self)
while (argc--) {
str = *argv++;
SafeStringValue(str);
add_history(RSTRING(str)->ptr);
add_history(RSTRING_PTR(str));
}
return self;
}

View file

@ -101,15 +101,15 @@ fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
dbm = 0;
if (mode >= 0)
dbm = sdbm_open(RSTRING(file)->ptr, O_RDWR|O_CREAT, mode);
dbm = sdbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT, mode);
if (!dbm)
dbm = sdbm_open(RSTRING(file)->ptr, O_RDWR, 0);
dbm = sdbm_open(RSTRING_PTR(file), O_RDWR, 0);
if (!dbm)
dbm = sdbm_open(RSTRING(file)->ptr, O_RDONLY, 0);
dbm = sdbm_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);
@ -144,8 +144,8 @@ fsdbm_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 = sdbm_fetch(dbm, key);
@ -184,14 +184,14 @@ fsdbm_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 = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_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);
}
return Qnil;
@ -251,8 +251,8 @@ fsdbm_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);
dbmp->di_size = -1;
@ -326,8 +326,8 @@ fsdbm_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 (sdbm_delete(dbm, key)) {
rb_raise(rb_eDBMError, "sdbm_delete failed");
}
@ -393,11 +393,11 @@ fsdbm_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;
@ -574,8 +574,8 @@ fsdbm_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 = sdbm_fetch(dbm, key);
@ -591,14 +591,14 @@ fsdbm_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 = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
val = sdbm_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;

View file

@ -359,8 +359,8 @@ bsock_setsockopt(VALUE sock, VALUE lev, VALUE optname, VALUE val)
break;
default:
StringValue(val);
v = RSTRING(val)->ptr;
vlen = RSTRING(val)->len;
v = RSTRING_PTR(val);
vlen = RSTRING_LEN(val);
break;
}
@ -480,13 +480,13 @@ bsock_send(int argc, VALUE *argv, VALUE sock)
retry:
if (!NIL_P(to)) {
TRAP_BEG;
n = sendto(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
(struct sockaddr*)RSTRING(to)->ptr, RSTRING(to)->len);
n = sendto(fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg), NUM2INT(flags),
(struct sockaddr*)RSTRING_PTR(to), RSTRING_LEN(to));
TRAP_END;
}
else {
TRAP_BEG;
n = send(fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags));
n = send(fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg), NUM2INT(flags));
TRAP_END;
}
if (n < 0) {
@ -564,11 +564,11 @@ s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
retry:
rb_thread_wait_fd(fd);
rb_io_check_closed(fptr);
if (RSTRING(str)->len != buflen) {
if (RSTRING_LEN(str) != buflen) {
rb_raise(rb_eRuntimeError, "buffer string modified");
}
TRAP_BEG;
slen = recvfrom(fd, RSTRING(str)->ptr, buflen, flags, (struct sockaddr*)buf, &alen);
slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)buf, &alen);
TRAP_END;
if (slen < 0) {
@ -577,9 +577,8 @@ s_recvfrom(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
}
rb_sys_fail("recvfrom(2)");
}
if (slen < RSTRING(str)->len) {
RSTRING(str)->len = slen;
RSTRING(str)->ptr[slen] = '\0';
if (slen < RSTRING_LEN(str)) {
rb_str_set_len(str, slen);
}
rb_obj_taint(str);
switch (from) {
@ -642,14 +641,13 @@ s_recvfrom_nonblock(VALUE sock, int argc, VALUE *argv, enum sock_recv_type from)
rb_io_check_closed(fptr);
rb_io_set_nonblock(fptr);
slen = recvfrom(fd, RSTRING(str)->ptr, buflen, flags, (struct sockaddr*)buf, &alen);
slen = recvfrom(fd, RSTRING_PTR(str), buflen, flags, (struct sockaddr*)buf, &alen);
if (slen < 0) {
rb_sys_fail("recvfrom(2)");
}
if (slen < RSTRING(str)->len) {
RSTRING(str)->len = slen;
RSTRING(str)->ptr[slen] = '\0';
if (slen < RSTRING_LEN(str)) {
rb_str_set_len(str, slen);
}
rb_obj_taint(str);
switch (from) {
@ -807,7 +805,7 @@ host_str(VALUE host, char *hbuf, size_t len)
char *name;
SafeStringValue(host);
name = RSTRING(host)->ptr;
name = RSTRING_PTR(host);
if (!name || *name == 0 || (name[0] == '<' && strcmp(name, "<any>") == 0)) {
make_inetaddr(INADDR_ANY, hbuf, len);
}
@ -838,7 +836,7 @@ port_str(VALUE port, char *pbuf, size_t len)
char *serv;
SafeStringValue(port);
serv = RSTRING(port)->ptr;
serv = RSTRING_PTR(port);
if (strlen(serv) >= len) {
rb_raise(rb_eArgError, "service name too long (%d)", strlen(serv));
}
@ -1560,7 +1558,7 @@ init_unixsock(VALUE sock, VALUE path, int server)
MEMZERO(&sockaddr, struct sockaddr_un, 1);
sockaddr.sun_family = AF_UNIX;
if (sizeof(sockaddr.sun_path) <= RSTRING(path)->len) {
if (sizeof(sockaddr.sun_path) <= RSTRING_LEN(path)) {
rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
(int)sizeof(sockaddr.sun_path)-1);
}
@ -1592,7 +1590,7 @@ init_unixsock(VALUE sock, VALUE path, int server)
init_sock(sock, fd);
GetOpenFile(sock, fptr);
if (server) {
fptr->path = strdup(RSTRING(path)->ptr);
fptr->path = strdup(RSTRING_PTR(path));
}
return sock;
@ -1742,7 +1740,7 @@ udp_send(int argc, VALUE *argv, VALUE sock)
GetOpenFile(sock, fptr);
for (res = res0; res; res = res->ai_next) {
retry:
n = sendto(fptr->fd, RSTRING(mesg)->ptr, RSTRING(mesg)->len, NUM2INT(flags),
n = sendto(fptr->fd, RSTRING_PTR(mesg), RSTRING_LEN(mesg), NUM2INT(flags),
res->ai_addr, res->ai_addrlen);
if (n >= 0) {
freeaddrinfo(res0);
@ -2143,7 +2141,7 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
if (!NIL_P(tmp)) {
domain = tmp;
rb_check_safe_obj(domain);
ptr = RSTRING(domain)->ptr;
ptr = RSTRING_PTR(domain);
if (strcmp(ptr, "AF_INET") == 0)
*dv = AF_INET;
#ifdef AF_UNIX
@ -2194,7 +2192,7 @@ setup_domain_and_type(VALUE domain, int *dv, VALUE type, int *tv)
if (!NIL_P(tmp)) {
type = tmp;
rb_check_safe_obj(type);
ptr = RSTRING(type)->ptr;
ptr = RSTRING_PTR(type);
if (strcmp(ptr, "SOCK_STREAM") == 0)
*tv = SOCK_STREAM;
else if (strcmp(ptr, "SOCK_DGRAM") == 0)
@ -2400,7 +2398,7 @@ sock_connect(VALUE sock, VALUE addr)
addr = rb_str_new4(addr);
GetOpenFile(sock, fptr);
fd = fptr->fd;
n = ruby_connect(fd, (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len, 0);
n = ruby_connect(fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr), 0);
if (n < 0) {
rb_sys_fail("connect(2)");
}
@ -2456,7 +2454,7 @@ sock_connect_nonblock(VALUE sock, VALUE addr)
addr = rb_str_new4(addr);
GetOpenFile(sock, fptr);
rb_io_set_nonblock(fptr);
n = connect(fptr->fd, (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len);
n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr));
if (n < 0) {
rb_sys_fail("connect(2)");
}
@ -2550,7 +2548,7 @@ sock_bind(VALUE sock, VALUE addr)
StringValue(addr);
GetOpenFile(sock, fptr);
if (bind(fptr->fd, (struct sockaddr*)RSTRING(addr)->ptr, RSTRING(addr)->len) < 0)
if (bind(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LEN(addr)) < 0)
rb_sys_fail("bind(2)");
return INT2FIX(0);
@ -3049,11 +3047,11 @@ sock_s_gethostbyaddr(int argc, VALUE *argv)
t = NUM2INT(type);
}
#ifdef INET6
else if (RSTRING(addr)->len == 16) {
else if (RSTRING_LEN(addr) == 16) {
t = AF_INET6;
}
#endif
h = gethostbyaddr(RSTRING(addr)->ptr, RSTRING(addr)->len, t);
h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_LEN(addr), t);
if (h == NULL) {
#ifdef HAVE_HSTRERROR
extern int h_errno;
@ -3100,12 +3098,12 @@ sock_s_getservbyname(int argc, VALUE *argv)
port = ntohs(sp->s_port);
}
else {
char *s = RSTRING(service)->ptr;
char *s = RSTRING_PTR(service);
char *end;
port = strtoul(s, &end, 0);
if (*end != '\0') {
rb_raise(rb_eSocket, "no such service %s/%s", s, RSTRING(proto)->ptr);
rb_raise(rb_eSocket, "no such service %s/%s", s, RSTRING_PTR(proto));
}
}
return INT2FIX(port);
@ -3123,7 +3121,7 @@ sock_s_getservbyport(int argc, VALUE *argv)
sp = getservbyport(NUM2INT(port), StringValueCStr(proto));
if (!sp) {
rb_raise(rb_eSocket, "no such service for port %d/%s", NUM2INT(port), RSTRING(proto)->ptr);
rb_raise(rb_eSocket, "no such service for port %d/%s", NUM2INT(port), RSTRING_PTR(proto));
}
return rb_tainted_str_new2(sp->s_name);
}
@ -3220,11 +3218,11 @@ sock_s_getnameinfo(int argc, VALUE *argv)
tmp = rb_check_string_type(sa);
if (!NIL_P(tmp)) {
sa = tmp;
if (sizeof(ss) < RSTRING(sa)->len) {
if (sizeof(ss) < RSTRING_LEN(sa)) {
rb_raise(rb_eTypeError, "sockaddr length too big");
}
memcpy(&ss, RSTRING(sa)->ptr, RSTRING(sa)->len);
if (RSTRING(sa)->len != SA_LEN((struct sockaddr*)&ss)) {
memcpy(&ss, RSTRING_PTR(sa), RSTRING_LEN(sa));
if (RSTRING_LEN(sa) != SA_LEN((struct sockaddr*)&ss)) {
rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
}
sap = (struct sockaddr*)&ss;
@ -3408,14 +3406,14 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
if (((struct sockaddr *)sockaddr)->sa_family != AF_UNIX) {
rb_raise(rb_eArgError, "not an AF_UNIX sockaddr");
}
if (sizeof(struct sockaddr_un) < RSTRING(addr)->len) {
if (sizeof(struct sockaddr_un) < RSTRING_LEN(addr)) {
rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
RSTRING(addr)->len, sizeof(struct sockaddr_un));
RSTRING_LEN(addr), sizeof(struct sockaddr_un));
}
sun_path = unixpath(sockaddr, RSTRING(addr)->len);
if (sizeof(struct sockaddr_un) == RSTRING(addr)->len &&
sun_path = unixpath(sockaddr, RSTRING_LEN(addr));
if (sizeof(struct sockaddr_un) == RSTRING_LEN(addr) &&
sun_path == sockaddr->sun_path &&
sun_path + strlen(sun_path) == RSTRING(addr)->ptr + RSTRING(addr)->len) {
sun_path + strlen(sun_path) == RSTRING_PTR(addr) + RSTRING_LEN(addr)) {
rb_raise(rb_eArgError, "sockaddr_un.sun_path not NUL terminated");
}
path = rb_str_new2(sun_path);

View file

@ -452,7 +452,7 @@ static VALUE
strio_eof(VALUE self)
{
struct StringIO *ptr = readable(StringIO(self));
if (ptr->pos < RSTRING(ptr->string)->len) return Qfalse;
if (ptr->pos < RSTRING_LEN(ptr->string)) return Qfalse;
return Qtrue;
}
@ -604,7 +604,7 @@ strio_seek(int argc, VALUE *argv, VALUE self)
offset += ptr->pos;
break;
case 2:
offset += RSTRING(ptr->string)->len;
offset += RSTRING_LEN(ptr->string);
break;
default:
rb_raise(rb_eArgError, "invalid whence %ld", NUM2LONG(whence));
@ -644,8 +644,8 @@ static VALUE
strio_each_byte(VALUE self)
{
struct StringIO *ptr = readable(StringIO(self));
while (ptr->pos < RSTRING(ptr->string)->len) {
char c = RSTRING(ptr->string)->ptr[ptr->pos++];
while (ptr->pos < RSTRING_LEN(ptr->string)) {
char c = RSTRING_PTR(ptr->string)[ptr->pos++];
rb_yield(CHR2FIX(c));
}
return Qnil;
@ -662,10 +662,10 @@ strio_getc(VALUE self)
{
struct StringIO *ptr = readable(StringIO(self));
int c;
if (ptr->pos >= RSTRING(ptr->string)->len) {
if (ptr->pos >= RSTRING_LEN(ptr->string)) {
return Qnil;
}
c = RSTRING(ptr->string)->ptr[ptr->pos++];
c = RSTRING_PTR(ptr->string)[ptr->pos++];
return CHR2FIX(c);
}
@ -675,11 +675,11 @@ strio_extend(struct StringIO *ptr, long pos, long len)
long olen;
check_modifiable(ptr);
olen = RSTRING(ptr->string)->len;
olen = RSTRING_LEN(ptr->string);
if (pos + len > olen) {
rb_str_resize(ptr->string, pos + len);
if (pos > olen)
MEMZERO(RSTRING(ptr->string)->ptr + olen, char, pos - olen);
MEMZERO(RSTRING_PTR(ptr->string) + olen, char, pos - olen);
}
else {
rb_str_modify(ptr->string);
@ -704,11 +704,11 @@ strio_ungetc(VALUE self, VALUE ch)
long len, pos = ptr->pos;
if (cc != EOF && pos > 0) {
if ((len = RSTRING(ptr->string)->len) < pos-- ||
(unsigned char)RSTRING(ptr->string)->ptr[pos] !=
if ((len = RSTRING_LEN(ptr->string)) < pos-- ||
(unsigned char)RSTRING_PTR(ptr->string)[pos] !=
(unsigned char)cc) {
strio_extend(ptr, pos, 1);
RSTRING(ptr->string)->ptr[pos] = cc;
RSTRING_PTR(ptr->string)[pos] = cc;
OBJ_INFECT(ptr->string, self);
}
--ptr->pos;
@ -777,16 +777,16 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
if (!NIL_P(str)) StringValue(str);
}
if (ptr->pos >= (n = RSTRING(ptr->string)->len)) {
if (ptr->pos >= (n = RSTRING_LEN(ptr->string))) {
return Qnil;
}
s = RSTRING(ptr->string)->ptr;
e = s + RSTRING(ptr->string)->len;
s = RSTRING_PTR(ptr->string);
e = s + RSTRING_LEN(ptr->string);
s += ptr->pos;
if (NIL_P(str)) {
str = rb_str_substr(ptr->string, ptr->pos, e - s);
}
else if ((n = RSTRING(str)->len) == 0) {
else if ((n = RSTRING_LEN(str)) == 0) {
p = s;
while (*p == '\n') {
if (++p == e) {
@ -800,10 +800,10 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
break;
}
}
str = rb_str_substr(ptr->string, s - RSTRING(ptr->string)->ptr, e - s);
str = rb_str_substr(ptr->string, s - RSTRING_PTR(ptr->string), e - s);
}
else if (n == 1) {
if ((p = memchr(s, RSTRING(str)->ptr[0], e - s)) != 0) {
if ((p = memchr(s, RSTRING_PTR(str)[0], e - s)) != 0) {
e = p + 1;
}
str = rb_str_substr(ptr->string, ptr->pos, e - s);
@ -812,7 +812,7 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
if (n < e - s) {
if (e - s < 1024) {
for (p = s; p + n <= e; ++p) {
if (MEMCMP(p, RSTRING(str)->ptr, char, n) == 0) {
if (MEMCMP(p, RSTRING_PTR(str), char, n) == 0) {
e = p + n;
break;
}
@ -820,7 +820,7 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
}
else {
long skip[1 << CHAR_BIT], pos;
p = RSTRING(str)->ptr;
p = RSTRING_PTR(str);
bm_init_skip(skip, p, n);
if ((pos = bm_search(p, n, s, e - s, skip)) >= 0) {
e = s + pos + n;
@ -829,7 +829,7 @@ strio_getline(int argc, VALUE *argv, struct StringIO *ptr)
}
str = rb_str_substr(ptr->string, ptr->pos, e - s);
}
ptr->pos = e - RSTRING(ptr->string)->ptr;
ptr->pos = e - RSTRING_PTR(ptr->string);
ptr->lineno++;
return str;
}
@ -917,15 +917,15 @@ strio_write(VALUE self, VALUE str)
if (TYPE(str) != T_STRING)
str = rb_obj_as_string(str);
len = RSTRING(str)->len;
len = RSTRING_LEN(str);
if (!len) return INT2FIX(0);
check_modifiable(ptr);
olen = RSTRING(ptr->string)->len;
olen = RSTRING_LEN(ptr->string);
if (ptr->flags & FMODE_APPEND) {
ptr->pos = olen;
}
if (ptr->pos == olen) {
rb_str_cat(ptr->string, RSTRING(str)->ptr, len);
rb_str_cat(ptr->string, RSTRING_PTR(str), len);
}
else {
strio_extend(ptr, ptr->pos, len);
@ -975,12 +975,12 @@ strio_putc(VALUE self, VALUE ch)
long olen;
check_modifiable(ptr);
olen = RSTRING(ptr->string)->len;
olen = RSTRING_LEN(ptr->string);
if (ptr->flags & FMODE_APPEND) {
ptr->pos = olen;
}
strio_extend(ptr, ptr->pos, 1);
RSTRING(ptr->string)->ptr[ptr->pos++] = c;
RSTRING_PTR(ptr->string)[ptr->pos++] = c;
OBJ_INFECT(ptr->string, self);
return ch;
}
@ -1017,7 +1017,7 @@ strio_read(int argc, VALUE *argv, VALUE self)
if (len < 0) {
rb_raise(rb_eArgError, "negative length %ld given", len);
}
if (len > 0 && ptr->pos >= RSTRING(ptr->string)->len) {
if (len > 0 && ptr->pos >= RSTRING_LEN(ptr->string)) {
if (!NIL_P(str)) rb_str_resize(str, 0);
return Qnil;
}
@ -1026,7 +1026,7 @@ strio_read(int argc, VALUE *argv, VALUE self)
/* fall through */
case 0:
olen = -1;
len = RSTRING(ptr->string)->len;
len = RSTRING_LEN(ptr->string);
if (len <= ptr->pos) {
if (NIL_P(str)) {
str = rb_str_new(0, 0);
@ -1047,17 +1047,17 @@ strio_read(int argc, VALUE *argv, VALUE self)
str = rb_str_substr(ptr->string, ptr->pos, len);
}
else {
long rest = RSTRING(ptr->string)->len - ptr->pos;
long rest = RSTRING_LEN(ptr->string) - ptr->pos;
if (len > rest) len = rest;
rb_str_resize(str, len);
MEMCPY(RSTRING(str)->ptr, RSTRING(ptr->string)->ptr + ptr->pos, char, len);
MEMCPY(RSTRING_PTR(str), RSTRING_PTR(ptr->string) + ptr->pos, char, len);
}
if (NIL_P(str)) {
str = rb_str_new(0, 0);
len = 0;
}
else {
ptr->pos += len = RSTRING(str)->len;
ptr->pos += len = RSTRING_LEN(str);
}
return str;
}
@ -1073,7 +1073,7 @@ static VALUE
strio_sysread(int argc, VALUE *argv, VALUE self)
{
VALUE val = strio_read(argc, argv, self);
if (NIL_P(val) || RSTRING(val)->len == 0) {
if (NIL_P(val) || RSTRING_LEN(val) == 0) {
rb_eof_error();
}
return val;
@ -1111,7 +1111,7 @@ strio_size(VALUE self)
if (NIL_P(string)) {
rb_raise(rb_eIOError, "not opened");
}
return ULONG2NUM(RSTRING(string)->len);
return ULONG2NUM(RSTRING_LEN(string));
}
/*
@ -1126,13 +1126,13 @@ strio_truncate(VALUE self, VALUE len)
{
VALUE string = writable(StringIO(self))->string;
long l = NUM2LONG(len);
long plen = RSTRING(string)->len;
long plen = RSTRING_LEN(string);
if (l < 0) {
error_inval("negative legnth");
}
rb_str_resize(string, l);
if (plen < l) {
MEMZERO(RSTRING(string)->ptr + plen, char, l - plen);
MEMZERO(RSTRING_PTR(string) + plen, char, l - plen);
}
return len;
}

View file

@ -41,13 +41,13 @@ struct strscanner
#define MATCHED(s) (s)->flags |= FLAG_MATCHED
#define CLEAR_MATCH_STATUS(s) (s)->flags &= ~FLAG_MATCHED
#define S_PBEG(s) (RSTRING((s)->str)->ptr)
#define S_LEN(s) (RSTRING((s)->str)->len)
#define S_PBEG(s) (RSTRING_PTR((s)->str))
#define S_LEN(s) (RSTRING_LEN((s)->str))
#define S_PEND(s) (S_PBEG(s) + S_LEN(s))
#define CURPTR(s) (S_PBEG(s) + (s)->curr)
#define S_RESTLEN(s) (S_LEN(s) - (s)->curr)
#define EOS_P(s) ((s)->curr >= RSTRING(p->str)->len)
#define EOS_P(s) ((s)->curr >= RSTRING_LEN(p->str))
#define GET_SCANNER(obj,var) do {\
Data_Get_Struct(obj, struct strscanner, var);\
@ -1069,7 +1069,7 @@ strscan_inspect(VALUE self)
len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld @ %s>",
rb_class2name(CLASS_OF(self)),
p->curr, S_LEN(p),
RSTRING(b)->ptr);
RSTRING_PTR(b));
return infect(rb_str_new(buf, len), p);
}
a = inspect1(p);
@ -1077,8 +1077,8 @@ strscan_inspect(VALUE self)
len = snprintf(buf, BUFSIZE, "#<%s %ld/%ld %s @ %s>",
rb_class2name(CLASS_OF(self)),
p->curr, S_LEN(p),
RSTRING(a)->ptr,
RSTRING(b)->ptr);
RSTRING_PTR(a),
RSTRING_PTR(b));
return infect(rb_str_new(buf, len), p);
}

View file

@ -149,8 +149,8 @@ rb_syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip )
if (!NIL_P(str2))
{
StringValue(str2);
len = RSTRING(str2)->len;
memcpy( buf + skip, RSTRING(str2)->ptr, len );
len = RSTRING_LEN(str2);
memcpy( buf + skip, RSTRING_PTR(str2), len );
}
}
len += skip;
@ -170,7 +170,7 @@ syck_parser_assign_io(SyckParser *parser, VALUE *pport)
if (!NIL_P(tmp = rb_check_string_type(port))) {
taint = OBJ_TAINTED(port); /* original taintedness */
port = tmp;
syck_parser_str( parser, RSTRING(port)->ptr, RSTRING(port)->len, NULL );
syck_parser_str( parser, RSTRING_PTR(port), RSTRING_LEN(port), NULL );
}
else if (rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
@ -1006,10 +1006,10 @@ syck_set_ivars(VALUE vars, VALUE obj)
VALUE ivname = rb_ary_entry( vars, 0 );
char *ivn;
StringValue( ivname );
ivn = S_ALLOCA_N( char, RSTRING(ivname)->len + 2 );
ivn = S_ALLOCA_N( char, RSTRING_LEN(ivname) + 2 );
ivn[0] = '@';
ivn[1] = '\0';
strncat( ivn, RSTRING(ivname)->ptr, RSTRING(ivname)->len );
strncat( ivn, RSTRING_PTR(ivname), RSTRING_LEN(ivname) );
rb_iv_set( obj, ivn, rb_ary_entry( vars, 1 ) );
return Qnil;
}
@ -1037,12 +1037,12 @@ syck_const_find(VALUE const_name)
VALUE
syck_resolver_transfer(VALUE self, VALUE type, VALUE val)
{
if (NIL_P(type) || RSTRING(StringValue(type))->len == 0)
if (NIL_P(type) || RSTRING_LEN(StringValue(type)) == 0)
{
type = rb_funcall( self, s_detect_implicit, 1, val );
}
if ( ! (NIL_P(type) || RSTRING(StringValue(type))->len == 0) )
if ( ! (NIL_P(type) || RSTRING_LEN(StringValue(type)) == 0) )
{
VALUE str_xprivate = rb_str_new2( "x-private" );
VALUE colon = rb_str_new2( ":" );
@ -1172,7 +1172,7 @@ syck_resolver_tagurize(VALUE self, VALUE val)
if ( !NIL_P(tmp) )
{
char *taguri = syck_type_id_to_uri( RSTRING(tmp)->ptr );
char *taguri = syck_type_id_to_uri( RSTRING_PTR(tmp) );
val = rb_str_new2( taguri );
S_FREE( taguri );
}
@ -1192,7 +1192,7 @@ syck_defaultresolver_detect_implicit(VALUE self, VALUE val)
if ( !NIL_P(tmp) )
{
val = tmp;
type_id = syck_match_implicit( RSTRING(val)->ptr, RSTRING(val)->len );
type_id = syck_match_implicit( RSTRING_PTR(val), RSTRING_LEN(val) );
return rb_str_new2( type_id );
}
@ -1451,8 +1451,8 @@ syck_scalar_value_set(VALUE self, VALUE val)
Data_Get_Struct( self, SyckNode, node );
StringValue( val );
node->data.str->ptr = syck_strndup( RSTRING(val)->ptr, RSTRING(val)->len );
node->data.str->len = RSTRING(val)->len;
node->data.str->ptr = syck_strndup( RSTRING_PTR(val), RSTRING_LEN(val) );
node->data.str->len = RSTRING_LEN(val);
node->data.str->style = scalar_none;
rb_iv_set( self, "@value", val );
@ -1711,7 +1711,7 @@ syck_node_type_id_set(VALUE self, VALUE type_id)
if ( !NIL_P( type_id ) ) {
StringValue( type_id );
node->type_id = syck_strndup( RSTRING(type_id)->ptr, RSTRING(type_id)->len );
node->type_id = syck_strndup( RSTRING_PTR(type_id), RSTRING_LEN(type_id) );
}
rb_iv_set( self, "@type_id", type_id );

View file

@ -32,7 +32,7 @@ static void syslog_write(int pri, int argc, VALUE *argv)
str = rb_f_sprintf(argc, argv);
syslog(pri, "%s", RSTRING(str)->ptr);
syslog(pri, "%s", RSTRING_PTR(str));
}
/* Syslog module methods */
@ -70,7 +70,7 @@ static VALUE mSyslog_open(int argc, VALUE *argv, VALUE self)
#else
Check_SafeStr(ident);
#endif
syslog_ident = strdup(RSTRING(ident)->ptr);
syslog_ident = strdup(RSTRING_PTR(ident));
if (NIL_P(opt)) {
syslog_options = LOG_PID | LOG_CONS;

View file

@ -292,7 +292,7 @@ do_checksum(argc, argv, func)
}
else {
StringValue(str);
sum = func(sum, (Bytef*)RSTRING(str)->ptr, RSTRING(str)->len);
sum = func(sum, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
}
return rb_uint2inum(sum);
}
@ -432,13 +432,13 @@ zstream_expand_buffer(struct zstream *z)
rb_str_buf_new makes a zero-length string. */
z->buf = rb_str_new(0, ZSTREAM_INITIAL_BUFSIZE);
z->buf_filled = 0;
z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr;
z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
z->stream.avail_out = ZSTREAM_INITIAL_BUFSIZE;
RBASIC(z->buf)->klass = 0;
return;
}
if (RSTRING(z->buf)->len - z->buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX) {
if (RSTRING_LEN(z->buf) - z->buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX) {
/* to keep other threads from freezing */
z->stream.avail_out = ZSTREAM_AVAIL_OUT_STEP_MAX;
}
@ -451,7 +451,7 @@ zstream_expand_buffer(struct zstream *z)
z->stream.avail_out = (inc < ZSTREAM_AVAIL_OUT_STEP_MAX) ?
inc : ZSTREAM_AVAIL_OUT_STEP_MAX;
}
z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr + z->buf_filled;
z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
}
static void
@ -462,13 +462,13 @@ zstream_expand_buffer_into(struct zstream *z, int size)
rb_str_buf_new makes a zero-length string. */
z->buf = rb_str_new(0, size);
z->buf_filled = 0;
z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr;
z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
z->stream.avail_out = size;
RBASIC(z->buf)->klass = 0;
}
else if (z->stream.avail_out != size) {
rb_str_resize(z->buf, z->buf_filled + size);
z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr + z->buf_filled;
z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
z->stream.avail_out = size;
}
}
@ -480,13 +480,13 @@ zstream_append_buffer(struct zstream *z, const Bytef *src, int len)
z->buf = rb_str_buf_new(len);
rb_str_buf_cat(z->buf, (const char*)src, len);
z->buf_filled = len;
z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr;
z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
z->stream.avail_out = 0;
RBASIC(z->buf)->klass = 0;
return;
}
if (RSTRING(z->buf)->len < z->buf_filled + len) {
if (RSTRING_LEN(z->buf) < z->buf_filled + len) {
rb_str_resize(z->buf, z->buf_filled + len);
z->stream.avail_out = 0;
}
@ -498,13 +498,13 @@ zstream_append_buffer(struct zstream *z, const Bytef *src, int len)
z->stream.avail_out = 0;
}
}
memcpy(RSTRING(z->buf)->ptr + z->buf_filled, src, len);
memcpy(RSTRING_PTR(z->buf) + z->buf_filled, src, len);
z->buf_filled += len;
z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr + z->buf_filled;
z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
}
#define zstream_append_buffer2(z,v) \
zstream_append_buffer((z),(Bytef*)RSTRING(v)->ptr,RSTRING(v)->len)
zstream_append_buffer((z),(Bytef*)RSTRING_PTR(v),RSTRING_LEN(v))
static VALUE
zstream_detach_buffer(struct zstream *z)
@ -539,10 +539,10 @@ zstream_shift_buffer(struct zstream *z, int len)
dst = rb_str_substr(z->buf, 0, len);
RBASIC(dst)->klass = rb_cString;
z->buf_filled -= len;
memmove(RSTRING(z->buf)->ptr, RSTRING(z->buf)->ptr + len,
memmove(RSTRING_PTR(z->buf), RSTRING_PTR(z->buf) + len,
z->buf_filled);
z->stream.next_out = (Bytef*)RSTRING(z->buf)->ptr + z->buf_filled;
z->stream.avail_out = RSTRING(z->buf)->len - z->buf_filled;
z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
z->stream.avail_out = RSTRING_LEN(z->buf) - z->buf_filled;
if (z->stream.avail_out > ZSTREAM_AVAIL_OUT_STEP_MAX) {
z->stream.avail_out = ZSTREAM_AVAIL_OUT_STEP_MAX;
}
@ -553,12 +553,12 @@ zstream_shift_buffer(struct zstream *z, int len)
static void
zstream_buffer_ungetc(struct zstream *z, int c)
{
if (NIL_P(z->buf) || RSTRING(z->buf)->len - z->buf_filled == 0) {
if (NIL_P(z->buf) || RSTRING_LEN(z->buf) - z->buf_filled == 0) {
zstream_expand_buffer(z);
}
memmove(RSTRING(z->buf)->ptr + 1, RSTRING(z->buf)->ptr, z->buf_filled);
RSTRING(z->buf)->ptr[0] = (char)c;
memmove(RSTRING_PTR(z->buf) + 1, RSTRING_PTR(z->buf), z->buf_filled);
RSTRING_PTR(z->buf)[0] = (char)c;
z->buf_filled++;
if (z->stream.avail_out > 0) {
z->stream.next_out++;
@ -582,18 +582,18 @@ zstream_append_input(struct zstream *z, const Bytef *src, unsigned int len)
}
#define zstream_append_input2(z,v)\
zstream_append_input((z), (Bytef*)RSTRING(v)->ptr, RSTRING(v)->len)
zstream_append_input((z), (Bytef*)RSTRING_PTR(v), RSTRING_LEN(v))
static void
zstream_discard_input(struct zstream *z, unsigned int len)
{
if (NIL_P(z->input) || RSTRING(z->input)->len <= len) {
if (NIL_P(z->input) || RSTRING_LEN(z->input) <= len) {
z->input = Qnil;
}
else {
memmove(RSTRING(z->input)->ptr, RSTRING(z->input)->ptr + len,
RSTRING(z->input)->len - len);
rb_str_resize(z->input, RSTRING(z->input)->len - len);
memmove(RSTRING_PTR(z->input), RSTRING_PTR(z->input) + len,
RSTRING_LEN(z->input) - len);
rb_str_resize(z->input, RSTRING_LEN(z->input) - len);
}
}
@ -682,8 +682,8 @@ zstream_run(struct zstream *z, Bytef *src, uInt len, int flush)
}
else {
zstream_append_input(z, src, len);
z->stream.next_in = (Bytef*)RSTRING(z->input)->ptr;
z->stream.avail_in = RSTRING(z->input)->len;
z->stream.next_in = (Bytef*)RSTRING_PTR(z->input);
z->stream.avail_in = RSTRING_LEN(z->input);
/* keep reference to `z->input' so as not to be garbage collected
after zstream_reset_input() and prevent `z->stream.next_in'
from dangling. */
@ -738,12 +738,12 @@ zstream_sync(struct zstream *z, Bytef *src, uInt len)
int err;
if (!NIL_P(z->input)) {
z->stream.next_in = (Bytef*)RSTRING(z->input)->ptr;
z->stream.avail_in = RSTRING(z->input)->len;
z->stream.next_in = (Bytef*)RSTRING_PTR(z->input);
z->stream.avail_in = RSTRING_LEN(z->input);
err = inflateSync(&z->stream);
if (err == Z_OK) {
zstream_discard_input(z,
RSTRING(z->input)->len - z->stream.avail_in);
RSTRING_LEN(z->input) - z->stream.avail_in);
zstream_append_input(z, src, len);
return Qtrue;
}
@ -992,7 +992,7 @@ rb_zstream_avail_in(VALUE obj)
{
struct zstream *z;
Data_Get_Struct(obj, struct zstream, z);
return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING(z->input)->len));
return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_LEN(z->input)));
}
/*
@ -1135,7 +1135,7 @@ deflate_run(VALUE args)
struct zstream *z = (struct zstream*)((VALUE*)args)[0];
VALUE src = ((VALUE*)args)[1];
zstream_run(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len, Z_FINISH);
zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_FINISH);
return zstream_detach_buffer(z);
}
@ -1193,8 +1193,8 @@ do_deflate(struct zstream *z, VALUE src, int flush)
return;
}
StringValue(src);
if (flush != Z_NO_FLUSH || RSTRING(src)->len > 0) { /* prevent BUF_ERROR */
zstream_run(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len, flush);
if (flush != Z_NO_FLUSH || RSTRING_LEN(src) > 0) { /* prevent BUF_ERROR */
zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), flush);
}
}
@ -1320,7 +1320,7 @@ rb_deflate_set_dictionary(VALUE obj, VALUE dic)
OBJ_INFECT(obj, dic);
StringValue(src);
err = deflateSetDictionary(&z->stream,
(Bytef*)RSTRING(src)->ptr, RSTRING(src)->len);
(Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
@ -1380,7 +1380,7 @@ inflate_run(VALUE args)
struct zstream *z = (struct zstream*)((VALUE*)args)[0];
VALUE src = ((VALUE*)args)[1];
zstream_run(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
zstream_run(z, (Bytef*)"", 0, Z_FINISH); /* for checking errors */
return zstream_detach_buffer(z);
}
@ -1433,8 +1433,8 @@ do_inflate(struct zstream *z, VALUE src)
return;
}
StringValue(src);
if (RSTRING(src)->len > 0) { /* prevent Z_BUF_ERROR */
zstream_run(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len, Z_SYNC_FLUSH);
if (RSTRING_LEN(src) > 0) { /* prevent Z_BUF_ERROR */
zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
}
}
@ -1527,7 +1527,7 @@ rb_inflate_sync(VALUE obj, VALUE src)
OBJ_INFECT(obj, src);
StringValue(src);
return zstream_sync(z, (Bytef*)RSTRING(src)->ptr, RSTRING(src)->len);
return zstream_sync(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
}
/*
@ -1569,7 +1569,7 @@ rb_inflate_set_dictionary(VALUE obj, VALUE dic)
OBJ_INFECT(obj, dic);
StringValue(src);
err = inflateSetDictionary(&z->stream,
(Bytef*)RSTRING(src)->ptr, RSTRING(src)->len);
(Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
@ -1781,7 +1781,7 @@ gzfile_read_raw_ensure(struct gzfile *gz, int size)
{
VALUE str;
while (NIL_P(gz->z.input) || RSTRING(gz->z.input)->len < size) {
while (NIL_P(gz->z.input) || RSTRING_LEN(gz->z.input) < size) {
str = gzfile_read_raw(gz);
if (NIL_P(str)) return Qfalse;
zstream_append_input2(&gz->z, str);
@ -1796,14 +1796,14 @@ gzfile_read_raw_until_zero(struct gzfile *gz, long offset)
char *p;
for (;;) {
p = memchr(RSTRING(gz->z.input)->ptr + offset, '\0',
RSTRING(gz->z.input)->len - offset);
p = memchr(RSTRING_PTR(gz->z.input) + offset, '\0',
RSTRING_LEN(gz->z.input) - offset);
if (p) break;
str = gzfile_read_raw(gz);
if (NIL_P(str)) {
rb_raise(cGzError, "unexpected end of file");
}
offset = RSTRING(gz->z.input)->len;
offset = RSTRING_LEN(gz->z.input);
zstream_append_input2(&gz->z, str);
}
return p;
@ -1904,7 +1904,7 @@ gzfile_read_header(struct gzfile *gz)
rb_raise(cGzError, "not in gzip format");
}
head = (unsigned char*)RSTRING(gz->z.input)->ptr;
head = (unsigned char*)RSTRING_PTR(gz->z.input);
if (head[0] != GZ_MAGIC1 || head[1] != GZ_MAGIC2) {
rb_raise(cGzError, "not in gzip format");
@ -1942,7 +1942,7 @@ gzfile_read_header(struct gzfile *gz)
if (!gzfile_read_raw_ensure(gz, 2)) {
rb_raise(cGzError, "unexpected end of file");
}
len = gzfile_get16((Bytef*)RSTRING(gz->z.input)->ptr);
len = gzfile_get16((Bytef*)RSTRING_PTR(gz->z.input));
if (!gzfile_read_raw_ensure(gz, 2 + len)) {
rb_raise(cGzError, "unexpected end of file");
}
@ -1950,20 +1950,20 @@ gzfile_read_header(struct gzfile *gz)
}
if (flags & GZ_FLAG_ORIG_NAME) {
p = gzfile_read_raw_until_zero(gz, 0);
len = p - RSTRING(gz->z.input)->ptr;
gz->orig_name = rb_str_new(RSTRING(gz->z.input)->ptr, len);
len = p - RSTRING_PTR(gz->z.input);
gz->orig_name = rb_str_new(RSTRING_PTR(gz->z.input), len);
OBJ_TAINT(gz->orig_name); /* for safe */
zstream_discard_input(&gz->z, len + 1);
}
if (flags & GZ_FLAG_COMMENT) {
p = gzfile_read_raw_until_zero(gz, 0);
len = p - RSTRING(gz->z.input)->ptr;
gz->comment = rb_str_new(RSTRING(gz->z.input)->ptr, len);
len = p - RSTRING_PTR(gz->z.input);
gz->comment = rb_str_new(RSTRING_PTR(gz->z.input), len);
OBJ_TAINT(gz->comment); /* for safe */
zstream_discard_input(&gz->z, len + 1);
}
if (gz->z.input != Qnil && RSTRING(gz->z.input)->len > 0) {
if (gz->z.input != Qnil && RSTRING_LEN(gz->z.input) > 0) {
zstream_run(&gz->z, 0, 0, Z_SYNC_FLUSH);
}
}
@ -1979,8 +1979,8 @@ gzfile_check_footer(struct gzfile *gz)
rb_raise(cNoFooter, "footer is not found");
}
crc = gzfile_get32((Bytef*)RSTRING(gz->z.input)->ptr);
length = gzfile_get32((Bytef*)RSTRING(gz->z.input)->ptr + 4);
crc = gzfile_get32((Bytef*)RSTRING_PTR(gz->z.input));
length = gzfile_get32((Bytef*)RSTRING_PTR(gz->z.input) + 4);
gz->z.stream.total_in += 8; /* to rewind correctly */
zstream_discard_input(&gz->z, 8);
@ -2021,8 +2021,8 @@ gzfile_read_more(struct gzfile *gz)
}
break;
}
if (RSTRING(str)->len > 0) { /* prevent Z_BUF_ERROR */
zstream_run(&gz->z, (Bytef*)RSTRING(str)->ptr, RSTRING(str)->len,
if (RSTRING_LEN(str) > 0) { /* prevent Z_BUF_ERROR */
zstream_run(&gz->z, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str),
Z_SYNC_FLUSH);
}
if (gz->z.buf_filled > 0) break;
@ -2033,12 +2033,12 @@ gzfile_read_more(struct gzfile *gz)
static void
gzfile_calc_crc(struct gzfile *gz, VALUE str)
{
if (RSTRING(str)->len <= gz->ungetc) {
gz->ungetc -= RSTRING(str)->len;
if (RSTRING_LEN(str) <= gz->ungetc) {
gz->ungetc -= RSTRING_LEN(str);
}
else {
gz->crc = crc32(gz->crc, (Bytef*)RSTRING(str)->ptr + gz->ungetc,
RSTRING(str)->len - gz->ungetc);
gz->crc = crc32(gz->crc, (Bytef*)RSTRING_PTR(str) + gz->ungetc,
RSTRING_LEN(str) - gz->ungetc);
gz->ungetc = 0;
}
}
@ -2108,8 +2108,8 @@ gzfile_readpartial(struct gzfile *gz, int len, VALUE outbuf)
return dst;
}
else {
rb_str_resize(outbuf, RSTRING(dst)->len);
memcpy(RSTRING(outbuf)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len);
rb_str_resize(outbuf, RSTRING_LEN(dst));
memcpy(RSTRING_PTR(outbuf), RSTRING_PTR(dst), RSTRING_LEN(dst));
return outbuf;
}
}
@ -2197,7 +2197,7 @@ gzfile_reader_rewind(struct gzfile *gz)
n = gz->z.stream.total_in;
if (!NIL_P(gz->z.input)) {
n += RSTRING(gz->z.input)->len;
n += RSTRING_LEN(gz->z.input);
}
rb_funcall(gz->io, id_seek, 2, rb_int2inum(-n), INT2FIX(1));
@ -2288,7 +2288,7 @@ gzfile_s_open(int argc, VALUE *argv, VALUE klass, const char *mode)
}
filename = argv[0];
SafeStringValue(filename);
io = rb_file_open(RSTRING(filename)->ptr, mode);
io = rb_file_open(RSTRING_PTR(filename), mode);
argv[0] = io;
return rb_gzfile_s_wrap(argc, argv, klass);
@ -2426,9 +2426,9 @@ rb_gzfile_set_orig_name(VALUE obj, VALUE str)
rb_raise(cGzError, "header is already written");
}
s = rb_str_dup(rb_str_to_str(str));
p = memchr(RSTRING(s)->ptr, '\0', RSTRING(s)->len);
p = memchr(RSTRING_PTR(s), '\0', RSTRING_LEN(s));
if (p) {
rb_str_resize(s, p - RSTRING(s)->ptr);
rb_str_resize(s, p - RSTRING_PTR(s));
}
gz->orig_name = s;
return str;
@ -2448,9 +2448,9 @@ rb_gzfile_set_comment(VALUE obj, VALUE str)
rb_raise(cGzError, "header is already written");
}
s = rb_str_dup(rb_str_to_str(str));
p = memchr(RSTRING(s)->ptr, '\0', RSTRING(s)->len);
p = memchr(RSTRING_PTR(s), '\0', RSTRING_LEN(s));
if (p) {
rb_str_resize(s, p - RSTRING(s)->ptr);
rb_str_resize(s, p - RSTRING_PTR(s));
}
gz->comment = s;
return str;
@ -2676,8 +2676,8 @@ rb_gzwriter_write(VALUE obj, VALUE str)
if (TYPE(str) != T_STRING) {
str = rb_obj_as_string(str);
}
gzfile_write(gz, (Bytef*)RSTRING(str)->ptr, RSTRING(str)->len);
return INT2FIX(RSTRING(str)->len);
gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
return INT2FIX(RSTRING_LEN(str));
}
/*
@ -2908,7 +2908,7 @@ rb_gzreader_getc(VALUE obj)
dst = gzfile_read(gz, 1);
if (!NIL_P(dst)) {
dst = INT2FIX((unsigned int)(RSTRING(dst)->ptr[0]) & 0xff);
dst = INT2FIX((unsigned int)(RSTRING_PTR(dst)[0]) & 0xff);
}
return dst;
}
@ -2963,7 +2963,7 @@ gzreader_skip_linebreaks(struct gzfile *gz)
gzfile_read_more(gz);
}
n = 0;
p = RSTRING(gz->z.buf)->ptr;
p = RSTRING_PTR(gz->z.buf);
while (n++, *(p++) == '\n') {
if (n >= gz->z.buf_filled) {
@ -2974,7 +2974,7 @@ gzreader_skip_linebreaks(struct gzfile *gz)
gzfile_read_more(gz);
}
n = 0;
p = RSTRING(gz->z.buf)->ptr;
p = RSTRING_PTR(gz->z.buf);
}
}
@ -2985,7 +2985,7 @@ gzreader_skip_linebreaks(struct gzfile *gz)
static void
rscheck(const char *rsptr, long rslen, VALUE rs)
{
if (RSTRING(rs)->ptr != rsptr && RSTRING(rs)->len != rslen)
if (RSTRING_PTR(rs) != rsptr && RSTRING_LEN(rs) != rslen)
rb_raise(rb_eRuntimeError, "rs modified");
}
@ -3012,17 +3012,17 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
if (NIL_P(rs)) {
dst = gzfile_read_all(gz);
if (RSTRING(dst)->len != 0) gz->lineno++;
if (RSTRING_LEN(dst) != 0) gz->lineno++;
return dst;
}
if (RSTRING(rs)->len == 0) {
if (RSTRING_LEN(rs) == 0) {
rsptr = "\n\n";
rslen = 2;
rspara = 1;
} else {
rsptr = RSTRING(rs)->ptr;
rslen = RSTRING(rs)->len;
rsptr = RSTRING_PTR(rs);
rslen = RSTRING_LEN(rs);
rspara = 0;
}
@ -3038,13 +3038,13 @@ gzreader_gets(int argc, VALUE *argv, VALUE obj)
gzfile_read_more(gz);
}
p = RSTRING(gz->z.buf)->ptr;
p = RSTRING_PTR(gz->z.buf);
n = rslen;
for (;;) {
if (n > gz->z.buf_filled) {
if (ZSTREAM_IS_FINISHED(&gz->z)) break;
gzfile_read_more(gz);
p = RSTRING(gz->z.buf)->ptr + n - rslen;
p = RSTRING_PTR(gz->z.buf) + n - rslen;
}
if (!rspara) rscheck(rsptr, rslen, rs);
res = memchr(p, rsptr[0], (gz->z.buf_filled - n + 1));