Skip to content

Commit e0561f0

Browse files
committed
xml: Migrate qualify_namespace to ZendMM
1 parent 20cc3a3 commit e0561f0

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

ext/xml/compat.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@
2222

2323
#ifdef LIBXML_EXPAT_COMPAT
2424

25-
static void
26-
qualify_namespace(XML_Parser parser, const xmlChar *name, const xmlChar *URI, xmlChar **qualified)
25+
static xmlChar *
26+
qualify_namespace(XML_Parser parser, const xmlChar *name, const xmlChar *URI)
2727
{
2828
if (URI) {
29-
/* Use libxml functions otherwise its memory deallocation is screwed up */
30-
*qualified = xmlStrdup(URI);
31-
*qualified = xmlStrncat(*qualified, parser->_ns_separator, 1);
32-
*qualified = xmlStrncat(*qualified, name, xmlStrlen(name));
29+
smart_string str = {0};
30+
smart_string_appends(&str, (const char *) URI);
31+
smart_string_appends(&str, (const char *) parser->_ns_separator);
32+
smart_string_appends(&str, (const char *) name);
33+
smart_string_0(&str);
34+
return BAD_CAST str.c;
3335
} else {
34-
*qualified = xmlStrdup(name);
36+
return BAD_CAST estrdup((const char *) name);
3537
}
3638
}
3739

@@ -151,7 +153,7 @@ start_element_handler_ns(void *user, const xmlChar *name, const xmlChar *prefix,
151153
}
152154
return;
153155
}
154-
qualify_namespace(parser, name, URI, &qualified_name);
156+
qualified_name = qualify_namespace(parser, name, URI);
155157

156158
if (attributes != NULL) {
157159
xmlChar *qualified_name_attr = NULL;
@@ -160,12 +162,12 @@ start_element_handler_ns(void *user, const xmlChar *name, const xmlChar *prefix,
160162
for (i = 0; i < nb_attributes; i += 1) {
161163

162164
if (attributes[y+1] != NULL) {
163-
qualify_namespace(parser, attributes[y] , attributes[y + 2], &qualified_name_attr);
165+
qualified_name_attr = qualify_namespace(parser, attributes[y] , attributes[y + 2]);
164166
} else {
165-
qualified_name_attr = xmlStrdup(attributes[y]);
167+
qualified_name_attr = BAD_CAST estrdup((const char *) attributes[y]);
166168
}
167169
attrs[z] = qualified_name_attr;
168-
attrs[z + 1] = xmlStrndup(attributes[y + 3] , (int) (attributes[y + 4] - attributes[y + 3]));
170+
attrs[z + 1] = BAD_CAST estrndup((const char *) attributes[y + 3], attributes[y + 4] - attributes[y + 3]);
169171
z += 2;
170172
y += 5;
171173
}
@@ -175,11 +177,11 @@ start_element_handler_ns(void *user, const xmlChar *name, const xmlChar *prefix,
175177
parser->h_start_element(parser->user, (const XML_Char *) qualified_name, (const XML_Char **) attrs);
176178
if (attrs) {
177179
for (i = 0; i < z; i++) {
178-
xmlFree(attrs[i]);
180+
efree(attrs[i]);
179181
}
180182
efree(attrs);
181183
}
182-
xmlFree(qualified_name);
184+
efree(qualified_name);
183185
}
184186

185187
static void
@@ -223,11 +225,11 @@ end_element_handler_ns(void *user, const xmlChar *name, const xmlChar * prefix,
223225
return;
224226
}
225227

226-
qualify_namespace(parser, name, URI, &qualified_name);
228+
qualified_name = qualify_namespace(parser, name, URI);
227229

228230
parser->h_end_element(parser->user, (const XML_Char *) qualified_name);
229231

230-
xmlFree(qualified_name);
232+
efree(qualified_name);
231233
}
232234

233235
static void

0 commit comments

Comments
 (0)