Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
- uses: actions/labeler@f27b608878404679385c85cfa523b85ccb86e213 # v6.1.0
2 changes: 1 addition & 1 deletion ext/objspace/objspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ type2sym(enum ruby_value_type i)
* T_DATA may be wrong.
*
* It returns a hash as:
* {:TOTAL=>1461154, :T_CLASS=>158280, :T_MODULE=>20672, :T_STRING=>527249, ...}
* {TOTAL: 1461154, T_CLASS: 158280, T_MODULE: 20672, T_STRING: 527249, ...}
*
* If the optional argument, result_hash, is given,
* it is overwritten and returned.
Expand Down
33 changes: 22 additions & 11 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ strio_substr(struct StringIO *ptr, long pos, long len, rb_encoding *enc)
return enc_subseq(str, pos, len, enc);
}

static VALUE
strio_readbuf(struct StringIO *ptr, VALUE str)
{
if (!NIL_P(str)) {
StringValue(str);
rb_str_modify(str);
if (str == ptr->string) {
rb_raise(rb_eArgError, "cannot read into the underlying string");
}
}
return str;
}

#define StringIO(obj) get_strio(obj)
#define StringIOForRead(obj) get_strio_for_read(obj)

Expand Down Expand Up @@ -1684,11 +1697,7 @@ strio_read(int argc, VALUE *argv, VALUE self)

switch (argc) {
case 2:
str = argv[1];
if (!NIL_P(str)) {
StringValue(str);
rb_str_modify(str);
}
str = strio_readbuf(ptr, argv[1]);
/* fall through */
case 1:
if (!NIL_P(argv[0])) {
Expand Down Expand Up @@ -1753,6 +1762,8 @@ static VALUE
strio_pread(int argc, VALUE *argv, VALUE self)
{
VALUE rb_len, rb_offset, rb_buf;
struct StringIO *ptr = readable(self);

rb_scan_args(argc, argv, "21", &rb_len, &rb_offset, &rb_buf);
long len = NUM2LONG(rb_len);
long offset = NUM2LONG(rb_offset);
Expand All @@ -1761,19 +1772,19 @@ strio_pread(int argc, VALUE *argv, VALUE self)
rb_raise(rb_eArgError, "negative string size (or size too big): %" PRIsVALUE, rb_len);
}

if (offset < 0) {
rb_syserr_fail_str(EINVAL, rb_sprintf("pread: Invalid offset argument: %" PRIsVALUE, rb_offset));
}

rb_buf = strio_readbuf(ptr, rb_buf);

if (len == 0) {
if (NIL_P(rb_buf)) {
return rb_str_new("", 0);
}
return rb_buf;
}

if (offset < 0) {
rb_syserr_fail_str(EINVAL, rb_sprintf("pread: Invalid offset argument: %" PRIsVALUE, rb_offset));
}

struct StringIO *ptr = readable(self);

if (outside_p(ptr, offset)) {
rb_eof_error();
}
Expand Down
Loading