Coverage Report

Created: 2025-06-13 06:43

/src/php-src/Zend/zend_weakrefs.h
Line
Count
Source (jump to first uncovered line)
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
22
BEGIN_EXTERN_C()
23
24
extern ZEND_API zend_class_entry *zend_ce_weakref;
25
26
void zend_register_weakref_ce(void);
27
28
void zend_weakrefs_init(void);
29
void zend_weakrefs_shutdown(void);
30
31
ZEND_API void zend_weakrefs_notify(zend_object *object);
32
33
ZEND_API zval *zend_weakrefs_hash_add(HashTable *ht, zend_object *key, zval *pData);
34
ZEND_API zend_result zend_weakrefs_hash_del(HashTable *ht, zend_object *key);
35
0
static zend_always_inline void *zend_weakrefs_hash_add_ptr(HashTable *ht, zend_object *key, void *ptr) {
36
0
  zval tmp, *zv;
37
0
  ZVAL_PTR(&tmp, ptr);
38
0
  if ((zv = zend_weakrefs_hash_add(ht, key, &tmp))) {
39
0
    return Z_PTR_P(zv);
40
0
  } else {
41
0
    return NULL;
42
0
  }
43
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
44
ZEND_API void zend_weakrefs_hash_clean(HashTable *ht);
45
0
static zend_always_inline void zend_weakrefs_hash_destroy(HashTable *ht) {
46
0
  zend_weakrefs_hash_clean(ht);
47
0
  ZEND_ASSERT(zend_hash_num_elements(ht) == 0);
48
0
  zend_hash_destroy(ht);
49
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
50
51
/* Because php uses the raw numbers as a hash function, raw pointers will lead to hash collisions.
52
 * We have a guarantee that the lowest ZEND_MM_ALIGNED_OFFSET_LOG2 bits of a pointer are zero.
53
 *
54
 * 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.
55
 *
56
 * NOTE: This function is only used for EG(weakrefs) and zend_weakmap->ht.
57
 * 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).
58
 * The ZEND_WEAKREF_TAG_HT instances are used to disambiguate between multiple weak references to the same zend_object.
59
 */
60
static zend_always_inline zend_ulong zend_object_to_weakref_key(const zend_object *object)
61
6.60k
{
62
6.60k
  ZEND_ASSERT(((uintptr_t)object) % ZEND_MM_ALIGNMENT == 0);
63
6.60k
  return ((uintptr_t) object) >> ZEND_MM_ALIGNMENT_LOG2;
64
6.60k
}
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
zend_weakrefs.c:zend_object_to_weakref_key
Line
Count
Source
61
6.60k
{
62
6.60k
  ZEND_ASSERT(((uintptr_t)object) % ZEND_MM_ALIGNMENT == 0);
63
6.60k
  return ((uintptr_t) object) >> ZEND_MM_ALIGNMENT_LOG2;
64
6.60k
}
65
66
static zend_always_inline zend_object *zend_weakref_key_to_object(zend_ulong key)
67
1.23k
{
68
1.23k
  return (zend_object *) (((uintptr_t) key) << ZEND_MM_ALIGNMENT_LOG2);
69
1.23k
}
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
zend_weakrefs.c:zend_weakref_key_to_object
Line
Count
Source
67
1.23k
{
68
1.23k
  return (zend_object *) (((uintptr_t) key) << ZEND_MM_ALIGNMENT_LOG2);
69
1.23k
}
70
71
HashTable *zend_weakmap_get_gc(zend_object *object, zval **table, int *n);
72
HashTable *zend_weakmap_get_key_entry_gc(zend_object *object, zval **table, int *n);
73
HashTable *zend_weakmap_get_entry_gc(zend_object *object, zval **table, int *n);
74
HashTable *zend_weakmap_get_object_key_entry_gc(zend_object *object, zval **table, int *n);
75
HashTable *zend_weakmap_get_object_entry_gc(zend_object *object, zval **table, int *n);
76
77
END_EXTERN_C()
78
79
#endif
80