php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
internal_helpers.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 3.01 of the PHP 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 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Niels Dossche <nielsdos@php.net> |
14 +----------------------------------------------------------------------+
15*/
16
17#ifndef DOM_INTERNAL_HELPERS
18#define DOM_INTERNAL_HELPERS
19
20/* We're using the type flags of the zval to store an extra flag. */
21#define DOM_Z_OWNED(z, v) ZVAL_PTR(z, (void *) (v))
22#define DOM_Z_UNOWNED(z, v) ZVAL_INDIRECT(z, (void *) (v))
23#define DOM_Z_IS_OWNED(z) (Z_TYPE_P(z) == IS_PTR)
24
25#ifdef DOM_CE_H
26
27#define DOM_DEF_GET_CE_FUNC(name) \
28static zend_always_inline zend_class_entry *dom_get_##name##_ce(bool modern) \
29{ \
30 return modern ? dom_modern_##name##_class_entry : dom_##name##_class_entry; \
31}
32
33static zend_always_inline zend_class_entry *dom_get_html_document_ce(bool modern)
34{
36}
37
38static zend_always_inline zend_class_entry *dom_get_xml_document_ce(bool modern)
39{
41}
42
43static zend_always_inline zend_class_entry *dom_get_dtd_namednodemap_ce(bool modern)
44{
46}
47
48DOM_DEF_GET_CE_FUNC(node)
49DOM_DEF_GET_CE_FUNC(documenttype)
50DOM_DEF_GET_CE_FUNC(attr)
51DOM_DEF_GET_CE_FUNC(entity)
52DOM_DEF_GET_CE_FUNC(entityreference)
53DOM_DEF_GET_CE_FUNC(processinginstruction)
54DOM_DEF_GET_CE_FUNC(comment)
55DOM_DEF_GET_CE_FUNC(text)
56DOM_DEF_GET_CE_FUNC(cdatasection)
57DOM_DEF_GET_CE_FUNC(notation)
58DOM_DEF_GET_CE_FUNC(documentfragment)
59DOM_DEF_GET_CE_FUNC(namednodemap)
60DOM_DEF_GET_CE_FUNC(nodelist)
61DOM_DEF_GET_CE_FUNC(domimplementation)
62
63#endif
64
65static zend_always_inline size_t dom_minimum_modification_nr_since_parsing(php_libxml_ref_obj *doc_ptr)
66{
67 /* For old-style DOM, we need a "new DOMDocument" + a load, so the minimum modification nr is 2.
68 * For new-style DOM, we need only to call a named constructor, so the minimum modification nr is 1. */
69 return doc_ptr->class_type == PHP_LIBXML_CLASS_MODERN ? 1 : 2;
70}
71
72static zend_always_inline void dom_mark_document_cache_as_modified_since_parsing(php_libxml_ref_obj *doc_ptr)
73{
74 if (doc_ptr) {
75 doc_ptr->cache_tag.modification_nr = MAX(dom_minimum_modification_nr_since_parsing(doc_ptr) + 1,
76 doc_ptr->cache_tag.modification_nr);
77 }
78}
79
80/* Marks the ID cache as potentially stale */
81static zend_always_inline void dom_mark_ids_modified(php_libxml_ref_obj *doc_ptr)
82{
83 /* Although this is currently a wrapper function, it's best to abstract the actual implementation away. */
84 dom_mark_document_cache_as_modified_since_parsing(doc_ptr);
85}
86
87static zend_always_inline bool dom_is_document_cache_modified_since_parsing(php_libxml_ref_obj *doc_ptr)
88{
89 return !doc_ptr || doc_ptr->cache_tag.modification_nr > dom_minimum_modification_nr_since_parsing(doc_ptr);
90}
91
92static zend_always_inline zend_long dom_mangle_pointer_for_key(const void *ptr)
93{
94 zend_ulong value = (zend_ulong) (uintptr_t) ptr;
95 /* Rotate 3/4 bits for better hash distribution because the low 3/4 bits are normally 0. */
96 const size_t rol_amount = (SIZEOF_ZEND_LONG == 8) ? 4 : 3;
97 return (value >> rol_amount) | (value << (sizeof(value) * 8 - rol_amount));
98}
99
100#endif
PHP_DOM_EXPORT zend_class_entry * dom_html_document_class_entry
PHP_DOM_EXPORT zend_class_entry * dom_modern_dtd_namednodemap_class_entry
PHP_DOM_EXPORT zend_class_entry * dom_xml_document_class_entry
PHP_DOM_EXPORT zend_class_entry * dom_namednodemap_class_entry
PHP_DOM_EXPORT zend_class_entry * dom_document_class_entry
void * ptr
Definition ffi.c:3814
new_type attr
Definition ffi.c:4364
unsigned const char * text
Definition php_ffi.h:53
int32_t zend_long
Definition zend_long.h:42
uint32_t zend_ulong
Definition zend_long.h:43
#define SIZEOF_ZEND_LONG
Definition zend_long.h:50
#define zend_always_inline
#define MAX(a, b)
struct _zend_class_entry zend_class_entry
value