Skip to content

Commit

Permalink
Fix compilation on windows
Browse files Browse the repository at this point in the history
Closes #41
  • Loading branch information
gaborcsardi committed Apr 22, 2018
1 parent 1a6840d commit b1efa6b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
9 changes: 5 additions & 4 deletions inst/include/RProgress.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cstring>
#include <cstdlib>

#include <R.h>
#include <Rinternals.h>
#include <R_ext/Print.h>

Expand Down Expand Up @@ -169,8 +170,8 @@ class RProgress {
if (bar_width < 0) bar_width = 0;

double complete_len = round(bar_width * ratio_now);
char *bar = (char*) calloc(bar_width + 1, sizeof char);
if (!bar) error("Progress bar: out of memory");
char *bar = (char*) calloc(bar_width + 1, sizeof(char));
if (!bar) Rf_error("Progress bar: out of memory");
for (int i = 0; i < complete_len; i++) { bar[i] = complete_char; }
for (int i = complete_len; i < bar_width; i++) {
bar[i] = incomplete_char;
Expand Down Expand Up @@ -219,8 +220,8 @@ class RProgress {

void clear_line(bool use_stderr, int width) {

char *spaces = calloc(width + 2, sizeof char);
if (!spaces) error("Progress bar: out of memory");
char *spaces = (char*) calloc(width + 2, sizeof(char));
if (!spaces) Rf_error("Progress bar: out of memory");
for (int i = 1; i <= width; i++) spaces[i] = ' ';
spaces[0] = '\r';
spaces[width + 1] = '\0';
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/progresstest/R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This file was generated by Rcpp::compileAttributes
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

test_progress <- function(formatSEXP = "[:bar] :percent ") {
.Call('progresstest_test_progress', PACKAGE = 'progresstest', formatSEXP)
.Call('_progresstest_test_progress', PACKAGE = 'progresstest', formatSEXP)
}

test_units <- function() {
.Call('progresstest_test_units', PACKAGE = 'progresstest')
.Call('_progresstest_test_units', PACKAGE = 'progresstest')
}

33 changes: 22 additions & 11 deletions tests/testthat/progresstest/src/RcppExports.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was generated by Rcpp::compileAttributes
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include <Rcpp.h>
Expand All @@ -7,22 +7,33 @@ using namespace Rcpp;

// test_progress
Rcpp::CharacterVector test_progress(Rcpp::CharacterVector formatSEXP);
RcppExport SEXP progresstest_test_progress(SEXP formatSEXPSEXP) {
RcppExport SEXP _progresstest_test_progress(SEXP formatSEXPSEXP) {
BEGIN_RCPP
Rcpp::RObject __result;
Rcpp::RNGScope __rngScope;
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::CharacterVector >::type formatSEXP(formatSEXPSEXP);
__result = Rcpp::wrap(test_progress(formatSEXP));
return __result;
rcpp_result_gen = Rcpp::wrap(test_progress(formatSEXP));
return rcpp_result_gen;
END_RCPP
}
// test_units
Rcpp::CharacterVector test_units();
RcppExport SEXP progresstest_test_units() {
RcppExport SEXP _progresstest_test_units() {
BEGIN_RCPP
Rcpp::RObject __result;
Rcpp::RNGScope __rngScope;
__result = Rcpp::wrap(test_units());
return __result;
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = Rcpp::wrap(test_units());
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_progresstest_test_progress", (DL_FUNC) &_progresstest_test_progress, 1},
{"_progresstest_test_units", (DL_FUNC) &_progresstest_test_units, 0},
{NULL, NULL, 0}
};

RcppExport void R_init_progresstest(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
2 changes: 1 addition & 1 deletion tests/testthat/progresstest/src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Rcpp::CharacterVector test_units() {
result[16] = RProgress::RProgress::pretty_bytes(13333337);
result[17] = RProgress::RProgress::pretty_bytes(133333337);
result[18] = RProgress::RProgress::pretty_bytes(1333333337);
result[19] = RProgress::RProgress::pretty_bytes(13333333337);
result[19] = RProgress::RProgress::pretty_bytes(1333333337);

return result;

Expand Down
Binary file modified tests/testthat/progresstest_1.0.0.tar.gz
Binary file not shown.

0 comments on commit b1efa6b

Please sign in to comment.