@@ -47,22 +47,27 @@ SEXP each_partition_template(
4747 if ( read_len > 0 ){
4848 *readlen_ptr = (double ) read_len;
4949 *count_ptr = (double ) *count;
50- if ( read_len < buffer_nelems ){
51- // if( tmp_arg == R_NilValue ){
52- // tmp_arg = PROTECT(sub_vec_range(argbuf, 0, read_len));
53- // } else if( read_len - Rf_xlength(tmp_arg) != 0 ){
54- // UNPROTECT(1);
55- // tmp_arg = PROTECT(sub_vec_range(argbuf, 0, read_len));
56- // }
57- SEXP tmp_arg = PROTECT (sub_vec_range (argbuf, 0 , read_len));
58- SEXP item = PROTECT ( fun (tmp_arg, readlen_sxp, count_sxp) );
59- ret.push_back ( item );
60- UNPROTECT ( 2 ); // item, tmp_arg
61- } else {
62- SEXP item = PROTECT ( fun (argbuf, readlen_sxp, count_sxp) );
63- ret.push_back ( item );
64- UNPROTECT ( 1 ); // item
65- // ret.push_back( Shield<SEXP>( fun(Shield<SEXP>(argbuf), Shield<SEXP>(wrap(read_len)), Shield<SEXP>(wrap(*count))) ) );
50+
51+ // https://github.com/RcppCore/Rcpp/issues/1268
52+ try {
53+ if ( read_len < buffer_nelems ) {
54+ SEXP tmp_arg = PROTECT (sub_vec_range (argbuf, 0 , read_len));
55+ SEXP item = fun (tmp_arg, readlen_sxp, count_sxp);
56+ PROTECT ( item );
57+ ret.push_back ( item );
58+ UNPROTECT ( 2 ); // item, tmp_arg
59+ } else {
60+ SEXP item = fun (argbuf, readlen_sxp, count_sxp);
61+ PROTECT ( item );
62+ ret.push_back ( item );
63+ UNPROTECT ( 1 ); // item
64+ }
65+ } catch (const Rcpp::LongjumpException& e) {
66+ std::rethrow_exception (std::current_exception ());
67+ } catch (const std::exception& e) {
68+ std::rethrow_exception (std::current_exception ());
69+ } catch (...) {
70+ throw std::runtime_error (" filearray C++: Caught an unknown exception in `each_partition_template`." );
6671 }
6772 }
6873
@@ -198,19 +203,39 @@ SEXP FARR_buffer_mapreduce(
198203 break ;
199204 }
200205 }
201- } catch (...) {}
206+ } catch (const Rcpp::LongjumpException& e) {
207+ std::rethrow_exception (std::current_exception ());
208+ } catch (const boost::interprocess::interprocess_exception& e) {
209+ // unable to find the file, skip
210+ } catch (const std::exception& e) {
211+ std::rethrow_exception (std::current_exception ());
212+ } catch (...) {
213+ throw std::runtime_error (" filearray C++: Caught an unknown exception in `FARR_buffer_mapreduce`." );
214+ }
215+ // } catch (...) {}
202216
203217 }
204218
205219 if (reduce == R_NilValue){
206- UNPROTECT ( 1 );
220+ UNPROTECT ( 1 ); // argbuffer
207221 return ret;
222+ } else {
223+ try {
224+
225+ Function reduce2 = (Function) reduce;
226+ SEXP re = PROTECT (reduce2 (ret));
227+ UNPROTECT ( 2 ); // argbuffer, re
228+ return (re);
229+
230+ } catch (const Rcpp::LongjumpException& e) {
231+ std::rethrow_exception (std::current_exception ());
232+ } catch (const std::exception& e) {
233+ std::rethrow_exception (std::current_exception ());
234+ } catch (...) {
235+ throw std::runtime_error (" filearray C++: Caught an unknown exception in `FARR_buffer_mapreduce`." );
236+ }
208237 }
209238
210- Function reduce2 = (Function) reduce;
211- SEXP re = PROTECT (reduce2 (ret));
212- UNPROTECT ( 2 );
213- return (re);
214239}
215240
216241
0 commit comments