1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
Commit graph

1114 commits

Author SHA1 Message Date
usa
cc938265eb merge revision(s) 57536: [Backport ]
doc: Add example for Symbol#to_s

	* string.c: add example for Symbol#to_s.

	The docs for Symbol#to_s only include an example for
	Symbol#id2name, but not for #to_s which is an alias;
	the docs should include examples for both methods.

	From: Marcus Stollsteimer <sto.mar@web.de>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-25 18:19:17 +00:00
usa
0d528f4a29 merge revision(s) 57374: [Backport ]
string.c: rindex(//) should set $~.

	This seems a bug introduced by r520 (1.4.0).  [ruby-core:79110] [Bug ]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-25 16:29:17 +00:00
usa
8dc3d3fd54 merge revision(s) 57302,57303,57304: [Backport ]
string.c: block for scrub with ASCII-incompatible

	* string.c (rb_enc_str_scrub): honor the given block with
	  ASCII-incompatible encoding.  [ruby-core:79039] [Bug ]
	string.c: yield invalid part

	* string.c (rb_enc_str_scrub): yield the invalid part only with
	  ASCII-incompatible.  [ruby-core:79039] [Bug ]
	string.c: replacement and block

	* string.c (rb_enc_str_scrub): only one of replacement and block
	  is allowed.  [ruby-core:79038] [Bug ]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-03-25 15:36:01 +00:00
usa
63e4f2120c merge revision(s) 55547,55551,55552,55555,55557,55559,55568,55575,55691: [Backport ]
* string.c: Fix memory corruptions when using UTF-16/32 strings.
	  [Bug ] [ruby-dev:49699]

	* string.c (TERM_LEN_MAX): Macro for the longest TERM_FILL length,
	  the same as largest value of rb_enc_mbminlen(enc) among encodings.

	* string.c (str_new, rb_str_buf_new, str_shared_replace): Allocate
	  +TERM_LEN_MAX bytes instead of +1. This change may increase memory
	  usage.

	* string.c (rb_str_new_with_class): Use TERM_LEN of the "obj".

	* string.c (rb_str_plus, rb_str_justify): Use str_new0 which is aware
	  of termlen.

	* string.c (str_shared_replace): Copy +termlen bytes instead of +1.

	* string.c (rb_str_times): termlen should not be included in capa.

	* string.c (RESIZE_CAPA_TERM): When using RSTRING_EMBED_LEN_MAX,
	  termlen should be counted with it because embedded strings are
	  also processed by TERM_FILL.

	* string.c (rb_str_capacity, str_shared_replace, str_buf_cat): ditto.

	* string.c (rb_str_drop_bytes, rb_str_setbyte, str_byte_substr): ditto.

	* string.c (rb_str_subseq, str_substr): When RSTRING_EMBED_LEN_MAX
	  is used, TERM_LEN(str) should be considered with it because
	  embedded strings are also processed by TERM_FILL.
	  Additional fix for [Bug ] [ruby-dev:49699].
	  Additional fix for [Bug ] [ruby-dev:49699].

	* string.c (rb_usascii_str_new, rb_utf8_str_new): Specify termlen
	  which is apparently 1 for the encodings.

	* string.c (str_new0_cstr): New static function to create a String
	  object from a C string with specifying termlen.

	* string.c (rb_usascii_str_new_cstr, rb_utf8_str_new_cstr): Specify
	  termlen by using new str_new0_cstr().

	* string.c (str_new_static): Specify termlen from the given encoding
	  when creating a new String object is needed.

	* string.c (rb_tainted_str_new_with_enc): New function to create a
	  tainted String object with the given encoding. This means that
	  the termlen is correctly specified. Curretly static function.
	  The function name might be renamed to rb_tainted_enc_str_new
	  or rb_enc_tainted_str_new.

	* string.c (rb_external_str_new_with_enc): Use encoding by using the
	  above rb_tainted_str_new_with_enc().

	* string.c (str_fill_term): When termlen increases, re-allocation
	  of memory for termlen should always be needed.
	  In this fix, if possible, decrease capa instead of realloc.
	  [Bug ] [ruby-dev:49699]

	* string.c: Partially reverts r55547 and r55555.
	  ChangeLog about the reverted changes are also deleted in this file.
	  [Bug ] [ruby-dev:49699] [ruby-dev:49702]

	* string.c: Specify termlen as far as possible.
	  the termlen is correctly specified. Currently static function.

	* string.c (rb_str_change_terminator_length): New function to change
	  termlen and resize heap for the terminator. This is split from
	  rb_str_fill_terminator (str_fill_term) because filling terminator
	  and changing terminator length are different things. [Bug ]

	* internal.h: declaration for rb_str_change_terminator_length.

	* string.c (str_fill_term): Simplify only to zero-fill the terminator.
	  For non-shared strings, it assumes that (capa + termlen) bytes of
	  heap is allocated. This partially reverts r55557.

	* encoding.c (rb_enc_associate_index): rb_str_change_terminator_length
	  is used, and it should be called whenever the termlen is changed.

	* string.c (str_capacity): New static function to return capacity
	  of a string with the given termlen, because the termlen may
	  sometimes be different from TERM_LEN(str) especially during
	  changing termlen or filling terminator with specific termlen.

	* string.c (rb_str_capacity): Use str_capacity.

	* string.c (str_buf_cat): Fix capa size for embed string.
	  Fix bug in r55547. [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@56301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-09-30 15:42:12 +00:00
usa
b76d7afffc merge revision(s) 55181: [Backport ]
* transcode.c (str_transcode0): scrub in the given encoding when
	  the source encoding is given, not in the encoding of the
	  receiver.  [ruby-core:75732] [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@55936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-16 11:39:21 +00:00
usa
eee441fdfe merge revision(s) 55729: [Backport ]
* vm.c (vm_set_main_stack): remove unnecessary check.  toplevel
	  binding must be initialized.  [Bug ] (N1)

	* win32/win32.c (w32_symlink): fix return type.  [Bug ] (N3)

	* string.c (rb_str_split_m): simplify the condition.
	  [Bug ](N4)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@55925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-16 04:56:04 +00:00
usa
9fbd5955c0 merge revision(s) 55427: [Backport ]
* string.c (tr_trans): consider terminator length and fix heap
	  overflow.  reported by Guido Vranken <guido AT guidovranken.nl>.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@55872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-08-12 02:35:50 +00:00
usa
23bc28e2df merge revision(s) 55054: [Backport ]
* string.c (rb_str_modify_expand): check integer overflow.
	  [ruby-core:75592] [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@55352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-06-10 06:58:57 +00:00
nagachika
305dd08c5a merge revision(s) 54210: [Backport ]
* string.c (enc_succ_alnum_char): try to skip an invalid character
	  gap between GREEK CAPITAL RHO and SIGMA.
	  [ruby-core:74478] [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@54336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-03-28 16:41:15 +00:00
nagachika
5ad41fa169 merge revision(s) 49096,51353,53168,53169: [Backport ]
test_m17n.rb: split test_scrub

	* test/ruby/test_m17n.rb (TestM17N#test_scrub): split into some
  tests.
	* include/ruby/ruby.h: add raw FL macros, which assume always the
	  argument object is not a special constant.

	* internal.h (STR_EMBED_P, STR_SHARED_P): valid only for T_STRING.

	* string.c: deal with taint flags directly across String instances.

	* transcode.c (rb_econv_substr_append, econv_primitive_convert):
	  the result should be infected by the original string.

	* string.c (rb_str_scrub): the result should be infected by the
	  original string.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@53825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-02-14 17:25:57 +00:00
nagachika
65f49d2dcf merge revision(s) 51470: [Backport ]
* re.c (rb_memsearch): should match only char boundaries in wide
	  character encodings.  [ruby-core:70220] [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@51590 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-15 18:30:35 +00:00
nagachika
00d499992b merge revision(s) 51344: [Backport ]
* string.c (rb_str_reverse): reversed string is not a substring,
	  and should not set coderange of the original string.
	  [ruby-dev:49189] [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@51520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-10 16:19:38 +00:00
nagachika
637d08241a merge revision(s) 50509: [Backport ]
* string.c: added documentation for character sequence \' with String#sub
	  [Bug ][ruby-core:69121][fix GH-900][ci skip] Patch by @shishir127


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@50628 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-23 18:39:11 +00:00
nagachika
20ef4699e5 merge revision(s) 50334,50337: [Backport ]
* string.c (STR_SET_EMBED): clear NOFREE flag at embedding as
	  embedded strings no longer refer static strings.
	  [ruby-core:68436] [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@50550 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-05-19 19:52:07 +00:00
naruse
6d90e59562 merge revision(s) 49706: [Backport ]
* string.c (chompped_length): enable smart chomp for all non-dummy
	  encoding strings, not only default_rs.
	  [ruby-core:68258] [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-24 07:40:44 +00:00
naruse
e6d4a21cb1 merge revision(s) 49695: [Backport ]
* string.c (rb_str_split_m): raise ArgumentError at broken string
	  not RegexpError, as Regexp is not involved in.
	  [ruby-core:68229] [Bug ]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-24 07:36:55 +00:00
naruse
d43dcc67ce merge revision(s) 49405-49408:
* string.c (str_make_independent_expand): terminate String when
	  moved from heap to embedded.  [Fix GH-821].


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-19 06:33:07 +00:00
naruse
d4f507ab97 merge revision(s) 49586: [Backport ]
* string.c (str_discard): does not free for STR_NOFREE string.
	  [Bug ][ruby-core:68110]

	* bootstraptest/test_string.rb: test for above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-02-17 02:50:37 +00:00
nobu
020fcc95fe string.c: fix coderange for non-endianness string
* string.c (rb_enc_str_coderange): dummy wchar, non-endianness
  encoding string cannot be ascii only.
  [ruby-core:66835] [Bug ]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-15 07:19:25 +00:00
nobu
4d3677e14b string.c: reduce intermediate string
* string.c (rb_str_succ_bang): get rid of making intermediate
  string object.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 07:23:18 +00:00
nobu
3b8c100418 string.c: term fill
* string.c (rb_str_succ): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48781 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 02:24:51 +00:00
nobu
b96ff20fef string.c: use local variables
* string.c (rb_str_succ): extract local variables from constant
  RSTRING_PTR and RSTRING_LEN.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 02:24:49 +00:00
nobu
01e621579a string.c: check arguments for crypt
* string.c (rb_str_crypt): check arguments more strictly.
  * crypt() is not for wide char strings
  * salt bytes should not be NUL

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48779 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 01:49:20 +00:00
nobu
9cabd72f5f string.c: term fill
* string.c (rb_str_justify): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 01:32:36 +00:00
nobu
88ae402cbf string.c: term fill
* string.c (tr_trans): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48777 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-12 01:20:41 +00:00
nobu
5c100b57f8 string.c: term fill
* string.c (rb_str_squeeze_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-11 00:37:58 +00:00
nobu
7a77cf7133 string.c: term fill
* string.c (rb_str_delete_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 12:26:11 +00:00
nobu
117438ee7b string.c: term fill
* string.c (rb_str_sub_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 12:09:49 +00:00
nobu
9d17096309 string.c: term fill
* string.c (rb_str_splice_0): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:49:10 +00:00
nobu
ed94c24944 string.c: term fill
* string.c (rb_str_chop_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:56 +00:00
nobu
c77efe1144 string.c: term fill
* string.c (rb_str_chomp_bang): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:48 +00:00
nobu
0c50d7ba15 string.c: term fill
* string.c (rb_str_times): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48759 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:43 +00:00
nobu
c00aca4aa0 string.c: term fill
* string.c (rb_str_plus): fill wchar terminator.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:34 +00:00
nobu
b890ed926a string.c: local variables
* string.c (rb_str_plus, rb_str_splice_0): extract local
  variables.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48757 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:21 +00:00
nobu
516b9026fd string.c: chompped_length chomp_rs
* string.c (chompped_length, chomp_rs): extract from
  rb_str_chomp_bang to share with rb_str_chomp.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-10 07:48:17 +00:00
hsbt
93db27d51f * string.c: [DOC] Add missing documentation around String#chomp.
Patchby @stderr [ci skip][fix GH-780]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-09 11:24:46 +00:00
nobu
49b3b2d8a2 string.c: fake string is not sharing
* string.c (setup_fake_str): fake string does not share another
  string, but just should not free.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-03 05:34:10 +00:00
nobu
aaed10716a intern.h: SIZED_ENUMERATOR
* include/ruby/intern.h (SIZED_ENUMERATOR): separate from
  RETURN_SIZED_ENUMERATOR.

* string.c (rb_str_enumerate_chars): get rid of calling
  rb_block_given_p() twice.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-12-03 03:25:12 +00:00
nobu
25bab786cb string.c: preserve encoding of global variable
* string.c (rb_str_setter): preserve encoding of global variable
  name in error message.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-23 17:03:48 +00:00
akr
2b9191e557 * internal.h: Gather declarations in non-header files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-18 15:13:05 +00:00
nobu
85ba516877 string.c: escape a backslash [ci skip]
* string.c (rb_str_count): [DOC] add a backslash to escape a
  backslash itself.  [ruby-core:66321]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-16 19:11:37 +00:00
akr
7cd76ab0c5 * internal.h: Include ruby.h and ruby/encoding.h to be
includable without prior inclusion.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-15 11:49:06 +00:00
ko1
495548ace4 * string.c (sym_equal): use rb_obj_equal().
rb_obj_equal() is specially optimized in
  opt_eq_func()@vm_insnhelper.c.
  This fix is made from this discussion:
  https://www.omniref.com/ruby/2.1.4/symbols/Symbol/%3D%3D#line=8361.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-11 01:42:01 +00:00
nobu
c58962d43f string.c: no exception in QUOTE
* string.c (sym_printable): QUOTE() should not raise an exception
  even on invalid byte sequence.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-06 14:55:20 +00:00
nobu
a707ab4bc8 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
2014-11-05 06:05:14 +00:00
nobu
62ede28373 string.c: reduce memory copy
* string.c (rb_str_lstrip, rb_str_strip): reduce memory copy by
  copying necessary part only.
* string.c (rb_str_strip_bang, rb_str_strip): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-05 03:13:55 +00:00
nobu
3614f8bd1c string.c: wchar terminator
* string.c (rb_str_lstrip_bang, rb_str_rstrip_bang): terminate
  wchar strings with wchar 0.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-11-05 01:54:22 +00:00
duerst
d26c49657d string.c: improved comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-26 02:24:28 +00:00
akr
0d4185f30e * Avoid undefined behaviors found by gcc -fsanitize=undefined.
gcc (Debian 4.9.1-16) 4.9.1

* string.c (rb_str_sum): Avoid undefined behavior.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47997 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-17 09:49:28 +00:00
nobu
5617e31771 symbol.c: rename rb_str_dynamic_intern
* iseq.c, marshal.c, string.c: use rb_str_intern instead of
  rb_str_dynamic_intern.
* symbol.c (rb_str_intern): rename rb_str_dynamic_intern.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-10-14 07:23:01 +00:00