Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/mathutils/mathutils.c
| Show First 20 Lines • Show All 691 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| int BaseMathObject_clear(BaseMathObject *self) | int BaseMathObject_clear(BaseMathObject *self) | ||||
| { | { | ||||
| Py_CLEAR(self->cb_user); | Py_CLEAR(self->cb_user); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| /** Only to validate assumptions when debugging. */ | |||||
| #ifndef NDEBUG | |||||
| static bool BaseMathObject_is_tracked(BaseMathObject *self) | |||||
| { | |||||
| PyObject *cb_user = self->cb_user; | |||||
| self->cb_user = (void *)(uintptr_t)-1; | |||||
| bool is_tracked = PyObject_GC_IsTracked((PyObject *)self); | |||||
| self->cb_user = cb_user; | |||||
| return is_tracked; | |||||
| } | |||||
| #endif /* NDEBUG */ | |||||
| void BaseMathObject_dealloc(BaseMathObject *self) | void BaseMathObject_dealloc(BaseMathObject *self) | ||||
| { | { | ||||
| /* only free non wrapped */ | /* only free non wrapped */ | ||||
| if ((self->flag & BASE_MATH_FLAG_IS_WRAP) == 0) { | if ((self->flag & BASE_MATH_FLAG_IS_WRAP) == 0) { | ||||
| PyMem_Free(self->data); | PyMem_Free(self->data); | ||||
| } | } | ||||
| if (self->cb_user) { | if (self->cb_user) { | ||||
| BLI_assert(BaseMathObject_is_tracked(self) == true); | |||||
| PyObject_GC_UnTrack(self); | PyObject_GC_UnTrack(self); | ||||
| BaseMathObject_clear(self); | BaseMathObject_clear(self); | ||||
| } | } | ||||
| else if (!BaseMathObject_CheckExact(self)) { | |||||
| /* Sub-classed types get an extra track (in Pythons internal `subtype_dealloc` function). */ | |||||
| BLI_assert(BaseMathObject_is_tracked(self) == true); | |||||
| PyObject_GC_UnTrack(self); | |||||
| BLI_assert(BaseMathObject_is_tracked(self) == false); | |||||
| } | |||||
| Py_TYPE(self)->tp_free(self); // PyObject_DEL(self); /* breaks sub-types. */ | Py_TYPE(self)->tp_free(self); // PyObject_DEL(self); /* breaks sub-types. */ | ||||
| } | } | ||||
| int BaseMathObject_is_gc(BaseMathObject *self) | |||||
| { | |||||
| return self->cb_user != NULL; | |||||
| } | |||||
| PyObject *_BaseMathObject_new_impl(PyTypeObject *root_type, PyTypeObject *base_type) | |||||
| { | |||||
| PyObject *obj; | |||||
| if (ELEM(base_type, NULL, root_type)) { | |||||
| obj = _PyObject_GC_New(root_type); | |||||
| if (obj) { | |||||
| BLI_assert(BaseMathObject_is_tracked((BaseMathObject *)obj) == false); | |||||
| } | |||||
| } | |||||
| else { | |||||
| /* Calls Generic allocation function which always tracks | |||||
| * (because `root_type` is flagged for GC). */ | |||||
| obj = base_type->tp_alloc(base_type, 0); | |||||
| if (obj) { | |||||
| BLI_assert(BaseMathObject_is_tracked((BaseMathObject *)obj) == true); | |||||
| PyObject_GC_UnTrack(obj); | |||||
| BLI_assert(BaseMathObject_is_tracked((BaseMathObject *)obj) == false); | |||||
| } | |||||
| } | |||||
| return obj; | |||||
| } | |||||
| /*----------------------------MODULE INIT-------------------------*/ | /*----------------------------MODULE INIT-------------------------*/ | ||||
| static struct PyMethodDef M_Mathutils_methods[] = { | static struct PyMethodDef M_Mathutils_methods[] = { | ||||
| {NULL, NULL, 0, NULL}, | {NULL, NULL, 0, NULL}, | ||||
| }; | }; | ||||
| static struct PyModuleDef M_Mathutils_module_def = { | static struct PyModuleDef M_Mathutils_module_def = { | ||||
| PyModuleDef_HEAD_INIT, | PyModuleDef_HEAD_INIT, | ||||
| "mathutils", /* m_name */ | "mathutils", /* m_name */ | ||||
| ▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines | |||||