MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / dealloc

Method dealloc

src/py_class/mod.rs:146–161  ·  view source on GitHub ↗
(_py: Python, obj: *mut ffi::PyObject)

Source from the content-addressed store, hash-verified

144 }
145
146 unsafe fn dealloc(_py: Python, obj: *mut ffi::PyObject) {
147 //println!("BaseObject::dealloc({:?})", ptr);
148 // Unfortunately, there is no PyType_GenericFree, so
149 // we have to manually un-do the work of PyType_GenericAlloc:
150 let ty = ffi::Py_TYPE(obj);
151 if ffi::PyType_IS_GC(ty) != 0 {
152 ffi::PyObject_GC_Del(obj as *mut libc::c_void);
153 } else {
154 ffi::PyObject_Free(obj as *mut libc::c_void);
155 }
156 // For heap types, PyType_GenericAlloc calls INCREF on the type objects,
157 // so we need to call DECREF here:
158 if ffi::PyType_HasFeature(ty, ffi::Py_TPFLAGS_HEAPTYPE) != 0 {
159 ffi::Py_DECREF(ty as *mut ffi::PyObject);
160 }
161 }
162}

Callers

nothing calls this directly

Calls 4

Py_TYPEFunction · 0.50
PyType_IS_GCFunction · 0.50
PyType_HasFeatureFunction · 0.50
Py_DECREFFunction · 0.50

Tested by

no test coverage detected