Skip to content

Commit f9c5fe3

Browse files
committed
Stop using internal struct fields for libxml2 2.14
1 parent c3d23eb commit f9c5fe3

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: xml2
22
Title: Parse XML
3-
Version: 1.3.9000
3+
Version: 1.4.0
44
Authors@R: c(
55
person("Hadley", "Wickham", role = "aut"),
66
person("Jim", "Hester", role = "aut"),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* Workaround for xQuartz/Cocoa on MacOS hitting our global error handler.
66

7+
* Avoid accessing some struct internals disallowed in libxml2 2.14
8+
79
# xml2 1.3.8
810

911
* Replace new "non-api" call IS_S4_OBJECT with Rf_isS4

src/xml2_doc.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,14 @@ extern "C" SEXP doc_url(SEXP doc_sxp) {
291291
extern "C" SEXP doc_new(SEXP version_sxp, SEXP encoding_sxp) {
292292

293293
const char* encoding = CHAR(STRING_ELT(encoding_sxp, 0));
294+
const xmlCharEncoding enc = xmlParseCharEncoding(encoding);
295+
if(enc < 0){
296+
Rf_error("Requested unsupported encoding '%s'", encoding);
297+
}
294298

295299
BEGIN_CPP
296300
XPtrDoc x(xmlNewDoc(asXmlChar(version_sxp)));
297-
xmlCharEncodingHandlerPtr p = xmlFindCharEncodingHandler(encoding);
298-
x->encoding = xmlStrdup(reinterpret_cast<const xmlChar *>(p->name));
301+
x->encoding = xmlStrdup(reinterpret_cast<const xmlChar *>(xmlGetCharEncodingName(enc)));
299302
return SEXP(x);
300303
END_CPP
301304
}

src/xml2_output.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ extern "C" SEXP doc_write_character(SEXP doc_sxp, SEXP encoding_sxp, SEXP option
161161
Rf_error("Error writing to buffer");
162162
}
163163
SEXP out = PROTECT(Rf_allocVector(STRSXP, 1));
164-
SET_STRING_ELT(out, 0, Xml2String(buffer->content).asRString());
164+
SET_STRING_ELT(out, 0, Xml2String(xmlBufferContent(buffer)).asRString());
165165

166166
xmlFree(buffer);
167167

@@ -235,7 +235,7 @@ extern "C" SEXP node_write_character(SEXP node_sxp, SEXP encoding_sxp, SEXP opti
235235
xmlFree(buffer);
236236
Rf_error("Error writing to buffer");
237237
}
238-
SEXP out = PROTECT(Rf_ScalarString(Xml2String(buffer->content).asRString()));
238+
SEXP out = PROTECT(Rf_ScalarString(Xml2String(xmlBufferContent(buffer)).asRString()));
239239
xmlFree(buffer);
240240

241241
UNPROTECT(1);

0 commit comments

Comments
 (0)