From 8489ac41cadc1ef80ea57799bc833a831d1afdc6 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 26 Jan 2011 23:32:22 +0000 Subject: * include/ruby/ruby.h (ALLOCV): new API for exception-safe temporary buffer. [ruby-core:34844] * string.c (rb_alloc_tmp_buffer, rb_free_tmp_buffer): implementation of the API. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'string.c') diff --git a/string.c b/string.c index f7c0ff7762..d4d1c9f7da 100644 --- a/string.c +++ b/string.c @@ -45,6 +45,8 @@ #undef rb_str_buf_cat2 #undef rb_str_cat2 +static VALUE rb_str_clear(VALUE str); + VALUE rb_cString; VALUE rb_cSymbol; @@ -765,6 +767,22 @@ rb_str_tmp_new(long len) return str_new(0, 0, len); } +void * +rb_alloc_tmp_buffer(volatile VALUE *store, long len) +{ + VALUE s = rb_str_tmp_new(len); + *store = s; + return RSTRING_PTR(s); +} + +void +rb_free_tmp_buffer(volatile VALUE *store) +{ + VALUE s = *store; + *store = 0; + if (s) rb_str_clear(s); +} + void rb_str_free(VALUE str) { -- cgit v1.2.3