diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 15ea901..e8990af 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 0.1.6 -Date: 2023-06-23 04:31:47 UTC -SHA: a08a8166daac9b742356bf2f12ac4287e57ee8a5 +Version: 0.1.7 +Date: 2024-07-16 20:14:07 UTC +SHA: 78b96f1f875b9e8f26e3a0320dac40d75b42f7b3 diff --git a/DESCRIPTION b/DESCRIPTION index 3a20bae..04f279c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: filearray Type: Package Title: File-Backed Array for Out-of-Memory Computation -Version: 0.1.7 +Version: 0.1.7.9000 Language: en-US Encoding: UTF-8 License: LGPL-3 diff --git a/src/load.cpp b/src/load.cpp index f82be7b..603dda3 100644 --- a/src/load.cpp +++ b/src/load.cpp @@ -242,7 +242,15 @@ SEXP FARR_subset_sequential( } } - } catch (...) {} + } catch (const Rcpp::LongjumpException& e) { + std::rethrow_exception(std::current_exception()); + } catch (const boost::interprocess::interprocess_exception& e) { + // unable to find the file, skip + } catch (const std::exception& e) { + std::rethrow_exception(std::current_exception()); + } catch (...) { + throw std::runtime_error("filearray C++: Caught an unknown exception in `FARR_subset_sequential`."); + } } diff --git a/src/mapreduce.cpp b/src/mapreduce.cpp index cb8b22c..f4597d4 100644 --- a/src/mapreduce.cpp +++ b/src/mapreduce.cpp @@ -47,22 +47,27 @@ SEXP each_partition_template( if( read_len > 0 ){ *readlen_ptr = (double) read_len; *count_ptr = (double) *count; - if( read_len < buffer_nelems ){ - // if( tmp_arg == R_NilValue ){ - // tmp_arg = PROTECT(sub_vec_range(argbuf, 0, read_len)); - // } else if( read_len - Rf_xlength(tmp_arg) != 0 ){ - // UNPROTECT(1); - // tmp_arg = PROTECT(sub_vec_range(argbuf, 0, read_len)); - // } - SEXP tmp_arg = PROTECT(sub_vec_range(argbuf, 0, read_len)); - SEXP item = PROTECT( fun(tmp_arg, readlen_sxp, count_sxp) ); - ret.push_back( item ); - UNPROTECT( 2 ); // item, tmp_arg - } else { - SEXP item = PROTECT( fun(argbuf, readlen_sxp, count_sxp) ); - ret.push_back( item ); - UNPROTECT( 1 ); // item - // ret.push_back( Shield( fun(Shield(argbuf), Shield(wrap(read_len)), Shield(wrap(*count))) ) ); + + // https://github.com/RcppCore/Rcpp/issues/1268 + try { + if( read_len < buffer_nelems ) { + SEXP tmp_arg = PROTECT(sub_vec_range(argbuf, 0, read_len)); + SEXP item = fun(tmp_arg, readlen_sxp, count_sxp); + PROTECT( item ); + ret.push_back( item ); + UNPROTECT( 2 ); // item, tmp_arg + } else { + SEXP item = fun(argbuf, readlen_sxp, count_sxp); + PROTECT( item ); + ret.push_back( item ); + UNPROTECT( 1 ); // item + } + } catch (const Rcpp::LongjumpException& e) { + std::rethrow_exception(std::current_exception()); + } catch (const std::exception& e) { + std::rethrow_exception(std::current_exception()); + } catch (...) { + throw std::runtime_error("filearray C++: Caught an unknown exception in `each_partition_template`."); } } @@ -198,19 +203,39 @@ SEXP FARR_buffer_mapreduce( break; } } - } catch (...) {} + } catch (const Rcpp::LongjumpException& e) { + std::rethrow_exception(std::current_exception()); + } catch (const boost::interprocess::interprocess_exception& e) { + // unable to find the file, skip + } catch (const std::exception& e) { + std::rethrow_exception(std::current_exception()); + } catch (...) { + throw std::runtime_error("filearray C++: Caught an unknown exception in `FARR_buffer_mapreduce`."); + } + // } catch (...) {} } if(reduce == R_NilValue){ - UNPROTECT( 1 ); + UNPROTECT( 1 ); // argbuffer return ret; + } else { + try{ + + Function reduce2 = (Function) reduce; + SEXP re = PROTECT(reduce2(ret)); + UNPROTECT( 2 ); // argbuffer, re + return(re); + + } catch (const Rcpp::LongjumpException& e) { + std::rethrow_exception(std::current_exception()); + } catch (const std::exception& e) { + std::rethrow_exception(std::current_exception()); + } catch (...) { + throw std::runtime_error("filearray C++: Caught an unknown exception in `FARR_buffer_mapreduce`."); + } } - Function reduce2 = (Function) reduce; - SEXP re = PROTECT(reduce2(ret)); - UNPROTECT( 2 ); - return(re); }