Skip to content

Commit 6366da4

Browse files
authored
Use unsigned int for the reference count APIs in ext/libxml (#16706)
Also removes impossible conditions.
1 parent 3942972 commit 6366da4

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ PHP 8.5 INTERNALS UPGRADE NOTES
2222
3. Module changes
2323
========================
2424

25+
- ext/libxml
26+
. The refcount APIs now return an `unsigned int` instead of an `int`.
27+
2528
========================
2629
4. OpCode changes
2730
========================

ext/dom/document.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,7 @@ PHP_METHOD(DOMDocument, __construct)
12831283
}
12841284
}
12851285
intern->document = NULL;
1286-
if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp) == -1) {
1287-
/* docp is always non-null so php_libxml_increment_doc_ref() never returns -1 */
1288-
ZEND_UNREACHABLE();
1289-
}
1286+
php_libxml_increment_doc_ref((php_libxml_node_object *)intern, docp);
12901287
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern);
12911288
}
12921289
/* }}} end DOMDocument::__construct */
@@ -1495,9 +1492,7 @@ static void php_dom_finish_loading_document(zval *this, zval *return_value, xmlD
14951492
}
14961493
}
14971494
intern->document = NULL;
1498-
if (php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc) == -1) {
1499-
RETURN_FALSE;
1500-
}
1495+
php_libxml_increment_doc_ref((php_libxml_node_object *)intern, newdoc);
15011496
intern->document->doc_props = doc_prop;
15021497
intern->document->class_type = class_type;
15031498
}

ext/libxml/libxml.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,9 +1291,9 @@ PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object)
12911291
return node;
12921292
}
12931293

1294-
PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object, xmlNodePtr node, void *private_data)
1294+
PHP_LIBXML_API unsigned int php_libxml_increment_node_ptr(php_libxml_node_object *object, xmlNodePtr node, void *private_data)
12951295
{
1296-
int ret_refcount = -1;
1296+
unsigned int ret_refcount = 0;
12971297

12981298
if (object != NULL && node != NULL) {
12991299
if (object->node != NULL) {
@@ -1323,11 +1323,11 @@ PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object,
13231323
return ret_refcount;
13241324
}
13251325

1326-
PHP_LIBXML_API int php_libxml_decrement_node_ptr_ref(php_libxml_node_ptr *ptr)
1326+
PHP_LIBXML_API unsigned int php_libxml_decrement_node_ptr_ref(php_libxml_node_ptr *ptr)
13271327
{
13281328
ZEND_ASSERT(ptr != NULL);
13291329

1330-
int ret_refcount = --ptr->refcount;
1330+
unsigned int ret_refcount = --ptr->refcount;
13311331
if (ret_refcount == 0) {
13321332
if (ptr->node != NULL) {
13331333
ptr->node->_private = NULL;
@@ -1341,17 +1341,17 @@ PHP_LIBXML_API int php_libxml_decrement_node_ptr_ref(php_libxml_node_ptr *ptr)
13411341
return ret_refcount;
13421342
}
13431343

1344-
PHP_LIBXML_API int php_libxml_decrement_node_ptr(php_libxml_node_object *object)
1344+
PHP_LIBXML_API unsigned int php_libxml_decrement_node_ptr(php_libxml_node_object *object)
13451345
{
13461346
if (object != NULL && object->node != NULL) {
13471347
return php_libxml_decrement_node_ptr_ref(object->node);
13481348
}
1349-
return -1;
1349+
return 0;
13501350
}
13511351

1352-
PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp)
1352+
PHP_LIBXML_API unsigned int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp)
13531353
{
1354-
int ret_refcount = -1;
1354+
unsigned int ret_refcount = 0;
13551355

13561356
if (object->document != NULL) {
13571357
object->document->refcount++;
@@ -1372,9 +1372,9 @@ PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object,
13721372
return ret_refcount;
13731373
}
13741374

1375-
PHP_LIBXML_API int php_libxml_decrement_doc_ref_directly(php_libxml_ref_obj *document)
1375+
PHP_LIBXML_API unsigned int php_libxml_decrement_doc_ref_directly(php_libxml_ref_obj *document)
13761376
{
1377-
int ret_refcount = --document->refcount;
1377+
unsigned int ret_refcount = --document->refcount;
13781378
if (ret_refcount == 0) {
13791379
if (document->private_data != NULL) {
13801380
document->private_data->dtor(document->private_data);
@@ -1395,9 +1395,9 @@ PHP_LIBXML_API int php_libxml_decrement_doc_ref_directly(php_libxml_ref_obj *doc
13951395
return ret_refcount;
13961396
}
13971397

1398-
PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object)
1398+
PHP_LIBXML_API unsigned int php_libxml_decrement_doc_ref(php_libxml_node_object *object)
13991399
{
1400-
int ret_refcount = -1;
1400+
unsigned int ret_refcount = 0;
14011401

14021402
if (object != NULL && object->document != NULL) {
14031403
ret_refcount = php_libxml_decrement_doc_ref_directly(object->document);
@@ -1445,7 +1445,7 @@ PHP_LIBXML_API void php_libxml_node_decrement_resource(php_libxml_node_object *o
14451445
if (object != NULL && object->node != NULL) {
14461446
php_libxml_node_ptr *obj_node = (php_libxml_node_ptr *) object->node;
14471447
xmlNodePtr nodep = obj_node->node;
1448-
int ret_refcount = php_libxml_decrement_node_ptr(object);
1448+
unsigned int ret_refcount = php_libxml_decrement_node_ptr(object);
14491449
if (ret_refcount == 0) {
14501450
php_libxml_node_free_resource(nodep);
14511451
} else {

ext/libxml/php_libxml.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ typedef enum {
189189
PHP_LIBXML_CTX_WARNING = 2,
190190
} php_libxml_error_level;
191191

192-
PHP_LIBXML_API int php_libxml_increment_node_ptr(php_libxml_node_object *object, xmlNodePtr node, void *private_data);
193-
PHP_LIBXML_API int php_libxml_decrement_node_ptr(php_libxml_node_object *object);
194-
PHP_LIBXML_API int php_libxml_decrement_node_ptr_ref(php_libxml_node_ptr *ptr);
195-
PHP_LIBXML_API int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp);
196-
PHP_LIBXML_API int php_libxml_decrement_doc_ref_directly(php_libxml_ref_obj *document);
197-
PHP_LIBXML_API int php_libxml_decrement_doc_ref(php_libxml_node_object *object);
192+
PHP_LIBXML_API unsigned int php_libxml_increment_node_ptr(php_libxml_node_object *object, xmlNodePtr node, void *private_data);
193+
PHP_LIBXML_API unsigned int php_libxml_decrement_node_ptr(php_libxml_node_object *object);
194+
PHP_LIBXML_API unsigned int php_libxml_decrement_node_ptr_ref(php_libxml_node_ptr *ptr);
195+
PHP_LIBXML_API unsigned int php_libxml_increment_doc_ref(php_libxml_node_object *object, xmlDocPtr docp);
196+
PHP_LIBXML_API unsigned int php_libxml_decrement_doc_ref_directly(php_libxml_ref_obj *document);
197+
PHP_LIBXML_API unsigned int php_libxml_decrement_doc_ref(php_libxml_node_object *object);
198198
PHP_LIBXML_API xmlNodePtr php_libxml_import_node(zval *object);
199199
PHP_LIBXML_API zval *php_libxml_register_export(zend_class_entry *ce, php_libxml_export_node export_function);
200200
/* When an explicit freeing of node and children is required */

0 commit comments

Comments
 (0)