diff --git a/python/cell_object.cpp b/python/cell_object.cpp index a1c341f42..951d77e5c 100644 --- a/python/cell_object.cpp +++ b/python/cell_object.cpp @@ -20,19 +20,19 @@ static void cell_object_dealloc(CellObject* self) { Cell* cell = self->cell; if (cell) { for (uint64_t i = 0; i < cell->polygon_array.count; i++) - Py_DECREF(cell->polygon_array[i]->owner); + Py_XDECREF(cell->polygon_array[i]->owner); for (uint64_t i = 0; i < cell->reference_array.count; i++) - Py_DECREF(cell->reference_array[i]->owner); + Py_XDECREF(cell->reference_array[i]->owner); for (uint64_t i = 0; i < cell->flexpath_array.count; i++) - Py_DECREF(cell->flexpath_array[i]->owner); + Py_XDECREF(cell->flexpath_array[i]->owner); for (uint64_t i = 0; i < cell->robustpath_array.count; i++) - Py_DECREF(cell->robustpath_array[i]->owner); + Py_XDECREF(cell->robustpath_array[i]->owner); for (uint64_t i = 0; i < cell->label_array.count; i++) - Py_DECREF(cell->label_array[i]->owner); + Py_XDECREF(cell->label_array[i]->owner); cell->clear(); free_allocation(cell); } - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int cell_object_init(CellObject* self, PyObject* args, PyObject* kwds) { @@ -60,6 +60,9 @@ static int cell_object_init(CellObject* self, PyObject* args, PyObject* kwds) { cell->name = copy_string(name, &len); cell->owner = self; if (len <= 1) { + free_allocation(cell->name); + free_allocation(cell); + self->cell = NULL; PyErr_SetString(PyExc_ValueError, "Empty cell name."); return -1; } diff --git a/python/curve_object.cpp b/python/curve_object.cpp index 4f19cc220..dcd026a18 100644 --- a/python/curve_object.cpp +++ b/python/curve_object.cpp @@ -17,7 +17,7 @@ static void curve_object_dealloc(CurveObject* self) { self->curve->clear(); free_allocation(self->curve); } - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int curve_object_init(CurveObject* self, PyObject* args, PyObject* kwds) { diff --git a/python/flexpath_object.cpp b/python/flexpath_object.cpp index 45bb4e6cc..e2b45d1d2 100644 --- a/python/flexpath_object.cpp +++ b/python/flexpath_object.cpp @@ -26,7 +26,7 @@ static void flexpath_cleanup(FlexPathObject* self) { static void flexpath_object_dealloc(FlexPathObject* self) { if (self->flexpath) flexpath_cleanup(self); - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int flexpath_object_init(FlexPathObject* self, PyObject* args, PyObject* kwds) { diff --git a/python/gdswriter_object.cpp b/python/gdswriter_object.cpp index 378d533e6..f91b5b41c 100644 --- a/python/gdswriter_object.cpp +++ b/python/gdswriter_object.cpp @@ -15,7 +15,7 @@ static PyObject* gdswriter_object_str(GdsWriterObject* self) { static void gdswriter_object_dealloc(GdsWriterObject* self) { free_allocation(self->gdswriter); - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int gdswriter_object_init(GdsWriterObject* self, PyObject* args, PyObject* kwds) { diff --git a/python/label_object.cpp b/python/label_object.cpp index 4a2a356db..c01b72432 100644 --- a/python/label_object.cpp +++ b/python/label_object.cpp @@ -17,7 +17,7 @@ static void label_object_dealloc(LabelObject* self) { self->label->clear(); free_allocation(self->label); } - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int label_object_init(LabelObject* self, PyObject* args, PyObject* kwds) { diff --git a/python/library_object.cpp b/python/library_object.cpp index d60fc30bf..40b5be75c 100644 --- a/python/library_object.cpp +++ b/python/library_object.cpp @@ -17,13 +17,13 @@ static void library_object_dealloc(LibraryObject* self) { Library* library = self->library; if (library) { for (uint64_t i = 0; i < library->cell_array.count; i++) - Py_DECREF(library->cell_array[i]->owner); + Py_XDECREF(library->cell_array[i]->owner); for (uint64_t i = 0; i < library->rawcell_array.count; i++) - Py_DECREF(library->rawcell_array[i]->owner); + Py_XDECREF(library->rawcell_array[i]->owner); library->clear(); free_allocation(library); } - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int library_object_init(LibraryObject* self, PyObject* args, PyObject* kwds) { diff --git a/python/polygon_object.cpp b/python/polygon_object.cpp index c057a302c..f40dc61f9 100644 --- a/python/polygon_object.cpp +++ b/python/polygon_object.cpp @@ -19,7 +19,7 @@ static void polygon_object_dealloc(PolygonObject* self) { self->polygon->clear(); free_allocation(self->polygon); } - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int polygon_object_init(PolygonObject* self, PyObject* args, PyObject* kwds) { diff --git a/python/rawcell_object.cpp b/python/rawcell_object.cpp index 85b9c328e..3c06c7f6b 100644 --- a/python/rawcell_object.cpp +++ b/python/rawcell_object.cpp @@ -22,7 +22,7 @@ static void rawcell_object_dealloc(RawCellObject* self) { rawcell->clear(); free_allocation(rawcell); } - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int rawcell_object_init(RawCellObject* self, PyObject* args, PyObject* kwds) { diff --git a/python/reference_object.cpp b/python/reference_object.cpp index ef2dcc1a5..1047fbda5 100644 --- a/python/reference_object.cpp +++ b/python/reference_object.cpp @@ -24,14 +24,14 @@ static void reference_object_dealloc(ReferenceObject* self) { Reference* reference = self->reference; if (reference) { if (reference->type == ReferenceType::Cell) { - Py_DECREF(reference->cell->owner); + Py_XDECREF(reference->cell->owner); } else if (reference->type == ReferenceType::RawCell) { - Py_DECREF(reference->rawcell->owner); + Py_XDECREF(reference->rawcell->owner); } reference->clear(); free_allocation(reference); } - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int reference_object_init(ReferenceObject* self, PyObject* args, PyObject* kwds) { @@ -79,6 +79,8 @@ static int reference_object_init(ReferenceObject* self, PyObject* args, PyObject reference->name = (char*)allocate(++len); memcpy(reference->name, name, len); } else { + free_allocation(reference); + self->reference = NULL; PyErr_SetString(PyExc_TypeError, "Argument cell must be a Cell, RawCell, or string."); return -1; } diff --git a/python/repetition_object.cpp b/python/repetition_object.cpp index 127af6084..04530f3b1 100644 --- a/python/repetition_object.cpp +++ b/python/repetition_object.cpp @@ -37,8 +37,7 @@ static PyObject* repetition_object_str(RepetitionObject* self) { static void repetition_object_dealloc(RepetitionObject* self) { Repetition repetition = self->repetition; repetition.clear(); - - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int repetition_object_init(RepetitionObject* self, PyObject* args, PyObject* kwds) { diff --git a/python/robustpath_object.cpp b/python/robustpath_object.cpp index d70a56ab0..b8d9cf52e 100644 --- a/python/robustpath_object.cpp +++ b/python/robustpath_object.cpp @@ -37,7 +37,7 @@ static void robustpath_cleanup(RobustPathObject* self) { static void robustpath_object_dealloc(RobustPathObject* self) { if (self->robustpath) robustpath_cleanup(self); - PyObject_Del(self); + Py_TYPE(self)->tp_free((PyObject*)self); } static int robustpath_object_init(RobustPathObject* self, PyObject* args, PyObject* kwds) {