diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-08-19 07:33:15 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-08-19 07:33:15 +0000 |
commit | d73fa69935a2d6657e13bfe2d3fa266fef55614d (patch) | |
tree | 2b91232f5c6bf8601ed38337fae396d2e391a41e /string.c | |
parent | 4c57b2b49905d652fb500249c34303d8c0571155 (diff) | |
download | ruby-d73fa69935a2d6657e13bfe2d3fa266fef55614d.tar.gz |
* dir.c (free_dir): fix memory leak. reported by yamamoto
madoka.
* eval.c (bind_eval): new method. [RCR 251]
* string.c (rb_str_clear): new method. [ruby-dev:24104]
* io.c (rb_io_reopen): should clear allocated OpenFile. pointed
out by Guy Decoux. [ruby-core:03288]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6794 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -2212,6 +2212,31 @@ rb_str_replace(str, str2) return str; } +/* + * call-seq: + * string.clear -> string + * + * Makes string empty. + * + * a = "abcde" + * a.clear #=> "" + */ + +static VALUE +rb_str_clear(str) + VALUE str; +{ + /* rb_str_modify() */ /* no need for str_make_independent */ + if (str_independent(str)) { + free(RSTRING(str)->ptr); + } + RSTRING(str)->aux.shared = 0; + FL_UNSET(str, ELTS_SHARED|STR_ASSOC); + RSTRING(str)->ptr = 0; + RARRAY(str)->len = 0; + return str; +} + static VALUE uscore_get() { @@ -4593,6 +4618,7 @@ Init_String() rb_define_method(rb_cString, "index", rb_str_index_m, -1); rb_define_method(rb_cString, "rindex", rb_str_rindex_m, -1); rb_define_method(rb_cString, "replace", rb_str_replace, 1); + rb_define_method(rb_cString, "clear", rb_str_clear, 0); rb_define_method(rb_cString, "to_i", rb_str_to_i, -1); rb_define_method(rb_cString, "to_f", rb_str_to_f, 0); |