Re: [Rd] Inconsistent behavior for the C AP's R_ParseVector() ?
Dear Laurent, could you please provide a complete reproducible example where parsing results in a crash of R? Calling parse(text="list(''=123") from R works fine for me (gives Error: attempt to use zero-length variable name). I don't think the problem you observed could be related to the memory leak. The leak is on the heap, not stack. Zero-length names of elements in a list are allowed. They are not the same thing as zero-length variables in an environment. If you try to convert "lst" from your example to an environment, you would get the error (attempt to use zero-length variable name). Best Tomas On 11/30/19 11:55 PM, Laurent Gautier wrote: Hi again, Beside R_ParseVector()'s possible inconsistent behavior, R's handling of zero-length named elements does not seem consistent either: ``` lst <- list() lst[[""]] <- 1 names(lst) [1] "" list("" = 1) Error: attempt to use zero-length variable name ``` Should the parser be made to accept as valid what is otherwise possible when using `[[<` ? Best, Laurent Le sam. 30 nov. 2019 à 17:33, Laurent Gautier a écrit : I found the following code comment in `src/main/gram.c`: ``` /* Memory leak yyparse(), as generated by bison, allocates extra space for the parser stack using malloc(). Unfortunately this means that there is a memory leak in case of an R error (long-jump). In principle, we could define yyoverflow() to relocate the parser stacks for bison and allocate say on the R heap, but yyoverflow() is undocumented and somewhat complicated (we would have to replicate some macros from the generated parser here). The same problem exists at least in the Rd and LaTeX parsers in tools. */ ``` Could this be related to be issue ? Le sam. 30 nov. 2019 à 14:04, Laurent Gautier a écrit : Hi, The behavior of ``` SEXP R_ParseVector(SEXP, int, ParseStatus *, SEXP); ``` defined in `src/include/R_ext/Parse.h` appears to be inconsistent depending on the string to be parsed. Trying to parse a string such as `"list(''=1+"` sets the `ParseStatus` to incomplete parsing error but trying to parse `"list(''=123"` will result in R sending a message to the console (followed but a crash): ``` R[write to console]: Error: attempt to use zero-length variable nameR[write to console]: Fatal error: unable to initialize the JIT*** stack smashing detected ***: terminated ``` Is there a reason for the difference in behavior, and is there a workaround ? Thanks, Laurent [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Inappropriate class(o)[!inherits(o,"AsIs")] in get_all_vars
> suharto anggono--- via R-devel > on Fri, 29 Nov 2019 18:05:34 + writes: > class(o)[!inherits(o,"AsIs")] is still in function > 'get_all_vars' in R patched (in > https://svn.r-project.org/R/branches/R-3-6-branch/src/library/stats/R/models.R). It > was ported to R patched by r77402. You are right it's no longer now, thank you very much, Suharto! Martin > On Monday, 18 November 2019, 8:12:10 PM GMT+7, Martin Maechler > wrote: >> Martin Maechler on Mon, 18 Nov 2019 12:15:38 >> +0100 writes: > suharto anggono--- via R-devel >> on Sun, 17 Nov 2019 10:34:31 + writes: > >> SVN revision 77401 changes >> x[isM] <- > lapply(x[isM], function(o) `class<-`(o, class(o)[class(o) > != "AsIs"])) >> to >> x[isM] <- lapply(x[isM], > function(o) `class<-`(o, class(o)[!inherits(o,"AsIs")])) > >> in function 'get_all_vars' in > src/library/stats/R/models.R in R devel. > >> The change is inappropriate. > >> class(o)[class(o) != "AsIs"] removes "AsIs" from > class(o), giving class(o) without "AsIs". > >> On the other hand, inherits(o,"AsIs") is just a > single logical value. If "AsIs" is in class(o), > inherits(o,"AsIs") is TRUE. In that case, by recycling of > logical index, class(o)[!inherits(o,"AsIs")] removes all > elements of class(o), giving character(0). > > Thank you, Suharto ! > > You are obviously right, and I'm a bit embarrassed > by my > overzealousness to follow my own > recommendations in the R Blog > > http://bit.ly/R_blog_class_think_2x > > {*wrongly*: The recommendation was to "think again" > ...} > > It's a "shame" that the wrong code did not trigger > any checks, > so if anybody has time... I'd be > grateful for such a regression > check. > Once I started thinking, it was easy to modify the > previous reg.check to trigger in the case of the erronous > r77401. > Fixed now in 77435. Martin > [[alternative HTML version deleted]] > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel