stringio 3.0.5 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd5cdd012959f081ba2717eb15a3a6f3ca015ec48bba03ef1bf318686007dac2
4
- data.tar.gz: 57842131091d3f2a38c03abfb8e294c51361c844b0777086126c034a1a904537
3
+ metadata.gz: 3f7f9c928c654ab73856e461f75e7f6171252633858472336a8900cb37c06d15
4
+ data.tar.gz: eb1583a64b9d4f4fdd46e3bffba21edb124074b7f1ce8f6c9cf25e5c9c45ae64
5
5
  SHA512:
6
- metadata.gz: 2cb53aa9936ad5464a40268c1b4477f06dcde9f4a456107aeb897812c1a1b52859bbe88a90e8d82dd8b30819444cb5c2b05193ab40c2ccb43a04e03002183b2d
7
- data.tar.gz: aefe614e34d66c31b2ddc0c78788e85fba60279c081b65645786cbcaf936e20a42edaa5ef5615dcf4aff6eb10258a1823eee99e89c81f5ed0e01348692bfeb38
6
+ metadata.gz: f8a13e0f7352087b716f1516829275c1ca5765cd3587c49f0c8bcd7ec3ff718b4fd09b3280159bb2fd1b4ab487e960468b361eda6121c6b45ed78b868b897bc2
7
+ data.tar.gz: 805c032b64a74d49c2583230a2116ea955e7be9ad52f635fbfcefdfaf7586b0ccc51463dbc3f7e7ece15db8abc069fb74d2616dd6e165bf6bf6ba4d6070a17da
@@ -1,4 +1,3 @@
1
1
  # frozen_string_literal: false
2
2
  require 'mkmf'
3
- have_func("rb_io_extract_modeenc", "ruby/io.h")
4
3
  create_makefile('stringio')
@@ -12,7 +12,7 @@
12
12
 
13
13
  **********************************************************************/
14
14
 
15
- #define STRINGIO_VERSION "3.0.5"
15
+ #define STRINGIO_VERSION "3.0.7"
16
16
 
17
17
  #include "ruby.h"
18
18
  #include "ruby/io.h"
@@ -32,86 +32,6 @@
32
32
  # define rb_class_new_instance_kw(argc, argv, klass, kw_splat) rb_class_new_instance(argc, argv, klass)
33
33
  #endif
34
34
 
35
- #ifndef HAVE_RB_IO_EXTRACT_MODEENC
36
- #define rb_io_extract_modeenc strio_extract_modeenc
37
- static void
38
- strio_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash,
39
- int *oflags_p, int *fmode_p, struct rb_io_enc_t *convconfig_p)
40
- {
41
- VALUE mode = *vmode_p;
42
- VALUE intmode;
43
- int fmode;
44
- int has_enc = 0, has_vmode = 0;
45
-
46
- convconfig_p->enc = convconfig_p->enc2 = 0;
47
-
48
- vmode_handle:
49
- if (NIL_P(mode)) {
50
- fmode = FMODE_READABLE;
51
- }
52
- else if (!NIL_P(intmode = rb_check_to_integer(mode, "to_int"))) {
53
- int flags = NUM2INT(intmode);
54
- fmode = rb_io_oflags_fmode(flags);
55
- }
56
- else {
57
- const char *m = StringValueCStr(mode), *n, *e;
58
- fmode = rb_io_modestr_fmode(m);
59
- n = strchr(m, ':');
60
- if (n) {
61
- long len;
62
- char encname[ENCODING_MAXNAMELEN+1];
63
- has_enc = 1;
64
- if (fmode & FMODE_SETENC_BY_BOM) {
65
- n = strchr(n, '|');
66
- }
67
- e = strchr(++n, ':');
68
- len = e ? e - n : (long)strlen(n);
69
- if (len > 0 && len <= ENCODING_MAXNAMELEN) {
70
- rb_encoding *enc;
71
- if (e) {
72
- memcpy(encname, n, len);
73
- encname[len] = '\0';
74
- n = encname;
75
- }
76
- enc = rb_enc_find(n);
77
- if (e)
78
- convconfig_p->enc2 = enc;
79
- else
80
- convconfig_p->enc = enc;
81
- }
82
- if (e && (len = strlen(++e)) > 0 && len <= ENCODING_MAXNAMELEN) {
83
- convconfig_p->enc = rb_enc_find(e);
84
- }
85
- }
86
- }
87
-
88
- if (!NIL_P(opthash)) {
89
- rb_encoding *extenc = 0, *intenc = 0;
90
- VALUE v;
91
- if (!has_vmode) {
92
- ID id_mode;
93
- CONST_ID(id_mode, "mode");
94
- v = rb_hash_aref(opthash, ID2SYM(id_mode));
95
- if (!NIL_P(v)) {
96
- if (!NIL_P(mode)) {
97
- rb_raise(rb_eArgError, "mode specified twice");
98
- }
99
- has_vmode = 1;
100
- mode = v;
101
- goto vmode_handle;
102
- }
103
- }
104
-
105
- if (rb_io_extract_encoding_option(opthash, &extenc, &intenc, &fmode)) {
106
- if (has_enc) {
107
- rb_raise(rb_eArgError, "encoding specified twice");
108
- }
109
- }
110
- }
111
- *fmode_p = fmode;
112
- }
113
- #endif
114
-
115
35
  struct StringIO {
116
36
  VALUE string;
117
37
  rb_encoding *enc;
@@ -171,7 +91,7 @@ static const rb_data_type_t strio_data_type = {
171
91
  strio_free,
172
92
  strio_memsize,
173
93
  },
174
- 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
94
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
175
95
  };
176
96
 
177
97
  #define check_strio(self) ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
@@ -356,7 +276,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
356
276
  {
357
277
  VALUE string, vmode, opt;
358
278
  int oflags;
359
- struct rb_io_enc_t convconfig;
279
+ rb_io_enc_t convconfig;
360
280
 
361
281
  argc = rb_scan_args(argc, argv, "02:", &string, &vmode, &opt);
362
282
  rb_io_extract_modeenc(&vmode, 0, opt, &oflags, &ptr->flags, &convconfig);
@@ -379,7 +299,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
379
299
  if (ptr->flags & FMODE_TRUNC) {
380
300
  rb_str_resize(string, 0);
381
301
  }
382
- ptr->string = string;
302
+ RB_OBJ_WRITE(self, &ptr->string, string);
383
303
  if (argc == 1) {
384
304
  ptr->enc = rb_enc_get(string);
385
305
  }
@@ -397,7 +317,7 @@ static VALUE
397
317
  strio_finalize(VALUE self)
398
318
  {
399
319
  struct StringIO *ptr = StringIO(self);
400
- ptr->string = Qnil;
320
+ RB_OBJ_WRITE(self, &ptr->string, Qnil);
401
321
  ptr->flags &= ~FMODE_READWRITE;
402
322
  return self;
403
323
  }
@@ -563,7 +483,8 @@ strio_set_string(VALUE self, VALUE string)
563
483
  ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
564
484
  ptr->pos = 0;
565
485
  ptr->lineno = 0;
566
- return ptr->string = string;
486
+ RB_OBJ_WRITE(self, &ptr->string, string);
487
+ return string;
567
488
  }
568
489
 
569
490
  /*
@@ -685,8 +606,6 @@ strio_to_read(VALUE self)
685
606
  * see {Position}[rdoc-ref:File@Position].
686
607
  *
687
608
  * Raises IOError if the stream is not opened for reading.
688
- *
689
- * StreamIO#eof is an alias for StreamIO#eof?.
690
609
  */
691
610
  static VALUE
692
611
  strio_eof(VALUE self)
@@ -699,15 +618,19 @@ strio_eof(VALUE self)
699
618
  static VALUE
700
619
  strio_copy(VALUE copy, VALUE orig)
701
620
  {
702
- struct StringIO *ptr;
621
+ struct StringIO *ptr, *old_ptr;
622
+ VALUE old_string = Qundef;
703
623
 
704
624
  orig = rb_convert_type(orig, T_DATA, "StringIO", "to_strio");
705
625
  if (copy == orig) return copy;
706
626
  ptr = StringIO(orig);
707
- if (check_strio(copy)) {
708
- strio_free(DATA_PTR(copy));
627
+ old_ptr = check_strio(copy);
628
+ if (old_ptr) {
629
+ old_string = old_ptr->string;
630
+ strio_free(old_ptr);
709
631
  }
710
632
  DATA_PTR(copy) = ptr;
633
+ RB_OBJ_WRITTEN(copy, old_string, ptr->string);
711
634
  RBASIC(copy)->flags &= ~STRIO_READWRITE;
712
635
  RBASIC(copy)->flags |= RBASIC(orig)->flags & STRIO_READWRITE;
713
636
  ++ptr->count;
@@ -808,8 +731,6 @@ strio_reopen(int argc, VALUE *argv, VALUE self)
808
731
  *
809
732
  * Returns the current position (in bytes);
810
733
  * see {Position}[rdoc-ref:IO@Position].
811
- *
812
- * StringIO#tell is an alias for StringIO#pos.
813
734
  */
814
735
  static VALUE
815
736
  strio_get_pos(VALUE self)
@@ -1420,8 +1341,6 @@ strio_readline(int argc, VALUE *argv, VALUE self)
1420
1341
  * does nothing if already at end-of-file;
1421
1342
  * returns +self+.
1422
1343
  * See {Line IO}[rdoc-ref:IO@Line+IO].
1423
- *
1424
- * StringIO#each is an alias for StringIO#each_line.
1425
1344
  */
1426
1345
  static VALUE
1427
1346
  strio_each(int argc, VALUE *argv, VALUE self)
@@ -1824,7 +1743,7 @@ strio_set_encoding(int argc, VALUE *argv, VALUE self)
1824
1743
  else {
1825
1744
  enc = rb_find_encoding(ext_enc);
1826
1745
  if (!enc) {
1827
- struct rb_io_enc_t convconfig;
1746
+ rb_io_enc_t convconfig;
1828
1747
  int oflags, fmode;
1829
1748
  VALUE vmode = rb_str_append(rb_str_new_cstr("r:"), ext_enc);
1830
1749
  rb_io_extract_modeenc(&vmode, 0, Qnil, &oflags, &fmode, &convconfig);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringio
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-03 00:00:00.000000000 Z
12
+ date: 2023-06-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Pseudo `IO` class from/to `String`.
15
15
  email:
@@ -36,14 +36,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '2.5'
39
+ version: '2.7'
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: '2.6'
44
+ version: '0'
45
45
  requirements: []
46
- rubygems_version: 3.4.1
46
+ rubygems_version: 3.5.0.dev
47
47
  signing_key:
48
48
  specification_version: 4
49
49
  summary: Pseudo IO on String