`rternalize`-d functions return NULL and print a ValueError.

Issue #538 resolved
Laurent Gautier created an issue

Reported on SO: https://stackoverflow.com/questions/55765380/


import rpy2.rinterface as ri

def cb_test():
    return ri.FloatSexpVector([1.0, 2.0, 3.0])


Comments (6)

  1. Laurent Gautier reporter

    The issue can be further narrowed down to:

     ri.conversion._python_to_cdata(ri.FloatSexpVector([1.0, 2.0, 3.0]))
  2. Laurent Gautier reporter

    The function rinterface_lib._rinterface_capi._evaluate_in_r() is returning a pointer to an R object. That object stops being protected from garbage collection as soon as that function returns (at that point the object's lifespan is not under R's protection and is no longer protected by the Python object having it as an attribute): https://bitbucket.org/rpy2/rpy2/src/0c1a75a62a0737fa445648f88d9b30afe7ea3d83/rpy/rinterface_lib/_rinterface_capi.py#lines-440 However, when used within "rternalized" functions, returning from that python function is immediately handing control back to R that protects it. From there lthe flow is the one of a regular R function called by rpy2.

    I do not think that a premature garbage collection of the R object returned can occur and this should be a good fix.

  3. Log in to comment