From 5240c80229655e332d9204d9839ab730558fb12a Mon Sep 17 00:00:00 2001 From: remi-k Date: Sun, 10 May 2009 21:33:22 +0000 Subject: [PATCH] Compiles with python 2.6 Fixed dangerous decref git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1089 4e206d99-4929-0410-ac5d-dfc041789085 --- python/src/Sprite.cpp | 7 ++----- python/src/compat.hpp | 5 ++++- 2 files changed, 6 insertions(+), 6 deletions(-) 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)