Skip to content

Commit 88024a3

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

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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)