From a707ab4bc8a29241440f56696098efa2f7f3ff45 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 5 Nov 2014 06:05:14 +0000 Subject: [PATCH] string.c: no terminator * string.c (rb_str_{,l,r}strip_bang): rb_str_subseq() will not NUL-terminate the result string, in the future, so it will not be needed in other cases. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ NEWS | 8 ++++---- string.c | 11 ++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e5ba75c65d..3561869b75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Nov 5 15:05:12 2014 Nobuyoshi Nakada + + * string.c (rb_str_{,l,r}strip_bang): rb_str_subseq() will not + NUL-terminate the result string, in the future, so it will not + be needed in other cases. + Wed Nov 5 14:11:30 2014 Nobuyoshi Nakada * common.mk (lib/unicode_normalize/tables.rb): do nothing unless diff --git a/NEWS b/NEWS index 7d6fc46fd5..d357a007ae 100644 --- a/NEWS +++ b/NEWS @@ -290,10 +290,10 @@ with all sufficient information, see the ChangeLog file. * rb_str_cat_cstr() added. This is same as `rb_str_cat2()`. -* `rb_str_substr()` and `rb_str_subseq()` now share middle of a string, - but not only the end of a string. Therefore, result strings may not - be NUL-terminated, `StringValueCStr()` is needed calling to obtain a - NUL-terminated C string. +* `rb_str_substr()` and `rb_str_subseq()` will share middle of a string, + but not only the end of a string, in the futre. Therefore, result + strings may not be NUL-terminated, `StringValueCStr()` is needed + calling to obtain a NUL-terminated C string. * rb_tracepoint_new() supports new internal events accessible only from C: * RUBY_INTERNAL_EVENT_GC_ENTER diff --git a/string.c b/string.c index e8cc8e37d8..5c87424d18 100644 --- a/string.c +++ b/string.c @@ -128,7 +128,10 @@ VALUE rb_cSymbol; #define STR_ENC_GET(str) get_encoding(str) -#if 1 +#if !defined SHARABLE_MIDDLE_SUBSTRING +# define SHARABLE_MIDDLE_SUBSTRING 0 +#endif +#if !SHARABLE_MIDDLE_SUBSTRING #define SHARABLE_SUBSTRING_P(beg, len, end) ((beg) + (len) == (end)) #else #define SHARABLE_SUBSTRING_P(beg, len, end) 1 @@ -7227,7 +7230,9 @@ rb_str_lstrip_bang(VALUE str) s = start + loffset; memmove(start, s, len); STR_SET_LEN(str, len); +#if !SHARABLE_MIDDLE_SUBSTRING TERM_FILL(start+len, rb_enc_mbminlen(enc)); +#endif return str; } return Qnil; @@ -7309,7 +7314,9 @@ rb_str_rstrip_bang(VALUE str) long len = olen - roffset; STR_SET_LEN(str, len); +#if !SHARABLE_MIDDLE_SUBSTRING TERM_FILL(start+len, rb_enc_mbminlen(enc)); +#endif return str; } return Qnil; @@ -7371,7 +7378,9 @@ rb_str_strip_bang(VALUE str) memmove(start, start + loffset, len); } STR_SET_LEN(str, len); +#if !SHARABLE_MIDDLE_SUBSTRING TERM_FILL(start+len, rb_enc_mbminlen(enc)); +#endif return str; } return Qnil;