diff --git a/src/Makevars b/src/Makevars new file mode 100644 index 0000000000..62b2507f4a --- /dev/null +++ b/src/Makevars @@ -0,0 +1 @@ +PKG_CPPFLAGS = -DSTRICT_R_HEADERS diff --git a/src/Makevars.win b/src/Makevars.win new file mode 100644 index 0000000000..62b2507f4a --- /dev/null +++ b/src/Makevars.win @@ -0,0 +1 @@ +PKG_CPPFLAGS = -DSTRICT_R_HEADERS diff --git a/src/ldc_ad2cp_in_file.cpp b/src/ldc_ad2cp_in_file.cpp index af14cda33f..e497fc6cb6 100644 --- a/src/ldc_ad2cp_in_file.cpp +++ b/src/ldc_ad2cp_in_file.cpp @@ -206,11 +206,11 @@ List do_ldc_ad2cp_in_file(CharacterVector filename, IntegerVector from, IntegerV unsigned short header_checksum; } header; unsigned int dbuflen = 10000; // may be increased later - unsigned char *dbuf = (unsigned char *)Calloc((size_t)dbuflen, unsigned char); + unsigned char *dbuf = (unsigned char *)R_Calloc((size_t)dbuflen, unsigned char); unsigned int nchunk = 100000; - unsigned int *index_buf = (unsigned int*)Calloc((size_t)nchunk, unsigned int); - unsigned int *length_buf = (unsigned int*)Calloc((size_t)nchunk, unsigned int); - unsigned int *id_buf = (unsigned int*)Calloc((size_t)nchunk, unsigned int); + unsigned int *index_buf = (unsigned int*)R_Calloc((size_t)nchunk, unsigned int); + unsigned int *length_buf = (unsigned int*)R_Calloc((size_t)nchunk, unsigned int); + unsigned int *id_buf = (unsigned int*)R_Calloc((size_t)nchunk, unsigned int); int early_EOF = 0; int reset_cindex = 0; // set to 1 if we skipped to find a new header start, after a bad checksum while (chunk < to_value) { // FIXME: use whole file here @@ -220,9 +220,9 @@ List do_ldc_ad2cp_in_file(CharacterVector filename, IntegerVector from, IntegerV if (debug) Rprintf(" increasing 'index_buf' size from %d", nchunk); nchunk = (unsigned int) floor(chunk * 1.4); // increase buffer size by sqrt(2) - index_buf = (unsigned int*)Realloc(index_buf, nchunk, unsigned int); - length_buf = (unsigned int*)Realloc(length_buf, nchunk, unsigned int); - id_buf = (unsigned int*)Realloc(id_buf, nchunk, unsigned int); + index_buf = (unsigned int*)R_Realloc(index_buf, nchunk, unsigned int); + length_buf = (unsigned int*)R_Realloc(length_buf, nchunk, unsigned int); + id_buf = (unsigned int*)R_Realloc(id_buf, nchunk, unsigned int); if (debug) Rprintf(" to %d\n", nchunk); } @@ -311,7 +311,7 @@ List do_ldc_ad2cp_in_file(CharacterVector filename, IntegerVector from, IntegerV Rprintf(" *BUG*: cindex is out of synch with ftell()\n"); dbuflen = header.data_size; - dbuf = (unsigned char *)Realloc(dbuf, dbuflen, unsigned char); + dbuf = (unsigned char *)R_Realloc(dbuf, dbuflen, unsigned char); } // Read the data bytes_read = fread(dbuf, 1, header.data_size, fp); @@ -402,9 +402,9 @@ List do_ldc_ad2cp_in_file(CharacterVector filename, IntegerVector from, IntegerV length[i] = length_buf[i]; id[i] = id_buf[i]; } - Free(index_buf); - Free(length_buf); - Free(id_buf); + R_Free(index_buf); + R_Free(length_buf); + R_Free(id_buf); if (debug) Rprintf("} # do_ldc_ad2cp_in_file()\n"); return(List::create(Named("index")=index, diff --git a/src/ldc_rdi_in_file.cpp b/src/ldc_rdi_in_file.cpp index 298eceb7ee..2be008c86e 100644 --- a/src/ldc_rdi_in_file.cpp +++ b/src/ldc_rdi_in_file.cpp @@ -226,7 +226,7 @@ List do_ldc_rdi_in_file(StringVector filename, IntegerVector from, IntegerVector // 'obuf' is a growable C buffer to hold the output, which eventually // gets saved in the R item "buf". unsigned long int nobuf = 100000; // BUFFER SIZE - unsigned char *obuf = (unsigned char *)Calloc((size_t)nobuf, unsigned char); + unsigned char *obuf = (unsigned char *)R_Calloc((size_t)nobuf, unsigned char); unsigned long int iobuf = 0; // 'ensembles', 'times' and 'sec100s' are growable buffers of equal length, with one @@ -237,12 +237,12 @@ List do_ldc_rdi_in_file(StringVector filename, IntegerVector from, IntegerVector // Note that we do not check the Calloc() results because the R docs say that // Calloc() performs its won tests, and that R will handle any problems. unsigned long int nensembles = 100000; // BUFFER SIZE - unsigned int *ensemble_in_files = (unsigned int *)Calloc((size_t)nensembles, unsigned int); - int *ensembles = (int *)Calloc((size_t)nensembles, int); - int *times = (int *)Calloc((size_t)nensembles, int); - int *sec100s = (int *)Calloc((size_t)nensembles, int); + unsigned int *ensemble_in_files = (unsigned int *)R_Calloc((size_t)nensembles, unsigned int); + int *ensembles = (int *)R_Calloc((size_t)nensembles, int); + int *times = (int *)R_Calloc((size_t)nensembles, int); + int *sec100s = (int *)R_Calloc((size_t)nensembles, int); unsigned long int nebuf = 50000; // BUFFER SIZE - unsigned char *ebuf = (unsigned char *)Calloc((size_t)nebuf, unsigned char); + unsigned char *ebuf = (unsigned char *)R_Calloc((size_t)nebuf, unsigned char); unsigned long int in_ensemble = 1, out_ensemble = 0; int b1, b2; @@ -291,10 +291,10 @@ List do_ldc_rdi_in_file(StringVector filename, IntegerVector from, IntegerVector if (debug_value > 0) Rprintf("\nbytes_to_check=%d based on b1=%d(0x%02x) and b2=%d(0x%02x)\n", bytes_to_check, b1, b1, b2, b2); if (bytes_to_check < 5) { // this will only happen in error; we check so bytes_to_read won't be crazy - Free(ensembles); - Free(times); - Free(sec100s); - Free(ebuf); + R_Free(ensembles); + R_Free(times); + R_Free(sec100s); + R_Free(ebuf); ::Rf_error("cannot decode the length of ensemble number %d", in_ensemble); } if (bytes_to_check < 4) @@ -305,7 +305,7 @@ List do_ldc_rdi_in_file(StringVector filename, IntegerVector from, IntegerVector if (bytes_to_read > nebuf) { if (debug_value > 0) Rprintf("Increasing 'ebuf' buffer size from %d bytes to %d bytes\n", nebuf, bytes_to_read); - ebuf = (unsigned char *)Realloc(ebuf, bytes_to_read, unsigned char); + ebuf = (unsigned char *)R_Realloc(ebuf, bytes_to_read, unsigned char); nebuf = bytes_to_read; } // Read the bytes in one operation, because fgetc() is too slow. @@ -351,10 +351,10 @@ List do_ldc_rdi_in_file(StringVector filename, IntegerVector from, IntegerVector nensembles = 3 * nensembles / 2; if (debug_value > -1) Rprintf("Increasing ensembles,times,sec100s storage to %d elements ...\n", nensembles); - ensemble_in_files = (unsigned int *) Realloc(ensemble_in_files, nensembles, unsigned int); - ensembles = (int *) Realloc(ensembles, nensembles, int); - times = (int *) Realloc(times, nensembles, int); - sec100s = (int *)Realloc(sec100s, nensembles, int); + ensemble_in_files = (unsigned int *) R_Realloc(ensemble_in_files, nensembles, unsigned int); + ensembles = (int *) R_Realloc(ensembles, nensembles, int); + times = (int *) R_Realloc(times, nensembles, int); + sec100s = (int *)R_Realloc(sec100s, nensembles, int); } // We will decide whether to keep this ensemble, based on ensemble // number, if mode_value==0 or on time, if mode_value==1. That @@ -407,7 +407,7 @@ List do_ldc_rdi_in_file(StringVector filename, IntegerVector from, IntegerVector nobuf = nobuf + 100 + bytes_to_read + nobuf / 2; if (debug_value > 0) Rprintf("about to enlarge obuf storage to %d elements ...\n", nobuf); - obuf = (unsigned char *)Realloc(obuf, nobuf, unsigned char); + obuf = (unsigned char *)R_Realloc(obuf, nobuf, unsigned char); if (debug_value > 0) Rprintf(" ... allocation was successful\n"); } @@ -540,15 +540,15 @@ List do_ldc_rdi_in_file(StringVector filename, IntegerVector from, IntegerVector sec100[i] = sec100s[i]; //Rprintf("i=%d ensemble=%d time=%d sec100=%d\n", i, ensemble[i], time[i], (int)sec100[i]); } - Free(ensemble_in_files); - Free(ensembles); - Free(times); - Free(sec100s); - Free(ebuf); + R_Free(ensemble_in_files); + R_Free(ensembles); + R_Free(times); + R_Free(sec100s); + R_Free(ebuf); for (unsigned long int i = 0; i < iobuf; i++) { buf[i] = obuf[i]; } - Free(obuf); + R_Free(obuf); if (debug_value > 0) Rprintf("Returning from C++ function named do_ldc_rdi_in_file.\n"); return(List::create(Named("ensembleStart")=ensemble, Named("time")=time, diff --git a/src/map.c b/src/map.c index d4a27efdbf..07c67f5b56 100644 --- a/src/map.c +++ b/src/map.c @@ -242,8 +242,8 @@ SEXP map_check_polygons(SEXP x, SEXP y, SEXP z, SEXP xokspan, SEXP usr) // retur if (j > (clen - 2)) { \ /*Rprintf("INCREASE storage from %d to %d [a]\n", clen, (int)(100 + clen));*/ \ clen += 100; \ - xbp = (double*)Realloc(xbp, clen, double); \ - ybp = (double*)Realloc(ybp, clen, double); \ + xbp = (double*)R_Realloc(xbp, clen, double); \ + ybp = (double*)R_Realloc(ybp, clen, double); \ } \ j++; @@ -268,8 +268,8 @@ SEXP map_clip_xy_OLD_BROKEN(SEXP x, SEXP y, SEXP usr) // returns list with new x error("must have at least two 'x' and 'y' pairs"); // xbp and xbp are growable buffers int clen = xlen + 100; // the 100 may save reallocs - double *xbp = (double*)Calloc((size_t)clen, double); - double *ybp = (double*)Calloc((size_t)clen, double); + double *xbp = (double*)R_Calloc((size_t)clen, double); + double *ybp = (double*)R_Calloc((size_t)clen, double); #ifdef DEBUG double distMIN = 10e6; // FIXME: temporary to find problem in Greenland #endif @@ -388,8 +388,8 @@ SEXP map_clip_xy(SEXP x, SEXP y, SEXP usr) // returns list with new x and y vect error("must have at least two 'x' and 'y' pairs"); // xb and yb are growable buffers; we copy to xc and yc near the end. int clen = xlen + 100; // the 100 may save reallocs - double *xbp = (double*)Calloc((size_t)clen, double); - double *ybp = (double*)Calloc((size_t)clen, double); + double *xbp = (double*)R_Calloc((size_t)clen, double); + double *ybp = (double*)R_Calloc((size_t)clen, double); #ifdef DEBUG double distMIN = 10e6; // FIXME: temporary to find problem in Greenland #endif