From 0f71c10acbb86ea272b665b61782bf5b502c11fc Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 12 Mar 2009 23:06:51 +0000 Subject: * util.c (rv_strdup): macro to duplicate nul-terminated string. [ruby-core:22852] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22919 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- util.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index b802202e9d..1417cb6fbd 100644 --- a/util.c +++ b/util.c @@ -3055,15 +3055,15 @@ quorem(Bigint *b, Bigint *S) static char *dtoa_result; #endif +#ifndef MULTIPLE_THREADS static char * rv_alloc(int i) { - return -#ifndef MULTIPLE_THREADS - dtoa_result = -#endif - xmalloc(i); + return dtoa_result = xmalloc(i); } +#else +#define rv_alloc(i) xmalloc(i) +#endif static char * nrv_alloc(const char *s, char **rve, int n) @@ -3077,6 +3077,8 @@ nrv_alloc(const char *s, char **rve, int n) return rv; } +#define rv_strdup(s, rve) nrv_alloc(s, rve, strlen(s)+1) + #ifndef MULTIPLE_THREADS /* freedtoa(s) must be used to free values s returned by dtoa * when MULTIPLE_THREADS is #defined. It should be used in all cases, @@ -3209,9 +3211,9 @@ ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve) *decpt = 9999; #ifdef IEEE_Arith if (!word1(d) && !(word0(d) & 0xfffff)) - return nrv_alloc("Infinity", rve, 8); + return rv_strdup("Infinity", rve); #endif - return nrv_alloc("NaN", rve, 3); + return rv_strdup("NaN", rve); } #endif #ifdef IBM @@ -3219,7 +3221,7 @@ ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve) #endif if (!dval(d)) { *decpt = 1; - return nrv_alloc("0", rve, 1); + return rv_strdup("0", rve); } #ifdef SET_INEXACT -- cgit v1.2.3