Skip to content

Commit

Permalink
Change dom_node_is_read_only() to return bool (#16757)
Browse files Browse the repository at this point in the history
Returning int or zend_result doesn't make sense, it's a yes/no question.
  • Loading branch information
nielsdos authored Nov 11, 2024
1 parent cec9a98 commit 7f5a888
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ext/dom/documentfragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ PHP_METHOD(DOMDocumentFragment, appendXML) {

DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);

if (dom_node_is_read_only(nodep) == SUCCESS) {
if (dom_node_is_read_only(nodep)) {
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
RETURN_FALSE;
}
Expand Down
8 changes: 4 additions & 4 deletions ext/dom/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,8 @@ static xmlNodePtr dom_insert_fragment(xmlNodePtr nodep, xmlNodePtr prevsib, xmlN

static bool dom_node_check_legacy_insertion_validity(xmlNodePtr parentp, xmlNodePtr child, bool stricterror, bool warn_empty_fragment)
{
if (dom_node_is_read_only(parentp) == SUCCESS ||
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
if (dom_node_is_read_only(parentp) ||
(child->parent != NULL && dom_node_is_read_only(child->parent))) {
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
return false;
}
Expand Down Expand Up @@ -1279,8 +1279,8 @@ static void dom_node_remove_child(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry
RETURN_FALSE;
}

if (dom_node_is_read_only(nodep) == SUCCESS ||
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
if (dom_node_is_read_only(nodep) ||
(child->parent != NULL && dom_node_is_read_only(child->parent))) {
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, stricterror);
RETURN_FALSE;
}
Expand Down
4 changes: 2 additions & 2 deletions ext/dom/parentnode/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ void dom_parent_node_before(dom_object *context, zval *nodes, uint32_t nodesc)

static zend_result dom_child_removal_preconditions(const xmlNode *child, const dom_object *context)
{
if (dom_node_is_read_only(child) == SUCCESS ||
(child->parent != NULL && dom_node_is_read_only(child->parent) == SUCCESS)) {
if (dom_node_is_read_only(child) ||
(child->parent != NULL && dom_node_is_read_only(child->parent))) {
php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(context->document));
return FAILURE;
}
Expand Down
11 changes: 3 additions & 8 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ typedef struct dom_prop_handler {
dom_write_t write_func;
} dom_prop_handler;

int dom_node_is_read_only(const xmlNode *node) {
bool dom_node_is_read_only(const xmlNode *node) {
switch (node->type) {
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
Expand All @@ -166,14 +166,9 @@ int dom_node_is_read_only(const xmlNode *node) {
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_NAMESPACE_DECL:
return SUCCESS;
break;
return true;
default:
if (node->doc == NULL) {
return SUCCESS;
} else {
return FAILURE;
}
return node->doc == NULL;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ext/dom/php_dom.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ xmlNode *dom_get_elements_by_tag_name_ns_raw(xmlNodePtr basep, xmlNodePtr nodep,
void php_dom_create_implementation(zval *retval, bool modern);
int dom_hierarchy(xmlNodePtr parent, xmlNodePtr child);
bool dom_has_feature(zend_string *feature, zend_string *version);
int dom_node_is_read_only(const xmlNode *node);
bool dom_node_is_read_only(const xmlNode *node);
bool dom_node_children_valid(const xmlNode *node);
void php_dom_create_iterator(zval *return_value, dom_iterator_type iterator_type, bool modern);
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);
Expand Down

0 comments on commit 7f5a888

Please sign in to comment.