Skip to content

Commit ca6caa0

Browse files
committed
Make ext/xml API private
Also remove dead functions
1 parent ba300b6 commit ca6caa0

File tree

3 files changed

+102
-176
lines changed

3 files changed

+102
-176
lines changed

UPGRADING.INTERNALS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PHP 7.4 INTERNALS UPGRADE NOTES
1111
b. Windows build system changes
1212

1313
3. Module changes
14+
a. ext/xml
1415

1516
========================
1617
1. Internal API changes
@@ -54,3 +55,7 @@ PHP 7.4 INTERNALS UPGRADE NOTES
5455
========================
5556
3. Module changes
5657
========================
58+
59+
a. ext/xml
60+
- The public (internal) API of the ext/xml extension has been removed. All
61+
functions and structures are private to the extension now.

ext/xml/php_xml.h

Lines changed: 4 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -22,132 +22,25 @@
2222
#define PHP_XML_H
2323

2424
#ifdef HAVE_XML
25+
2526
extern zend_module_entry xml_module_entry;
2627
#define xml_module_ptr &xml_module_entry
2728

2829
#include "php_version.h"
2930
#define PHP_XML_VERSION PHP_VERSION
3031

31-
#else
32-
#define xml_module_ptr NULL
33-
#endif
34-
35-
#ifdef HAVE_XML
36-
3732
#include "expat_compat.h"
3833

3934
#ifdef XML_UNICODE
4035
#error "UTF-16 Unicode support not implemented!"
4136
#endif
4237

43-
ZEND_BEGIN_MODULE_GLOBALS(xml)
44-
XML_Char *default_encoding;
45-
ZEND_END_MODULE_GLOBALS(xml)
46-
47-
typedef struct {
48-
int case_folding;
49-
XML_Parser parser;
50-
XML_Char *target_encoding;
51-
52-
zval index;
53-
zval startElementHandler;
54-
zval endElementHandler;
55-
zval characterDataHandler;
56-
zval processingInstructionHandler;
57-
zval defaultHandler;
58-
zval unparsedEntityDeclHandler;
59-
zval notationDeclHandler;
60-
zval externalEntityRefHandler;
61-
zval unknownEncodingHandler;
62-
zval startNamespaceDeclHandler;
63-
zval endNamespaceDeclHandler;
64-
65-
zend_function *startElementPtr;
66-
zend_function *endElementPtr;
67-
zend_function *characterDataPtr;
68-
zend_function *processingInstructionPtr;
69-
zend_function *defaultPtr;
70-
zend_function *unparsedEntityDeclPtr;
71-
zend_function *notationDeclPtr;
72-
zend_function *externalEntityRefPtr;
73-
zend_function *unknownEncodingPtr;
74-
zend_function *startNamespaceDeclPtr;
75-
zend_function *endNamespaceDeclPtr;
76-
77-
zval object;
78-
79-
zval data;
80-
zval info;
81-
int level;
82-
int toffset;
83-
int curtag;
84-
zval *ctag;
85-
char **ltags;
86-
int lastwasopen;
87-
int skipwhite;
88-
int isparsing;
89-
90-
XML_Char *baseURI;
91-
} xml_parser;
92-
93-
94-
typedef struct {
95-
XML_Char *name;
96-
char (*decoding_function)(unsigned short);
97-
unsigned short (*encoding_function)(unsigned char);
98-
} xml_encoding;
99-
100-
101-
enum php_xml_option {
102-
PHP_XML_OPTION_CASE_FOLDING = 1,
103-
PHP_XML_OPTION_TARGET_ENCODING,
104-
PHP_XML_OPTION_SKIP_TAGSTART,
105-
PHP_XML_OPTION_SKIP_WHITE
106-
};
107-
108-
/* for xml_parse_into_struct */
109-
110-
#define XML_MAXLEVEL 255 /* XXX this should be dynamic */
111-
112-
PHP_FUNCTION(xml_parser_create);
113-
PHP_FUNCTION(xml_parser_create_ns);
114-
PHP_FUNCTION(xml_set_object);
115-
PHP_FUNCTION(xml_set_element_handler);
116-
PHP_FUNCTION(xml_set_character_data_handler);
117-
PHP_FUNCTION(xml_set_processing_instruction_handler);
118-
PHP_FUNCTION(xml_set_default_handler);
119-
PHP_FUNCTION(xml_set_unparsed_entity_decl_handler);
120-
PHP_FUNCTION(xml_set_notation_decl_handler);
121-
PHP_FUNCTION(xml_set_external_entity_ref_handler);
122-
PHP_FUNCTION(xml_set_start_namespace_decl_handler);
123-
PHP_FUNCTION(xml_set_end_namespace_decl_handler);
124-
PHP_FUNCTION(xml_parse);
125-
PHP_FUNCTION(xml_get_error_code);
126-
PHP_FUNCTION(xml_error_string);
127-
PHP_FUNCTION(xml_get_current_line_number);
128-
PHP_FUNCTION(xml_get_current_column_number);
129-
PHP_FUNCTION(xml_get_current_byte_index);
130-
PHP_FUNCTION(xml_parser_free);
131-
PHP_FUNCTION(xml_parser_set_option);
132-
PHP_FUNCTION(xml_parser_get_option);
133-
PHP_FUNCTION(utf8_encode);
134-
PHP_FUNCTION(utf8_decode);
135-
PHP_FUNCTION(xml_parse_into_struct);
136-
137-
PHP_XML_API char *_xml_zval_strdup(zval *);
138-
PHP_XML_API zend_string *xml_utf8_decode(const XML_Char *, size_t, const XML_Char *);
139-
PHP_XML_API zend_string *xml_utf8_encode(const char *, size_t, const XML_Char *);
140-
141-
#endif /* HAVE_LIBEXPAT */
38+
#else
39+
#define xml_module_ptr NULL
40+
#endif /* HAVE_XML */
14241

14342
#define phpext_xml_ptr xml_module_ptr
14443

145-
#define XML(v) ZEND_MODULE_GLOBALS_ACCESSOR(xml, v)
146-
147-
#if defined(ZTS) && defined(COMPILE_DL_XML)
148-
ZEND_TSRMLS_CACHE_EXTERN()
149-
#endif
150-
15144
#endif /* PHP_XML_H */
15245

15346
/*

ext/xml/xml.c

Lines changed: 93 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,75 @@
5656
* - Weird things happen with <![CDATA[]]> sections.
5757
*/
5858

59+
ZEND_BEGIN_MODULE_GLOBALS(xml)
60+
XML_Char *default_encoding;
61+
ZEND_END_MODULE_GLOBALS(xml)
62+
5963
ZEND_DECLARE_MODULE_GLOBALS(xml)
6064

65+
#define XML(v) ZEND_MODULE_GLOBALS_ACCESSOR(xml, v)
66+
67+
typedef struct {
68+
int case_folding;
69+
XML_Parser parser;
70+
XML_Char *target_encoding;
71+
72+
zval index;
73+
zval startElementHandler;
74+
zval endElementHandler;
75+
zval characterDataHandler;
76+
zval processingInstructionHandler;
77+
zval defaultHandler;
78+
zval unparsedEntityDeclHandler;
79+
zval notationDeclHandler;
80+
zval externalEntityRefHandler;
81+
zval unknownEncodingHandler;
82+
zval startNamespaceDeclHandler;
83+
zval endNamespaceDeclHandler;
84+
85+
zend_function *startElementPtr;
86+
zend_function *endElementPtr;
87+
zend_function *characterDataPtr;
88+
zend_function *processingInstructionPtr;
89+
zend_function *defaultPtr;
90+
zend_function *unparsedEntityDeclPtr;
91+
zend_function *notationDeclPtr;
92+
zend_function *externalEntityRefPtr;
93+
zend_function *unknownEncodingPtr;
94+
zend_function *startNamespaceDeclPtr;
95+
zend_function *endNamespaceDeclPtr;
96+
97+
zval object;
98+
99+
zval data;
100+
zval info;
101+
int level;
102+
int toffset;
103+
int curtag;
104+
zval *ctag;
105+
char **ltags;
106+
int lastwasopen;
107+
int skipwhite;
108+
int isparsing;
109+
110+
XML_Char *baseURI;
111+
} xml_parser;
112+
113+
114+
typedef struct {
115+
XML_Char *name;
116+
char (*decoding_function)(unsigned short);
117+
unsigned short (*encoding_function)(unsigned char);
118+
} xml_encoding;
119+
120+
121+
enum php_xml_option {
122+
PHP_XML_OPTION_CASE_FOLDING = 1,
123+
PHP_XML_OPTION_TARGET_ENCODING,
124+
PHP_XML_OPTION_SKIP_TAGSTART,
125+
PHP_XML_OPTION_SKIP_WHITE
126+
};
127+
61128
/* {{{ dynamically loadable module stuff */
62129
#ifdef COMPILE_DL_XML
63130
#ifdef ZTS
@@ -67,6 +134,7 @@ ZEND_GET_MODULE(xml)
67134
#endif /* COMPILE_DL_XML */
68135
/* }}} */
69136

137+
#define XML_MAXLEVEL 255 /* XXX this should be dynamic */
70138

71139
#define SKIP_TAGSTART(str) ((str) + (parser->toffset > (int)strlen(str) ? strlen(str) : parser->toffset))
72140

@@ -76,6 +144,30 @@ PHP_MINIT_FUNCTION(xml);
76144
PHP_MINFO_FUNCTION(xml);
77145
static PHP_GINIT_FUNCTION(xml);
78146

147+
PHP_FUNCTION(xml_parser_create);
148+
PHP_FUNCTION(xml_parser_create_ns);
149+
PHP_FUNCTION(xml_set_object);
150+
PHP_FUNCTION(xml_set_element_handler);
151+
PHP_FUNCTION(xml_set_character_data_handler);
152+
PHP_FUNCTION(xml_set_processing_instruction_handler);
153+
PHP_FUNCTION(xml_set_default_handler);
154+
PHP_FUNCTION(xml_set_unparsed_entity_decl_handler);
155+
PHP_FUNCTION(xml_set_notation_decl_handler);
156+
PHP_FUNCTION(xml_set_external_entity_ref_handler);
157+
PHP_FUNCTION(xml_set_start_namespace_decl_handler);
158+
PHP_FUNCTION(xml_set_end_namespace_decl_handler);
159+
PHP_FUNCTION(xml_parse);
160+
PHP_FUNCTION(xml_get_error_code);
161+
PHP_FUNCTION(xml_error_string);
162+
PHP_FUNCTION(xml_get_current_line_number);
163+
PHP_FUNCTION(xml_get_current_column_number);
164+
PHP_FUNCTION(xml_get_current_byte_index);
165+
PHP_FUNCTION(xml_parser_free);
166+
PHP_FUNCTION(xml_parser_set_option);
167+
PHP_FUNCTION(xml_parser_get_option);
168+
PHP_FUNCTION(xml_parse_into_struct);
169+
170+
static zend_string *xml_utf8_decode(const XML_Char *, size_t, const XML_Char *);
79171
static void xml_parser_dtor(zend_resource *rsrc);
80172
static void xml_set_handler(zval *, zval *);
81173
inline static unsigned short xml_encode_iso_8859_1(unsigned char);
@@ -549,59 +641,8 @@ static const xml_encoding *xml_get_encoding(const XML_Char *name)
549641
}
550642
/* }}} */
551643

552-
/* {{{ xml_utf8_encode() */
553-
PHP_XML_API zend_string *xml_utf8_encode(const char *s, size_t len, const XML_Char *encoding)
554-
{
555-
size_t pos = len;
556-
zend_string *str;
557-
unsigned int c;
558-
unsigned short (*encoder)(unsigned char) = NULL;
559-
const xml_encoding *enc = xml_get_encoding(encoding);
560-
561-
if (enc) {
562-
encoder = enc->encoding_function;
563-
} else {
564-
/* If the target encoding was unknown, fail */
565-
return NULL;
566-
}
567-
if (encoder == NULL) {
568-
/* If no encoder function was specified, return the data as-is.
569-
*/
570-
str = zend_string_init(s, len, 0);
571-
return str;
572-
}
573-
/* This is the theoretical max (will never get beyond len * 2 as long
574-
* as we are converting from single-byte characters, though) */
575-
str = zend_string_safe_alloc(len, 4, 0, 0);
576-
ZSTR_LEN(str) = 0;
577-
while (pos > 0) {
578-
c = encoder ? encoder((unsigned char)(*s)) : (unsigned short)(*s);
579-
if (c < 0x80) {
580-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (char) c;
581-
} else if (c < 0x800) {
582-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0xc0 | (c >> 6));
583-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0x80 | (c & 0x3f));
584-
} else if (c < 0x10000) {
585-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0xe0 | (c >> 12));
586-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0xc0 | ((c >> 6) & 0x3f));
587-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0x80 | (c & 0x3f));
588-
} else if (c < 0x200000) {
589-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0xf0 | (c >> 18));
590-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0xe0 | ((c >> 12) & 0x3f));
591-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0xc0 | ((c >> 6) & 0x3f));
592-
ZSTR_VAL(str)[ZSTR_LEN(str)++] = (0x80 | (c & 0x3f));
593-
}
594-
pos--;
595-
s++;
596-
}
597-
ZSTR_VAL(str)[ZSTR_LEN(str)] = '\0';
598-
str = zend_string_truncate(str, ZSTR_LEN(str), 0);
599-
return str;
600-
}
601-
/* }}} */
602-
603644
/* {{{ xml_utf8_decode() */
604-
PHP_XML_API zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XML_Char *encoding)
645+
static zend_string *xml_utf8_decode(const XML_Char *s, size_t len, const XML_Char *encoding)
605646
{
606647
size_t pos = 0;
607648
unsigned int c;
@@ -655,19 +696,6 @@ static int _xml_xmlcharlen(const XML_Char *s)
655696
}
656697
/* }}} */
657698

658-
/* {{{ _xml_zval_strdup() */
659-
PHP_XML_API char *_xml_zval_strdup(zval *val)
660-
{
661-
if (Z_TYPE_P(val) == IS_STRING) {
662-
char *buf = emalloc(Z_STRLEN_P(val) + 1);
663-
memcpy(buf, Z_STRVAL_P(val), Z_STRLEN_P(val));
664-
buf[Z_STRLEN_P(val)] = '\0';
665-
return buf;
666-
}
667-
return NULL;
668-
}
669-
/* }}} */
670-
671699
/* {{{ _xml_add_to_info() */
672700
static void _xml_add_to_info(xml_parser *parser,char *name)
673701
{

0 commit comments

Comments
 (0)