Skip to content

Commit 007b6c3

Browse files
authored
Merge branch 'php:master' into power-division-by-zero-deprecation
2 parents c8c4d4b + 9c4beac commit 007b6c3

21 files changed

+131
-221
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ PHP 8.4 UPGRADE NOTES
4141
DOMException now. This situation is extremely unlikely though and probably
4242
will not affect you. As a result DOMImplementation::createDocument() now has
4343
a tentative return type of DOMDocument instead of DOMDocument|false.
44+
. Previously, DOMXPath objects could be cloned, but resulted in an unusable
45+
object. This is no longer possible, and cloning a DOMXPath object now throws
46+
an error.
4447

4548
- MBString:
4649
. mb_encode_numericentity() and mb_decode_numericentity() now check that

UPGRADING.INTERNALS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
3737
* The zend_*printf family of functions now supports the "%S" modifier to print
3838
out zend_string*. This won't cut off the string if it embeds a NUL byte.
3939

40+
* The inet_aton() and win32/inet.h on Windows have been removed. Use Windows
41+
native inet_pton() from ws2tcpip.h.
42+
4043
========================
4144
2. Build system changes
4245
========================
@@ -67,6 +70,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
6770
- Symbol MISSING_FCLOSE_DECL and M4 macro PHP_MISSING_FCLOSE_DECL removed.
6871
- Symbol HAVE_BSD_ICONV has been removed.
6972
- Symbol ZEND_FIBER_ASM has been removed.
73+
- Symbols HAVE_DLOPEN and HAVE_DLSYM have been removed.
74+
- Symbol HAVE_LIBM has been removed.
75+
- Symbol HAVE_INET_ATON has been removed.
7076
- M4 macro PHP_DEFINE (atomic includes) removed (use AC_DEFINE and config.h).
7177
- M4 macro PHP_WITH_SHARED has been removed (use PHP_ARG_WITH).
7278
- M4 macro PHP_STRUCT_FLOCK has been removed (use AC_CHECK_TYPES).

configure.ac

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,16 @@ PHP_CHECK_FUNC(socketpair, socket, network)
362362
PHP_CHECK_FUNC(htonl, socket, network)
363363
PHP_CHECK_FUNC(gethostname, nsl, network)
364364
PHP_CHECK_FUNC(gethostbyaddr, nsl, network)
365-
PHP_CHECK_FUNC(dlopen, dl)
366-
PHP_CHECK_FUNC(dlsym, dl)
367-
if test "$ac_cv_func_dlopen" = "yes"; then
368-
AC_DEFINE(HAVE_LIBDL, 1, [ ])
369-
fi
370-
AC_CHECK_LIB(m, sin)
365+
AC_SEARCH_LIBS([dlopen], [dl],
366+
[AC_DEFINE([HAVE_LIBDL], [1], [Define to 1 if the dl library is available.])])
367+
AC_SEARCH_LIBS([sin], [m])
371368

372369
case $host_alias in
373370
riscv64*)
374371
PHP_CHECK_FUNC(__atomic_exchange_1, atomic)
375372
;;
376373
esac
377374

378-
dnl Check for inet_aton in -lc and -lresolv.
379-
PHP_CHECK_FUNC(inet_aton, resolv)
380-
381375
dnl Then headers.
382376
dnl ----------------------------------------------------------------------------
383377

ext/dom/php_dom.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ PHP_MINIT_FUNCTION(dom)
872872
dom_xpath_object_handlers.offset = XtOffsetOf(dom_xpath_object, dom) + XtOffsetOf(dom_object, std);
873873
dom_xpath_object_handlers.free_obj = dom_xpath_objects_free_storage;
874874
dom_xpath_object_handlers.get_gc = dom_xpath_get_gc;
875+
dom_xpath_object_handlers.clone_obj = NULL;
875876

876877
dom_xpath_class_entry = register_class_DOMXPath();
877878
dom_xpath_class_entry->create_object = dom_xpath_objects_new;

ext/dom/tests/DOMXPath_clone.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
DOMXPath: Cloning a DOMXPath object
3+
--EXTENSIONS--
4+
dom
5+
--SKIPIF--
6+
<?php
7+
if (!class_exists('DOMXPath')) die('skip no xpath support');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
$dom = new DOMDocument;
13+
$xpath = new DOMXPath($dom);
14+
try {
15+
clone $xpath;
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
?>
21+
--EXPECT--
22+
Trying to clone an uncloneable object of class DOMXPath
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
DOMXPath: Calling __construct() again when functions were already registered
3+
--EXTENSIONS--
4+
dom
5+
--SKIPIF--
6+
<?php
7+
if (!class_exists('DOMXPath')) die('skip no xpath support');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
$dom = new DOMDocument;
13+
$dom->loadXML('<root/>');
14+
15+
class Test {
16+
public function __destruct() {
17+
echo "destruct\n";
18+
}
19+
20+
public function test() {
21+
echo "test\n";
22+
}
23+
}
24+
25+
echo "=== First run ===\n";
26+
27+
$xpath = new DOMXPath($dom);
28+
$xpath->registerNamespace('foo', 'urn:foo');
29+
$xpath->registerPhpFunctionNS('urn:foo', 'test', [new Test, 'test']);
30+
31+
echo "=== Reconstruct ===\n";
32+
33+
$xpath->__construct($dom, true);
34+
35+
echo "=== Second run ===\n";
36+
37+
$xpath->registerNamespace('foo', 'urn:foo');
38+
$xpath->query('//*[foo:test()]');
39+
$xpath->registerPhpFunctionNS('urn:foo', 'test', [new Test, 'test']);
40+
$xpath->query('//*[foo:test()]');
41+
42+
?>
43+
--EXPECTF--
44+
=== First run ===
45+
=== Reconstruct ===
46+
destruct
47+
=== Second run ===
48+
49+
Warning: DOMXPath::query(): xmlXPathCompOpEval: function test not found in %s on line %d
50+
51+
Warning: DOMXPath::query(): Unregistered function in %s on line %d
52+
test
53+
destruct

ext/dom/xpath.c

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -116,45 +116,43 @@ static void dom_xpath_ext_function_trampoline(xmlXPathParserContextPtr ctxt, int
116116
PHP_METHOD(DOMXPath, __construct)
117117
{
118118
zval *doc;
119-
bool register_node_ns = 1;
119+
bool register_node_ns = true;
120120
xmlDocPtr docp = NULL;
121121
dom_object *docobj;
122-
dom_xpath_object *intern;
123-
xmlXPathContextPtr ctx, oldctx;
124122

125123
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|b", &doc, dom_abstract_base_document_class_entry, &register_node_ns) == FAILURE) {
126124
RETURN_THROWS();
127125
}
128126

129127
DOM_GET_OBJ(docp, doc, xmlDocPtr, docobj);
130128

131-
ctx = xmlXPathNewContext(docp);
129+
xmlXPathContextPtr ctx = xmlXPathNewContext(docp);
132130
if (ctx == NULL) {
133131
php_dom_throw_error(INVALID_STATE_ERR, 1);
134132
RETURN_THROWS();
135133
}
136134

137-
intern = Z_XPATHOBJ_P(ZEND_THIS);
138-
if (intern != NULL) {
139-
oldctx = (xmlXPathContextPtr)intern->dom.ptr;
140-
if (oldctx != NULL) {
141-
php_libxml_decrement_doc_ref((php_libxml_node_object *) &intern->dom);
142-
xmlXPathFreeContext(oldctx);
143-
}
144-
145-
xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "functionString",
146-
(const xmlChar *) "http://php.net/xpath",
147-
dom_xpath_ext_function_string_php);
148-
xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "function",
149-
(const xmlChar *) "http://php.net/xpath",
150-
dom_xpath_ext_function_object_php);
151-
152-
intern->dom.ptr = ctx;
153-
ctx->userData = (void *)intern;
154-
intern->dom.document = docobj->document;
155-
intern->register_node_ns = register_node_ns;
156-
php_libxml_increment_doc_ref((php_libxml_node_object *) &intern->dom, docp);
135+
dom_xpath_object *intern = Z_XPATHOBJ_P(ZEND_THIS);
136+
xmlXPathContextPtr oldctx = intern->dom.ptr;
137+
if (oldctx != NULL) {
138+
php_libxml_decrement_doc_ref((php_libxml_node_object *) &intern->dom);
139+
xmlXPathFreeContext(oldctx);
140+
php_dom_xpath_callbacks_dtor(&intern->xpath_callbacks);
141+
php_dom_xpath_callbacks_ctor(&intern->xpath_callbacks);
157142
}
143+
144+
xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "functionString",
145+
(const xmlChar *) "http://php.net/xpath",
146+
dom_xpath_ext_function_string_php);
147+
xmlXPathRegisterFuncNS (ctx, (const xmlChar *) "function",
148+
(const xmlChar *) "http://php.net/xpath",
149+
dom_xpath_ext_function_object_php);
150+
151+
intern->dom.ptr = ctx;
152+
ctx->userData = (void *)intern;
153+
intern->dom.document = docobj->document;
154+
intern->register_node_ns = register_node_ns;
155+
php_libxml_increment_doc_ref((php_libxml_node_object *) &intern->dom, docp);
158156
}
159157
/* }}} end DOMXPath::__construct */
160158

@@ -196,20 +194,16 @@ zend_result dom_xpath_register_node_ns_write(dom_object *obj, zval *newval)
196194
/* {{{ */
197195
PHP_METHOD(DOMXPath, registerNamespace)
198196
{
199-
zval *id;
200-
xmlXPathContextPtr ctxp;
201197
size_t prefix_len, ns_uri_len;
202-
dom_xpath_object *intern;
203198
unsigned char *prefix, *ns_uri;
204199

205-
id = ZEND_THIS;
206200
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prefix, &prefix_len, &ns_uri, &ns_uri_len) == FAILURE) {
207201
RETURN_THROWS();
208202
}
209203

210-
intern = Z_XPATHOBJ_P(id);
204+
dom_xpath_object *intern = Z_XPATHOBJ_P(ZEND_THIS);
211205

212-
ctxp = (xmlXPathContextPtr) intern->dom.ptr;
206+
xmlXPathContextPtr ctxp = intern->dom.ptr;
213207
if (ctxp == NULL) {
214208
zend_throw_error(NULL, "Invalid XPath Context");
215209
RETURN_THROWS();
@@ -233,33 +227,27 @@ static void dom_xpath_iter(zval *baseobj, dom_object *intern) /* {{{ */
233227

234228
static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
235229
{
236-
zval *id, retval, *context = NULL;
237-
xmlXPathContextPtr ctxp;
230+
zval *context = NULL;
238231
xmlNodePtr nodep = NULL;
239-
xmlXPathObjectPtr xpathobjp;
240232
size_t expr_len, nsnbr = 0, xpath_type;
241-
dom_xpath_object *intern;
242233
dom_object *nodeobj;
243234
char *expr;
244-
xmlDoc *docp = NULL;
245235
xmlNsPtr *ns = NULL;
246-
bool register_node_ns;
247236

248-
id = ZEND_THIS;
249-
intern = Z_XPATHOBJ_P(id);
250-
register_node_ns = intern->register_node_ns;
237+
dom_xpath_object *intern = Z_XPATHOBJ_P(ZEND_THIS);
238+
bool register_node_ns = intern->register_node_ns;
251239

252240
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|O!b", &expr, &expr_len, &context, dom_node_class_entry, &register_node_ns) == FAILURE) {
253241
RETURN_THROWS();
254242
}
255243

256-
ctxp = (xmlXPathContextPtr) intern->dom.ptr;
244+
xmlXPathContextPtr ctxp = intern->dom.ptr;
257245
if (ctxp == NULL) {
258246
zend_throw_error(NULL, "Invalid XPath Context");
259247
RETURN_THROWS();
260248
}
261249

262-
docp = (xmlDocPtr) ctxp->doc;
250+
xmlDocPtr docp = ctxp->doc;
263251
if (docp == NULL) {
264252
php_error_docref(NULL, E_WARNING, "Invalid XPath Document Pointer");
265253
RETURN_FALSE;
@@ -285,15 +273,16 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
285273
ns = xmlGetNsList(docp, nodep);
286274

287275
if (ns != NULL) {
288-
while (ns[nsnbr] != NULL)
289-
nsnbr++;
276+
while (ns[nsnbr] != NULL) {
277+
nsnbr++;
278+
}
290279
}
291280
}
292281

293282
ctxp->namespaces = ns;
294283
ctxp->nsNr = nsnbr;
295284

296-
xpathobjp = xmlXPathEvalExpression((xmlChar *) expr, ctxp);
285+
xmlXPathObjectPtr xpathobjp = xmlXPathEvalExpression((xmlChar *) expr, ctxp);
297286
ctxp->node = NULL;
298287

299288
if (ns != NULL) {
@@ -317,13 +306,13 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
317306

318307
case XPATH_NODESET:
319308
{
320-
int i;
321309
xmlNodeSetPtr nodesetp;
310+
zval retval;
322311

323312
if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) {
324313
array_init_size(&retval, nodesetp->nodeNr);
325314
zend_hash_real_init_packed(Z_ARRVAL_P(&retval));
326-
for (i = 0; i < nodesetp->nodeNr; i++) {
315+
for (int i = 0; i < nodesetp->nodeNr; i++) {
327316
xmlNodePtr node = nodesetp->nodeTab[i];
328317
zval child;
329318

ext/dom/xpath_callbacks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ PHP_DOM_EXPORT void php_dom_xpath_callback_ns_dtor(php_dom_xpath_callback_ns *ns
4646

4747
PHP_DOM_EXPORT void php_dom_xpath_callbacks_ctor(php_dom_xpath_callbacks *registry)
4848
{
49+
registry->php_ns = NULL;
50+
registry->namespaces = NULL;
51+
registry->node_list = NULL;
4952
}
5053

5154
PHP_DOM_EXPORT void php_dom_xpath_callbacks_clean_node_list(php_dom_xpath_callbacks *registry)

ext/sockets/sockets.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "php_ini.h"
3131
#ifdef PHP_WIN32
3232
# include "windows_common.h"
33-
# include <win32/inet.h>
3433
# include <windows.h>
3534
# include <Ws2tcpip.h>
3635
# include "php_sockets.h"

ext/standard/basic_functions.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
6868

6969
#ifndef PHP_WIN32
7070
# include <netdb.h>
71-
#else
72-
#include "win32/inet.h"
7371
#endif
7472

7573
#ifdef HAVE_ARPA_INET_H

ext/standard/dns.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#endif
2626

2727
#ifdef PHP_WIN32
28-
# include "win32/inet.h"
2928
# include <winsock2.h>
3029
# include <windows.h>
3130
# include <Ws2tcpip.h>

0 commit comments

Comments
 (0)