php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_objects_API.h
Go to the documentation of this file.
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 +----------------------------------------------------------------------+
18*/
19
20#ifndef ZEND_OBJECTS_API_H
21#define ZEND_OBJECTS_API_H
22
23#include "zend_types.h"
24#include "zend_gc.h"
25#include "zend_alloc.h"
26#include "zend_compile.h" /* For zend_property_info */
27
28#define OBJ_BUCKET_INVALID (1<<0)
29
30#define IS_OBJ_VALID(o) (!(((uintptr_t)(o)) & OBJ_BUCKET_INVALID))
31
32#define SET_OBJ_INVALID(o) ((zend_object*)((((uintptr_t)(o)) | OBJ_BUCKET_INVALID)))
33
34#define GET_OBJ_BUCKET_NUMBER(o) (((intptr_t)(o)) >> 1)
35
36#define SET_OBJ_BUCKET_NUMBER(o, n) do { \
37 (o) = (zend_object*)((((uintptr_t)(n)) << 1) | OBJ_BUCKET_INVALID); \
38 } while (0)
39
40#define ZEND_OBJECTS_STORE_ADD_TO_FREE_LIST(h) do { \
41 SET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[(h)], EG(objects_store).free_list_head); \
42 EG(objects_store).free_list_head = (h); \
43 } while (0)
44
45#define OBJ_RELEASE(obj) zend_object_release(obj)
46
53
54/* Global store handling functions */
56ZEND_API void ZEND_FASTCALL zend_objects_store_init(zend_objects_store *objects, uint32_t init_size);
61
62/* Store API functions */
65
66/* Called when the ctor was terminated by an exception */
67static zend_always_inline void zend_object_store_ctor_failed(zend_object *obj)
68{
70}
71
73
74static zend_always_inline void zend_object_release(zend_object *obj)
75{
76 if (GC_DELREF(obj) == 0) {
78 } else if (UNEXPECTED(GC_MAY_LEAK((zend_refcounted*)obj))) {
80 }
81}
82
83static zend_always_inline size_t zend_object_properties_size(zend_class_entry *ce)
84{
85 return sizeof(zval) *
87 ((ce->ce_flags & ZEND_ACC_USE_GUARDS) ? 0 : 1));
88}
89
90/* Allocates object type and zeros it, but not the standard zend_object and properties.
91 * Standard object MUST be initialized using zend_object_std_init().
92 * Properties MUST be initialized using object_properties_init(). */
93static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_entry *ce) {
94 void *obj = emalloc(obj_size + zend_object_properties_size(ce));
95 memset(obj, 0, obj_size - sizeof(zend_object));
96 return obj;
97}
98
100
101/* Use when 'slot' was obtained directly from obj->properties_table, or when
102 * 'obj' can not be lazy. Otherwise, use zend_get_property_info_for_slot(). */
103static inline zend_property_info *zend_get_property_info_for_slot_self(zend_object *obj, zval *slot)
104{
106 intptr_t prop_num = slot - obj->properties_table;
107 ZEND_ASSERT(prop_num >= 0 && prop_num < obj->ce->default_properties_count);
108 if (table[prop_num]) {
109 return table[prop_num];
110 } else {
111 return zend_get_property_info_for_slot_slow(obj, slot);
112 }
113}
114
115static inline zend_property_info *zend_get_property_info_for_slot(zend_object *obj, zval *slot)
116{
117 if (UNEXPECTED(zend_object_is_lazy_proxy(obj))) {
119 }
121 intptr_t prop_num = slot - obj->properties_table;
122 ZEND_ASSERT(prop_num >= 0 && prop_num < obj->ce->default_properties_count);
123 if (table[prop_num]) {
124 return table[prop_num];
125 } else {
126 return zend_get_property_info_for_slot_slow(obj, slot);
127 }
128}
129
130/* Helper for cases where we're only interested in property info of typed properties. */
131static inline zend_property_info *zend_get_typed_property_info_for_slot(zend_object *obj, zval *slot)
132{
133 zend_property_info *prop_info = zend_get_property_info_for_slot(obj, slot);
134 if (prop_info && ZEND_TYPE_IS_SET(prop_info->type)) {
135 return prop_info;
136 }
137 return NULL;
138}
139
140
141#endif /* ZEND_OBJECTS_H */
memset(ptr, 0, type->size)
#define NULL
Definition gdcache.h:45
uint32_t ce_flags
Definition zend.h:156
int default_properties_count
Definition zend.h:158
struct _zend_property_info ** properties_info_table
Definition zend.h:170
zend_class_entry * ce
Definition zend_types.h:560
zval properties_table[1]
Definition zend_types.h:563
zend_object ** object_buckets
#define emalloc(size)
Definition zend_alloc.h:151
struct _zval_struct zval
struct _zend_property_info zend_property_info
#define ZEND_ACC_USE_GUARDS
#define ZEND_API
ZEND_API void ZEND_FASTCALL gc_possible_root(zend_refcounted *ref)
Definition zend_gc.c:698
#define GC_MAY_LEAK(ref)
Definition zend_gc.h:84
zend_property_info * zend_lazy_object_get_property_info_for_slot(zend_object *obj, zval *slot)
ZEND_API void ZEND_FASTCALL zend_objects_store_destroy(zend_objects_store *objects)
ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object)
ZEND_API void ZEND_FASTCALL zend_objects_store_put(zend_object *object)
ZEND_API void ZEND_FASTCALL zend_objects_store_free_object_storage(zend_objects_store *objects, bool fast_shutdown)
ZEND_API void ZEND_FASTCALL zend_objects_store_mark_destructed(zend_objects_store *objects)
ZEND_API void ZEND_FASTCALL zend_objects_store_call_destructors(zend_objects_store *objects)
ZEND_API void ZEND_FASTCALL zend_objects_store_init(zend_objects_store *objects, uint32_t init_size)
ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object)
ZEND_API ZEND_COLD zend_property_info * zend_get_property_info_for_slot_slow(zend_object *obj, zval *slot)
struct _zend_objects_store zend_objects_store
#define END_EXTERN_C()
#define zend_always_inline
#define ZEND_FASTCALL
#define ZEND_ASSERT(c)
#define ZEND_COLD
#define UNEXPECTED(condition)
#define BEGIN_EXTERN_C()
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define GC_DELREF(p)
Definition zend_types.h:710
#define IS_OBJ_DESTRUCTOR_CALLED
Definition zend_types.h:828
#define ZEND_TYPE_IS_SET(t)
Definition zend_types.h:166
struct _zend_refcounted zend_refcounted
Definition zend_types.h:95
#define GC_ADD_FLAGS(p, flags)
Definition zend_types.h:759
zend_property_info * prop_info