summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-12 23:06:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-03-12 23:06:51 +0000
commit0f71c10acbb86ea272b665b61782bf5b502c11fc (patch)
tree7e6f19f9e9494a088b0e183080d21cf27dbc5281 /util.c
parent241216295911bd7cf2008efd534e583678fa9569 (diff)
* 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
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 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