Jeffrey Horner wrote:
Joe Conway wrote:
I was debugging a problem reported to me regarding PL/R, and found that I can duplicate it using only R sources. It might be characterized as possibly a misuse of the findFun() function, but I leave that for the R devel experts to decide.

My question is -- is the above an abuse of findFun() by RNamedCall.c (meaning I should avoid the same pattern)? Or maybe it should be wrapped in something similar to R_ToplevelExec?

Yes, when one embeds R, findFun() will call error() which causes the longjmp() to the top level, so the embedding application shouldn't use findFun().

OK, thanks for the confirmation. I just wonder if RNamedCall.c ought to be changed then...

Here's what I've written for the next version of RApache. Note that it's behavior is slightly different than the original findFun(), in that it doesn't search the enclosing environments. (Also, comments welcome as the implementation is based on the original, and I'm unsure if promise evaluation is needed.)


/* This one doesn't longjmp when function not found */
static SEXP MyfindFun(SEXP symb, SEXP envir){

Yes, if I patch RNamedCall.c with the attached (based on your function), everything seems to work.

Thanks,

Joe


*** ../../../R-2.5.1/tests/Embedding/RNamedCall.c	Fri Jul  6 10:28:18 2007
--- RNamedCall.c	Fri Jul  6 10:19:46 2007
***************
*** 2,8 ****
  
  void bar1() ;
  void source(const char *name);
! SEXP MyfindFun(SEXP symb, SEXP envir);
  
  /*
    Creates and evaluates a call 
--- 2,8 ----
  
  void bar1() ;
  void source(const char *name);
! static SEXP MyfindFun(SEXP symb, SEXP envir);
  
  /*
    Creates and evaluates a call 
***************
*** 82,88 ****
      UNPROTECT(1);
  }
  
! SEXP
  MyfindFun(SEXP symb, SEXP envir)
  {
      SEXP fun;
--- 82,88 ----
      UNPROTECT(1);
  }
  
! static SEXP
  MyfindFun(SEXP symb, SEXP envir)
  {
      SEXP fun;
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to