8000 segfault if py_module gets garbage collected · Issue #5 · dabeaz/bitey · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
segfault if py_module gets garbage collected #5
Open
@bfroehle

Description

@bfroehle

I was working on an IPython extension which provides a cell magic for running C code via bitey, e.g.:

In [4]: %load_ext biteymagic

In [5]: %%bitey
   ...: int life() { return 42; }
   ...: 

In [6]: life()
Out[6]: 42

However I was running into random segfaults, often after running %timeit or similar, indicating that garbage collection was likely to blame. To cut to the chase, the issue was because I called bitey.loader.build_module to build a module, extracted the functions into the current namespace, but never saved the built module in sys.modules. When the module was garbage collected (and hence _llvm_engine/_llvm_module get deleted).... BOOM!

To fix the bug, either of the following would be sufficient:

  1. I could add the module to sys.modules. In this case, I'd suggest a short note in the docstring.
  2. Keep a reference in the python wrapper function object to the execution engine, i.e. set _llvm_engine and _llvm_module as attributes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0