Skip to content

Commit

Permalink
Fix segfault when calling rinternalize and R not initialized. (#972)
Browse files Browse the repository at this point in the history
This is fixing issue #971.
  • Loading branch information
lgautier committed Jan 7, 2023
1 parent 734f736 commit 8c9a026
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Bugs fixed
- With the "R magic", converters in a local namespace were inadvertently
skipped (the local namespace was not searched).

- Calling :func:`rpy2.rinterface.rternalize` before the embedded R is
initialized was ending with a segfault. It is now raising an
:class:`rpy2.rinterface_lib/embedded/RNotReady` (issue #971).

Changes
-------

Expand Down
2 changes: 2 additions & 0 deletions rpy2/rinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,8 @@ def foo(x, *, y, z):
:return: A wrapped R object that can be use like any other rpy2
object.
"""
if not embedded.isinitialized():
raise embedded.RNotReadyError('The embedded R is not yet initialized.')

if function is None:
return functools.partial(rternalize, signature=signature)
Expand Down
6 changes: 6 additions & 0 deletions rpy2/tests/rinterface/test_noinitialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ def test_assert_isready():
def test_assert_environment_geitem():
with pytest.raises(embedded.RNotReadyError):
sexp.globalenv['x']

@pytest.mark.skipif(embedded.rpy2_embeddedR_isinitialized,
reason='Can only be tested before R is initialized.')
def test_assert_rternalize():
with pytest.raises(embedded.RNotReadyError):
rinterface.rternalize(lambda x: x)

0 comments on commit 8c9a026

Please sign in to comment.