Commit 59343342 authored by Adam P. Goucher's avatar Adam P. Goucher

Prevent Python interpreter from segfaulting on exit

parent b5acede0
Pipeline #56465919 passed with stages
in 7 minutes and 31 seconds
__version__=[x.replace('"', '') for x in '''
#define LIFELIB_VERSION "ll2.2.11"
#define LIFELIB_VERSION "ll2.2.12"
// '''.split() if ('ll' in x)][0][2:]
......@@ -30,9 +30,13 @@ class Pattern(object):
self.session = session
self.owner = owner
def __del__(self):
self.lifelib('DeletePattern', self.ptr)
if self.ptr in self.session.pattern_ptrs:
self.lifelib('DeletePattern', self.ptr)
def __repr__(self):
......@@ -3,6 +3,7 @@ from .pattern import Pattern
from .samples import download_samples as dsamples
from .samples import validate_symmetry
import os
import atexit
from ..genera import sanirule
......@@ -22,6 +23,8 @@ class Lifetree(object):
self.ptr = lifelib('CreateLifetree', memory, n_layers)
self.n_layers = n_layers
def load(self, filename, compressed='deduce', tempfile='tempfile'):
filename = os.path.abspath(filename)
......@@ -110,7 +113,25 @@ class Lifetree(object):
def __del__(self):
self.lifelib('DeleteLifetree', self.ptr)
if self.ptr in self.session.lifetree_ptrs:
self.lifelib('DeleteLifetree', self.ptr)
all_sessions = []
def cleanup_sessions():
for sess in all_sessions:
for ptr in sess.pattern_ptrs:
sess.lifelib('DeletePattern', ptr)
sess.pattern_ptrs = set([])
for sess in all_sessions:
for ptr in sess.lifetree_ptrs:
sess.lifelib('DeleteLifetree', ptr)
sess.lifetree_ptrs = set([])
class Session(object):
......@@ -128,6 +149,10 @@ class Session(object):
self.default_planes = default_planes
self.rules = list(rules)
self.lifelib = WrappedLibrary(soname, local_bash=local_bash, local_python=local_python)
self.lifetree_ptrs = set([])
self.pattern_ptrs = set([])
def lifetree(self, *args, **kwargs):
......@@ -61,3 +61,8 @@ for testtype in "unit" "integration" "indirection"; do
"$python_name" -m unittest discover "lifelib/tests/$testtype"
printf "\n\033[1;36m **** segfault tests ****\033[0m\n"
for python_name in "${pythons[@]}"; do
"$python_name" -c 'import lifelib; lt = lifelib.load_rules("b3s23").lifetree(); pat = lt.pattern(); f = lambda x : x'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment