dtoa_config.h 1.9 KB

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