summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-04-19 13:32:41 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-04-19 13:32:41 +0000
commit606ac38e20db5bbde6210444539153242c52e9fd (patch)
tree33f5af3b114a84a6365c76a13090d1e3fb7849bf /util.c
parent32203423909cea1f1857fc918e150331acc595f0 (diff)
merges r22919 from trunk into ruby_1_9_1.
-- * util.c (rv_strdup): macro to duplicate nul-terminated string. [ruby-core:22852] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@23213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/util.c b/util.c
index 0e065ff0b2..0d9a7a35d4 100644
--- a/util.c
+++ b/util.c
@@ -3063,15 +3063,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)
@@ -3085,6 +3085,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,
@@ -3217,9 +3219,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
@@ -3227,7 +3229,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