Skip to content

Commit 1f8b494

Browse files
committed
Cleanups
1 parent 3c13abc commit 1f8b494

5 files changed

Lines changed: 15 additions & 37 deletions

File tree

R/init.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.onLoad <- function(lib, pkg) {
2-
.Call(init_libxml2)
3-
}
4-
51
libxml2_version <- function() {
62
as.numeric_version(.Call(libxml2_version_))
73
}

src/Makevars.win

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PKG_CONFIG_NAME = libxml-2.0
22
PKG_CONFIG ?= $(BINPREF)pkg-config
33
PKG_LIBS := $(shell $(PKG_CONFIG) --libs $(PKG_CONFIG_NAME))
4-
STATIC_CFLAGS = -DLIBXML_STATIC -I../inst/include
4+
STATIC_CFLAGS = -DSTRICT_R_HEADERS -DR_NO_REMAP -DLIBXML_STATIC -I../inst/include
55

66
ifneq ($(PKG_LIBS),)
77
$(info using $(PKG_CONFIG_NAME) from Rtools)

src/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ extern SEXP doc_validate(SEXP, SEXP);
2020
extern SEXP doc_write_character(SEXP, SEXP, SEXP);
2121
extern SEXP doc_write_connection(SEXP, SEXP, SEXP, SEXP);
2222
extern SEXP doc_write_file(SEXP, SEXP, SEXP, SEXP);
23-
extern SEXP init_libxml2(void);
2423
extern SEXP libxml2_version_(void);
2524
extern SEXP node_append_child(SEXP, SEXP);
2625
extern SEXP node_append_content(SEXP, SEXP);
@@ -85,7 +84,6 @@ static const R_CallMethodDef CallEntries[] = {
8584
{"doc_write_character", (DL_FUNC) &doc_write_character, 3},
8685
{"doc_write_connection", (DL_FUNC) &doc_write_connection, 4},
8786
{"doc_write_file", (DL_FUNC) &doc_write_file, 4},
88-
{"init_libxml2", (DL_FUNC) &init_libxml2, 0},
8987
{"libxml2_version_", (DL_FUNC) &libxml2_version_, 0},
9088
{"node_append_child", (DL_FUNC) &node_append_child, 2},
9189
{"node_append_content", (DL_FUNC) &node_append_content, 2},
@@ -138,8 +136,10 @@ static const R_CallMethodDef CallEntries[] = {
138136
{NULL, NULL, 0}
139137
};
140138

139+
void init_libxml2_library();
141140
void R_init_xml2(DllInfo *dll)
142141
{
143142
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
144143
R_useDynamicSymbols(dll, FALSE);
144+
init_libxml2_library();
145145
}
Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#include <Rinternals.h>
2-
#include <R_ext/Rdynload.h>
3-
#include <stdio.h>
42
#include <libxml/xmlversion.h>
53
#include <libxml/xmlerror.h>
6-
#include <libxml/parser.h>
7-
#include <string>
8-
#include "xml2_utils.h"
4+
95

106
/* * *
117
* Author: Nick Wellnhofer <wellnhofer@aevum.de>
@@ -20,21 +16,16 @@ void handleStructuredError(void* userData, const xmlError* error) {
2016
void handleStructuredError(void* userData, xmlError* error) {
2117
#endif
2218

23-
BEGIN_CPP
24-
std::string message = std::string(error->message);
25-
message.resize(message.size() - 1); // trim off trailing newline
26-
19+
//std::string message = std::string(error->message);
20+
//message.resize(message.size() - 1); // trim off trailing newline
2721
if (error->level <= 2) {
28-
Rf_warning("%s [%i]", message.c_str(), (int) error->code);
22+
Rf_warning("%s [%i]", error->message, (int) error->code);
2923
} else {
30-
Rf_error("%s [%i]", message.c_str(), (int) error->code);
24+
Rf_error("%s [%i]", error->message, (int) error->code);
3125
}
32-
END_CPP
33-
3426
}
3527

36-
void handleGenericError(void *ctx, const char *fmt, ...)
37-
{
28+
void handleGenericError(void *ctx, const char *fmt, ...){
3829
char buffer[BUFSIZ];
3930
va_list arg;
4031

@@ -45,26 +36,12 @@ void handleGenericError(void *ctx, const char *fmt, ...)
4536
Rf_error("%s", buffer);
4637
}
4738

48-
// [[export]]
49-
extern "C" SEXP init_libxml2() {
39+
void init_libxml2_library() {
5040
// Check that header and libs are compatible
5141
LIBXML_TEST_VERSION
5242

5343
xmlInitParser();
5444
xmlSetStructuredErrorFunc(NULL, handleStructuredError);
5545
xmlSetGenericErrorFunc(NULL, handleGenericError);
56-
57-
return R_NilValue;
5846
}
5947

60-
extern "C" {
61-
void R_unload_xml2(DllInfo *info) {
62-
xmlCleanupParser();
63-
}
64-
65-
}
66-
67-
// [[export]]
68-
extern "C" SEXP libxml2_version_(){
69-
return Rf_mkString(LIBXML_DOTTED_VERSION);
70-
}

src/xml2_namespace.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ extern "C" SEXP ns_lookup(SEXP doc_sxp, SEXP node_sxp, SEXP prefix_sxp) {
7272
return SEXP(out);
7373
END_CPP
7474
}
75+
76+
// [[export]]
77+
extern "C" SEXP libxml2_version_(){
78+
return Rf_mkString(LIBXML_DOTTED_VERSION);
79+
}

0 commit comments

Comments
 (0)