From simon.urbanek at r-project.org  Wed Nov 16 20:59:51 2011
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Wed, 16 Nov 2011 14:59:51 -0500
Subject: [Rd] Question on parsing R code from C
In-Reply-To: <loom.20111116T203740-838@post.gmane.org>
References: <loom.20111108T203022-872@post.gmane.org>
	<9465BE63-EA88-4BE2-8D1C-9E33BE8AA45D@r-project.org>
	<loom.20111108T224700-655@post.gmane.org>
	<3D4F776D-4D5D-4C39-90B3-12DF09C5C6BA@r-project.org>
	<loom.20111109T001139-68@post.gmane.org>
	<AF0744B1-C119-4BF1-99D0-9DBA31E734F9@r-project.org>
	<loom.20111111T000844-348@post.gmane.org>
	<84A85DE6-2914-4C8D-834A-07DE5820B5AD@r-project.org>
	<loom.20111115T225950-180@post.gmane.org>
	<F4E5DACB-DBAC-46AE-B647-6A93CAA8FAB2@r-project.org>
	<loom.20111116T203740-838@post.gmane.org>
Message-ID: <303AC369-BDB4-438A-99C6-E604E04A7D20@r-project.org>


On Nov 16, 2011, at 2:48 PM, KR wrote:

> Simon Urbanek <simon.urbanek <at> r-project.org> writes:
>> Not without seeing the actual code. (And details such as which platform you're 
> on).
>> Note that setup_Rmainloop() is the last to set the SETJMP context target so 
> you should make sure the stack is
>> still present after it finished (i.e. you can't call it from a sub-function - 
> which Rf_initEmbeddedR
>> does) otherwise error without an enclosing context will crash. Or to put it 
> other way round, create a
>> context around your parse/eval code (probably the easiest way to do that is to 
> use R_ToplevelExec).
> 
> I will try to produce the exact code I am using (at the moment it embedded in
> other code you would not be interested in), platforms are Windows XP and
> Windows7-64. Some points:
> 
> 1. Actually R_tryEvalSilent (and R_tryEval) calls R_ToplevelExec.

Yes, but that's not where you get the crash.


> Moreover if 
> the problem is linked to the SETJMP (which I do not know much about 
> unfortunately, my background is C++) it's my understanding that it should 
> manifest itself even for other parse and evaluation errors. Instead the problem
> arise if and only if I pass a wrongly escaped string. I.e. rnorm(10a10) does not 
> result in a crash.
> Is the R code doing something differently in this specific case?
> 

Your crash is in the parsing step, not in the evaluator (if I understand you correctly) and the parsing step is not wrapped in a context - that's my guess based on what you told us.

Cheers,
Simon


> 2. My code is almost exactly the same as:
> http://stackoverflow.com/questions/2463437/r-from-c-simplest-possible-
> helloworld/2464479#2464479
> skipping the EXAMPLE 1 part and passing the capture.output(eval(parse(text="
> <code>"))) string to R_tryEval in EXAMPLE 2.
> 
> Cheers,
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 



[Rd] Question on parsing R code from C
Simon Urbanek