xref: /PHP-7.2/Zend/zend_objects_API.h (revision 7a7ec01a)
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@zend.com>                                |
16    |          Zeev Suraski <zeev@zend.com>                                |
17    +----------------------------------------------------------------------+
18 */
19 
20 /* $Id$ */
21 
22 #ifndef ZEND_OBJECTS_API_H
23 #define ZEND_OBJECTS_API_H
24 
25 #include "zend.h"
26 #include "zend_compile.h"
27 
28 #define OBJ_BUCKET_INVALID			(1<<0)
29 
30 #define IS_OBJ_VALID(o)				(!(((zend_uintptr_t)(o)) & OBJ_BUCKET_INVALID))
31 
32 #define SET_OBJ_INVALID(o)			((zend_object*)((((zend_uintptr_t)(o)) | OBJ_BUCKET_INVALID)))
33 
34 #define GET_OBJ_BUCKET_NUMBER(o)	(((zend_intptr_t)(o)) >> 1)
35 
36 #define SET_OBJ_BUCKET_NUMBER(o, n)	do { \
37 		(o) = (zend_object*)((((zend_uintptr_t)(n)) << 1) | OBJ_BUCKET_INVALID); \
38 	} while (0)
39 
40 
41 #define OBJ_RELEASE(obj) zend_object_release(obj)
42 
43 typedef struct _zend_objects_store {
44 	zend_object **object_buckets;
45 	uint32_t top;
46 	uint32_t size;
47 	int free_list_head;
48 } zend_objects_store;
49 
50 /* Global store handling functions */
51 BEGIN_EXTERN_C()
52 ZEND_API void zend_objects_store_init(zend_objects_store *objects, uint32_t init_size);
53 ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects);
54 ZEND_API void zend_objects_store_mark_destructed(zend_objects_store *objects);
55 ZEND_API void zend_objects_store_free_object_storage(zend_objects_store *objects, zend_bool fast_shutdown);
56 ZEND_API void zend_objects_store_destroy(zend_objects_store *objects);
57 
58 /* Store API functions */
59 ZEND_API void zend_objects_store_put(zend_object *object);
60 ZEND_API void zend_objects_store_del(zend_object *object);
61 
62 /* Called when the ctor was terminated by an exception */
zend_object_store_ctor_failed(zend_object * obj)63 static zend_always_inline void zend_object_store_ctor_failed(zend_object *obj)
64 {
65 	GC_FLAGS(obj) |= IS_OBJ_DESTRUCTOR_CALLED;
66 }
67 
68 #define ZEND_OBJECTS_STORE_HANDLERS 0, zend_object_std_dtor, zend_objects_destroy_object, zend_objects_clone_obj
69 
70 ZEND_API zend_object_handlers *zend_get_std_object_handlers(void);
END_EXTERN_C()71 END_EXTERN_C()
72 
73 static zend_always_inline void zend_object_release(zend_object *obj)
74 {
75 	if (--GC_REFCOUNT(obj) == 0) {
76 		zend_objects_store_del(obj);
77 	} else if (UNEXPECTED(GC_MAY_LEAK((zend_refcounted*)obj))) {
78 		gc_possible_root((zend_refcounted*)obj);
79 	}
80 }
81 
zend_object_properties_size(zend_class_entry * ce)82 static zend_always_inline size_t zend_object_properties_size(zend_class_entry *ce)
83 {
84 	return sizeof(zval) *
85 		(ce->default_properties_count -
86 			((ce->ce_flags & ZEND_ACC_USE_GUARDS) ? 0 : 1));
87 }
88 
89 #endif /* ZEND_OBJECTS_H */
90 
91 /*
92  * Local variables:
93  * tab-width: 4
94  * c-basic-offset: 4
95  * indent-tabs-mode: t
96  * End:
97  * vim600: sw=4 ts=4 fdm=marker
98  * vim<600: sw=4 ts=4
99  */
100