diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-01-18 08:43:14 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-01-18 08:43:14 +0000 |
| commit | 4388b897db0ad4945640191c3050e1436c902e81 (patch) | |
| tree | 83fdd95738b0470346716b47dcb3ffdac299764a /pack.c | |
| parent | 6b06917aa49c9d0cbba5f0019d8db8c9d1738ff1 (diff) | |
| download | ruby-4388b897db0ad4945640191c3050e1436c902e81.tar.gz ruby-4388b897db0ad4945640191c3050e1436c902e81.tar.xz ruby-4388b897db0ad4945640191c3050e1436c902e81.zip | |
* io.c (rb_io_s_read): new method to call IO#read from
pathname. In addition, it accepts third optional argument to
specify starting point.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@1137 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'pack.c')
| -rw-r--r-- | pack.c | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -1625,8 +1625,12 @@ pack_unpack(str, fmt) p = RARRAY(a)->ptr; pend = p + RARRAY(a)->len; while (p < pend) { - if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) + if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) { + if (len > RSTRING(*p)->len) { + len = RSTRING(*p)->len; + } break; + } p++; } if (p == pend) { @@ -1649,13 +1653,31 @@ pack_unpack(str, fmt) break; else { char *t; - VALUE str = rb_str_new(0, 0); + VALUE a, tmp; + VALUE *p, *pend; + + + if (!(a = rb_str_associated(str))) { + rb_raise(rb_eArgError, "no associated pointer"); + } memcpy(&t, s, sizeof(char *)); s += sizeof(char *); + if (t) { - rb_str_cat2(str, t); + p = RARRAY(a)->ptr; + pend = p + RARRAY(a)->len; + while (p < pend) { + if (TYPE(*p) == T_STRING && RSTRING(*p)->ptr == t) { + break; + } + p++; + } + if (p == pend) { + rb_raise(rb_eArgError, "non associated pointer"); + } + tmp = rb_str_new2(t); } - rb_ary_push(ary, str); + rb_ary_push(ary, tmp); } } break; |
