Modified: MacRuby/trunk/ext/zlib/zlib.c (544 => 545)
--- MacRuby/trunk/ext/zlib/zlib.c 2008-09-02 05:47:11 UTC (rev 544)
+++ MacRuby/trunk/ext/zlib/zlib.c 2008-09-03 07:16:08 UTC (rev 545)
@@ -292,7 +292,7 @@
}
else {
StringValue(str);
- sum = func(sum, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
+ sum = func(sum, (Bytef*)RSTRING_BYTEPTR(str), RSTRING_BYTELEN(str));
}
return rb_uint2inum(sum);
}
@@ -398,7 +398,7 @@
static void
zlib_mem_free(voidpf opaque, voidpf address)
{
- free(address);
+ xfree(address);
}
static void
@@ -430,19 +430,17 @@
if (NIL_P(z->buf)) {
/* I uses rb_str_new here not rb_str_buf_new because
rb_str_buf_new makes a zero-length string. */
- z->buf = rb_str_new(0, ZSTREAM_INITIAL_BUFSIZE);
+ GC_WB(&z->buf, rb_str_new(0, ZSTREAM_INITIAL_BUFSIZE));
z->buf_filled = 0;
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+ z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf);
z->stream.avail_out = ZSTREAM_INITIAL_BUFSIZE;
-#if WITH_OBJC
- RSTRING_BYTEPTR(z->buf); /* force bytestring creation */
-#else
+#if !WITH_OBJC
RBASIC(z->buf)->klass = 0;
#endif
return;
}
- if (RSTRING_LEN(z->buf) - z->buf_filled >= ZSTREAM_AVAIL_OUT_STEP_MAX) {
+ if (RSTRING_BYTELEN(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;
}
@@ -455,7 +453,7 @@
z->stream.avail_out = (inc < ZSTREAM_AVAIL_OUT_STEP_MAX) ?
inc : ZSTREAM_AVAIL_OUT_STEP_MAX;
}
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+ z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf) + z->buf_filled;
}
static void
@@ -464,15 +462,17 @@
if (NIL_P(z->buf)) {
/* I uses rb_str_new here not rb_str_buf_new because
rb_str_buf_new makes a zero-length string. */
- z->buf = rb_str_new(0, size);
+ GC_WB(&z->buf, rb_str_new(0, size));
z->buf_filled = 0;
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+ z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf);
z->stream.avail_out = size;
+#if !WITH_OBJC
RBASIC(z->buf)->klass = 0;
+#endif
}
else if (z->stream.avail_out != size) {
rb_str_resize(z->buf, z->buf_filled + size);
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+ z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf) + z->buf_filled;
z->stream.avail_out = size;
}
}
@@ -481,16 +481,19 @@
zstream_append_buffer(struct zstream *z, const Bytef *src, int len)
{
if (NIL_P(z->buf)) {
- z->buf = rb_str_buf_new(len);
+ GC_WB(&z->buf, rb_str_buf_new(len));
+ RSTRING_BYTEPTR(z->buf); /* create bytestring */
rb_str_buf_cat(z->buf, (const char*)src, len);
z->buf_filled = len;
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf);
+ z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf);
z->stream.avail_out = 0;
+#if !WITH_OBJC
RBASIC(z->buf)->klass = 0;
+#endif
return;
}
- if (RSTRING_LEN(z->buf) < z->buf_filled + len) {
+ if (RSTRING_BYTELEN(z->buf) < z->buf_filled + len) {
rb_str_resize(z->buf, z->buf_filled + len);
z->stream.avail_out = 0;
}
@@ -502,13 +505,14 @@
z->stream.avail_out = 0;
}
}
- memcpy(RSTRING_PTR(z->buf) + z->buf_filled, src, len);
+
+ memcpy(RSTRING_BYTEPTR(z->buf) + z->buf_filled, src, len);
z->buf_filled += len;
- z->stream.next_out = (Bytef*)RSTRING_PTR(z->buf) + z->buf_filled;
+ z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf) + z->buf_filled;
}
#define zstream_append_buffer2(z,v) \
- zstream_append_buffer((z),(Bytef*)RSTRING_PTR(v),RSTRING_LEN(v))
+ zstream_append_buffer((z),(Bytef*)RSTRING_BYTEPTR(v),RSTRING_BYTELEN(v))
static VALUE
zstream_detach_buffer(struct zstream *z)
@@ -521,7 +525,11 @@
else {
dst = z->buf;
rb_str_resize(dst, z->buf_filled);
+#if WITH_OBJC
+ RSTRING_SYNC(dst);
+#else
RBASIC(dst)->klass = rb_cString;
+#endif
}
z->buf = Qnil;
@@ -541,31 +549,38 @@
}
dst = rb_str_substr(z->buf, 0, len);
+#if !WITH_OBJC
RBASIC(dst)->klass = rb_cString;
+#endif
z->buf_filled -= len;
- memmove(RSTRING_PTR(z->buf), RSTRING_PTR(z->buf) + len,
+ memmove(RSTRING_BYTEPTR(z->buf), RSTRING_BYTEPTR(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;
+ z->stream.next_out = (Bytef*)RSTRING_BYTEPTR(z->buf) + z->buf_filled;
+ z->stream.avail_out = RSTRING_BYTELEN(z->buf) - z->buf_filled;
if (z->stream.avail_out > ZSTREAM_AVAIL_OUT_STEP_MAX) {
z->stream.avail_out = ZSTREAM_AVAIL_OUT_STEP_MAX;
}
+ RSTRING_SYNC(dst);
+
return dst;
}
static void
zstream_buffer_ungetc(struct zstream *z, int c)
{
- if (NIL_P(z->buf) || RSTRING_LEN(z->buf) - z->buf_filled == 0) {
+ if (NIL_P(z->buf) || RSTRING_BYTELEN(z->buf) - z->buf_filled == 0) {
zstream_expand_buffer(z);
}
#if WITH_OBJC
- CFStringInsert((CFMutableStringRef)z->buf, 0, rb_str_new(&c, 1));
+ char buf[2];
+ buf[0] = (char)c;
+ buf[1] = '\0';
+ CFStringInsert((CFMutableStringRef)z->buf, 0, (CFStringRef)rb_str_new2(buf));
#else
- memmove(RSTRING_PTR(z->buf) + 1, RSTRING_PTR(z->buf), z->buf_filled);
- RSTRING_PTR(z->buf)[0] = (char)c;
+ memmove(RSTRING_BYTEPTR(z->buf) + 1, RSTRING_BYTEPTR(z->buf), z->buf_filled);
+ RSTRING_BYTEPTR(z->buf)[0] = (char)c;
#endif
z->buf_filled++;
if (z->stream.avail_out > 0) {
@@ -581,8 +596,11 @@
if (NIL_P(z->input)) {
z->input = rb_str_buf_new(len);
+ RSTRING_BYTEPTR(z->input); /* create bytestring */
rb_str_buf_cat(z->input, (const char*)src, len);
+#if !WITH_OBJC
RBASIC(z->input)->klass = 0;
+#endif
}
else {
rb_str_buf_cat(z->input, (const char*)src, len);
@@ -590,18 +608,18 @@
}
#define zstream_append_input2(z,v)\
- zstream_append_input((z), (Bytef*)RSTRING_PTR(v), RSTRING_LEN(v))
+ zstream_append_input((z), (Bytef*)RSTRING_BYTEPTR(v), RSTRING_BYTELEN(v))
static void
zstream_discard_input(struct zstream *z, unsigned int len)
{
- if (NIL_P(z->input) || RSTRING_LEN(z->input) <= len) {
+ if (NIL_P(z->input) || RSTRING_BYTELEN(z->input) <= len) {
z->input = Qnil;
}
else {
- 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);
+ memmove(RSTRING_BYTEPTR(z->input), RSTRING_BYTEPTR(z->input) + len,
+ RSTRING_BYTELEN(z->input) - len);
+ rb_str_resize(z->input, RSTRING_BYTELEN(z->input) - len);
}
}
@@ -630,10 +648,14 @@
}
else {
dst = z->input;
+#if !WITH_OBJC
RBASIC(dst)->klass = rb_cString;
+#endif
}
z->input = Qnil;
+#if !WITH_OBJC
RBASIC(dst)->klass = rb_cString;
+#endif
return dst;
}
@@ -690,8 +712,8 @@
}
else {
zstream_append_input(z, src, len);
- z->stream.next_in = (Bytef*)RSTRING_PTR(z->input);
- z->stream.avail_in = RSTRING_LEN(z->input);
+ z->stream.next_in = (Bytef*)RSTRING_BYTEPTR(z->input);
+ z->stream.avail_in = RSTRING_BYTELEN(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. */
@@ -746,12 +768,12 @@
int err;
if (!NIL_P(z->input)) {
- z->stream.next_in = (Bytef*)RSTRING_PTR(z->input);
- z->stream.avail_in = RSTRING_LEN(z->input);
+ z->stream.next_in = (Bytef*)RSTRING_BYTEPTR(z->input);
+ z->stream.avail_in = RSTRING_BYTELEN(z->input);
err = inflateSync(&z->stream);
if (err == Z_OK) {
zstream_discard_input(z,
- RSTRING_LEN(z->input) - z->stream.avail_in);
+ RSTRING_BYTELEN(z->input) - z->stream.avail_in);
zstream_append_input(z, src, len);
return Qtrue;
}
@@ -1000,7 +1022,7 @@
{
struct zstream *z;
Data_Get_Struct(obj, struct zstream, z);
- return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_LEN(z->input)));
+ return INT2FIX(NIL_P(z->input) ? 0 : (int)(RSTRING_BYTELEN(z->input)));
}
/*
@@ -1143,7 +1165,7 @@
struct zstream *z = (struct zstream*)((VALUE*)args)[0];
VALUE src = ((VALUE*)args)[1];
- zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_FINISH);
+ zstream_run(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src), Z_FINISH);
return zstream_detach_buffer(z);
}
@@ -1201,8 +1223,8 @@
return;
}
StringValue(src);
- if (flush != Z_NO_FLUSH || RSTRING_LEN(src) > 0) { /* prevent BUF_ERROR */
- zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), flush);
+ if (flush != Z_NO_FLUSH || RSTRING_BYTELEN(src) > 0) { /* prevent BUF_ERROR */
+ zstream_run(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src), flush);
}
}
@@ -1328,7 +1350,7 @@
OBJ_INFECT(obj, dic);
StringValue(src);
err = deflateSetDictionary(&z->stream,
- (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+ (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
@@ -1388,7 +1410,7 @@
struct zstream *z = (struct zstream*)((VALUE*)args)[0];
VALUE src = ((VALUE*)args)[1];
- zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
+ zstream_run(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src), Z_SYNC_FLUSH);
zstream_run(z, (Bytef*)"", 0, Z_FINISH); /* for checking errors */
return zstream_detach_buffer(z);
}
@@ -1413,21 +1435,23 @@
static VALUE
rb_inflate_s_inflate(VALUE obj, VALUE src)
{
- struct zstream z;
+ struct zstream *z;
VALUE dst, args[2];
int err;
+ z = (struct zstream *)xmalloc(sizeof(struct zstream));
+
StringValue(src);
- zstream_init_inflate(&z);
- err = inflateInit(&z.stream);
+ zstream_init_inflate(z);
+ err = inflateInit(&z->stream);
if (err != Z_OK) {
- raise_zlib_error(err, z.stream.msg);
+ raise_zlib_error(err, z->stream.msg);
}
- ZSTREAM_READY(&z);
+ ZSTREAM_READY(z);
- args[0] = (VALUE)&z;
+ args[0] = (VALUE)z;
args[1] = src;
- dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)&z);
+ dst = rb_ensure(inflate_run, (VALUE)args, zstream_end, (VALUE)z);
OBJ_INFECT(dst, src);
return dst;
@@ -1441,8 +1465,8 @@
return;
}
StringValue(src);
- if (RSTRING_LEN(src) > 0) { /* prevent Z_BUF_ERROR */
- zstream_run(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src), Z_SYNC_FLUSH);
+ if (RSTRING_BYTELEN(src) > 0) { /* prevent Z_BUF_ERROR */
+ zstream_run(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src), Z_SYNC_FLUSH);
}
}
@@ -1535,7 +1559,7 @@
OBJ_INFECT(obj, src);
StringValue(src);
- return zstream_sync(z, (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+ return zstream_sync(z, (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src));
}
/*
@@ -1577,7 +1601,7 @@
OBJ_INFECT(obj, dic);
StringValue(src);
err = inflateSetDictionary(&z->stream,
- (Bytef*)RSTRING_PTR(src), RSTRING_LEN(src));
+ (Bytef*)RSTRING_BYTEPTR(src), RSTRING_BYTELEN(src));
if (err != Z_OK) {
raise_zlib_error(err, z->stream.msg);
}
@@ -1789,7 +1813,7 @@
{
VALUE str;
- while (NIL_P(gz->z.input) || RSTRING_LEN(gz->z.input) < size) {
+ while (NIL_P(gz->z.input) || RSTRING_BYTELEN(gz->z.input) < size) {
str = gzfile_read_raw(gz);
if (NIL_P(str)) return Qfalse;
zstream_append_input2(&gz->z, str);
@@ -1804,14 +1828,14 @@
char *p;
for (;;) {
- p = memchr(RSTRING_PTR(gz->z.input) + offset, '\0',
- RSTRING_LEN(gz->z.input) - offset);
+ p = memchr(RSTRING_BYTEPTR(gz->z.input) + offset, '\0',
+ RSTRING_BYTELEN(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_LEN(gz->z.input);
+ offset = RSTRING_BYTELEN(gz->z.input);
zstream_append_input2(&gz->z, str);
}
return p;
@@ -1912,7 +1936,7 @@
rb_raise(cGzError, "not in gzip format");
}
- head = (unsigned char*)RSTRING_PTR(gz->z.input);
+ head = (unsigned char*)RSTRING_BYTEPTR(gz->z.input);
if (head[0] != GZ_MAGIC1 || head[1] != GZ_MAGIC2) {
rb_raise(cGzError, "not in gzip format");
@@ -1950,7 +1974,7 @@
if (!gzfile_read_raw_ensure(gz, 2)) {
rb_raise(cGzError, "unexpected end of file");
}
- len = gzfile_get16((Bytef*)RSTRING_PTR(gz->z.input));
+ len = gzfile_get16((Bytef*)RSTRING_BYTEPTR(gz->z.input));
if (!gzfile_read_raw_ensure(gz, 2 + len)) {
rb_raise(cGzError, "unexpected end of file");
}
@@ -1958,20 +1982,20 @@
}
if (flags & GZ_FLAG_ORIG_NAME) {
p = gzfile_read_raw_until_zero(gz, 0);
- len = p - RSTRING_PTR(gz->z.input);
- gz->orig_name = rb_str_new(RSTRING_PTR(gz->z.input), len);
+ len = p - RSTRING_BYTEPTR(gz->z.input);
+ gz->orig_name = rb_str_new(RSTRING_BYTEPTR(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_PTR(gz->z.input);
- gz->comment = rb_str_new(RSTRING_PTR(gz->z.input), len);
+ len = p - RSTRING_BYTEPTR(gz->z.input);
+ gz->comment = rb_str_new(RSTRING_BYTEPTR(gz->z.input), len);
OBJ_TAINT(gz->comment); /* for safe */
zstream_discard_input(&gz->z, len + 1);
}
- if (gz->z.input != Qnil && RSTRING_LEN(gz->z.input) > 0) {
+ if (gz->z.input != Qnil && RSTRING_BYTELEN(gz->z.input) > 0) {
zstream_run(&gz->z, 0, 0, Z_SYNC_FLUSH);
}
}
@@ -1987,8 +2011,8 @@
rb_raise(cNoFooter, "footer is not found");
}
- crc = gzfile_get32((Bytef*)RSTRING_PTR(gz->z.input));
- length = gzfile_get32((Bytef*)RSTRING_PTR(gz->z.input) + 4);
+ crc = gzfile_get32((Bytef*)RSTRING_BYTEPTR(gz->z.input));
+ length = gzfile_get32((Bytef*)RSTRING_BYTEPTR(gz->z.input) + 4);
gz->z.stream.total_in += 8; /* to rewind correctly */
zstream_discard_input(&gz->z, 8);
@@ -2029,8 +2053,8 @@
}
break;
}
- if (RSTRING_LEN(str) > 0) { /* prevent Z_BUF_ERROR */
- zstream_run(&gz->z, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str),
+ if (RSTRING_BYTELEN(str) > 0) { /* prevent Z_BUF_ERROR */
+ zstream_run(&gz->z, (Bytef*)RSTRING_BYTEPTR(str), RSTRING_BYTELEN(str),
Z_SYNC_FLUSH);
}
if (gz->z.buf_filled > 0) break;
@@ -2041,12 +2065,12 @@
static void
gzfile_calc_crc(struct gzfile *gz, VALUE str)
{
- if (RSTRING_LEN(str) <= gz->ungetc) {
- gz->ungetc -= RSTRING_LEN(str);
+ if (RSTRING_BYTELEN(str) <= gz->ungetc) {
+ gz->ungetc -= RSTRING_BYTELEN(str);
}
else {
- gz->crc = crc32(gz->crc, (Bytef*)RSTRING_PTR(str) + gz->ungetc,
- RSTRING_LEN(str) - gz->ungetc);
+ gz->crc = crc32(gz->crc, (Bytef*)RSTRING_BYTEPTR(str) + gz->ungetc,
+ RSTRING_BYTELEN(str) - gz->ungetc);
gz->ungetc = 0;
}
}
@@ -2116,8 +2140,8 @@
return dst;
}
else {
- rb_str_resize(outbuf, RSTRING_LEN(dst));
- memcpy(RSTRING_PTR(outbuf), RSTRING_PTR(dst), RSTRING_LEN(dst));
+ rb_str_resize(outbuf, RSTRING_BYTELEN(dst));
+ memcpy(RSTRING_BYTEPTR(outbuf), RSTRING_BYTEPTR(dst), RSTRING_BYTELEN(dst));
return outbuf;
}
}
@@ -2205,7 +2229,7 @@
n = gz->z.stream.total_in;
if (!NIL_P(gz->z.input)) {
- n += RSTRING_LEN(gz->z.input);
+ n += RSTRING_BYTELEN(gz->z.input);
}
rb_funcall(gz->io, id_seek, 2, rb_int2inum(-n), INT2FIX(1));
@@ -2296,7 +2320,7 @@
}
filename = argv[0];
FilePathValue(filename);
- io = rb_file_open(RSTRING_PTR(filename), mode);
+ io = rb_file_open(RSTRING_BYTEPTR(filename), mode);
argv[0] = io;
return rb_gzfile_s_wrap(argc, argv, klass);
@@ -2434,9 +2458,9 @@
rb_raise(cGzError, "header is already written");
}
s = rb_str_dup(rb_str_to_str(str));
- p = memchr(RSTRING_PTR(s), '\0', RSTRING_LEN(s));
+ p = memchr(RSTRING_BYTEPTR(s), '\0', RSTRING_BYTELEN(s));
if (p) {
- rb_str_resize(s, p - RSTRING_PTR(s));
+ rb_str_resize(s, p - RSTRING_BYTEPTR(s));
}
gz->orig_name = s;
return str;
@@ -2456,9 +2480,9 @@
rb_raise(cGzError, "header is already written");
}
s = rb_str_dup(rb_str_to_str(str));
- p = memchr(RSTRING_PTR(s), '\0', RSTRING_LEN(s));
+ p = memchr(RSTRING_BYTEPTR(s), '\0', RSTRING_BYTELEN(s));
if (p) {
- rb_str_resize(s, p - RSTRING_PTR(s));
+ rb_str_resize(s, p - RSTRING_BYTEPTR(s));
}
gz->comment = s;
return str;
@@ -2684,8 +2708,8 @@
if (TYPE(str) != T_STRING) {
str = rb_obj_as_string(str);
}
- gzfile_write(gz, (Bytef*)RSTRING_PTR(str), RSTRING_LEN(str));
- return INT2FIX(RSTRING_LEN(str));
+ gzfile_write(gz, (Bytef*)RSTRING_BYTEPTR(str), RSTRING_BYTELEN(str));
+ return INT2FIX(RSTRING_BYTELEN(str));
}
/*
@@ -2916,7 +2940,7 @@
dst = gzfile_read(gz, 1);
if (!NIL_P(dst)) {
- dst = INT2FIX((unsigned int)(RSTRING_PTR(dst)[0]) & 0xff);
+ dst = INT2FIX((unsigned int)(RSTRING_BYTEPTR(dst)[0]) & 0xff);
}
return dst;
}
@@ -2974,7 +2998,7 @@
gzfile_read_more(gz);
}
n = 0;
- p = RSTRING_PTR(gz->z.buf);
+ p = RSTRING_BYTEPTR(gz->z.buf);
while (n++, *(p++) == '\n') {
if (n >= gz->z.buf_filled) {
@@ -2985,7 +3009,7 @@
gzfile_read_more(gz);
}
n = 0;
- p = RSTRING_PTR(gz->z.buf);
+ p = RSTRING_BYTEPTR(gz->z.buf);
}
}
@@ -2996,7 +3020,7 @@
static void
rscheck(const char *rsptr, long rslen, VALUE rs)
{
- if (RSTRING_PTR(rs) != rsptr && RSTRING_LEN(rs) != rslen)
+ if (RSTRING_BYTEPTR(rs) != rsptr && RSTRING_BYTELEN(rs) != rslen)
rb_raise(rb_eRuntimeError, "rs modified");
}
@@ -3023,19 +3047,19 @@
if (NIL_P(rs)) {
dst = gzfile_read_all(gz);
- if (RSTRING_LEN(dst) != 0) gz->lineno++;
+ if (RSTRING_BYTELEN(dst) != 0) gz->lineno++;
else
return Qnil;
return dst;
}
- if (RSTRING_LEN(rs) == 0) {
+ if (RSTRING_BYTELEN(rs) == 0) {
rsptr = "\n\n";
rslen = 2;
rspara = 1;
} else {
- rsptr = RSTRING_PTR(rs);
- rslen = RSTRING_LEN(rs);
+ rsptr = RSTRING_BYTEPTR(rs);
+ rslen = RSTRING_BYTELEN(rs);
rspara = 0;
}
@@ -3051,13 +3075,13 @@
gzfile_read_more(gz);
}
- p = RSTRING_PTR(gz->z.buf);
+ p = RSTRING_BYTEPTR(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_PTR(gz->z.buf) + n - rslen;
+ p = RSTRING_BYTEPTR(gz->z.buf) + n - rslen;
}
if (!rspara) rscheck(rsptr, rslen, rs);
res = memchr(p, rsptr[0], (gz->z.buf_filled - n + 1));