Skip to content

Commit

Permalink
Build with NO_REMAP (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen authored Feb 20, 2024
1 parent 038a428 commit dc3e08d
Show file tree
Hide file tree
Showing 19 changed files with 247 additions and 247 deletions.
2 changes: 1 addition & 1 deletion src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKG_CFLAGS=$(C_VISIBILITY)
PKG_CPPFLAGS=@cflags@ -DSTRICT_R_HEADERS
PKG_CPPFLAGS=@cflags@ -DSTRICT_R_HEADERS -DR_NO_REMAP
PKG_LIBS=@libs@

all: clean
Expand Down
2 changes: 1 addition & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PKG_LIBS = \
-lwinhttp -lcurl -lnghttp2 -lssh2 -lz -lssl -lcrypto -pthread -lgdi32 -lws2_32 -lcrypt32 -lbcrypt -lwldap32

PKG_CPPFLAGS= \
-I$(RWINLIB)/include -DCURL_STATICLIB -DSTRICT_R_HEADERS
-I$(RWINLIB)/include -DCURL_STATICLIB -DSTRICT_R_HEADERS -DR_NO_REMAP

all: clean winlibs

Expand Down
18 changes: 9 additions & 9 deletions src/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ int R_curl_callback_progress(SEXP fun,
double dltotal, double dlnow,
double ultotal, double ulnow) {

SEXP down = PROTECT(allocVector(REALSXP, 2));
SEXP down = PROTECT(Rf_allocVector(REALSXP, 2));
REAL(down)[0] = dltotal;
REAL(down)[1] = dlnow;

SEXP up = PROTECT(allocVector(REALSXP, 2));
SEXP up = PROTECT(Rf_allocVector(REALSXP, 2));
REAL(up)[0] = ultotal;
REAL(up)[1] = ulnow;

Expand All @@ -21,19 +21,19 @@ int R_curl_callback_progress(SEXP fun,
return CURL_READFUNC_ABORT;
}

if (TYPEOF(res) != LGLSXP || length(res) != 1) {
if (TYPEOF(res) != LGLSXP || Rf_length(res) != 1) {
UNPROTECT(4);
Rf_warning("progress callback must return boolean");
return 0;
}

int out = asLogical(res);
int out = Rf_asLogical(res);
UNPROTECT(4);
return !out;
}

size_t R_curl_callback_read(char *buffer, size_t size, size_t nitems, SEXP fun) {
SEXP nbytes = PROTECT(ScalarInteger(size * nitems));
SEXP nbytes = PROTECT(Rf_ScalarInteger(size * nitems));
SEXP call = PROTECT(Rf_lang2(fun, nbytes));

int ok;
Expand All @@ -50,7 +50,7 @@ size_t R_curl_callback_read(char *buffer, size_t size, size_t nitems, SEXP fun)
return CURL_READFUNC_ABORT;
}

size_t bytes_read = length(res);
size_t bytes_read = Rf_length(res);
memcpy(buffer, RAW(res), bytes_read);

UNPROTECT(3);
Expand All @@ -59,7 +59,7 @@ size_t R_curl_callback_read(char *buffer, size_t size, size_t nitems, SEXP fun)

/* origin is always SEEK_SET in libcurl, not really useful to pass on */
int R_curl_callback_seek(SEXP fun, curl_off_t offset, int origin){
SEXP soffset = PROTECT(ScalarReal(offset));
SEXP soffset = PROTECT(Rf_ScalarReal(offset));
SEXP call = PROTECT(Rf_lang2(fun, soffset));
int ok;
R_tryEval(call, R_GlobalEnv, &ok);
Expand All @@ -71,8 +71,8 @@ int R_curl_callback_debug(CURL *handle, curl_infotype type_, char *data,
size_t size, SEXP fun) {

/* wrap type and msg into R types */
SEXP type = PROTECT(ScalarInteger(type_));
SEXP msg = PROTECT(allocVector(RAWSXP, size));
SEXP type = PROTECT(Rf_ScalarInteger(type_));
SEXP msg = PROTECT(Rf_allocVector(RAWSXP, size));
memcpy(RAW(msg), data, size);

/* call the R function */
Expand Down
14 changes: 7 additions & 7 deletions src/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static size_t push(void *contents, size_t sz, size_t nmemb, void *ctx) {
//Rprintf("Resizing buffer to %d.\n", newlimit);
void *newbuf = realloc(req->buf, newlimit);
if(!newbuf)
error("Failure in realloc. Out of memory?");
Rf_error("Failure in realloc. Out of memory?");
req->buf = newbuf;
req->limit = newlimit;
}
Expand Down Expand Up @@ -256,14 +256,14 @@ static Rboolean rcurl_open(Rconnection con) {
}

SEXP R_curl_connection(SEXP url, SEXP ptr, SEXP partial) {
if(!isString(url))
error("Argument 'url' must be string.");
if(!Rf_isString(url))
Rf_error("Argument 'url' must be string.");

/* create the R connection object, mimicking base::url() */
Rconnection con;

/* R wants description in native encoding, but we use UTF-8 URL below */
SEXP rc = PROTECT(R_new_custom_connection(translateChar(STRING_ELT(url, 0)), "r", "curl", &con));
SEXP rc = PROTECT(R_new_custom_connection(Rf_translateChar(STRING_ELT(url, 0)), "r", "curl", &con));

/* setup curl. These are the parts that are recycable. */
request *req = malloc(sizeof(request));
Expand All @@ -272,12 +272,12 @@ SEXP R_curl_connection(SEXP url, SEXP ptr, SEXP partial) {
req->limit = CURL_MAX_WRITE_SIZE;
req->buf = malloc(req->limit);
req->manager = curl_multi_init();
req->partial = asLogical(partial); //only for curl_fetch_stream()
req->partial = Rf_asLogical(partial); //only for curl_fetch_stream()
req->used = 0;

/* allocate url string */
req->url = malloc(strlen(translateCharUTF8(asChar(url))) + 1);
strcpy(req->url, translateCharUTF8(asChar(url)));
req->url = malloc(strlen(Rf_translateCharUTF8(Rf_asChar(url))) + 1);
strcpy(req->url, Rf_translateCharUTF8(Rf_asChar(url)));

/* set connection properties */
con->incomplete = FALSE;
Expand Down
28 changes: 14 additions & 14 deletions src/download.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@
#include "curl-common.h"

SEXP R_download_curl(SEXP url, SEXP destfile, SEXP quiet, SEXP mode, SEXP ptr, SEXP nonblocking) {
if(!isString(url))
error("Argument 'url' must be string.");
if(!Rf_isString(url))
Rf_error("Argument 'url' must be string.");

if(!isString(destfile))
error("Argument 'destfile' must be string.");
if(!Rf_isString(destfile))
Rf_error("Argument 'destfile' must be string.");

if(!isLogical(quiet))
error("Argument 'quiet' must be TRUE/FALSE.");
if(!Rf_isLogical(quiet))
Rf_error("Argument 'quiet' must be TRUE/FALSE.");

if(!isString(mode))
error("Argument 'mode' must be string.");
if(!Rf_isString(mode))
Rf_error("Argument 'mode' must be string.");

/* get the handle */
CURL *handle = get_handle(ptr);
reset_errbuf(get_ref(ptr));

/* open file */
FILE *dest = fopen(CHAR(asChar(destfile)), CHAR(asChar(mode)));
FILE *dest = fopen(CHAR(Rf_asChar(destfile)), CHAR(Rf_asChar(mode)));
if(!dest)
error("Failed to open file %s.", CHAR(asChar(destfile)));
Rf_error("Failed to open file %s.", CHAR(Rf_asChar(destfile)));

/* set options */
curl_easy_setopt(handle, CURLOPT_URL, translateCharUTF8(asChar(url)));
curl_easy_setopt(handle, CURLOPT_NOPROGRESS, asLogical(quiet));
curl_easy_setopt(handle, CURLOPT_URL, Rf_translateCharUTF8(Rf_asChar(url)));
curl_easy_setopt(handle, CURLOPT_NOPROGRESS, Rf_asLogical(quiet));
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, push_disk);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, dest);

/* perform blocking request */
CURLcode status = asLogical(nonblocking) ?
CURLcode status = Rf_asLogical(nonblocking) ?
curl_perform_with_interrupt(handle) : curl_easy_perform(handle);

/* cleanup */
Expand All @@ -47,5 +47,5 @@ SEXP R_download_curl(SEXP url, SEXP destfile, SEXP quiet, SEXP mode, SEXP ptr, S

/* check for success */
stop_for_status(handle);
return ScalarInteger(0);
return Rf_ScalarInteger(0);
}
8 changes: 4 additions & 4 deletions src/escape.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

SEXP R_curl_escape(SEXP url, SEXP unescape_) {
if (!Rf_isString(url))
error("`url` must be a character vector.");
Rf_error("`url` must be a character vector.");
CURL *handle = curl_easy_init();
int n = Rf_length(url);
SEXP output = PROTECT(allocVector(STRSXP, n));
SEXP output = PROTECT(Rf_allocVector(STRSXP, n));

for (int i = 0; i < n; i++) {
const char *input = CHAR(STRING_ELT(url, i));
char *out = asLogical(unescape_) ?
char *out = Rf_asLogical(unescape_) ?
curl_easy_unescape(handle, input, 0, NULL) : curl_easy_escape(handle, input, 0);
if(out != NULL){
SET_STRING_ELT(output, i, mkCharCE(out, CE_UTF8));
SET_STRING_ELT(output, i, Rf_mkCharCE(out, CE_UTF8));
curl_free(out);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "curl-common.h"

SEXP R_curl_fetch_memory(SEXP url, SEXP ptr, SEXP nonblocking){
if (!isString(url) || length(url) != 1)
error("Argument 'url' must be string.");
if (!Rf_isString(url) || Rf_length(url) != 1)
Rf_error("Argument 'url' must be string.");

/* get the handle */
CURL *handle = get_handle(ptr);
Expand All @@ -25,7 +25,7 @@ SEXP R_curl_fetch_memory(SEXP url, SEXP ptr, SEXP nonblocking){
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &body);

/* perform blocking request */
CURLcode status = asLogical(nonblocking) ?
CURLcode status = Rf_asLogical(nonblocking) ?
curl_perform_with_interrupt(handle) : curl_easy_perform(handle);

/* Reset for reuse */
Expand All @@ -39,7 +39,7 @@ SEXP R_curl_fetch_memory(SEXP url, SEXP ptr, SEXP nonblocking){
}

/* create output */
SEXP out = PROTECT(allocVector(RAWSXP, body.size));
SEXP out = PROTECT(Rf_allocVector(RAWSXP, body.size));

/* copy only if there is actual content */
if(body.size)
Expand All @@ -52,10 +52,10 @@ SEXP R_curl_fetch_memory(SEXP url, SEXP ptr, SEXP nonblocking){
}

SEXP R_curl_fetch_disk(SEXP url, SEXP ptr, SEXP path, SEXP mode, SEXP nonblocking){
if (!isString(url) || length(url) != 1)
error("Argument 'url' must be string.");
if (!isString(path) || length(path) != 1)
error("`path` must be string.");
if (!Rf_isString(url) || Rf_length(url) != 1)
Rf_error("Argument 'url' must be string.");
if (!Rf_isString(path) || Rf_length(path) != 1)
Rf_error("`path` must be string.");

/* get the handle */
CURL *handle = get_handle(ptr);
Expand All @@ -68,14 +68,14 @@ SEXP R_curl_fetch_disk(SEXP url, SEXP ptr, SEXP path, SEXP mode, SEXP nonblockin
reset_errbuf(get_ref(ptr));

/* open file */
FILE *dest = fopen(CHAR(asChar(path)), CHAR(asChar(mode)));
FILE *dest = fopen(CHAR(Rf_asChar(path)), CHAR(Rf_asChar(mode)));
if(!dest)
error("Failed to open file %s.", CHAR(asChar(path)));
Rf_error("Failed to open file %s.", CHAR(Rf_asChar(path)));
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, push_disk);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, dest);

/* perform blocking request */
CURLcode status = asLogical(nonblocking) ?
CURLcode status = Rf_asLogical(nonblocking) ?
curl_perform_with_interrupt(handle): curl_easy_perform(handle);

/* cleanup */
Expand Down
2 changes: 1 addition & 1 deletion src/findport.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ SEXP R_findport(SEXP candidates){
for(int i = 0; i < Rf_length(candidates); i++){
int port = INTEGER(candidates)[i];
if(port_is_available(port)){
return ScalarInteger(port);
return Rf_ScalarInteger(port);
}
}
return R_NilValue;
Expand Down
30 changes: 15 additions & 15 deletions src/form.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
struct curl_httppost* make_form(SEXP form){
struct curl_httppost* post = NULL;
struct curl_httppost* last = NULL;
SEXP ln = PROTECT(getAttrib(form, R_NamesSymbol));
for(int i = 0; i < length(form); i++){
const char *name = translateCharUTF8(STRING_ELT(ln, i));
SEXP ln = PROTECT(Rf_getAttrib(form, R_NamesSymbol));
for(int i = 0; i < Rf_length(form); i++){
const char *name = Rf_translateCharUTF8(STRING_ELT(ln, i));
SEXP val = VECTOR_ELT(form, i);
if(TYPEOF(val) == RAWSXP){
long datalen = Rf_length(val);
Expand All @@ -16,21 +16,21 @@ struct curl_httppost* make_form(SEXP form){
//Note if 'CURLFORM_CONTENTLEN == 0' then libcurl assumes strlen() !
curl_formadd(&post, &last, CURLFORM_COPYNAME, name, CURLFORM_COPYCONTENTS, "", CURLFORM_END);
}
} else if(isVector(val) && Rf_length(val)){
if(isString(VECTOR_ELT(val, 0))){
} else if(Rf_isVector(val) && Rf_length(val)){
if(Rf_isString(VECTOR_ELT(val, 0))){
//assume a form_file upload
const char *path = CHAR(asChar(VECTOR_ELT(val, 0)));
if(isString(VECTOR_ELT(val, 1))) {
const char *content_type = CHAR(asChar(VECTOR_ELT(val, 1)));
if(isString(VECTOR_ELT(val, 2))) {
const char *file_name = CHAR(asChar(VECTOR_ELT(val, 2)));
const char *path = CHAR(Rf_asChar(VECTOR_ELT(val, 0)));
if(Rf_isString(VECTOR_ELT(val, 1))) {
const char *content_type = CHAR(Rf_asChar(VECTOR_ELT(val, 1)));
if(Rf_isString(VECTOR_ELT(val, 2))) {
const char *file_name = CHAR(Rf_asChar(VECTOR_ELT(val, 2)));
curl_formadd(&post, &last, CURLFORM_COPYNAME, name, CURLFORM_FILE, path, CURLFORM_CONTENTTYPE, content_type, CURLFORM_FILENAME, file_name, CURLFORM_END);
} else {
curl_formadd(&post, &last, CURLFORM_COPYNAME, name, CURLFORM_FILE, path, CURLFORM_CONTENTTYPE, content_type, CURLFORM_END);
}
} else {
if(isString(VECTOR_ELT(val, 2))) {
const char *file_name = CHAR(asChar(VECTOR_ELT(val, 2)));
if(Rf_isString(VECTOR_ELT(val, 2))) {
const char *file_name = CHAR(Rf_asChar(VECTOR_ELT(val, 2)));
curl_formadd(&post, &last, CURLFORM_COPYNAME, name, CURLFORM_FILE, path, CURLFORM_FILENAME, file_name, CURLFORM_END);
} else {
curl_formadd(&post, &last, CURLFORM_COPYNAME, name, CURLFORM_FILE, path, CURLFORM_END);
Expand All @@ -40,15 +40,15 @@ struct curl_httppost* make_form(SEXP form){
//assume a form_value upload
unsigned char * data = RAW(VECTOR_ELT(val, 0));
long datalen = Rf_length(VECTOR_ELT(val, 0));
if(isString(VECTOR_ELT(val, 1))){
const char * content_type = CHAR(asChar(VECTOR_ELT(val, 1)));
if(Rf_isString(VECTOR_ELT(val, 1))){
const char * content_type = CHAR(Rf_asChar(VECTOR_ELT(val, 1)));
curl_formadd(&post, &last, CURLFORM_COPYNAME, name, CURLFORM_COPYCONTENTS, data, CURLFORM_CONTENTSLENGTH, datalen, CURLFORM_CONTENTTYPE, content_type, CURLFORM_END);
} else {
curl_formadd(&post, &last, CURLFORM_COPYNAME, name, CURLFORM_COPYCONTENTS, data, CURLFORM_CONTENTSLENGTH, datalen, CURLFORM_END);
}
}
} else {
error("form value %s not supported", name);
Rf_error("form value %s not supported", name);
}
}
UNPROTECT(1);
Expand Down
8 changes: 4 additions & 4 deletions src/getdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include <Rinternals.h>

SEXP R_curl_getdate(SEXP datestring) {
if(!isString(datestring))
error("Argument 'datestring' must be string.");
if(!Rf_isString(datestring))
Rf_error("Argument 'datestring' must be string.");

int len = length(datestring);
SEXP out = PROTECT(allocVector(INTSXP, len));
int len = Rf_length(datestring);
SEXP out = PROTECT(Rf_allocVector(INTSXP, len));

for(int i = 0; i < len; i++){
time_t date = curl_getdate(CHAR(STRING_ELT(datestring, i)), NULL);
Expand Down
Loading

0 comments on commit dc3e08d

Please sign in to comment.