php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_weakrefs.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 2.00 of the Zend license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | http://www.zend.com/license/2_00.txt. |
9 | If you did not receive a copy of the Zend license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@zend.com so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: krakjoe@php.net |
14 +----------------------------------------------------------------------+
15*/
16
17#ifndef ZEND_WEAKREFS_H
18#define ZEND_WEAKREFS_H
19
20#include "zend_alloc.h"
21
23
25
27
28void zend_weakrefs_init(void);
29void zend_weakrefs_shutdown(void);
30
32
35static zend_always_inline void *zend_weakrefs_hash_add_ptr(HashTable *ht, zend_object *key, void *ptr) {
36 zval tmp, *zv;
37 ZVAL_PTR(&tmp, ptr);
38 if ((zv = zend_weakrefs_hash_add(ht, key, &tmp))) {
39 return Z_PTR_P(zv);
40 } else {
41 return NULL;
42 }
43}
44
45/* Because php uses the raw numbers as a hash function, raw pointers will lead to hash collisions.
46 * We have a guarantee that the lowest ZEND_MM_ALIGNED_OFFSET_LOG2 bits of a pointer are zero.
47 *
48 * E.g. On most 64-bit platforms, pointers are aligned to 8 bytes, so the least significant 3 bits are always 0 and can be discarded.
49 *
50 * NOTE: This function is only used for EG(weakrefs) and zend_weakmap->ht.
51 * It is not used for the HashTable instances associated with ZEND_WEAKREF_TAG_HT tags (created in zend_weakref_register, which uses ZEND_WEAKREF_ENCODE instead).
52 * The ZEND_WEAKREF_TAG_HT instances are used to disambiguate between multiple weak references to the same zend_object.
53 */
54static zend_always_inline zend_ulong zend_object_to_weakref_key(const zend_object *object)
55{
56 ZEND_ASSERT(((uintptr_t)object) % ZEND_MM_ALIGNMENT == 0);
57 return ((uintptr_t) object) >> ZEND_MM_ALIGNMENT_LOG2;
58}
59
60static zend_always_inline zend_object *zend_weakref_key_to_object(zend_ulong key)
61{
62 return (zend_object *) (((uintptr_t) key) << ZEND_MM_ALIGNMENT_LOG2);
63}
64
65HashTable *zend_weakmap_get_gc(zend_object *object, zval **table, int *n);
70
72
73#endif
74
zval * zv
Definition ffi.c:3975
zend_long n
Definition ffi.c:4979
void * ptr
Definition ffi.c:3814
HashTable * ht
Definition ffi.c:4838
#define NULL
Definition gdcache.h:45
unsigned char key[REFLECTION_KEY_LEN]
struct _zval_struct zval
#define ZEND_API
uint32_t zend_ulong
Definition zend_long.h:43
#define END_EXTERN_C()
#define zend_always_inline
#define ZEND_ASSERT(c)
#define BEGIN_EXTERN_C()
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
struct _zend_array HashTable
Definition zend_types.h:386
#define Z_PTR_P(zval_p)
#define ZVAL_PTR(z, p)
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
ZEND_API zend_result zend_weakrefs_hash_del(HashTable *ht, zend_object *key)
void zend_weakrefs_notify(zend_object *object)
ZEND_API zval * zend_weakrefs_hash_add(HashTable *ht, zend_object *key, zval *pData)
void zend_weakrefs_shutdown(void)
void zend_register_weakref_ce(void)
void zend_weakrefs_init(void)
zend_class_entry * zend_ce_weakref
HashTable * zend_weakmap_get_gc(zend_object *object, zval **table, int *n)
HashTable * zend_weakmap_get_object_entry_gc(zend_object *object, zval **table, int *n)
ZEND_API zval * zend_weakrefs_hash_add(HashTable *ht, zend_object *key, zval *pData)
HashTable * zend_weakmap_get_key_entry_gc(zend_object *object, zval **table, int *n)
HashTable * zend_weakmap_get_object_key_entry_gc(zend_object *object, zval **table, int *n)
HashTable * zend_weakmap_get_entry_gc(zend_object *object, zval **table, int *n)