[R] R_NilValue blows up on Windows

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri Aug 23 07:42:24 CEST 2002


There is no such problem, as R itself uses this construction repeatedly.
You are using a non-standard compiler, and also your example is incorrect,
as the recommended compiler warns.

On Thu, 22 Aug 2002, Vele Samak wrote:

> Ok, Here's the c code that's loaded into R as dll on windows:
>
> #include <R.h>
> #include <Rdefines.h>
> SEXP test1(SEXP col);
>
> SEXP test1(SEXP col)
> {
>   SEXP col2;
>   Rprintf("no value!\n");
>   return col2;
> }
>
> Compiles ok with bcc32 into a dll, loads into R as part of a library, I
> Run library(rkdb), then
> > .Call("test1", 2)
> no value!
>
> And puf! Rterm crashes.

As it should.  You have returned an unassigned pointer.  Does your
compiler not warn you about such an error?  The recommended one does:

gcc   -Ic:/R/rw1060/src/include -Wall -O2   -c foo.c -o foo.o
foo.c: In function `test1':
foo.c:6: warning: `col2' might be used uninitialized in this function

> What's the point of this? I developed a library for connecting to a kdb
> database from within R. Similar to RODBC, but faster and more
> streamlined for access of real-time tick data. Everything works great,
> compiles on Win2000, R 1.3.1 and R 1.5.1 with Borland's free C++ 5.5,
> and runs into .dll.

Are you sure that R_NilValue is being linked correctly?  It is an
exported variable from R.dll.  There is a caveat in `readme.packages'
about this, and it is the usual cause of such problems.

> All functions work great except when there's no data
> from the database I do
>   if (nrows <= 0) {
>     Rprintf("No rows...");
>     return R_NilValue;
>   }
> And there lies the blow up of Rterm!!! Apparently R_NilValue can be
> assigned to any SEXP object internally, but when it's returned, Rterm
> doesn't know what to do with it.

It does if linked as recommended,

> I tried another bypass:
> 	SEXP NIL;
>   if (nrows <= 0) {
>     Rprintf("No rows...");
>     return NIL;
>   }
> This works in most but not all cases. Weird!

What's NIL?

> Any suggestions, comments are highly appreciated. Thanks,


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list