Skip to content

segmentation fault second run of rust function in python pyo3 0.21.2 #4105

@Crispy13

Description

@Crispy13

Hi. I'm trying to apply pyo3 0.21.2 to 0.20 codes.

With 0.20 codes my python app works, but with the new code does not.

The current situation:

  • python version = 3.9.15
  1. the first call of rust_function in python succeeds, but the second call fails.
  2. The error was segmentation fault.
  3. The error messages are slightly different per run:
vk[d].setdefault(a, dict())[p_key] = sound_data
KeyError: 'chr11:871499/2' // <- this string can't be one of p_key, a or d. The string like that comes from another variable.

Exception ignored deletion of interned string failed:
Traceback (most recent call last):
  File "python_project.py", line 333, in rust_function
    self.rust_have_been_failed = True
KeyError: 'À\xad\x8dU' // <- A value that shouldn't exist if it's working properly.

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
--Type <RET> for more, q to quit, c to continue without paging--
pymalloc_free (ctx=0x0, p=0x1)
    at /usr/local/src/conda/python-3.9.15/Objects/obmalloc.c:1866
1866    /usr/local/src/conda/python-3.9.15/Objects/obmalloc.c: No such file or directory.
/usr/local/src/conda/python-3.9.15/Objects/object.c: No such file or directory.
  1. returning (String, i32) instead of (Py<PyString>, i32) does not raise the error.

The codes here: https://gist.github.com/Crispy13/03d25f8d556e644b5425ddf1decff6dc

The rust function get input string from python, and return it back with additional i32.

Is it me? What's the cause of the error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions