stringio 3.1.1 → 3.1.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: 0f8291051ef78bfdd817200ff02c25db3e2fa495d9b4a164c9737511d6eadb38
4
- data.tar.gz: 8593995f8dbb66e6a3dc9f2755f97d0cc05e2d363e6cd027cc15a7d46deaf60f
3
+ metadata.gz: d32a3b9eb5ecb12a5c78c7a79418ed351272fe49a2fc1bbde837880a8e6a2a53
4
+ data.tar.gz: 8f965cb4f731147e7d6da44db5acbeda3a08ac51df419445d8001f35b17a1dc9
5
5
  SHA512:
6
- metadata.gz: 5060643c29e66ccc88df7a7ab4c19943d89ce3779641b9be7e0cfc61ce79db7c53af06367875b1892b80f31d98be32d10da2590445cb86425b7d89f285a30b5f
7
- data.tar.gz: 1a6dcf694eaa38dd0d939b8db9cb4f29cc96db93ac545f5f06d6354ad5e75f92fb9807f529f54ae6801a3f791e7139db7ad371bf8efd6b7ca34f45f61fb10429
6
+ metadata.gz: 6c3f11fa1dee2b8e00269cad5e99db7014ecdc7b1b7d99f5086d15fb3f04d17105dabd838887e5f87af817851e2a8a59260c7c7af26a5ea40f2ce103ad830775
7
+ data.tar.gz: c9e2afe1c8104c27591454cfeefdc71926c76196d3afc343f76052b9e465566f62df19ae25baaa1217839684910b0c94e4d05b7b08723f1960065f0c2d0844df
data/NEWS.md CHANGED
@@ -1,5 +1,82 @@
1
1
  # News
2
2
 
3
+ ## 3.1.7 - 2025-04-21
4
+
5
+ ### Improvements
6
+
7
+ * CRuby: Added support for `rb_io_mode_t` that will be introduced in
8
+ Ruby 3.5 or later.
9
+ * GH-129
10
+ * Patch by Samuel Williams
11
+
12
+ ### Thanks
13
+
14
+ * Samuel Williams
15
+
16
+ ## 3.1.6 - 2025-03-25
17
+
18
+ ### Fixes
19
+
20
+ * CRuby: Fix SEGV at unget to a null device StringIO
21
+ * JRuby:
22
+ * Fix NullPointerException at unget to a null device StringIO
23
+ * Use proper checkEncoding signature
24
+ * Update strioWrite logic to match CRuby
25
+ * GH-124
26
+
27
+ ## 3.1.5 - 2025-02-21
28
+
29
+ ### Improvements
30
+
31
+ * JRuby: Improved compatibility with CRuby for `StringIO#seek` with
32
+ frozen string.
33
+ * GH-119
34
+ * GH-121
35
+
36
+ ## 3.1.4 - 2025-02-20
37
+
38
+ ### Improvements
39
+
40
+ * JRuby: Improved compatibility with CRuby.
41
+ * GH-116
42
+
43
+ ### Fixes
44
+
45
+ * CRuby: Fixed a bug that `StringIO` may mutate a shared string.
46
+ * GH-117
47
+
48
+ ## 3.1.3 - 2025-02-14
49
+
50
+ ### Fixes
51
+
52
+ * JRuby: Fixed a bug that JRuby may not be able to be started
53
+ * GH-112
54
+ * GH-113
55
+ * Reported by Karol Bucek
56
+
57
+ ### Thanks
58
+
59
+ * Karol Bucek
60
+
61
+ ## 3.1.2 - 2024-11-07
62
+
63
+ ### Improvements
64
+
65
+ * JRuby: Added support for detecting encoding by BOM.
66
+ * GH-100
67
+ * GH-101
68
+
69
+ ### Fixes
70
+
71
+ * CRuby: Fixed a bug that unknown memory may be used by
72
+ `StringIO#ungetc`/`StringIO#ungetbyte`.
73
+ * https://hackerone.com/reports/2805165
74
+ * Reported by manun.
75
+
76
+ ### Thanks
77
+
78
+ * manun
79
+
3
80
  ## 3.1.1 - 2024-06-13
4
81
 
5
82
  ### Improvements
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: false
2
2
  require 'mkmf'
3
3
  if RUBY_ENGINE == 'ruby'
4
+ have_type("rb_io_mode_t", "ruby/io.h")
5
+
4
6
  create_makefile('stringio')
5
7
  else
6
8
  File.write('Makefile', dummy_makefile("").join)
@@ -13,7 +13,7 @@
13
13
  **********************************************************************/
14
14
 
15
15
  static const char *const
16
- STRINGIO_VERSION = "3.1.1";
16
+ STRINGIO_VERSION = "3.1.7";
17
17
 
18
18
  #include <stdbool.h>
19
19
 
@@ -35,12 +35,16 @@ STRINGIO_VERSION = "3.1.1";
35
35
  # define rb_class_new_instance_kw(argc, argv, klass, kw_splat) rb_class_new_instance(argc, argv, klass)
36
36
  #endif
37
37
 
38
+ #ifndef HAVE_TYPE_RB_IO_MODE_T
39
+ typedef int rb_io_mode_t;
40
+ #endif
41
+
38
42
  struct StringIO {
39
43
  VALUE string;
40
44
  rb_encoding *enc;
41
45
  long pos;
42
46
  long lineno;
43
- int flags;
47
+ rb_io_mode_t flags;
44
48
  int count;
45
49
  };
46
50
 
@@ -180,6 +184,9 @@ check_modifiable(struct StringIO *ptr)
180
184
  else if (OBJ_FROZEN_RAW(ptr->string)) {
181
185
  rb_raise(rb_eIOError, "not modifiable string");
182
186
  }
187
+ else {
188
+ rb_str_modify(ptr->string);
189
+ }
183
190
  }
184
191
 
185
192
  static VALUE
@@ -930,6 +937,18 @@ strio_extend(struct StringIO *ptr, long pos, long len)
930
937
  }
931
938
  }
932
939
 
940
+ static void
941
+ strio_unget_string(struct StringIO *ptr, VALUE c)
942
+ {
943
+ const char *cp = NULL;
944
+ long cl = RSTRING_LEN(c);
945
+ if (cl > 0) {
946
+ if (c != ptr->string) cp = RSTRING_PTR(c);
947
+ strio_unget_bytes(ptr, cp, cl);
948
+ RB_GC_GUARD(c);
949
+ }
950
+ }
951
+
933
952
  /*
934
953
  * call-seq:
935
954
  * ungetc(character) -> nil
@@ -952,19 +971,22 @@ strio_ungetc(VALUE self, VALUE c)
952
971
 
953
972
  enc = rb_enc_get(ptr->string);
954
973
  len = rb_enc_codelen(cc, enc);
955
- if (len <= 0) rb_enc_uint_chr(cc, enc);
974
+ if (len <= 0) {
975
+ rb_enc_uint_chr(cc, enc); /* to raise an exception */
976
+ UNREACHABLE;
977
+ }
956
978
  rb_enc_mbcput(cc, buf, enc);
957
979
  return strio_unget_bytes(ptr, buf, len);
958
980
  }
959
981
  else {
960
- SafeStringValue(c);
982
+ StringValue(c);
983
+ if (RSTRING_LEN(c) == 0) return Qnil;
961
984
  enc = rb_enc_get(ptr->string);
962
985
  enc2 = rb_enc_get(c);
963
986
  if (enc != enc2 && enc != rb_ascii8bit_encoding()) {
964
987
  c = rb_str_conv_enc(c, enc2, enc);
965
988
  }
966
- strio_unget_bytes(ptr, RSTRING_PTR(c), RSTRING_LEN(c));
967
- RB_GC_GUARD(c);
989
+ strio_unget_string(ptr, c);
968
990
  return Qnil;
969
991
  }
970
992
  }
@@ -991,13 +1013,8 @@ strio_ungetbyte(VALUE self, VALUE c)
991
1013
  strio_unget_bytes(ptr, &cc, 1);
992
1014
  }
993
1015
  else {
994
- long cl;
995
- SafeStringValue(c);
996
- cl = RSTRING_LEN(c);
997
- if (cl > 0) {
998
- strio_unget_bytes(ptr, RSTRING_PTR(c), cl);
999
- RB_GC_GUARD(c);
1000
- }
1016
+ StringValue(c);
1017
+ strio_unget_string(ptr, c);
1001
1018
  }
1002
1019
  return Qnil;
1003
1020
  }
@@ -1028,7 +1045,7 @@ strio_unget_bytes(struct StringIO *ptr, const char *cp, long cl)
1028
1045
  if (rest > cl) memset(s + len, 0, rest - cl);
1029
1046
  pos -= cl;
1030
1047
  }
1031
- memcpy(s + pos, cp, cl);
1048
+ memcpy(s + pos, (cp ? cp : s), cl);
1032
1049
  ptr->pos = pos;
1033
1050
  return Qnil;
1034
1051
  }
@@ -1839,7 +1856,8 @@ strio_set_encoding(int argc, VALUE *argv, VALUE self)
1839
1856
  enc = rb_find_encoding(ext_enc);
1840
1857
  if (!enc) {
1841
1858
  rb_io_enc_t convconfig;
1842
- int oflags, fmode;
1859
+ int oflags;
1860
+ rb_io_mode_t fmode;
1843
1861
  VALUE vmode = rb_str_append(rb_str_new_cstr("r:"), ext_enc);
1844
1862
  rb_io_extract_modeenc(&vmode, 0, Qnil, &oflags, &fmode, &convconfig);
1845
1863
  enc = convconfig.enc2;
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringio
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobu Nakada
8
8
  - Charles Oliver Nutter
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-06-13 00:00:00.000000000 Z
11
+ date: 2025-04-21 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Pseudo `IO` class from/to `String`.
15
14
  email:
@@ -42,8 +41,8 @@ homepage: https://github.com/ruby/stringio
42
41
  licenses:
43
42
  - Ruby
44
43
  - BSD-2-Clause
45
- metadata: {}
46
- post_install_message:
44
+ metadata:
45
+ changelog_uri: https://github.com/ruby/stringio/releases/tag/v3.1.7
47
46
  rdoc_options: []
48
47
  require_paths:
49
48
  - lib
@@ -58,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
57
  - !ruby/object:Gem::Version
59
58
  version: '0'
60
59
  requirements: []
61
- rubygems_version: 3.5.11
62
- signing_key:
60
+ rubygems_version: 3.6.7
63
61
  specification_version: 4
64
62
  summary: Pseudo IO on String
65
63
  test_files: []