zend_variables.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 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)
  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. ZEND_API void zval_add_ref(zval *p);
  74. END_EXTERN_C()
  75. #define ZVAL_PTR_DTOR zval_ptr_dtor
  76. #define ZVAL_INTERNAL_PTR_DTOR zval_internal_ptr_dtor
  77. #endif