Skip to content

Commit 6121f84

Browse files
committed
Merge pull request #287 from romainfrancois/master
Fix memory leaks. closes #286
2 parents 01bd959 + 0cf1aaf commit 6121f84

File tree

7 files changed

+187
-583
lines changed

7 files changed

+187
-583
lines changed

inst/include/Rcpp/InternalFunctionWithStdFunction.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// InternalFunction_with_std_function.h: Rcpp R/C++ interface class library -- exposing C++ std::function's
44
//
55
// Copyright (C) 2014 Christian Authmann
6+
// Copyright (C) 2015 Romain Francois
67
//
78
// This file is part of Rcpp.
89
//
@@ -37,10 +38,8 @@ namespace Rcpp{
3738
virtual ~CppFunctionBaseFromStdFunction() {}
3839

3940
SEXP operator()(SEXP* args) {
40-
BEGIN_RCPP
4141
auto result = call<RESULT_TYPE, Args...>(fun, args);
4242
return Rcpp::module_wrap<RESULT_TYPE>(result);
43-
END_RCPP
4443
}
4544

4645
private:
@@ -54,9 +53,7 @@ namespace Rcpp{
5453
virtual ~CppFunctionBaseFromStdFunction() {}
5554

5655
SEXP operator()(SEXP* args) {
57-
BEGIN_RCPP
5856
call<void, Args...>(fun, args);
59-
END_RCPP
6057
}
6158

6259
private:

inst/include/Rcpp/api/meat/module/Module.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Module.h: Rcpp R/C++ interface class library -- Rcpp modules
22
//
3-
// Copyright (C) 2013 Romain Francois
3+
// Copyright (C) 2013 - 2015 Romain Francois
44
//
55
// This file is part of Rcpp.
66
//
@@ -37,12 +37,10 @@ namespace Rcpp {
3737
}
3838

3939
inline CppClass Module::get_class( const std::string& cl ){
40-
BEGIN_RCPP
4140
CLASS_MAP::iterator it = classes.find(cl) ;
4241
if( it == classes.end() ) throw std::range_error( "no such class" ) ;
4342
std::string buffer ;
4443
return CppClass( this, it->second, buffer ) ;
45-
END_RCPP
4644
}
4745

4846
}

inst/include/Rcpp/macros/macros.h

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// macros.h: Rcpp R/C++ interface class library -- Rcpp macros
44
//
5-
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -27,21 +27,33 @@
2727
#define RCPP_GET_CLASS(x) Rf_getAttrib(x, R_ClassSymbol)
2828

2929
#ifndef BEGIN_RCPP
30-
#define BEGIN_RCPP try {
30+
#define BEGIN_RCPP \
31+
int rcpp_output_type = 0 ; \
32+
SEXP rcpp_output_condition = R_NilValue ; \
33+
try {
3134
#endif
3235

3336
#ifndef VOID_END_RCPP
34-
#define VOID_END_RCPP \
35-
} \
36-
catch (Rcpp::internal::InterruptedException &__ex__) { \
37-
Rf_onintr(); \
38-
} \
39-
catch (std::exception &__ex__) { \
40-
forward_exception_to_r(__ex__); \
41-
} \
42-
catch (...) { \
43-
::Rf_error("c++ exception (unknown reason)"); \
44-
}
37+
#define VOID_END_RCPP \
38+
} \
39+
catch( Rcpp::internal::InterruptedException &__ex__) { \
40+
rcpp_output_type = 1 ; \
41+
} \
42+
catch( std::exception& __ex__ ){ \
43+
rcpp_output_type = 2 ; \
44+
rcpp_output_condition = PROTECT(exception_to_r_condition(__ex__)) ; \
45+
} catch( ... ){ \
46+
rcpp_output_type = 2 ; \
47+
rcpp_output_condition = PROTECT(string_to_try_error("c++ exception (unknown reason)")) ; \
48+
} \
49+
if( rcpp_output_type == 1 ){ \
50+
Rf_onintr() ; \
51+
} \
52+
if( rcpp_output_type == 2 ){ \
53+
SEXP stop_sym = Rf_install( "stop" ) ; \
54+
SEXP expr = PROTECT( Rf_lang2( stop_sym , rcpp_output_condition ) ) ; \
55+
Rf_eval( expr, R_GlobalEnv ) ; \
56+
}
4557
#endif
4658

4759
#ifndef END_RCPP

inst/include/Rcpp/macros/xp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// xp.h: Rcpp R/C++ interface class library -- pre processor help
44
//
5-
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -33,11 +33,11 @@ extern "C" SEXP RCPP_PP_CAT(__NAME__,__rcpp_info__)(){ \
3333
return info ; \
3434
} \
3535
extern "C" SEXP __NAME__( SEXP xp ){ \
36-
SEXP res = R_NilValue ; \
3736
BEGIN_RCPP \
37+
SEXP res = R_NilValue ; \
3838
::Rcpp::XPtr< __CLASS__ > ptr(xp) ; \
3939
res = ::Rcpp::wrap( ptr->__FIELD__ ) ; \
40-
return res ; \
40+
return res ; \
4141
END_RCPP \
4242
}
4343

0 commit comments

Comments
 (0)