Skip to content

Use uint32_t for the number of nodes #11371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ PHP 8.3 INTERNALS UPGRADE NOTES
the base node of the node list. This function also no longer accepts -1 as the index argument.
- The function dom_namednode_iter() has additional arguments to avoid recomputing the length of
the strings.
- The functions dom_parent_node_prepend(), dom_parent_node_append(), dom_parent_node_after(), and
dom_parent_node_before() now use an uint32_t argument for the number of nodes instead of int.

g. ext/libxml
- Two new functions: php_libxml_invalidate_node_list_cache_from_doc() and
Expand Down
6 changes: 3 additions & 3 deletions ext/dom/characterdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ PHP_METHOD(DOMCharacterData, remove)

PHP_METHOD(DOMCharacterData, after)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand All @@ -381,7 +381,7 @@ PHP_METHOD(DOMCharacterData, after)

PHP_METHOD(DOMCharacterData, before)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand All @@ -398,7 +398,7 @@ PHP_METHOD(DOMCharacterData, before)

PHP_METHOD(DOMCharacterData, replaceWith)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand Down
4 changes: 2 additions & 2 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMDocument, append)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand All @@ -2125,7 +2125,7 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMDocument, prepend)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand Down
4 changes: 2 additions & 2 deletions ext/dom/documentfragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMDocumentFragment, append)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand All @@ -156,7 +156,7 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMDocumentFragment, prepend)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand Down
10 changes: 5 additions & 5 deletions ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ PHP_METHOD(DOMElement, remove)

PHP_METHOD(DOMElement, after)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand All @@ -1172,7 +1172,7 @@ PHP_METHOD(DOMElement, after)

PHP_METHOD(DOMElement, before)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand All @@ -1192,7 +1192,7 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMElement, append)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand All @@ -1213,7 +1213,7 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMElement, prepend)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand All @@ -1234,7 +1234,7 @@ Since: DOM Living Standard (DOM4)
*/
PHP_METHOD(DOMElement, replaceWith)
{
int argc;
uint32_t argc;
zval *args, *id;
dom_object *intern;
xmlNode *context;
Expand Down
23 changes: 11 additions & 12 deletions ext/dom/parentnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ int dom_parent_node_child_element_count(dom_object *obj, zval *retval)
}
/* }}} */

static bool dom_is_node_in_list(const zval *nodes, int nodesc, const xmlNodePtr node_to_find)
static bool dom_is_node_in_list(const zval *nodes, uint32_t nodesc, const xmlNodePtr node_to_find)
{
for (int i = 0; i < nodesc; i++) {
for (uint32_t i = 0; i < nodesc; i++) {
if (Z_TYPE(nodes[i]) == IS_OBJECT) {
const zend_class_entry *ce = Z_OBJCE(nodes[i]);

Expand All @@ -141,9 +141,8 @@ static bool dom_is_node_in_list(const zval *nodes, int nodesc, const xmlNodePtr
return false;
}

xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNode, zval *nodes, int nodesc)
xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNode, zval *nodes, uint32_t nodesc)
{
int i;
xmlDoc *documentNode;
xmlNode *fragment;
xmlNode *newNode;
Expand All @@ -170,7 +169,7 @@ xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNod

stricterror = dom_get_strict_error(document);

for (i = 0; i < nodesc; i++) {
for (uint32_t i = 0; i < nodesc; i++) {
if (Z_TYPE(nodes[i]) == IS_OBJECT) {
ce = Z_OBJCE(nodes[i]);

Expand Down Expand Up @@ -253,9 +252,9 @@ static void dom_fragment_assign_parent_node(xmlNodePtr parentNode, xmlNodePtr fr
fragment->last = NULL;
}

static zend_result dom_hierarchy_node_list(xmlNodePtr parentNode, zval *nodes, int nodesc)
static zend_result dom_hierarchy_node_list(xmlNodePtr parentNode, zval *nodes, uint32_t nodesc)
{
for (int i = 0; i < nodesc; i++) {
for (uint32_t i = 0; i < nodesc; i++) {
if (Z_TYPE(nodes[i]) == IS_OBJECT) {
const zend_class_entry *ce = Z_OBJCE(nodes[i]);

Expand All @@ -270,7 +269,7 @@ static zend_result dom_hierarchy_node_list(xmlNodePtr parentNode, zval *nodes, i
return SUCCESS;
}

void dom_parent_node_append(dom_object *context, zval *nodes, int nodesc)
void dom_parent_node_append(dom_object *context, zval *nodes, uint32_t nodesc)
{
xmlNode *parentNode = dom_object_get_node(context);
xmlNodePtr newchild, prevsib;
Expand Down Expand Up @@ -311,7 +310,7 @@ void dom_parent_node_append(dom_object *context, zval *nodes, int nodesc)
xmlFree(fragment);
}

void dom_parent_node_prepend(dom_object *context, zval *nodes, int nodesc)
void dom_parent_node_prepend(dom_object *context, zval *nodes, uint32_t nodesc)
{
xmlNode *parentNode = dom_object_get_node(context);

Expand Down Expand Up @@ -379,7 +378,7 @@ static void dom_pre_insert(xmlNodePtr insertion_point, xmlNodePtr parentNode, xm
}
}

void dom_parent_node_after(dom_object *context, zval *nodes, int nodesc)
void dom_parent_node_after(dom_object *context, zval *nodes, uint32_t nodesc)
{
/* Spec link: https://dom.spec.whatwg.org/#dom-childnode-after */

Expand Down Expand Up @@ -432,7 +431,7 @@ void dom_parent_node_after(dom_object *context, zval *nodes, int nodesc)
xmlFree(fragment);
}

void dom_parent_node_before(dom_object *context, zval *nodes, int nodesc)
void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc)
{
/* Spec link: https://dom.spec.whatwg.org/#dom-childnode-before */

Expand Down Expand Up @@ -544,7 +543,7 @@ void dom_child_node_remove(dom_object *context)
php_dom_throw_error(NOT_FOUND_ERR, stricterror);
}

void dom_child_replace_with(dom_object *context, zval *nodes, int nodesc)
void dom_child_replace_with(dom_object *context, zval *nodes, uint32_t nodesc)
{
xmlNodePtr child = dom_object_get_node(context);
xmlNodePtr parentNode = child->parent;
Expand Down
10 changes: 5 additions & 5 deletions ext/dom/php_dom.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ xmlNode *php_dom_libxml_notation_iter(xmlHashTable *ht, int index);
zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object, int by_ref);
void dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry *basece, zend_class_entry *ce);

void dom_parent_node_prepend(dom_object *context, zval *nodes, int nodesc);
void dom_parent_node_append(dom_object *context, zval *nodes, int nodesc);
void dom_parent_node_after(dom_object *context, zval *nodes, int nodesc);
void dom_parent_node_before(dom_object *context, zval *nodes, int nodesc);
void dom_parent_node_prepend(dom_object *context, zval *nodes, uint32_t nodesc);
void dom_parent_node_append(dom_object *context, zval *nodes, uint32_t nodesc);
void dom_parent_node_after(dom_object *context, zval *nodes, uint32_t nodesc);
void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc);
void dom_child_node_remove(dom_object *context);
void dom_child_replace_with(dom_object *context, zval *nodes, int nodesc);
void dom_child_replace_with(dom_object *context, zval *nodes, uint32_t nodesc);

#define DOM_GET_OBJ(__ptr, __id, __prtype, __intern) { \
__intern = Z_DOMOBJ_P(__id); \
Expand Down