You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.0 KiB

  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Dmitry Stogov <dmitry@zend.com> |
  16. +----------------------------------------------------------------------+
  17. */
  18. #ifndef ZEND_MAP_PTR_H
  19. #define ZEND_MAP_PTR_H
  20. #include "zend_portability.h"
  21. #define ZEND_MAP_PTR_KIND_PTR 0
  22. #define ZEND_MAP_PTR_KIND_PTR_OR_OFFSET 1
  23. //#if defined(ZTS) || defined(TSRM_WIN32)
  24. # define ZEND_MAP_PTR_KIND ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
  25. //#else
  26. //# define ZEND_MAP_PTR_KIND ZEND_MAP_PTR_KIND_PTR
  27. //#endif
  28. #if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
  29. # define ZEND_MAP_PTR(ptr) \
  30. ptr ## __ptr
  31. # define ZEND_MAP_PTR_DEF(type, name) \
  32. type * ZEND_MAP_PTR(name)
  33. # define ZEND_MAP_PTR_GET(ptr) \
  34. (*(ZEND_MAP_PTR(ptr)))
  35. # define ZEND_MAP_PTR_SET(ptr, val) do { \
  36. (*(ZEND_MAP_PTR(ptr))) = (val); \
  37. } while (0)
  38. # define ZEND_MAP_PTR_INIT(ptr, val) do { \
  39. ZEND_MAP_PTR(ptr) = (val); \
  40. } while (0)
  41. # define ZEND_MAP_PTR_NEW(ptr) do { \
  42. ZEND_MAP_PTR(ptr) = zend_map_ptr_new(); \
  43. } while (0)
  44. #elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
  45. # define ZEND_MAP_PTR(ptr) \
  46. ptr ## __ptr
  47. # define ZEND_MAP_PTR_DEF(type, name) \
  48. type * ZEND_MAP_PTR(name)
  49. # define ZEND_MAP_PTR_GET(ptr) \
  50. ((((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L) ? \
  51. *(void**)((char*)CG(map_ptr_base) + (uintptr_t)ZEND_MAP_PTR(ptr) - 1) : \
  52. (void*)(*(ZEND_MAP_PTR(ptr))))
  53. # define ZEND_MAP_PTR_SET(ptr, val) do { \
  54. if (((uintptr_t)ZEND_MAP_PTR(ptr)) & 1L) { \
  55. *(void**)((char*)CG(map_ptr_base) + (uintptr_t)ZEND_MAP_PTR(ptr) - 1) = (val); \
  56. } else { \
  57. *(ZEND_MAP_PTR(ptr)) = (val); \
  58. } \
  59. } while (0)
  60. # define ZEND_MAP_PTR_INIT(ptr, val) do { \
  61. ZEND_MAP_PTR(ptr) = (val); \
  62. } while (0)
  63. # define ZEND_MAP_PTR_NEW(ptr) do { \
  64. ZEND_MAP_PTR(ptr) = zend_map_ptr_new(); \
  65. } while (0)
  66. #else
  67. # error "Unknown ZEND_MAP_PTR_KIND"
  68. #endif
  69. ZEND_API void zend_map_ptr_reset(void);
  70. ZEND_API void *zend_map_ptr_new(void);
  71. ZEND_API void zend_map_ptr_extend(size_t last);
  72. #endif /* ZEND_MAP_PTR_H */
  73. /*
  74. * Local variables:
  75. * tab-width: 4
  76. * c-basic-offset: 4
  77. * indent-tabs-mode: t
  78. * End:
  79. * vim600: sw=4 ts=4 fdm=marker
  80. * vim<600: sw=4 ts=4
  81. */