Skip to content

Commit 7f5a888

Browse files
authored
Change dom_node_is_read_only() to return bool (#16757)
Returning int or zend_result doesn't make sense, it's a yes/no question.
1 parent cec9a98 commit 7f5a888

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

ext/dom/documentfragment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ PHP_METHOD(DOMDocumentFragment, appendXML) {
7373

7474
DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
7575

76-
if (dom_node_is_read_only(nodep) == SUCCESS) {
76+
if (dom_node_is_read_only(nodep)) {
7777
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
7878
RETURN_FALSE;
7979
}

ext/dom/node.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,8 @@ static xmlNodePtr dom_insert_fragment(xmlNodePtr nodep, xmlNodePtr prevsib, xmlN
837837

838838
static bool dom_node_check_legacy_insertion_validity(xmlNodePtr parentp, xmlNodePtr child, bool stricterror, bool warn_empty_fragment)
839839
{
840-
if (dom_node_is_read_only(parentp) == SUCCESS ||
841-
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
840+
if (dom_node_is_read_only(parentp) ||
841+
(child->parent != NULL && dom_node_is_read_only(child->parent))) {
842842
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
843843
return false;
844844
}
@@ -1279,8 +1279,8 @@ static void dom_node_remove_child(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry
12791279
RETURN_FALSE;
12801280
}
12811281

1282-
if (dom_node_is_read_only(nodep) == SUCCESS ||
1283-
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
1282+
if (dom_node_is_read_only(nodep) ||
1283+
(child->parent != NULL && dom_node_is_read_only(child->parent))) {
12841284
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
12851285
RETURN_FALSE;
12861286
}

ext/dom/parentnode/tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,8 @@ void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc)
699699

700700
static zend_result dom_child_removal_preconditions(const xmlNode *child, const dom_object *context)
701701
{
702-
if (dom_node_is_read_only(child) == SUCCESS ||
703-
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
702+
if (dom_node_is_read_only(child) ||
703+
(child->parent != NULL && dom_node_is_read_only(child->parent))) {
704704
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(context->document));
705705
return FAILURE;
706706
}

ext/dom/php_dom.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ typedef struct dom_prop_handler {
155155
dom_write_t write_func;
156156
} dom_prop_handler;
157157

158-
int dom_node_is_read_only(const xmlNode *node) {
158+
bool dom_node_is_read_only(const xmlNode *node) {
159159
switch (node->type) {
160160
case XML_ENTITY_REF_NODE:
161161
case XML_ENTITY_NODE:
@@ -166,14 +166,9 @@ int dom_node_is_read_only(const xmlNode *node) {
166166
case XML_ATTRIBUTE_DECL:
167167
case XML_ENTITY_DECL:
168168
case XML_NAMESPACE_DECL:
169-
return SUCCESS;
170-
break;
169+
return true;
171170
default:
172-
if (node->doc == NULL) {
173-
return SUCCESS;
174-
} else {
175-
return FAILURE;
176-
}
171+
return node->doc == NULL;
177172
}
178173
}
179174

ext/dom/php_dom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr basep, xmlNodePtr nodep,
147147
void php_dom_create_implementation(zval *retval, bool modern);
148148
int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child);
149149
bool dom_has_feature(zend_string *feature, zend_string *version);
150-
int dom_node_is_read_only(const xmlNode *node);
150+
bool dom_node_is_read_only(const xmlNode *node);
151151
bool dom_node_children_valid(const xmlNode *node);
152152
void php_dom_create_iterator(zval *return_value, dom_iterator_type iterator_type, bool modern);
153153
void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xmlHashTablePtr ht, const char *local, size_t local_len, const char *ns, size_t ns_len);

0 commit comments

Comments
 (0)