dtoa_config.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef _DTOA_CONFIG_H
  2. #define _DTOA_CONFIG_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <stdint.h>
  6. /* Ensure dtoa.c does not USE_LOCALE. Lua CJSON must not use locale
  7. * aware conversion routines. */
  8. #undef USE_LOCALE
  9. /* dtoa.c should not touch errno, Lua CJSON does not use it, and it
  10. * may not be threadsafe */
  11. #define NO_ERRNO
  12. #define Long int32_t
  13. #define ULong uint32_t
  14. #define Llong int64_t
  15. #define ULLong uint64_t
  16. #ifdef IEEE_BIG_ENDIAN
  17. #define IEEE_MC68k
  18. #else
  19. #define IEEE_8087
  20. #endif
  21. #define MALLOC(n) xmalloc(n)
  22. static void *xmalloc(size_t size)
  23. {
  24. void *p;
  25. p = malloc(size);
  26. if (!p) {
  27. fprintf(stderr, "Out of memory");
  28. abort();
  29. }
  30. return p;
  31. }
  32. #ifdef MULTIPLE_THREADS
  33. /* Enable locking to support multi-threaded applications */
  34. #include <pthread.h>
  35. static pthread_mutex_t private_dtoa_lock[2] = {
  36. PTHREAD_MUTEX_INITIALIZER,
  37. PTHREAD_MUTEX_INITIALIZER
  38. };
  39. #define ACQUIRE_DTOA_LOCK(n) do { \
  40. int r = pthread_mutex_lock(&private_dtoa_lock[n]); \
  41. if (r) { \
  42. fprintf(stderr, "pthread_mutex_lock failed with %d\n", r); \
  43. abort(); \
  44. } \
  45. } while (0)
  46. #define FREE_DTOA_LOCK(n) do { \
  47. int r = pthread_mutex_unlock(&private_dtoa_lock[n]); \
  48. if (r) { \
  49. fprintf(stderr, "pthread_mutex_unlock failed with %d\n", r);\
  50. abort(); \
  51. } \
  52. } while (0)
  53. #endif /* MULTIPLE_THREADS */
  54. #endif /* _DTOA_CONFIG_H */
  55. /* vi:ai et sw=4 ts=4:
  56. */