1 /*
2 +----------------------------------------------------------------------+
3 | Zend Engine |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998-2017 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_destroy(zend_objects_store *objects);
56
57 /* Store API functions */
58 ZEND_API void zend_objects_store_put(zend_object *object);
59 ZEND_API void zend_objects_store_del(zend_object *object);
60 ZEND_API void zend_objects_store_free(zend_object *object);
61
62 /* See comment in zend_objects_API.c before you use this */
63 ZEND_API void zend_object_store_set_object(zval *zobject, zend_object *object);
64 ZEND_API void zend_object_store_ctor_failed(zend_object *object);
65
66 ZEND_API void zend_objects_store_free_object_storage(zend_objects_store *objects);
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 *zend_object_create_proxy(zval *object, zval *member);
71
72 ZEND_API zend_object_handlers *zend_get_std_object_handlers(void);
END_EXTERN_C()73 END_EXTERN_C()
74
75 static zend_always_inline void zend_object_release(zend_object *obj)
76 {
77 if (--GC_REFCOUNT(obj) == 0) {
78 zend_objects_store_del(obj);
79 } else if (UNEXPECTED(!GC_INFO(obj))) {
80 gc_possible_root((zend_refcounted*)obj);
81 }
82 }
83
zend_object_properties_size(zend_class_entry * ce)84 static zend_always_inline size_t zend_object_properties_size(zend_class_entry *ce)
85 {
86 return sizeof(zval) *
87 (ce->default_properties_count -
88 ((ce->ce_flags & ZEND_ACC_USE_GUARDS) ? 0 : 1));
89 }
90
91 #endif /* ZEND_OBJECTS_H */
92
93 /*
94 * Local variables:
95 * tab-width: 4
96 * c-basic-offset: 4
97 * indent-tabs-mode: t
98 * End:
99 */
100