stringio 3.0.4 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/ext/stringio/stringio.c +34 -38
  4. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b4cc8d1bfde389be40d5e1e51c9df833390781c6673f7e611f925feafa04603
4
- data.tar.gz: 037b50e91d31766555917bba6dc6f161fde4f7b5270ac17a4a8b01e5370b9ec9
3
+ metadata.gz: 33cdb98e67de55576e5f0f3ab5d77db8cd85a1b78287ab4533bee4c28782618a
4
+ data.tar.gz: a49ad49fe395ffd92fbd1dcf94be2b932ae7fc225905b83c1b22e4ead26c90fe
5
5
  SHA512:
6
- metadata.gz: fffa2a725486b9439bfe34c0e78609cc988ca97cdf3af30e0aaa7a4fd06a84fedf5d5220ce242489bcba773bfcb14707d3b9fff677b52bf394577ef8c96abc91
7
- data.tar.gz: a09107a6fee19fa1f3d3f8bc6cae95dc3bc8e46d8e17c4c5d52d42db2b84b2cc004feffa4669840e729fd4595ad65c1d45881aefd685a93ed5a23a25728c045c
6
+ metadata.gz: cd54ab4876d5d4a74854dc1fc649b4fcef93775cc043e7c4bb8dea1f8fd1ebc0f80106e16488806167e5dda6577c2e017535200f93f0fac7e9af356cfa927b14
7
+ data.tar.gz: 6a1a2425eaa1d105955c140ee4c6457dec97605e3b0b1583fd4d3061f7a92ee4ce106d7654bd758934ad5e42d17dc0862f9bf77abf97f575853ba5454fdad19f
data/README.md CHANGED
@@ -12,6 +12,7 @@ This library is based on MoonWolf version written in Ruby. Thanks a lot.
12
12
 
13
13
  * `fileno` raises `NotImplementedError`.
14
14
  * encoding conversion is not implemented, and ignored silently.
15
+ * there is no `#to_io` method because this is not an `IO.
15
16
 
16
17
  ## Installation
17
18
 
@@ -31,7 +32,7 @@ Or install it yourself as:
31
32
 
32
33
  ## Development
33
34
 
34
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+ Run `bundle install` to install dependencies and then `bundle exec rake test` to run the tests.
35
36
 
36
37
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
38
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  **********************************************************************/
14
14
 
15
- #define STRINGIO_VERSION "3.0.4"
15
+ #define STRINGIO_VERSION "3.0.6"
16
16
 
17
17
  #include "ruby.h"
18
18
  #include "ruby/io.h"
@@ -171,7 +171,7 @@ static const rb_data_type_t strio_data_type = {
171
171
  strio_free,
172
172
  strio_memsize,
173
173
  },
174
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
174
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
175
175
  };
176
176
 
177
177
  #define check_strio(self) ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
@@ -263,7 +263,7 @@ strio_s_allocate(VALUE klass)
263
263
  * Note that +mode+ defaults to <tt>'r'</tt> if +string+ is frozen.
264
264
  *
265
265
  * Returns a new \StringIO instance formed from +string+ and +mode+;
266
- * see {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes]:
266
+ * see {Access Modes}[rdoc-ref:File@Access+Modes]:
267
267
  *
268
268
  * strio = StringIO.new # => #<StringIO>
269
269
  * strio.close
@@ -379,7 +379,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
379
379
  if (ptr->flags & FMODE_TRUNC) {
380
380
  rb_str_resize(string, 0);
381
381
  }
382
- ptr->string = string;
382
+ RB_OBJ_WRITE(self, &ptr->string, string);
383
383
  if (argc == 1) {
384
384
  ptr->enc = rb_enc_get(string);
385
385
  }
@@ -397,7 +397,7 @@ static VALUE
397
397
  strio_finalize(VALUE self)
398
398
  {
399
399
  struct StringIO *ptr = StringIO(self);
400
- ptr->string = Qnil;
400
+ RB_OBJ_WRITE(self, &ptr->string, Qnil);
401
401
  ptr->flags &= ~FMODE_READWRITE;
402
402
  return self;
403
403
  }
@@ -409,7 +409,7 @@ strio_finalize(VALUE self)
409
409
  * Note that +mode+ defaults to <tt>'r'</tt> if +string+ is frozen.
410
410
  *
411
411
  * Creates a new \StringIO instance formed from +string+ and +mode+;
412
- * see {Access Modes}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Access+Modes].
412
+ * see {Access Modes}[rdoc-ref:File@Access+Modes].
413
413
  *
414
414
  * With no block, returns the new instance:
415
415
  *
@@ -563,7 +563,8 @@ strio_set_string(VALUE self, VALUE string)
563
563
  ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
564
564
  ptr->pos = 0;
565
565
  ptr->lineno = 0;
566
- return ptr->string = string;
566
+ RB_OBJ_WRITE(self, &ptr->string, string);
567
+ return string;
567
568
  }
568
569
 
569
570
  /*
@@ -682,11 +683,9 @@ strio_to_read(VALUE self)
682
683
  * eof? -> true or false
683
684
  *
684
685
  * Returns +true+ if positioned at end-of-stream, +false+ otherwise;
685
- * see {Position}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Position].
686
+ * see {Position}[rdoc-ref:File@Position].
686
687
  *
687
688
  * Raises IOError if the stream is not opened for reading.
688
- *
689
- * StreamIO#eof is an alias for StreamIO#eof?.
690
689
  */
691
690
  static VALUE
692
691
  strio_eof(VALUE self)
@@ -719,7 +718,7 @@ strio_copy(VALUE copy, VALUE orig)
719
718
  * lineno -> current_line_number
720
719
  *
721
720
  * Returns the current line number in +self+;
722
- * see {Line Number}[https://docs.ruby-lang.org/en/master/IO.html#label-Line+Number].
721
+ * see {Line Number}[rdoc-ref:IO@Line+Number].
723
722
  */
724
723
  static VALUE
725
724
  strio_get_lineno(VALUE self)
@@ -732,7 +731,7 @@ strio_get_lineno(VALUE self)
732
731
  * lineno = new_line_number -> new_line_number
733
732
  *
734
733
  * Sets the current line number in +self+ to the given +new_line_number+;
735
- * see {Line Number}[https://docs.ruby-lang.org/en/master/IO.html#label-Line+Number].
734
+ * see {Line Number}[rdoc-ref:IO@Line+Number].
736
735
  */
737
736
  static VALUE
738
737
  strio_set_lineno(VALUE self, VALUE lineno)
@@ -746,7 +745,7 @@ strio_set_lineno(VALUE self, VALUE lineno)
746
745
  * binmode -> self
747
746
  *
748
747
  * Sets the data mode in +self+ to binary mode;
749
- * see {Data Mode}[https://docs.ruby-lang.org/en/master/File.html#class-File-label-Data+Mode].
748
+ * see {Data Mode}[rdoc-ref:File@Data+Mode].
750
749
  *
751
750
  */
752
751
  static VALUE
@@ -807,9 +806,7 @@ strio_reopen(int argc, VALUE *argv, VALUE self)
807
806
  * pos -> stream_position
808
807
  *
809
808
  * Returns the current position (in bytes);
810
- * see {Position}[https://docs.ruby-lang.org/en/master/IO.html#label-Position].
811
- *
812
- * StringIO#tell is an alias for StringIO#pos.
809
+ * see {Position}[rdoc-ref:IO@Position].
813
810
  */
814
811
  static VALUE
815
812
  strio_get_pos(VALUE self)
@@ -822,7 +819,7 @@ strio_get_pos(VALUE self)
822
819
  * pos = new_position -> new_position
823
820
  *
824
821
  * Sets the current position (in bytes);
825
- * see {Position}[https://docs.ruby-lang.org/en/master/IO.html#label-Position].
822
+ * see {Position}[rdoc-ref:IO@Position].
826
823
  */
827
824
  static VALUE
828
825
  strio_set_pos(VALUE self, VALUE pos)
@@ -841,8 +838,8 @@ strio_set_pos(VALUE self, VALUE pos)
841
838
  * rewind -> 0
842
839
  *
843
840
  * Sets the current position and line number to zero;
844
- * see {Position}[https://docs.ruby-lang.org/en/master/IO.html#label-Position]
845
- * and {Line Number}[https://docs.ruby-lang.org/en/master/IO.html#label-Line+Number].
841
+ * see {Position}[rdoc-ref:IO@Position]
842
+ * and {Line Number}[rdoc-ref:IO@Line+Number].
846
843
  */
847
844
  static VALUE
848
845
  strio_rewind(VALUE self)
@@ -859,7 +856,7 @@ strio_rewind(VALUE self)
859
856
  *
860
857
  * Sets the current position to the given integer +offset+ (in bytes),
861
858
  * with respect to a given constant +whence+;
862
- * see {Position}[https://docs.ruby-lang.org/en/master/IO.html#label-Position].
859
+ * see {Position}[rdoc-ref:IO@Position].
863
860
  */
864
861
  static VALUE
865
862
  strio_seek(int argc, VALUE *argv, VALUE self)
@@ -915,7 +912,7 @@ strio_get_sync(VALUE self)
915
912
  * each_byte {|byte| ... } -> self
916
913
  *
917
914
  * With a block given, calls the block with each remaining byte in the stream;
918
- * see {Byte IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Byte+IO].
915
+ * see {Byte IO}[rdoc-ref:IO@Byte+IO].
919
916
  *
920
917
  * With no block given, returns an enumerator.
921
918
  */
@@ -938,7 +935,7 @@ strio_each_byte(VALUE self)
938
935
  * getc -> character or nil
939
936
  *
940
937
  * Reads and returns the next character from the stream;
941
- * see {Character IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Character+IO].
938
+ * see {Character IO}[rdoc-ref:IO@Character+IO].
942
939
  */
943
940
  static VALUE
944
941
  strio_getc(VALUE self)
@@ -964,7 +961,7 @@ strio_getc(VALUE self)
964
961
  * getbyte -> byte or nil
965
962
  *
966
963
  * Reads and returns the next 8-bit byte from the stream;
967
- * see {Byte IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Byte+IO].
964
+ * see {Byte IO}[rdoc-ref:IO@Byte+IO].
968
965
  */
969
966
  static VALUE
970
967
  strio_getbyte(VALUE self)
@@ -1003,7 +1000,7 @@ strio_extend(struct StringIO *ptr, long pos, long len)
1003
1000
  * ungetc(character) -> nil
1004
1001
  *
1005
1002
  * Pushes back ("unshifts") a character or integer onto the stream;
1006
- * see {Character IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Character+IO].
1003
+ * see {Character IO}[rdoc-ref:IO@Character+IO].
1007
1004
  */
1008
1005
  static VALUE
1009
1006
  strio_ungetc(VALUE self, VALUE c)
@@ -1041,7 +1038,7 @@ strio_ungetc(VALUE self, VALUE c)
1041
1038
  * ungetbyte(byte) -> nil
1042
1039
  *
1043
1040
  * Pushes back ("unshifts") an 8-bit byte onto the stream;
1044
- * see {Byte IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Byte+IO].
1041
+ * see {Byte IO}[rdoc-ref:IO@Byte+IO].
1045
1042
  */
1046
1043
  static VALUE
1047
1044
  strio_ungetbyte(VALUE self, VALUE c)
@@ -1104,7 +1101,7 @@ strio_unget_bytes(struct StringIO *ptr, const char *cp, long cl)
1104
1101
  * readchar -> string
1105
1102
  *
1106
1103
  * Like +getc+, but raises an exception if already at end-of-stream;
1107
- * see {Character IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Character+IO].
1104
+ * see {Character IO}[rdoc-ref:IO@Character+IO].
1108
1105
  */
1109
1106
  static VALUE
1110
1107
  strio_readchar(VALUE self)
@@ -1119,7 +1116,7 @@ strio_readchar(VALUE self)
1119
1116
  * readbyte -> byte
1120
1117
  *
1121
1118
  * Like +getbyte+, but raises an exception if already at end-of-stream;
1122
- * see {Byte IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Byte+IO].
1119
+ * see {Byte IO}[rdoc-ref:IO@Byte+IO].
1123
1120
  */
1124
1121
  static VALUE
1125
1122
  strio_readbyte(VALUE self)
@@ -1134,7 +1131,7 @@ strio_readbyte(VALUE self)
1134
1131
  * each_char {|c| ... } -> self
1135
1132
  *
1136
1133
  * With a block given, calls the block with each remaining character in the stream;
1137
- * see {Character IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Character+IO].
1134
+ * see {Character IO}[rdoc-ref:IO@Character+IO].
1138
1135
  *
1139
1136
  * With no block given, returns an enumerator.
1140
1137
  */
@@ -1156,7 +1153,7 @@ strio_each_char(VALUE self)
1156
1153
  * each_codepoint {|codepoint| ... } -> self
1157
1154
  *
1158
1155
  * With a block given, calls the block with each remaining codepoint in the stream;
1159
- * see {Codepoint IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Codepoint+IO].
1156
+ * see {Codepoint IO}[rdoc-ref:IO@Codepoint+IO].
1160
1157
  *
1161
1158
  * With no block given, returns an enumerator.
1162
1159
  */
@@ -1340,8 +1337,9 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr)
1340
1337
  str = strio_substr(ptr, ptr->pos, e - s - w, enc);
1341
1338
  }
1342
1339
  else {
1343
- if (n < e - s) {
1344
- if (e - s < 1024) {
1340
+ if (n < e - s + arg->chomp) {
1341
+ /* unless chomping, RS at the end does not matter */
1342
+ if (e - s < 1024 || n == e - s) {
1345
1343
  for (p = s; p + n <= e; ++p) {
1346
1344
  if (MEMCMP(p, RSTRING_PTR(str), char, n) == 0) {
1347
1345
  e = p + n;
@@ -1374,7 +1372,7 @@ strio_getline(struct getline_arg *arg, struct StringIO *ptr)
1374
1372
  *
1375
1373
  * Reads and returns a line from the stream;
1376
1374
  * assigns the return value to <tt>$_</tt>;
1377
- * see {Line IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Line+IO].
1375
+ * see {Line IO}[rdoc-ref:IO@Line+IO].
1378
1376
  */
1379
1377
  static VALUE
1380
1378
  strio_gets(int argc, VALUE *argv, VALUE self)
@@ -1399,7 +1397,7 @@ strio_gets(int argc, VALUE *argv, VALUE self)
1399
1397
  * readline(sep, limit, chomp: false) -> string
1400
1398
  *
1401
1399
  * Reads a line as with IO#gets, but raises EOFError if already at end-of-file;
1402
- * see {Line IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Line+IO].
1400
+ * see {Line IO}[rdoc-ref:IO@Line+IO].
1403
1401
  */
1404
1402
  static VALUE
1405
1403
  strio_readline(int argc, VALUE *argv, VALUE self)
@@ -1418,9 +1416,7 @@ strio_readline(int argc, VALUE *argv, VALUE self)
1418
1416
  * Calls the block with each remaining line read from the stream;
1419
1417
  * does nothing if already at end-of-file;
1420
1418
  * returns +self+.
1421
- * See {Line IO}[https://docs.ruby-lang.org/en/master/IO.html#label-Line+IO].
1422
- *
1423
- * StringIO#each is an alias for StringIO#each_line.
1419
+ * See {Line IO}[rdoc-ref:IO@Line+IO].
1424
1420
  */
1425
1421
  static VALUE
1426
1422
  strio_each(int argc, VALUE *argv, VALUE self)
@@ -1849,8 +1845,8 @@ strio_set_encoding_by_bom(VALUE self)
1849
1845
 
1850
1846
  /*
1851
1847
  * \IO streams for strings, with access similar to
1852
- * {IO}[https://docs.ruby-lang.org/en/master/IO.html];
1853
- * see {IO}[https://docs.ruby-lang.org/en/master/IO.html].
1848
+ * {IO}[rdoc-ref:IO];
1849
+ * see {IO}[rdoc-ref:IO].
1854
1850
  *
1855
1851
  * === About the Examples
1856
1852
  *
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringio
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  - Charles Oliver Nutter
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-12-08 00:00:00.000000000 Z
12
+ date: 2023-04-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Pseudo `IO` class from/to `String`.
15
15
  email:
@@ -28,7 +28,7 @@ licenses:
28
28
  - Ruby
29
29
  - BSD-2-Clause
30
30
  metadata: {}
31
- post_install_message:
31
+ post_install_message:
32
32
  rdoc_options: []
33
33
  require_paths:
34
34
  - lib
@@ -43,8 +43,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  - !ruby/object:Gem::Version
44
44
  version: '2.6'
45
45
  requirements: []
46
- rubygems_version: 3.3.26
47
- signing_key:
46
+ rubygems_version: 3.4.10
47
+ signing_key:
48
48
  specification_version: 4
49
49
  summary: Pseudo IO on String
50
50
  test_files: []