ruby-changes:57020
From: Nobuyoshi <ko1@a...>
Date: Wed, 14 Aug 2019 11:27:31 +0900 (JST)
Subject: [ruby-changes:57020] Nobuyoshi Nakada: 22e942deb2 (master): [ruby/stringio] Supported `mode:` option
https://git.ruby-lang.org/ruby.git/commit/?id=22e942deb2 From 22e942deb2580faae44176064a569a84bccb5028 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 14 Aug 2019 10:42:46 +0900 Subject: [ruby/stringio] Supported `mode:` option https://github.com/ruby/stringio/commit/53def32ba0 diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 284a256..6ca5db3 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -35,8 +35,11 @@ strio_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L35 VALUE mode = *vmode_p; VALUE intmode; int fmode; + int has_enc = 0, has_vmode = 0; convconfig_p->enc = convconfig_p->enc2 = 0; + + vmode_handle: if (NIL_P(mode)) { fmode = FMODE_READABLE; } @@ -51,6 +54,7 @@ strio_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L54 if (n) { long len; char encname[ENCODING_MAXNAMELEN+1]; + has_enc = 1; if (fmode & FMODE_SETENC_BY_BOM) { n = strchr(n, '|'); } @@ -72,8 +76,23 @@ strio_extract_modeenc(VALUE *vmode_p, VALUE *vperm_p, VALUE opthash, https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L76 if (!NIL_P(opthash)) { rb_encoding *extenc = 0, *intenc = 0; + VALUE v; + if (!has_vmode) { + ID id_mode; + CONST_ID(id_mode, "mode"); + v = rb_hash_aref(opthash, ID2SYM(id_mode)); + if (!NIL_P(v)) { + if (!NIL_P(mode)) { + rb_raise(rb_eArgError, "mode specified twice"); + } + has_vmode = 1; + mode = v; + goto vmode_handle; + } + } + if (rb_io_extract_encoding_option(opthash, &extenc, &intenc, &fmode)) { - if (convconfig_p->enc || convconfig_p->enc2) { + if (has_enc) { rb_raise(rb_eArgError, "encoding specified twice"); } } -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/