Hi,
* Kynn Jones wrote: > > I'm very green with R, so maybe this is not a bug, but it looks like one to > > me. The following program segfaults at the second call to > > Rf_PrintValue(). Yes, I think you found a bug. * On 2009-06-26 at 16:09 -0700 Martin Morgan wrote: > mkChar creates a CHARSXP. These are not normally user-visible, but > instead are placed into a STRSXP (vector type of 'character' in R). So > you want to > > PROTECT( x_r = allocVector(STRSXP, 1) ); > SET_STRING_ELT(x_r, 0, mkChar( x )); > > (There is also mkString( x ) for the special case of constructing > character(1)). > > I think the segfault is because the CHARSXP returned by mkChar is > initialized with information different from that expected of > user-visible SEXPs (I think it is the information on chaining the node > to the hash table; see Defn.h:120 and memory.c:2844); I think the > success of Rf_PrintValue on 'foo' is a ghost left over from when > CHARSXPs were user-visible. CHARSXPs are not intended to be user-visible. However, Rf_PrintValue should not segfault either. Indeed the root cause was attempting to print the attributes for the CHARSXP which have been repurposed for handling the CHARSXP cache. I have patched R-devel so that PrintValue works as expected on CHARSXPs. The original code should now work without crashing. But this should really only be used to assist in debugging. CHARSXPs should never be exposed at the user level and should instead be elements of a character vector (STRSXP). + seth -- Seth Falcon http://userprimary.net/user ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel