mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
d6eb807878
commit
8489ac41ca
3 changed files with 38 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Thu Jan 27 08:32:17 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Thu Jan 27 08:22:49 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Jan 27 08:22:49 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* dln_find.c (dln_find_1): use rb_warning and return immediately
|
* dln_find.c (dln_find_1): use rb_warning and return immediately
|
||||||
|
|
|
@ -1028,6 +1028,18 @@ NUM2CHR(VALUE x)
|
||||||
|
|
||||||
#define ALLOCA_N(type,n) (type*)alloca(sizeof(type)*(n))
|
#define ALLOCA_N(type,n) (type*)alloca(sizeof(type)*(n))
|
||||||
|
|
||||||
|
void *rb_alloc_tmp_buffer(volatile VALUE *store, long len);
|
||||||
|
void rb_free_tmp_buffer(volatile VALUE *store);
|
||||||
|
/* allocates _n_ bytes temporary buffer and stores VALUE including it
|
||||||
|
* in _v_. _n_ may be evaluated twice. */
|
||||||
|
#ifdef C_ALLOCA
|
||||||
|
# define ALLOCV(v, n) rb_alloc_tmp_buffer(&(v), (n))
|
||||||
|
#else
|
||||||
|
# define ALLOCV(v, n) ((n) < 1024 ? (RB_GC_GUARD(v) = 0, alloca(n)) : rb_alloc_tmp_buffer(&(v), (n)))
|
||||||
|
#endif
|
||||||
|
#define ALLOCV_N(type, v, n) (type*)ALLOCV((v), sizeof(type)*(n))
|
||||||
|
#define ALLOCV_END(v) rb_free_tmp_buffer(&(v))
|
||||||
|
|
||||||
#define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n))
|
#define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n))
|
||||||
#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n))
|
#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n))
|
||||||
#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n))
|
#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n))
|
||||||
|
|
18
string.c
18
string.c
|
@ -45,6 +45,8 @@
|
||||||
#undef rb_str_buf_cat2
|
#undef rb_str_buf_cat2
|
||||||
#undef rb_str_cat2
|
#undef rb_str_cat2
|
||||||
|
|
||||||
|
static VALUE rb_str_clear(VALUE str);
|
||||||
|
|
||||||
VALUE rb_cString;
|
VALUE rb_cString;
|
||||||
VALUE rb_cSymbol;
|
VALUE rb_cSymbol;
|
||||||
|
|
||||||
|
@ -765,6 +767,22 @@ rb_str_tmp_new(long len)
|
||||||
return str_new(0, 0, 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
|
void
|
||||||
rb_str_free(VALUE str)
|
rb_str_free(VALUE str)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue