aboutsummaryrefslogtreecommitdiff
path: root/dtoa_config.h
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-12-29 23:03:58 +1030
committerMark Pulford <mark@kyne.com.au>2012-03-04 18:54:34 +1030
commitca42b9a996f9046ba3876ad8a81cda1d935b39cf (patch)
tree229cc0e408e28abc882778c68496c87af0d781ba /dtoa_config.h
parent8eecc878e0560461ef42bd3cd8d6dfe33cf148e8 (diff)
downloadlua-cjson-ca42b9a996f9046ba3876ad8a81cda1d935b39cf.tar.gz
lua-cjson-ca42b9a996f9046ba3876ad8a81cda1d935b39cf.tar.bz2
lua-cjson-ca42b9a996f9046ba3876ad8a81cda1d935b39cf.zip
Use internal dtoa/strtod for double conversion
The internal Lua CJSON dtoa/strtod routines have locale support disabled. This avoids problems under locales with comma decimal separators. Build changes: - CMake: Check for big endian architectures - Makefile: Provide option to build with dtoa.c Modifications to dtoa.c: - Include locale dtoa_config.h configuration - Rename Infinity/NaN to inf/nan to match common C libraries - Rename strtod() -> internal_strtod() to prevent conflict with libc function Modifications to g_fmt.c: - Return output string length (instead of original buffer pointer) - Provide precision as an argument to g_fmt() - Silence compilations warnings from vendor source - while(a = b) - Unused label "done:" - Only swap to scientific notation when once the number of decimal digits required exceeds the precision available. This matches standard printf format %g. - Display a "0" in front of numbers < 1.
Diffstat (limited to 'dtoa_config.h')
-rw-r--r--dtoa_config.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/dtoa_config.h b/dtoa_config.h
new file mode 100644
index 0000000..294351d
--- /dev/null
+++ b/dtoa_config.h
@@ -0,0 +1,66 @@
1#ifndef _DTOA_CONFIG_H
2#define _DTOA_CONFIG_H
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <stdint.h>
7
8/* Ensure dtoa.c does not USE_LOCALE. Lua CJSON must not use locale
9 * aware conversion routines. */
10#undef USE_LOCALE
11
12/* dtoa.c should not touch errno, Lua CJSON does not use it, and it
13 * may not be threadsafe */
14#define NO_ERRNO
15
16#define Long int32_t
17#define ULong uint32_t
18#define Llong int64_t
19#define ULLong uint64_t
20
21#ifdef IEEE_BIG_ENDIAN
22#define IEEE_MC68k
23#else
24#define IEEE_8087
25#endif
26
27#define MALLOC(n) xmalloc(n)
28
29static void *xmalloc(size_t size)
30{
31 void *p;
32
33 p = malloc(size);
34 if (!p) {
35 fprintf(stderr, "Out of memory");
36 abort();
37 }
38
39 return p;
40}
41
42#ifdef MULTIPLE_THREADS
43
44/* Enable locking to support multi-threaded applications */
45
46#include <pthread.h>
47
48static pthread_mutex_t private_dtoa_lock[2] = {
49 PTHREAD_MUTEX_INITIALIZER,
50 PTHREAD_MUTEX_INITIALIZER
51};
52
53#define ACQUIRE_DTOA_LOCK(n) do { \
54 pthread_mutex_lock(&private_dtoa_lock[n]); \
55} while (0)
56
57#define FREE_DTOA_LOCK(n) do { \
58 pthread_mutex_unlock(&private_dtoa_lock[n]); \
59} while (0)
60
61#endif /* MULTIPLE_THREADS */
62
63#endif /* _DTOA_CONFIG_H */
64
65/* vi:ai et sw=4 ts=4:
66 */