Coverage Report

Created: 2026-06-02 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/Zend/zend_weakrefs.h
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright © The PHP Group and Contributors.                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to the Modified BSD License that is      |
6
   | bundled with this package in the file LICENSE, and is available      |
7
   | through the World Wide Web at <https://www.php.net/license/>.        |
8
   |                                                                      |
9
   | SPDX-License-Identifier: BSD-3-Clause                                |
10
   +----------------------------------------------------------------------+
11
   | Authors: krakjoe@php.net                                             |
12
   +----------------------------------------------------------------------+
13
*/
14
15
#ifndef ZEND_WEAKREFS_H
16
#define ZEND_WEAKREFS_H
17
18
#include "zend_alloc.h"
19
20
BEGIN_EXTERN_C()
21
22
extern ZEND_API zend_class_entry *zend_ce_weakref;
23
24
void zend_register_weakref_ce(void);
25
26
void zend_weakrefs_init(void);
27
void zend_weakrefs_shutdown(void);
28
29
ZEND_API void zend_weakrefs_notify(zend_object *object);
30
31
ZEND_API zval *zend_weakrefs_hash_add(HashTable *ht, zend_object *key, zval *pData);
32
ZEND_API zend_result zend_weakrefs_hash_del(HashTable *ht, zend_object *key);
33
0
static zend_always_inline void *zend_weakrefs_hash_add_ptr(HashTable *ht, zend_object *key, void *ptr) {
34
0
  zval tmp, *zv;
35
0
  ZVAL_PTR(&tmp, ptr);
36
0
  if ((zv = zend_weakrefs_hash_add(ht, key, &tmp))) {
37
0
    return Z_PTR_P(zv);
38
0
  } else {
39
0
    return NULL;
40
0
  }
41
0
}
Unexecuted instantiation: zend_default_classes.c:zend_weakrefs_hash_add_ptr
Unexecuted instantiation: zend_execute_API.c:zend_weakrefs_hash_add_ptr
Unexecuted instantiation: zend_gc.c:zend_weakrefs_hash_add_ptr
Unexecuted instantiation: zend_objects.c:zend_weakrefs_hash_add_ptr
Unexecuted instantiation: zend_weakrefs.c:zend_weakrefs_hash_add_ptr
42
ZEND_API void zend_weakrefs_hash_clean(HashTable *ht);
43
0
static zend_always_inline void zend_weakrefs_hash_destroy(HashTable *ht) {
44
0
  zend_weakrefs_hash_clean(ht);
45
0
  ZEND_ASSERT(zend_hash_num_elements(ht) == 0);
46
0
  zend_hash_destroy(ht);
47
0
}
Unexecuted instantiation: zend_default_classes.c:zend_weakrefs_hash_destroy
Unexecuted instantiation: zend_execute_API.c:zend_weakrefs_hash_destroy
Unexecuted instantiation: zend_gc.c:zend_weakrefs_hash_destroy
Unexecuted instantiation: zend_objects.c:zend_weakrefs_hash_destroy
Unexecuted instantiation: zend_weakrefs.c:zend_weakrefs_hash_destroy
48
49
/* Because php uses the raw numbers as a hash function, raw pointers will lead to hash collisions.
50
 * We have a guarantee that the lowest ZEND_MM_ALIGNED_OFFSET_LOG2 bits of a pointer are zero.
51
 *
52
 * 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.
53
 *
54
 * NOTE: This function is only used for EG(weakrefs) and zend_weakmap->ht.
55
 * 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).
56
 * The ZEND_WEAKREF_TAG_HT instances are used to disambiguate between multiple weak references to the same zend_object.
57
 */
58
static zend_always_inline zend_ulong zend_object_to_weakref_key(const zend_object *object)
59
0
{
60
0
  ZEND_ASSERT(((uintptr_t)object) % ZEND_MM_ALIGNMENT == 0);
61
0
  return ((uintptr_t) object) >> ZEND_MM_ALIGNMENT_LOG2;
62
0
}
Unexecuted instantiation: zend_default_classes.c:zend_object_to_weakref_key
Unexecuted instantiation: zend_execute_API.c:zend_object_to_weakref_key
Unexecuted instantiation: zend_gc.c:zend_object_to_weakref_key
Unexecuted instantiation: zend_objects.c:zend_object_to_weakref_key
Unexecuted instantiation: zend_weakrefs.c:zend_object_to_weakref_key
63
64
static zend_always_inline zend_object *zend_weakref_key_to_object(zend_ulong key)
65
0
{
66
0
  return (zend_object *) (((uintptr_t) key) << ZEND_MM_ALIGNMENT_LOG2);
67
0
}
Unexecuted instantiation: zend_default_classes.c:zend_weakref_key_to_object
Unexecuted instantiation: zend_execute_API.c:zend_weakref_key_to_object
Unexecuted instantiation: zend_gc.c:zend_weakref_key_to_object
Unexecuted instantiation: zend_objects.c:zend_weakref_key_to_object
Unexecuted instantiation: zend_weakrefs.c:zend_weakref_key_to_object
68
69
HashTable *zend_weakmap_get_gc(zend_object *object, zval **table, int *n);
70
HashTable *zend_weakmap_get_key_entry_gc(zend_object *object, zval **table, int *n);
71
HashTable *zend_weakmap_get_entry_gc(zend_object *object, zval **table, int *n);
72
HashTable *zend_weakmap_get_object_key_entry_gc(zend_object *object, zval **table, int *n);
73
HashTable *zend_weakmap_get_object_entry_gc(zend_object *object, zval **table, int *n);
74
75
END_EXTERN_C()
76
77
#endif
78