php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
xml_common.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: Christian Stocker <chregu@php.net> |
14 | Rob Richards <rrichards@php.net> |
15 +----------------------------------------------------------------------+
16*/
17
18#ifndef PHP_XML_COMMON_H
19#define PHP_XML_COMMON_H
20
22
23typedef libxml_doc_props *dom_doc_propsptr;
24
25typedef struct _dom_object {
26 void *ptr;
27 php_libxml_ref_obj *document;
31
32static inline dom_object *php_dom_obj_from_obj(zend_object *obj) {
33 return (dom_object*)((char*)(obj) - XtOffsetOf(dom_object, std));
34}
35
36#define Z_DOMOBJ_P(zv) php_dom_obj_from_obj(Z_OBJ_P((zv)))
37
38#ifdef PHP_WIN32
39# ifdef DOM_EXPORTS
40# define PHP_DOM_EXPORT __declspec(dllexport)
41# elif !defined(DOM_LOCAL_DEFINES) /* Allow to counteract LNK4049 warning. */
42# define PHP_DOM_EXPORT __declspec(dllimport)
43# else
44# define PHP_DOM_EXPORT
45# endif /* DOM_EXPORTS */
46#elif defined(__GNUC__) && __GNUC__ >= 4
47# define PHP_DOM_EXPORT __attribute__ ((visibility("default")))
48#elif defined(PHPAPI)
49# define PHP_DOM_EXPORT PHPAPI
50#else
51# define PHP_DOM_EXPORT
52#endif
53
58
59#define NODE_GET_OBJ(__ptr, __id, __prtype, __intern) { \
60 __intern = Z_LIBXML_NODE_P(__id); \
61 if (UNEXPECTED(__intern->node == NULL)) { \
62 php_error_docref(NULL, E_WARNING, "Couldn't fetch %s", \
63 ZSTR_VAL(Z_OBJCE_P(__zv)->name));\
64 RETURN_NULL();\
65 } \
66 __ptr = (__prtype)__intern->node->node; \
67}
68
69#define DOC_GET_OBJ(__ptr, __id, __prtype, __intern) { \
70 __intern = Z_LIBXML_NODE_P(__id); \
71 if (EXPECTED(__intern->document != NULL)) { \
72 __ptr = (__prtype)__intern->document->ptr); \
73 } \
74}
75
76#define DOM_RET_OBJ(obj, domobject) \
77 php_dom_create_object(obj, return_value, domobject)
78
79#define DOM_GET_THIS_OBJ(__ptr, __id, __prtype, __intern) \
80 __id = ZEND_THIS; \
81 DOM_GET_OBJ(__ptr, __id, __prtype, __intern);
82
85
86static zend_always_inline php_dom_private_data *php_dom_get_private_data(dom_object *intern)
87{
88 ZEND_ASSERT(intern->document != NULL);
89 return (php_dom_private_data *) intern->document->private_data;
90}
91
92static zend_always_inline xmlNodePtr php_dom_next_in_tree_order(const xmlNode *nodep, const xmlNode *basep)
93{
94 if (nodep->type == XML_ELEMENT_NODE && nodep->children) {
95 return nodep->children;
96 }
97
98 if (nodep->next) {
99 return nodep->next;
100 } else {
101 /* Go upwards, until we find a parent node with a next sibling, or until we hit the base. */
102 do {
103 nodep = nodep->parent;
104 if (nodep == basep) {
105 return NULL;
106 }
107 /* This shouldn't happen, unless there's an invalidation bug somewhere. */
108 if (UNEXPECTED(nodep == NULL)) {
109 zend_throw_error(NULL, "Current node in traversal is not in the document. Please report this as a bug in php-src.");
110 return NULL;
111 }
112 } while (nodep->next == NULL);
113 return nodep->next;
114 }
115}
116
117static zend_always_inline bool php_dom_follow_spec_doc_ref(const php_libxml_ref_obj *document)
118{
119 return document != NULL && document->class_type == PHP_LIBXML_CLASS_MODERN;
120}
121
122static zend_always_inline bool php_dom_follow_spec_intern(const dom_object *intern)
123{
124 ZEND_ASSERT(intern != NULL);
125 return php_dom_follow_spec_doc_ref(intern->document);
126}
127
128#endif
PHP_DOM_EXPORT zend_class_entry * dom_node_class_entry
#define NULL
Definition gdcache.h:45
const XML_ELEMENT_NODE
HashTable * prop_handler
Definition xml_common.h:28
void * ptr
Definition xml_common.h:26
zend_object std
Definition xml_common.h:29
php_libxml_ref_obj * document
Definition xml_common.h:27
#define PHP_DOM_EXPORT
Definition xml_common.h:51
PHP_DOM_EXPORT xmlNodePtr dom_object_get_node(dom_object *obj)
struct _dom_object dom_object
PHP_DOM_EXPORT dom_object * php_dom_object_get_data(xmlNodePtr obj)
libxml_doc_props * dom_doc_propsptr
Definition xml_common.h:23
PHP_DOM_EXPORT bool php_dom_create_object(xmlNodePtr obj, zval *return_value, dom_object *domobj)
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
struct _zval_struct zval
#define zend_always_inline
#define XtOffsetOf(s_type, field)
#define ZEND_ASSERT(c)
#define UNEXPECTED(condition)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
struct _zend_array HashTable
Definition zend_types.h:386
zval * return_value