Re: [Rd] Package crashes R under Windows Vista

2009-09-19 Thread cstrato

Dear Duncan,

I know that I am asking an unusual question, since MS VC++ is not 
supported, and I have of course installed the Rtools. However, asking 
support from MS is not an option for the following reason:


Looking at different VC forums everybody tells you that you should 
compile all libraries with the same option and you should not mix 
options /MD with /MT, and this is the answer I will get.


Furthermore, as I have already mentioned, library xps.dll compiled with 
/MD works perfectly fine on WinXP and Vista when used independent from 
R. The problem is that when calling library(xps) from within R, R can 
load library xps.dll, but it cannot load the libraries which are called 
from library xps.dll such as library libCore.dll.


Since the question is why can R not load a C++ library which is called 
from library xps.dll, asking this question at R-devel seems for me to be 
the only option.


Best regards
Christian


Duncan Murdoch wrote:

On 18/09/2009 6:12 PM, cstrato wrote:

Dear all,

Please, please I really need your help, since I am not able to solve 
the problem myself:
It seems that until now most Windows users of my Bioconductor package 
"xps" use Windows XP, but recently a user tried to use it on Windows 
Vista where it crashed R immediately. Since I assume that some users 
may migrate to the upcoming Windows 7 where the problem will be the 
same, I would appreciate any help to be able to support Vista/Windows 
7, thank you in advance.


You are requiring specific Microsoft tools to compile a package, which 
fails on one Microsoft OS, but not another.  Isn't this a question you 
should address to Microsoft?


For the record:

We support compiling in the compiler listed in the R-admin manual, 
which is available from www.murdoch-sutherland.com/Rtools.  If you 
choose to use a different compiler, you should seek support from its 
supplier.


Duncan Murdoch



The problem ist that my package consists mainly of C++ code which I 
must compile with Visual C++ (Express Edition 2008), since it depends 
on the ROOT C++ framework. Windows users download and install first 
the ROOT Windows binary compiled with VC9 and then install the 
Windows binary of xps.


Thus package xps contains a "Makefile.win" where I use one of the 
compiler options "/MT" or "/MD", respectively, see: 
http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx


Since the Windows binary of ROOT is compiled with option "/MD" I 
should in principle use this option, however, R does not accept this 
option. Luckily, for Winodws XP I can compile xps with "/MT" and this 
works perfectly fine.


The real problem is that neither option works on Windows Vista, 
although I can run "R CMD INSTALL" in both cases. However, when 
loading "library(xps)" using Rterm.exe I get the following two cases:


1, xps compiled on Vista with option "/MD":
   new R session:
   > library(xps,lib.loc="C:/home/Rabbitus/CRAN/myRlib")
   Error in inDL(x, as.logical(local), as.logical(now), ...) :
 cannot load shared library 
'C:/home/CS/CRAN/myRlib/xps/libs/xps.dll':

LoadLibrary failure:  A DLL-Initialisationroutine failed.

Then R crashes and Vista displays a Dialogbox with the following 
message:

R for Windows terminal front-end does no longer function
  Anwendungszeitstempel:4a928a5c
  Fehlermodulname:libCore.dll_unloaded
  Fehlermodulversion:0.0.0.0
  Fehlermodulzeitstempel:4a4b94a1
  Ausnahmecode:c005
  Ausnahmeoffset:0413a6f0
  Betriebsystemversion:6.0.6001.2.1.0.768.3
  Gebietsschema-ID:1031
  Zusatzinformation 1:b2be
  Zusatzinformation 2:82109204b3973566ace818217390e302
  Zusatzinformation 3:1563
  Zusatzinformation 4:deee40b8797d25628c21b9ef47e8a50c

2, xps compiled on Vista with option "/MT":
   new R session:
   > library(xps,lib.loc="C:/home/CS/CRAN/myRlib")
   > scheme.test3 <- 
root.scheme(paste(.path.package("xps"),"schemes/SchemeTest3.root",sep="/")) 

   > data.test3 <- import.data(scheme.test3, "DataTest3", 
celdir=paste(.path.package("xps"),"raw",sep="/"))


   ==
   === STACKTRACE ===
   ==


   ==
   = END STACKTRACE =
   ==

Then R crashes and Vista displays a Dialogbox with the following 
message:

R for Windows terminal front-end does no longer function
Problemsignatur:
  Problemereignisname:APPCRASH
  Anwendungsname:Rterm.exe
  Anwendungsversion:2.92.49384.0
  Anwendungszeitstempel:4a928a5c
  Fehlermodulname:ntdll.dll
  Fehlermodulversion:6.0.6001.18000
  Fehlermodulzeitstempel:4791a7a6
  Ausnahmecode:c005
  Ausnahmeoffset:0006814c
  Betriebsystemversion:6.0.6001.2.1.0.768.3
  Gebietsschema-ID:1031
  Zusatzinformation 1:92ec
  Zusatzinformation 2:c556221fb8ba46fdaae5867fc20d6575
  Zusatzinformation 3:c65f
  Zus

[Rd] Return a list from a .Call but segfaults

2009-09-19 Thread Saptarshi Guha

Hello,
I call a function via .Call passing to it a raw vector(D) and an  
integer(I)

The vector is a series  K1,KData1, V1,VData1, K2, KData2, ...
where the integer K1 is the length of Data1 and similarly for Ki (wrt  
Datai)(similarly for V*) There 2*I such pairs( (Ki,KDatai), (Vi,VDatai))


The numbers Ki(and Vi) are written in network order.

I am returning a list of I elements each element a list of two  
elements corresponding to KData and VData (which are serialized R  
objects) .


 ll <- .Call("returnListOfKV", rawkv, numread)

When use the function with browser(), and type head(ll) i get valid  
results.

However, i get a segfault when the code runs the next line

  j <- append(j,ll)

(where j was defined as vector(mode='list') )

The code below looks alright, but it appears to crash when getting  
copied.
Now one could blame message2rexp (in kk_), but once in R, the result  
of .Call is assigned to ll, everything should be protected.
In fact, if in kk_ i simply return a VECSXP with 2 elements, no  
errors, so one could conclude that message2rexp is to blame.


Yet, when i replace the code with R code, that is using readBin and  
only calling calling C(to call message2rexp) to deserialize a raw  
vector, I get no such error.


There is something I'm missing , could someone tell me where?
Thank you for your time
Regards
Saptarshi


=== Using GDB? 
I would like to run it through gdb, i get the following message
[Thread debugging using libthread_db enabled]
Error while reading shared library symbols:
Cannot find new threads: generic error
Cannot find new threads: generic error]

and cannot proceed.

 Code 
  SEXP returnListOfKV(SEXP raw,SEXP numread){

if(TYPEOF(raw)!=RAWSXP){
  return(R_NilValue);
}
int num = INTEGER(numread)[0];
char *rawdata = (char*)RAW(raw);
SEXP KV ,rval;
int r;
PROTECT(rval = Rf_allocVector(VECSXP, num));
for(int i=0;i  r = reverseUInt(*((int*) rawdata)); //converts network order to  
host

  rawdata+=4; //yes, hard code size of int
  PROTECT(k= kk_(rawdata,r)); //deserializes data and returns a  
SEXP

  rawdata+= r;
  SET_VECTOR_ELT(KV,0, k);
  UNPROTECT(1);

  r = reverseUInt(*((int*) rawdata));
  rawdata+=4;
  PROTECT(k= kk_(rawdata,r));
  rawdata+=r;
  SET_VECTOR_ELT(KV,1, k);
  UNPROTECT(1);

  SET_VECTOR_ELT(rval,i,KV);
  UNPROTECT(1);
}
UNPROTECT(1);
return(rval);
  }


  SEXP kk_(char *d,int n){
SEXP k;
REXP *rexp = new REXP();
rexp->Clear();
rexp->ParseFromArray(d,n);
PROTECT(k = message2rexp(*rexp));
delete(rexp);
UNPROTECT(1);
return(k);
  }

Saptarshi Guha | saptarshi.g...@gmail.com | http://www.stat.purdue.edu/~sguha

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Return a list from a .Call but segfaults

2009-09-19 Thread Saptarshi Guha
After some examination, this is what i found (i changed the code
somewhat, i dont modify rawdata anymore)

load("/tmp/v.Rdata")
dyn.load("/ln/meraki/custom/lib64/R/library/mylib/libs/lib.so")
v=.Call("returnListOfKV",rawkv,numread)

## v is a list of 28231 lists each of length 2
j=v[1:1] ; u=list();u=append(u,j)
and
 j=v[1:15164] ; u=list();u=append(u,j)
both work but for n> 15164
 j=v[1:n] ; u=list();u=append(u,j)
returns
Error: protect(): protection stack overflow

I have no idea why...
Regards
Saptarshi




On Sat, Sep 19, 2009 at 10:15 PM, Saptarshi Guha
 wrote:
> Hello,
> I call a function via .Call passing to it a raw vector(D) and an integer(I)
> The vector is a series  K1,KData1, V1,VData1, K2, KData2, ...
> where the integer K1 is the length of Data1 and similarly for Ki (wrt
> Datai)(similarly for V*) There 2*I such pairs( (Ki,KDatai), (Vi,VDatai))
>
> The numbers Ki(and Vi) are written in network order.
>
> I am returning a list of I elements each element a list of two elements
> corresponding to KData and VData (which are serialized R objects) .
>
>  ll <- .Call("returnListOfKV", rawkv, numread)
>
> When use the function with browser(), and type head(ll) i get valid results.
> However, i get a segfault when the code runs the next line
>
>  j <- append(j,ll)
>
> (where j was defined as vector(mode='list') )
>
> The code below looks alright, but it appears to crash when getting copied.
> Now one could blame message2rexp (in kk_), but once in R, the result of
> .Call is assigned to ll, everything should be protected.
> In fact, if in kk_ i simply return a VECSXP with 2 elements, no errors, so
> one could conclude that message2rexp is to blame.
>
> Yet, when i replace the code with R code, that is using readBin and only
> calling calling C(to call message2rexp) to deserialize a raw vector, I get
> no such error.
>
> There is something I'm missing , could someone tell me where?
> Thank you for your time
> Regards
> Saptarshi
>
>
> === Using GDB? 
> I would like to run it through gdb, i get the following message
> [Thread debugging using libthread_db enabled]
> Error while reading shared library symbols:
> Cannot find new threads: generic error
> Cannot find new threads: generic error]
>
> and cannot proceed.
>
>  Code 
>  SEXP returnListOfKV(SEXP raw,SEXP numread){
>
>    if(TYPEOF(raw)!=RAWSXP){
>      return(R_NilValue);
>    }
>    int num = INTEGER(numread)[0];
>    char *rawdata = (char*)RAW(raw);
>    SEXP KV ,rval;
>    int r;
>    PROTECT(rval = Rf_allocVector(VECSXP, num));
>    for(int i=0;i      SEXP k = R_NilValue;
>      PROTECT(KV = Rf_allocVector(VECSXP, 2));
>
>      r = reverseUInt(*((int*) rawdata)); //converts network order to host
>      rawdata+=4; //yes, hard code size of int
>      PROTECT(k= kk_(rawdata,r)); //deserializes data and returns a SEXP
>      rawdata+= r;
>      SET_VECTOR_ELT(KV,0, k);
>      UNPROTECT(1);
>
>      r = reverseUInt(*((int*) rawdata));
>      rawdata+=4;
>      PROTECT(k= kk_(rawdata,r));
>      rawdata+=r;
>      SET_VECTOR_ELT(KV,1, k);
>      UNPROTECT(1);
>
>      SET_VECTOR_ELT(rval,i,KV);
>      UNPROTECT(1);
>    }
>    UNPROTECT(1);
>    return(rval);
>  }
>
>
>  SEXP kk_(char *d,int n){
>    SEXP k;
>    REXP *rexp = new REXP();
>    rexp->Clear();
>    rexp->ParseFromArray(d,n);
>    PROTECT(k = message2rexp(*rexp));
>    delete(rexp);
>    UNPROTECT(1);
>    return(k);
>  }
>
> Saptarshi Guha | saptarshi.g...@gmail.com |
> http://www.stat.purdue.edu/~sguha
>
>
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel