Get rid of reserved name usage in ext/libxml (#16707)

Names starting with an _ are reserved in C.
This commit is contained in:
Niels Dossche 2024-11-06 17:47:48 +01:00 committed by GitHub
parent 6366da48ec
commit bc4fa01de7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -49,11 +49,11 @@
#include "libxml_arginfo.h" #include "libxml_arginfo.h"
/* a true global for initialization */ /* a true global for initialization */
static int _php_libxml_initialized = 0; static int php_libxml_initialized = 0;
static int _php_libxml_per_request_initialization = 1; static int php_libxml_per_request_initialization = 1;
static xmlExternalEntityLoader _php_libxml_default_entity_loader; static xmlExternalEntityLoader php_libxml_default_entity_loader;
typedef struct _php_libxml_func_handler { typedef struct php_libxml_func_handler {
php_libxml_export_node export_func; php_libxml_export_node export_func;
} php_libxml_func_handler; } php_libxml_func_handler;
@ -601,16 +601,16 @@ php_libxml_output_buffer_create_filename(const char *URI,
return(ret); return(ret);
} }
static void _php_libxml_free_error(void *ptr) static void php_libxml_free_error(void *ptr)
{ {
/* This will free the libxml alloc'd memory */ /* This will free the libxml alloc'd memory */
xmlResetError((xmlErrorPtr) ptr); xmlResetError((xmlErrorPtr) ptr);
} }
#if LIBXML_VERSION >= 21200 #if LIBXML_VERSION >= 21200
static void _php_list_set_error_structure(const xmlError *error, const char *msg, int line, int column) static void php_list_set_error_structure(const xmlError *error, const char *msg, int line, int column)
#else #else
static void _php_list_set_error_structure(xmlError *error, const char *msg, int line, int column) static void php_list_set_error_structure(xmlError *error, const char *msg, int line, int column)
#endif #endif
{ {
xmlError error_copy; xmlError error_copy;
@ -655,7 +655,7 @@ static void php_libxml_ctx_error_level(int level, void *ctx, const char *msg, in
void php_libxml_issue_error(int level, const char *msg) void php_libxml_issue_error(int level, const char *msg)
{ {
if (LIBXML(error_list)) { if (LIBXML(error_list)) {
_php_list_set_error_structure(NULL, msg, 0, 0); php_list_set_error_structure(NULL, msg, 0, 0);
} else { } else {
php_error_docref(NULL, level, "%s", msg); php_error_docref(NULL, level, "%s", msg);
} }
@ -681,7 +681,7 @@ static void php_libxml_internal_error_handler_ex(php_libxml_error_level error_ty
if (output) { if (output) {
if (LIBXML(error_list)) { if (LIBXML(error_list)) {
_php_list_set_error_structure(NULL, ZSTR_VAL(LIBXML(error_buffer).s), line, column); php_list_set_error_structure(NULL, ZSTR_VAL(LIBXML(error_buffer).s), line, column);
} else if (!EG(exception)) { } else if (!EG(exception)) {
/* Don't throw additional notices/warnings if an exception has already been thrown. */ /* Don't throw additional notices/warnings if an exception has already been thrown. */
switch (error_type) { switch (error_type) {
@ -712,7 +712,7 @@ PHP_LIBXML_API void php_libxml_error_handler_va(php_libxml_error_level error_typ
php_libxml_internal_error_handler_ex(error_type, ctx, msg, ap, line, column); php_libxml_internal_error_handler_ex(error_type, ctx, msg, ap, line, column);
} }
static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL, static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,
const char *ID, xmlParserCtxtPtr context) const char *ID, xmlParserCtxtPtr context)
{ {
xmlParserInputPtr ret = NULL; xmlParserInputPtr ret = NULL;
@ -722,7 +722,7 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
/* no custom user-land callback set up; delegate to original loader */ /* no custom user-land callback set up; delegate to original loader */
if (!ZEND_FCC_INITIALIZED(LIBXML(entity_loader_callback))) { if (!ZEND_FCC_INITIALIZED(LIBXML(entity_loader_callback))) {
return _php_libxml_default_entity_loader(URL, ID, context); return php_libxml_default_entity_loader(URL, ID, context);
} }
if (ID != NULL) { if (ID != NULL) {
@ -821,7 +821,7 @@ is_string:
return ret; return ret;
} }
static xmlParserInputPtr _php_libxml_pre_ext_ent_loader(const char *URL, static xmlParserInputPtr php_libxml_pre_ext_ent_loader(const char *URL,
const char *ID, xmlParserCtxtPtr context) const char *ID, xmlParserCtxtPtr context)
{ {
@ -833,11 +833,11 @@ static xmlParserInputPtr _php_libxml_pre_ext_ent_loader(const char *URL,
* we don't even have a resource list by then), but then whether one * we don't even have a resource list by then), but then whether one
* extension would be using the custom external entity loader or not * extension would be using the custom external entity loader or not
* could depend on extension loading order * could depend on extension loading order
* (if _php_libxml_per_request_initialization */ * (if php_libxml_per_request_initialization */
if (xmlGenericError == php_libxml_error_handler && PG(modules_activated)) { if (xmlGenericError == php_libxml_error_handler && PG(modules_activated)) {
return _php_libxml_external_entity_loader(URL, ID, context); return php_libxml_external_entity_loader(URL, ID, context);
} else { } else {
return _php_libxml_default_entity_loader(URL, ID, context); return php_libxml_default_entity_loader(URL, ID, context);
} }
} }
@ -879,7 +879,7 @@ static void php_libxml_structured_error_handler(void *userData, const xmlError *
static void php_libxml_structured_error_handler(void *userData, xmlErrorPtr error) static void php_libxml_structured_error_handler(void *userData, xmlErrorPtr error)
#endif #endif
{ {
_php_list_set_error_structure(error, NULL, 0, 0); php_list_set_error_structure(error, NULL, 0, 0);
} }
PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...) PHP_LIBXML_API void php_libxml_error_handler(void *ctx, const char *msg, ...)
@ -897,32 +897,32 @@ static void php_libxml_exports_dtor(zval *zv)
PHP_LIBXML_API void php_libxml_initialize(void) PHP_LIBXML_API void php_libxml_initialize(void)
{ {
if (!_php_libxml_initialized) { if (!php_libxml_initialized) {
/* we should be the only one's to ever init!! */ /* we should be the only one's to ever init!! */
ZEND_IGNORE_LEAKS_BEGIN(); ZEND_IGNORE_LEAKS_BEGIN();
xmlInitParser(); xmlInitParser();
ZEND_IGNORE_LEAKS_END(); ZEND_IGNORE_LEAKS_END();
_php_libxml_default_entity_loader = xmlGetExternalEntityLoader(); php_libxml_default_entity_loader = xmlGetExternalEntityLoader();
xmlSetExternalEntityLoader(_php_libxml_pre_ext_ent_loader); xmlSetExternalEntityLoader(php_libxml_pre_ext_ent_loader);
zend_hash_init(&php_libxml_exports, 0, NULL, php_libxml_exports_dtor, 1); zend_hash_init(&php_libxml_exports, 0, NULL, php_libxml_exports_dtor, 1);
_php_libxml_initialized = 1; php_libxml_initialized = 1;
} }
} }
PHP_LIBXML_API void php_libxml_shutdown(void) PHP_LIBXML_API void php_libxml_shutdown(void)
{ {
if (_php_libxml_initialized) { if (php_libxml_initialized) {
#if defined(LIBXML_SCHEMAS_ENABLED) && LIBXML_VERSION < 21000 #if defined(LIBXML_SCHEMAS_ENABLED) && LIBXML_VERSION < 21000
xmlRelaxNGCleanupTypes(); xmlRelaxNGCleanupTypes();
#endif #endif
/* xmlCleanupParser(); */ /* xmlCleanupParser(); */
zend_hash_destroy(&php_libxml_exports); zend_hash_destroy(&php_libxml_exports);
xmlSetExternalEntityLoader(_php_libxml_default_entity_loader); xmlSetExternalEntityLoader(php_libxml_default_entity_loader);
_php_libxml_initialized = 0; php_libxml_initialized = 0;
} }
} }
@ -954,13 +954,13 @@ static PHP_MINIT_FUNCTION(libxml)
for (sapi_name = supported_sapis; *sapi_name; sapi_name++) { for (sapi_name = supported_sapis; *sapi_name; sapi_name++) {
if (strcmp(sapi_module.name, *sapi_name) == 0) { if (strcmp(sapi_module.name, *sapi_name) == 0) {
_php_libxml_per_request_initialization = 0; php_libxml_per_request_initialization = 0;
break; break;
} }
} }
} }
if (!_php_libxml_per_request_initialization) { if (!php_libxml_per_request_initialization) {
/* report errors via handler rather than stderr */ /* report errors via handler rather than stderr */
xmlSetGenericErrorFunc(NULL, php_libxml_error_handler); xmlSetGenericErrorFunc(NULL, php_libxml_error_handler);
xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename); xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
@ -973,7 +973,7 @@ static PHP_MINIT_FUNCTION(libxml)
static PHP_RINIT_FUNCTION(libxml) static PHP_RINIT_FUNCTION(libxml)
{ {
if (_php_libxml_per_request_initialization) { if (php_libxml_per_request_initialization) {
/* report errors via handler rather than stderr */ /* report errors via handler rather than stderr */
xmlSetGenericErrorFunc(NULL, php_libxml_error_handler); xmlSetGenericErrorFunc(NULL, php_libxml_error_handler);
xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename); xmlParserInputBufferCreateFilenameDefault(php_libxml_input_buffer_create_filename);
@ -1000,7 +1000,7 @@ static PHP_RSHUTDOWN_FUNCTION(libxml)
static PHP_MSHUTDOWN_FUNCTION(libxml) static PHP_MSHUTDOWN_FUNCTION(libxml)
{ {
if (!_php_libxml_per_request_initialization) { if (!php_libxml_per_request_initialization) {
xmlSetGenericErrorFunc(NULL, NULL); xmlSetGenericErrorFunc(NULL, NULL);
xmlParserInputBufferCreateFilenameDefault(NULL); xmlParserInputBufferCreateFilenameDefault(NULL);
@ -1014,7 +1014,7 @@ static PHP_MSHUTDOWN_FUNCTION(libxml)
static zend_result php_libxml_post_deactivate(void) static zend_result php_libxml_post_deactivate(void)
{ {
/* reset libxml generic error handling */ /* reset libxml generic error handling */
if (_php_libxml_per_request_initialization) { if (php_libxml_per_request_initialization) {
xmlSetGenericErrorFunc(NULL, NULL); xmlSetGenericErrorFunc(NULL, NULL);
xmlParserInputBufferCreateFilenameDefault(NULL); xmlParserInputBufferCreateFilenameDefault(NULL);
@ -1097,7 +1097,7 @@ PHP_FUNCTION(libxml_use_internal_errors)
xmlSetStructuredErrorFunc(NULL, php_libxml_structured_error_handler); xmlSetStructuredErrorFunc(NULL, php_libxml_structured_error_handler);
if (LIBXML(error_list) == NULL) { if (LIBXML(error_list) == NULL) {
LIBXML(error_list) = (zend_llist *) emalloc(sizeof(zend_llist)); LIBXML(error_list) = (zend_llist *) emalloc(sizeof(zend_llist));
zend_llist_init(LIBXML(error_list), sizeof(xmlError), _php_libxml_free_error, 0); zend_llist_init(LIBXML(error_list), sizeof(xmlError), php_libxml_free_error, 0);
} }
} }
RETURN_BOOL(retval); RETURN_BOOL(retval);