zend_variables.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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: Andi Gutmans <andi@php.net> |
  16. | Zeev Suraski <zeev@php.net> |
  17. | Dmitry Stogov <dmitry@php.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. #ifndef ZEND_VARIABLES_H
  21. #define ZEND_VARIABLES_H
  22. #include "zend_types.h"
  23. #include "zend_gc.h"
  24. BEGIN_EXTERN_C()
  25. ZEND_API void ZEND_FASTCALL rc_dtor_func(zend_refcounted *p);
  26. ZEND_API void ZEND_FASTCALL zval_copy_ctor_func(zval *zvalue);
  27. static zend_always_inline void zval_ptr_dtor_nogc(zval *zval_ptr)
  28. {
  29. if (Z_REFCOUNTED_P(zval_ptr) && !Z_DELREF_P(zval_ptr)) {
  30. rc_dtor_func(Z_COUNTED_P(zval_ptr));
  31. }
  32. }
  33. static zend_always_inline void i_zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC)
  34. {
  35. if (Z_REFCOUNTED_P(zval_ptr)) {
  36. zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
  37. if (!GC_DELREF(ref)) {
  38. rc_dtor_func(ref);
  39. } else {
  40. gc_check_possible_root(ref);
  41. }
  42. }
  43. }
  44. static zend_always_inline void zval_copy_ctor(zval *zvalue)
  45. {
  46. if (Z_TYPE_P(zvalue) == IS_ARRAY) {
  47. ZVAL_ARR(zvalue, zend_array_dup(Z_ARR_P(zvalue)));
  48. } else if (Z_REFCOUNTED_P(zvalue)) {
  49. Z_ADDREF_P(zvalue);
  50. }
  51. }
  52. static zend_always_inline void zval_opt_copy_ctor(zval *zvalue)
  53. {
  54. if (Z_OPT_TYPE_P(zvalue) == IS_ARRAY) {
  55. ZVAL_ARR(zvalue, zend_array_dup(Z_ARR_P(zvalue)));
  56. } else if (Z_OPT_REFCOUNTED_P(zvalue)) {
  57. Z_ADDREF_P(zvalue);
  58. }
  59. }
  60. static zend_always_inline void zval_ptr_dtor_str(zval *zval_ptr)
  61. {
  62. if (Z_REFCOUNTED_P(zval_ptr) && !Z_DELREF_P(zval_ptr)) {
  63. ZEND_ASSERT(Z_TYPE_P(zval_ptr) == IS_STRING);
  64. ZEND_ASSERT(!ZSTR_IS_INTERNED(Z_STR_P(zval_ptr)));
  65. ZEND_ASSERT(!(GC_FLAGS(Z_STR_P(zval_ptr)) & IS_STR_PERSISTENT));
  66. efree(Z_STR_P(zval_ptr));
  67. }
  68. }
  69. ZEND_API void zval_ptr_dtor(zval *zval_ptr);
  70. ZEND_API void zval_internal_ptr_dtor(zval *zvalue);
  71. /* Kept for compatibility */
  72. #define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue)
  73. #define zval_internal_dtor(zvalue) zval_internal_ptr_dtor(zvalue)
  74. #define zval_dtor_func rc_dtor_func
  75. #define zval_ptr_dtor_wrapper zval_ptr_dtor
  76. #define zval_internal_ptr_dtor_wrapper zval_internal_ptr_dtor
  77. ZEND_API void zval_add_ref(zval *p);
  78. END_EXTERN_C()
  79. #define ZVAL_PTR_DTOR zval_ptr_dtor
  80. #define ZVAL_INTERNAL_PTR_DTOR zval_internal_ptr_dtor
  81. #endif
  82. /*
  83. * Local variables:
  84. * tab-width: 4
  85. * c-basic-offset: 4
  86. * indent-tabs-mode: t
  87. * End:
  88. * vim600: sw=4 ts=4 fdm=marker
  89. * vim<600: sw=4 ts=4
  90. */