[Rd] Bug: C-level and _set_rl_word_breaks

Laurent Gautier lgautier at gmail.com
Thu Jan 31 03:48:58 CET 2013


Hi,

I filed a bug report in the tracker (id #15169) a short while ago,
along with a patch, but I came back to it to see that there is
relatively little movement or participation on the tracker so I
thought I'd pitch it here (patch attached).

The function `set_rl_word_breaks` in src/unix/sys-std.c relies on
statically-allocated strings local to the function, making other C
code using the readline library, such as a program embedding
R and using readline as well, at risk of creating a segfault when
trying to free `rl_basic_word_break_characters` or
`rl_completer_word_break_characters` when changing them.

The issue was noticed when embedding R in Python (rpy2); I had an
ugly hack for a long time (less work than champion the inclusion
of a patch in R) but the iPython developers pushed what could be
demanded from the rpy2 with their "R magic" extension and
so I wrote a patch (and they have made a brittle workaround in
the meantime).

The fix would be of interest to anyone embedding R in C and using
readline (e.g., language interface developers if the language either
has a console using readline - and chances are that it does - or
an interface to readline).

The patch attached is against today's R-dev and will likely apply to
current R-2.15 branch. With the patch applied, R is building and is
passing `make check`. It could be slightly expanded by handling
cases where the calloc() or realloc() faills, although not an absolute
priority (if allocating 200 bytes fails, the system might have
bigger worries than keeping R from crashing).


Laurent

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix__set_rl_word_breaks.diff
Type: text/x-patch
Size: 1496 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20130131/454e2ca1/attachment.bin>


More information about the R-devel mailing list