Hi Dirk, Douglas,

Many thanks for your time in digging into this.  I did some further
experiments yesterday and cut down the PROTECT()s a bit, but your
version below is much tidier.  I confirm that your suggested code

        SEXP cppExceptExpr = PROTECT(Rf_lang3(cppExceptSym,
                                              
Rf_mkString(exception_what.c_str()),
                                              
Rf_mkString(exception_class.c_str())));
        Rf_eval(cppExceptExpr, R_FindNamespace(Rf_mkString("Rcpp"))); // Should 
not return.

        // Do this in case somehow someone replaces the definition of
        // "cpp_exception" such that it does return:
        UNPROTECT(1);

behaves correctly in my case.  For completeness, the full text of the
forward_exception_to_r() function I now have is:


void forward_exception_to_r( const std::exception& ex){
    std::string exception_class ;
    std::string exception_what  = ex.what();
    const char *name = typeid(ex).name() ;
    // now we need to demangle "name"
    {
        int status = -1;
        char *dem = 0;
        dem = abi::__cxa_demangle(name, 0, 0, &status);
        if( status == 0){
            exception_class = dem ; /* great we can use the demangled name */
            free(dem);
        } else{
            exception_class = name ; /* just using the mangled name */
        }
    }
    SEXP cppExceptSym = Rf_install("cpp_exception"); // cannot cause a gc() 
once in symbol table
    SEXP cppExceptExpr = PROTECT(Rf_lang3(cppExceptSym,
                                          Rf_mkString(exception_what.c_str()),
                                          
Rf_mkString(exception_class.c_str())));
    Rf_eval(cppExceptExpr, R_FindNamespace(Rf_mkString("Rcpp"))); // Should not 
return.

    // Do this in case somehow someone replaces the definition of
    // "cpp_exception" such that it does return:
    UNPROTECT(1);
}


(I did try using Rf_install() but as Douglas predicted, this creates a
symbol rather than a string, and cpp_exception doesn't like this.)

I am now seeing another strange error under gctorture() which I might try
to track down further, and will report back if it looks like Rcpp rather
than my code.

Thanks,

Ben.


________________________________

Susquehanna International Group Limited

Susquehanna International Group Limited is a private company limited by shares 
and registered in Ireland. Registration No.: 445356. Registered Address: 4th 
Floor, Georges Dock House, IFSC, Dublin 1, Ireland.
Susquehanna Ireland Limited is a private company limited by shares and 
registered in Ireland. Registration No.: 305632. Registered Address: 4th Floor, 
Georges Dock House, IFSC, Dublin 1, Ireland.
Susquehanna International Securities Limited is a private company limited by 
shares and registered in Ireland. Registration No.: 337946. Registered Address: 
4th Floor, Georges Dock House, IFSC, Dublin 1, Ireland.

IMPORTANT: The information contained in this email and/or its attachments is 
confidential. If you are not the intended recipient, please notify the sender 
immediately by reply and immediately delete this message and all its 
attachments. Any review, use, reproduction, disclosure or dissemination of this 
message or any attachment by an unintended recipient is strictly prohibited. 
Neither this message nor any attachment is intended as or should be construed 
as an offer, solicitation or recommendation to buy or sell any security or 
other financial instrument. Neither the sender, his or her employer nor any of 
their respective affiliates makes any warranties as to the completeness or 
accuracy of any of the information contained herein or that this message or any 
of its attachments is free of viruses.
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to