Skip to content

Commit

Permalink
Add a test which used to fail (crash)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdonline committed Sep 18, 2024
1 parent fff7439 commit 9310354
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/unit_tests/hoc_python/test_refcounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from neuron import h
import sys


def test_seg_from_sec_x_ref():
"""A reproducer of calling `seg_from_sec_x` without a Python Section
Without the fix generally we would get (upon interpreter exit)
Fatal Python error: bool_dealloc: "deallocating True or False: bug likely caused by a refcount error in a C extension"
"""
## Pure python (ok)
# soma1 = nrn.Section("soma1")
# nc1 = h.NetCon(soma1(0.5)._ref_v, None)
# seg1 = nc1.preseg()
# print(sys.getrefcount(seg1))
# print(sys.getrefcount(seg1.sec))

h("create soma")
h("objref nc")
h("objref nil")
h('soma nc = new NetCon(&v(0.5), nil)')
nc = h.nc
seg = nc.preseg() # uses `seg_from_sec_x`

assert sys.getrefcount(seg) == 2
assert sys.getrefcount(seg.sec) == 3

0 comments on commit 9310354

Please sign in to comment.