Skip to content

Commit d43f4bf

Browse files
committed
Use cpp11 raws with memcpy
1 parent 10f3f75 commit d43f4bf

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/connection.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ SEXP read_bin(SEXP con, size_t bytes = 64 * 1024);
1313
cpp11::sexp write_bin(cpp11::sexp data, cpp11::sexp con);
1414

1515
inline size_t R_WriteConnection(SEXP con, void* buf, size_t n) {
16-
SEXP payload = PROTECT(Rf_allocVector(RAWSXP, n));
16+
cpp11::writable::raws payload(n);
17+
SEXP payload_sexp = SEXP(payload);
1718

18-
memcpy(RAW(payload), buf, n);
19+
memcpy(RAW(payload_sexp), buf, n);
1920

20-
write_bin(payload, con);
21-
22-
UNPROTECT(1);
21+
write_bin(payload_sexp, con);
2322

2423
return n;
2524
}

src/cpp11.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extern "C" SEXP _xml2_init_libxml2() {
8383
END_CPP11
8484
}
8585
// xml2_init.cpp
86-
cpp11::sexp libxml2_version_();
86+
cpp11::strings libxml2_version_();
8787
extern "C" SEXP _xml2_libxml2_version_() {
8888
BEGIN_CPP11
8989
return cpp11::as_sexp(libxml2_version_());

0 commit comments

Comments
 (0)