diff --git a/python/src/Sprite.cpp b/python/src/Sprite.cpp index 5482acc7d..7aa0d81c1 100644 --- a/python/src/Sprite.cpp +++ b/python/src/Sprite.cpp @@ -39,10 +39,7 @@ extern PyTypeObject PySfDrawableType; static void PySfSprite_dealloc(PySfSprite *self) { - if (self->Image != NULL) - { - Py_DECREF(self->Image); - } + Py_XDECREF(self->Image); delete self->obj; free_object(self); } @@ -96,7 +93,7 @@ PySfSprite_SetImage(PySfSprite* self, PyObject *args) PyErr_SetString(PyExc_TypeError, "Sprite.SetImage() Argument is not a sf.Image"); return NULL; } - Py_DECREF(self->Image); + Py_CLEAR(self->Image); Py_INCREF(Image); self->Image = Image; self->obj->SetImage(*(Image->obj)); diff --git a/python/src/compat.hpp b/python/src/compat.hpp index 8439f5891..4bbdc028a 100644 --- a/python/src/compat.hpp +++ b/python/src/compat.hpp @@ -53,12 +53,15 @@ #define load_from_file(self, args) \ return PyBool_FromLong(self->obj->LoadFromFile(PyString_AsString(args))) -#define Py_TYPE(a) a->ob_type #define head_init PyObject_HEAD_INIT(NULL) 0, #define PyBytes_FromStringAndSize PyString_FromStringAndSize #endif +#ifndef Py_TYPE +#define Py_TYPE(a) a->ob_type +#endif + #define free_object(a) Py_TYPE(a)->tp_free((PyObject*)a) #define PyBool_AsBool(a) ((PyObject_IsTrue(a))?true:false)