Hi Toby, Unfortunately, the R documentation (and source code) doesn't make it clear how to convert a 'user' string to an R unicode string. I'll send off a query to the R developer list to see if they'll help.
In the mean time, I've simply added a case for unicode strings that first converts each python unicode string to a python ascii string and then to an R string. This fix is now in the SVN repository. -G On Oct 17, 2007, at 3:06PM , Toby Hocking wrote: > Thanks for the response, Gregory. But I need a bit more help. > > So far I am using the test python code > > from rpy import r > r.print_(u'') > r.print_(u' ') > > By inserting print statements into the RPy C code (rpymodule.c), I > have determined that every time RPy accesses an R object, it goes > through the C function Robj_call, which calls make_args, which in > turn calls to_Robj. For some reason to_Robj thinks that the unicode > string is a sequence, so PySequence_Check returns TRUE and thus > seq_to_R(obj) gets called. The problem is that seq_to_R calls > to_Robj, which causes an infinite loop and an eventual segfault. > > Interestingly, the empty unicode string does not cause a segfault, > since it causes seq_to_R to return before calling to_Robj. > > I suppose the solution is to use the Python API's PyUnicode_Check > function before PySequenceCheck (http://docs.python.org/api/ > unicodeObjects.html) and treat conversion of this type of data > especially. As I see it, there are 2 options: > > 1. Convert the unicode string to normal string, and then pass it to > R (lose unicode functionality). > 2. Pass to R as Unicode -- I believe Python and R both support UCS2 > -- is the translation straightforward? > > Case 2 is preferable, case 1 is more of a hack. I presume we will > have to do something similar to what RPy does when PyString_Check > works: > > PROTECT(robj=NEW_STRING(1)); > SET_STRING_ELT(robj,0,COPY_TO_USER_STRING(PyString_AsString(obj))); > > But what are NEW_STRING, SET_STRING_ELT, and COPY_TO_USER_STRING > defined as? I can't seem to find definitions of any of these. There > is a PyUnicode_AsUnicode function in Python's C API, so we should > be able to use that. > > I'm going to take a short break from this for a bit, but please > email me any suggestions/ideas and what to do next. > > Toby Dylan Hocking > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Gregory > Warnes > Sent: Tuesday, October 16, 2007 6:20 PM > To: RPy help, support and design discussion list > Subject: Re: [Rpy] segfault on unicode string conversion > > > I've been trying to make time to work on fixing all of the > outstanding bugs. Other duties keep pulling me away. > > This should be a simple fix... > > > On Oct 16, 2007, at 7:56PM , Toby Dylan Hocking wrote: > >> Hi all, >> >> I really need RPy to resolve this issue: >> http://sourceforge.net/tracker/index.php? >> func=detail&aid=1592811&group_id=48422&atid=453021 >> >> Basically, I have a python app that is using RPy to make some neat >> graphics for a website, and some parameters are passed from Python >> to R in >> function arguments as unicode strings. This causes the python >> interpreter >> to segfault, presumably in seq_to_R in rpymodule.c (confirm or deny?) >> >> Is there any chance the dev team can fix this bug -- unicode >> support for >> rpy -- anytime soon? >> >> Sincerely, >> Toby Dylan Hocking >> http://www.ocf.berkeley.edu/~tdhock >> >> --------------------------------------------------------------------- >> - >> --- >> This SF.net email is sponsored by: Splunk Inc. >> Still grepping through log files to find problems? Stop. >> Now Search log events and configuration files using AJAX and a >> browser. >> Download your FREE copy of Splunk now >> http://get.splunk.com/ >> _______________________________________________ >> rpy-list mailing list >> rpy-list@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/rpy-list > > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a > browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > rpy-list mailing list > rpy-list@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rpy-list > > ---------------------------------------------------------------------- > --- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a > browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > rpy-list mailing list > rpy-list@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rpy-list ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ rpy-list mailing list rpy-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rpy-list