[Rd] Question on the R's C stack limit

From: zhangxiaoning <xiaoning_zhang_at_hotmail.com>
Date: Thu, 28 Jun 2007 15:55:38 +0800

Hi, Simon & all, I try to embed R in my win32 multiple threads program and get c stack error.I have tried to disable the stack limit by setting R_CStackLimit to -1.However, if I do this in R source code \src\gnuwin32\system.c (in functionR_SetWin32(Rstart Rp), after line R_CStackLimit = top - bottom;) and rebuildR.dll, it works well. If I do this in my win32 program, it crashes at lineR_CStackLimit = (uintptr_t)-1. The error message says that "Access violationwritting location 0x00411078". From debug window, I can see the location0x00411078 is just the address of variable R_CStackLimit. From your response to the issue above, you said that "There is no need tochange the R source code." Could you please explain more on how to setR_CStackLimit to -1 without change the R source code? I have read somearticles about this and found that all of them are talking about Linuxplatform. I followed these suggestions and tried them in a simple test case(\src\gnuwin32\front-ends\rtest.c)!   to simplify my issue, below is what Itried:1. Build a vc7 program with rtest.c -- it works well. (I don't expect that I can reproduce c stack error with the simple test case, what I want is todisable stack checking in the test case.) 2. Try to disable stack checking by adding below code into rtest.c: after line #include <psignal.h>, add: #define CSTACK_DEFNS #include <Rinterface.h> in main, add: R_CStackLimit = (uintptr_t)-1. I tried a few different locations to add the command -- the beginning of the main, before and after R_SetParams(Rp), before and after setup_Rmainloop(). It always crashes at every location above when step to R_CStackLimit =(uintptr_t)-1. I guess that R_CStackLimit is not defined at this point, so I copy belowdefinition from \src\include\Defn.h to rtest.c: extern uintptr_t R_CStackLimit INI_as((uintptr_t)-1), and define INI_as correctly.There is no crashes but by debuging into \src\main\errors.c -- function void R_CheckStack(void), I see the R_CStack!  Limit is not changed (-1 is expected) -- still 1MB(default value of vc

7 program). And, applying above to my multiple threadprogram, I still get c stack error.  Am I doing something wrong? Thanks very much for spending time on this.  Xiaoning Simon Urbanek wrote:> > On Jun 1, 2007, at 5:44 AM, Ev Whin wrote:> >> Dear r-devel members,>>     I encountered a C stack limit issue, when I tried to embed R  >> 2.5 into my>> application.> > If you are embedding R, you can change or disable the stack limit by  > setting R_CStackLimit appropriately. There is no need to change the R  > source code.> > Cheers,> Simon> > > >> In the R-exts document, it says:"Note that R's own front ends>> use a stack size of 10Mb". I desire to know: is it possible to  >> decrease this>> stack size>> by modifying R's source code? If it's possible, which part of the  >> source>> code is responsible for the issue?>>>> Thank you all.>>> > ______________________________________________> R-devel@r-project.org mailing list> https://stat.ethz.ch/mailman/listinfo/r-devel> > Quoted f!
 rom: http://www.nabble.com/Question-on-the-R%27s-C-stack-limit-tf3851358.html#a10912632

        [[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 28 Jun 2007 - 08:00:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Jun 2007 - 13:35:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.