sgiannerini at gmail.com
2009-Dec-10 08:30 UTC
[Rd] switch() called with just the EXPR argument causes R to hang (PR#14124)
Dear all, switch() called with just the EXPR argument causes R to hang so that the only way to stop it is to kill R. Reproducible example:> switch(EXPR="a")the internal C subroutine behind switch is do_switch located in R/src/main/builtin.c For convenience I reproduce it below. ***************************************************************************** SEXP attribute_hidden do_switch(SEXP call, SEXP op, SEXP args, SEXP rho) { int argval; SEXP x, y, w; x = eval(CAR(args), rho); if (!isVector(x) || length(x) != 1) error(_("switch: EXPR must return a length 1 vector")); PROTECT(w = switchList(CDR(args), rho)); if (isString(x)) { for (y = w; y != R_NilValue; y = CDR(y)) if (TAG(y) != R_NilValue && pmatch(STRING_ELT(x, 0), TAG(y), 1)) { while (CAR(y) == R_MissingArg && y != R_NilValue) y = CDR(y); UNPROTECT(1); return (eval(CAR(y), rho)); } for (y = w; y != R_NilValue; y = CDR(y)) if (TAG(y) == R_NilValue) { UNPROTECT(1); return (eval(CAR(y), rho)); } UNPROTECT(1); return R_NilValue; } argval = asInteger(x); if (argval <= 0 || argval > (length(w))) { UNPROTECT(1); return R_NilValue; } x = eval(CAR(nthcdr(w, argval - 1)), rho); UNPROTECT(1); return x; } ************************************************************************** I do not know C but it seems to me that do_switch expects two arguments. regards Simone tested both on Windows VISTA 32 bit platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 10.0 year 2009 month 10 day 26 svn rev 50208 language R version.string R version 2.10.0 (2009-10-26) and on Linux OpenSuSE 11.0 64bit> R.version_ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status Patched major 2 minor 10.0 year 2009 month 11 day 19 svn rev 50499 language R version.string R version 2.10.0 Patched (2009-11-19 r50499) -- ______________________________________________________ Simone Giannerini Dipartimento di Scienze Statistiche "Paolo Fortunati" Universita' di Bologna Via delle belle arti 41 - 40126 Bologna, ITALY Tel: +39 051 2098262 Fax: +39 051 232153 http://www2.stat.unibo.it/giannerini/ ______________________________________________________ [[alternative HTML version deleted]]
maechler at stat.math.ethz.ch
2009-Dec-10 11:20 UTC
[Rd] switch() called with just the EXPR argument causes R to hang (PR#14124)
>>>>> "SG" == Simone Giannerini <sgiannerini at gmail.com> >>>>> on Thu, 10 Dec 2009 09:30:10 +0100 (CET) writes:SG> Dear all, switch() called with just the EXPR argument SG> causes R to hang so that the only way to stop it is to SG> kill R. SG> Reproducible example: >> switch(EXPR="a") SG> the internal C subroutine behind switch is do_switch SG> located in R/src/main/builtin.c For convenience I SG> reproduce it below. [..........] SG> I do not know C but it seems to me that do_switch SG> expects two arguments. One can argue that it should return NULL when it has no further arguments. A fix is very simple and I'll commit it (after testing) for R-devel and "R 2.10.1 RC". Martin Maechler, ETH ZUrich SG> regards SG> Simone SG> tested both on Windows VISTA 32 bit SG> platform i386-pc-mingw32 arch i386 os mingw32 system SG> i386, mingw32 status major 2 minor 10.0 year 2009 month SG> 10 day 26 svn rev 50208 language R version.string R SG> version 2.10.0 (2009-10-26) SG> and on Linux OpenSuSE 11.0 64bit >> R.version SG> _ platform x86_64-unknown-linux-gnu arch SG> x86_64 os linux-gnu system x86_64, linux-gnu status SG> Patched major 2 minor 10.0 year 2009 month 11 day 19 svn SG> rev 50499 language R version.string R version 2.10.0 SG> Patched (2009-11-19 r50499) SG> -- SG> ______________________________________________________ SG> Simone Giannerini Dipartimento di Scienze Statistiche SG> "Paolo Fortunati" Universita' di Bologna Via delle belle SG> arti 41 - 40126 Bologna, ITALY Tel: +39 051 2098262 Fax: SG> +39 051 232153 http://www2.stat.unibo.it/giannerini/ SG> ______________________________________________________ SG> [[alternative HTML version deleted]] SG> ______________________________________________ SG> R-devel at r-project.org mailing list SG> https://stat.ethz.ch/mailman/listinfo/r-devel