Skip to content

Commit 99ee307

Browse files
committed
Declare tidy properties
1 parent 59b4fdb commit 99ee307

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

ext/tidy/tidy.c

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,6 @@
122122
zend_hash_str_update(_table, #_key, sizeof(#_key) - 1, &tmp); \
123123
}
124124

125-
#define ADD_PROPERTY_NULL(_table, _key) \
126-
{ \
127-
zval tmp; \
128-
ZVAL_NULL(&tmp); \
129-
zend_hash_str_update(_table, #_key, sizeof(#_key) - 1, &tmp); \
130-
}
131-
132125
#define ADD_PROPERTY_BOOL(_table, _key, _bool) \
133126
{ \
134127
zval tmp; \
@@ -585,35 +578,38 @@ static int tidy_node_cast_handler(zend_object *in, zval *out, int type)
585578

586579
static void tidy_doc_update_properties(PHPTidyObj *obj)
587580
{
588-
589581
TidyBuffer output;
590-
zval temp;
591582

592583
tidyBufInit(&output);
593584
tidySaveBuffer (obj->ptdoc->doc, &output);
594585

595586
if (output.size) {
596-
if (!obj->std.properties) {
597-
rebuild_object_properties(&obj->std);
598-
}
599-
ZVAL_STRINGL(&temp, (char*)output.bp, output.size-1);
600-
zend_hash_str_update(obj->std.properties, "value", sizeof("value") - 1, &temp);
587+
zend_update_property_stringl(
588+
tidy_ce_doc,
589+
&obj->std,
590+
"value",
591+
sizeof("value") - 1,
592+
(char*)output.bp,
593+
output.size-1
594+
);
601595
}
602596

603597
tidyBufFree(&output);
604598

605599
if (obj->ptdoc->errbuf->size) {
606-
if (!obj->std.properties) {
607-
rebuild_object_properties(&obj->std);
608-
}
609-
ZVAL_STRINGL(&temp, (char*)obj->ptdoc->errbuf->bp, obj->ptdoc->errbuf->size-1);
610-
zend_hash_str_update(obj->std.properties, "errorBuffer", sizeof("errorBuffer") - 1, &temp);
600+
zend_update_property_stringl(
601+
tidy_ce_doc,
602+
&obj->std,
603+
"errorBuffer",
604+
sizeof("errorBuffer") - 1,
605+
(char*)obj->ptdoc->errbuf->bp,
606+
obj->ptdoc->errbuf->size-1
607+
);
611608
}
612609
}
613610

614611
static void tidy_add_default_properties(PHPTidyObj *obj, tidy_obj_type type)
615612
{
616-
617613
TidyBuffer buf;
618614
TidyAttr tempattr;
619615
TidyNode tempnode;
@@ -690,14 +686,6 @@ static void tidy_add_default_properties(PHPTidyObj *obj, tidy_obj_type type)
690686
zend_hash_str_update(obj->std.properties, "child", sizeof("child") - 1, &children);
691687

692688
break;
693-
694-
case is_doc:
695-
if (!obj->std.properties) {
696-
rebuild_object_properties(&obj->std);
697-
}
698-
ADD_PROPERTY_NULL(obj->std.properties, errorBuffer);
699-
ADD_PROPERTY_NULL(obj->std.properties, value);
700-
break;
701689
}
702690
}
703691

ext/tidy/tidy.stub.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ function tidy_get_body(tidy $tidy): ?tidyNode {}
5454

5555
class tidy
5656
{
57+
public ?string $errorBuffer = null;
58+
public ?string $value = null;
59+
5760
public function __construct(?string $filename = null, array|string|null $config = null, ?string $encoding = null, bool $useIncludePath = false) {}
5861

5962
/**

ext/tidy/tidy_arginfo.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 4e5f6c0e7c6b8a6939a13276e3e68d2614a73d7e */
2+
* Stub hash: 7ec9389d5540e60e5bffeeca866168f0a6d6835c */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_tidy_parse_string, 0, 1, tidy, MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
@@ -303,6 +303,18 @@ static zend_class_entry *register_class_tidy(void)
303303
INIT_CLASS_ENTRY(ce, "tidy", class_tidy_methods);
304304
class_entry = zend_register_internal_class_ex(&ce, NULL);
305305

306+
zval property_errorBuffer_default_value;
307+
ZVAL_NULL(&property_errorBuffer_default_value);
308+
zend_string *property_errorBuffer_name = zend_string_init("errorBuffer", sizeof("errorBuffer") - 1, 1);
309+
zend_declare_typed_property(class_entry, property_errorBuffer_name, &property_errorBuffer_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
310+
zend_string_release(property_errorBuffer_name);
311+
312+
zval property_value_default_value;
313+
ZVAL_NULL(&property_value_default_value);
314+
zend_string *property_value_name = zend_string_init("value", sizeof("value") - 1, 1);
315+
zend_declare_typed_property(class_entry, property_value_name, &property_value_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
316+
zend_string_release(property_value_name);
317+
306318
return class_entry;
307319
}
308320

0 commit comments

Comments
 (0)