Commit 300c37a4 authored by Pan's avatar Pan

fixup! fixup! fixup! Added documentation on extension class instantiation from existing pointer

parent e98b190f
...@@ -554,10 +554,8 @@ contructors, this necessitates the use of factory functions. For example, :: ...@@ -554,10 +554,8 @@ contructors, this necessitates the use of factory functions. For example, ::
cdef my_c_struct *_ptr cdef my_c_struct *_ptr
cdef bint ptr_owner cdef bint ptr_owner
def __cinit__(self, owner=False): def __cinit__(self):
# On cinit, do not create new structure but set pointer to NULL self.ptr_owner = False
self._ptr = NULL
self.ptr_owner = owner
def __dealloc__(self): def __dealloc__(self):
# De-allocate if not null and flag is set # De-allocate if not null and flag is set
...@@ -583,8 +581,9 @@ contructors, this necessitates the use of factory functions. For example, :: ...@@ -583,8 +581,9 @@ contructors, this necessitates the use of factory functions. For example, ::
the extension type to ``free`` the structure pointed to by ``_ptr`` the extension type to ``free`` the structure pointed to by ``_ptr``
when the wrapper object is deallocated.""" when the wrapper object is deallocated."""
# Call to __new__ bypasses __init__ constructor # Call to __new__ bypasses __init__ constructor
cdef WrapperClass wrapper = WrapperClass.__new__(WrapperClass, owner=True) cdef WrapperClass wrapper = WrapperClass.__new__(WrapperClass)
wrapper._ptr = _ptr wrapper._ptr = _ptr
wrapper.ptr_owner = owner
return wrapper return wrapper
@staticmethod @staticmethod
......
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