Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2016-06-20 Qin Wenfeng <mail@qinwenfeng.com>

* inst/include/Rcpp/exceptions.h: add RCPP_USING_UTF8_ERROR_STRING macro to use UTF-8 encoding exception string in R

2016-06-14 Artem Klevtsov <a.a.klevtsov@gmail.com>

* inst/include/Rcpp/sugar/functions/na_omit.h: Improve na_omit for
Expand Down
1 change: 1 addition & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
\ghit{486}).
\item String replacement was corrected (Qiang in \ghpr{479} following
mailing list bug report by Masaki Tsuda)
\item Add RCPP_USING_UTF8_ERROR_STRING macro to use UTF-8 encoding exception string in R (Qin Wenfeng in \ghpr{493})
}
\item Changes in Rcpp Sugar:
\itemize{
Expand Down
27 changes: 22 additions & 5 deletions inst/include/Rcpp/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ inline SEXP get_last_call(){

inline SEXP get_exception_classes( const std::string& ex_class) {
Rcpp::Shield<SEXP> res( Rf_allocVector( STRSXP, 4 ) );

#ifndef RCPP_USING_UTF8_ERROR_STRING
SET_STRING_ELT( res, 0, Rf_mkChar( ex_class.c_str() ) ) ;
#else
SET_STRING_ELT( res, 0, Rf_mkCharLenCE( ex_class.c_str(), ex_class.size(), CE_UTF8 ) );
#endif
SET_STRING_ELT( res, 1, Rf_mkChar( "C++Error" ) ) ;
SET_STRING_ELT( res, 2, Rf_mkChar( "error" ) ) ;
SET_STRING_ELT( res, 3, Rf_mkChar( "condition" ) ) ;
Expand All @@ -146,8 +151,13 @@ inline SEXP get_exception_classes( const std::string& ex_class) {

inline SEXP make_condition(const std::string& ex_msg, SEXP call, SEXP cppstack, SEXP classes){
Rcpp::Shield<SEXP> res( Rf_allocVector( VECSXP, 3 ) ) ;

SET_VECTOR_ELT( res, 0, Rf_mkString( ex_msg.c_str() ) ) ;
#ifndef RCPP_USING_UTF8_ERROR_STRING
SET_VECTOR_ELT( res, 0, Rf_mkString( ex_msg.c_str() ) ) ;
#else
Rcpp::Shield<SEXP> ex_msg_rstring( Rf_allocVector( STRSXP, 1 ) ) ;
SET_STRING_ELT( ex_msg_rstring, 0, Rf_mkCharLenCE( ex_msg.c_str(), ex_msg.size(), CE_UTF8 ) );
SET_VECTOR_ELT( res, 0, ex_msg_rstring ) ;
#endif
SET_VECTOR_ELT( res, 1, call ) ;
SET_VECTOR_ELT( res, 2, cppstack ) ;

Expand All @@ -174,10 +184,17 @@ inline SEXP exception_to_r_condition( const std::exception& ex){

inline SEXP string_to_try_error( const std::string& str){
using namespace Rcpp;

Rcpp::Shield<SEXP> simpleErrorExpr( Rf_lang2(::Rf_install("simpleError"), Rf_mkString(str.c_str())) );

#ifndef RCPP_USING_UTF8_ERROR_STRING
Rcpp::Shield<SEXP> simpleErrorExpr( Rf_lang2(::Rf_install("simpleError"), Rf_mkString(str.c_str())) );
Rcpp::Shield<SEXP> tryError( Rf_mkString( str.c_str() ) );
#else
Rcpp::Shield<SEXP> tryError( Rf_allocVector( STRSXP, 1 ) ) ;
SET_STRING_ELT( tryError, 0, Rf_mkCharLenCE( str.c_str(), str.size(), CE_UTF8 ) );
Rcpp::Shield<SEXP> simpleErrorExpr( Rf_lang2(::Rf_install("simpleError"), tryError ));
#endif

Rcpp::Shield<SEXP> simpleError( Rf_eval(simpleErrorExpr, R_GlobalEnv) );
Rcpp::Shield<SEXP> tryError( Rf_mkString( str.c_str() ) );
Rf_setAttrib( tryError, R_ClassSymbol, Rf_mkString("try-error") ) ;
Rf_setAttrib( tryError, Rf_install( "condition") , simpleError ) ;

Expand Down