Skip to content

Commit ad8c214

Browse files
committed
Avoid deprecation warnings for libxml2 2.12.0
We can't fully get rid of the parser globals as there are still APIs that implicitly use them.
1 parent ff5c8ae commit ad8c214

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

ext/libxml/libxml.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,11 @@ static void _php_libxml_free_error(void *ptr)
580580
xmlResetError((xmlErrorPtr) ptr);
581581
}
582582

583-
static void _php_list_set_error_structure(xmlErrorPtr error, const char *msg, int line, int column)
583+
#if LIBXML_VERSION >= 21200
584+
static void _php_list_set_error_structure(const xmlError *error, const char *msg, int line, int column)
585+
#else
586+
static void _php_list_set_error_structure(xmlError *error, const char *msg, int line, int column)
587+
#endif
584588
{
585589
xmlError error_copy;
586590
int ret;
@@ -824,7 +828,10 @@ PHP_LIBXML_API void php_libxml_pretend_ctx_error_ex(const char *file, int line,
824828
if (!last->file) {
825829
last->file = strdup(file);
826830
}
831+
/* Until there is a replacement */
832+
ZEND_DIAGNOSTIC_IGNORED_START("-Wdeprecated-declarations")
827833
xmlCopyError(last, &xmlLastError);
834+
ZEND_DIAGNOSTIC_IGNORED_END
828835
}
829836
}
830837
}
@@ -845,11 +852,13 @@ PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...)
845852
va_end(args);
846853
}
847854

855+
#if LIBXML_VERSION >= 21200
856+
static void php_libxml_structured_error_handler(void *userData, const xmlError *error)
857+
#else
848858
static void php_libxml_structured_error_handler(void *userData, xmlErrorPtr error)
859+
#endif
849860
{
850861
_php_list_set_error_structure(error, NULL, 0, 0);
851-
852-
return;
853862
}
854863

855864
PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...)
@@ -1077,11 +1086,9 @@ PHP_FUNCTION(libxml_use_internal_errors)
10771086
/* {{{ Retrieve last error from libxml */
10781087
PHP_FUNCTION(libxml_get_last_error)
10791088
{
1080-
xmlErrorPtr error;
1081-
10821089
ZEND_PARSE_PARAMETERS_NONE();
10831090

1084-
error = xmlGetLastError();
1091+
const xmlError* error = xmlGetLastError();
10851092

10861093
if (error) {
10871094
object_init_ex(return_value, libxmlerror_class_entry);
@@ -1108,7 +1115,6 @@ PHP_FUNCTION(libxml_get_last_error)
11081115
/* {{{ Retrieve array of errors */
11091116
PHP_FUNCTION(libxml_get_errors)
11101117
{
1111-
11121118
xmlErrorPtr error;
11131119

11141120
ZEND_PARSE_PARAMETERS_NONE();

ext/libxml/php_libxml.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,27 @@ ZEND_TSRMLS_CACHE_EXTERN()
160160
* See libxml2 globals.c and parserInternals.c.
161161
* The unique_name argument allows multiple sanitizes and restores within the
162162
* same function, even nested is necessary. */
163-
#define PHP_LIBXML_SANITIZE_GLOBALS(unique_name) \
163+
# define PHP_LIBXML_SANITIZE_GLOBALS(unique_name) \
164+
ZEND_DIAGNOSTIC_IGNORED_START("-Wdeprecated-declarations") \
164165
int xml_old_loadsubset_##unique_name = xmlLoadExtDtdDefaultValue; \
165166
xmlLoadExtDtdDefaultValue = 0; \
166167
int xml_old_validate_##unique_name = xmlDoValidityCheckingDefaultValue; \
167168
xmlDoValidityCheckingDefaultValue = 0; \
168169
int xml_old_pedantic_##unique_name = xmlPedanticParserDefault(0); \
169170
int xml_old_substitute_##unique_name = xmlSubstituteEntitiesDefault(0); \
170171
int xml_old_linenrs_##unique_name = xmlLineNumbersDefault(0); \
171-
int xml_old_blanks_##unique_name = xmlKeepBlanksDefault(1);
172+
int xml_old_blanks_##unique_name = xmlKeepBlanksDefault(1); \
173+
ZEND_DIAGNOSTIC_IGNORED_END
172174

173-
#define PHP_LIBXML_RESTORE_GLOBALS(unique_name) \
175+
# define PHP_LIBXML_RESTORE_GLOBALS(unique_name) \
176+
ZEND_DIAGNOSTIC_IGNORED_START("-Wdeprecated-declarations") \
174177
xmlLoadExtDtdDefaultValue = xml_old_loadsubset_##unique_name; \
175178
xmlDoValidityCheckingDefaultValue = xml_old_validate_##unique_name; \
176179
(void) xmlPedanticParserDefault(xml_old_pedantic_##unique_name); \
177180
(void) xmlSubstituteEntitiesDefault(xml_old_substitute_##unique_name); \
178181
(void) xmlLineNumbersDefault(xml_old_linenrs_##unique_name); \
179-
(void) xmlKeepBlanksDefault(xml_old_blanks_##unique_name);
182+
(void) xmlKeepBlanksDefault(xml_old_blanks_##unique_name); \
183+
ZEND_DIAGNOSTIC_IGNORED_END
180184

181185
/* Alternative for above, working directly on the context and not setting globals.
182186
* Generally faster because no locking is involved, and this has the advantage that it sets the options to a known good value. */

0 commit comments

Comments
 (0)