Skip to content

Commit

Permalink
fix for CPyNodeWrapper making a reference cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
maniek2332 committed Feb 2, 2020
1 parent 58a6c70 commit ebdc2e9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion kaa/kaacore/nodes.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cdef extern from "kaacore/nodes.h" nogil:
text "kaacore::NodeType::text",

cdef cppclass CForeignNodeWrapper "kaacore::ForeignNodeWrapper":
pass
void on_add_to_parent()

cdef cppclass CNode "kaacore::Node":
# UNION!
Expand Down
13 changes: 11 additions & 2 deletions kaa/nodes.pxi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from cpython.ref cimport PyObject, Py_XINCREF, Py_XDECREF

from libc.stdint cimport uint32_t
from libcpp cimport bool
from libcpp.memory cimport unique_ptr

from cymove cimport cymove as cmove
Expand All @@ -18,15 +19,23 @@ from .kaacore.geometry cimport CAlignment

cdef cppclass CPyNodeWrapper(CForeignNodeWrapper):
PyObject* py_wrapper
bool added_to_parent

__init__(PyObject* py_wrapper):
Py_XINCREF(py_wrapper)
this.py_wrapper = py_wrapper
this.added_to_parent = False

__dealloc__():
Py_XDECREF(this.py_wrapper)
if this.added_to_parent:
Py_XDECREF(this.py_wrapper)
this.py_wrapper = NULL

void on_add_to_parent() nogil:
with gil:
Py_XINCREF(py_wrapper)
this.added_to_parent = True



cdef class NodeBase:
cdef:
Expand Down
2 changes: 1 addition & 1 deletion kaacore

0 comments on commit ebdc2e9

Please sign in to comment.