Generalize access to ob_type so that they work with both Python 2.* and Python 3.*
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 15 Oct 2009 19:14:56 +0000 (15:14 -0400)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 19 Oct 2009 07:50:24 +0000 (10:50 +0300)
Python 2's various object structs use macros to implement common fields at the top of each
struct.

Python 3's objects instead embed a PyObject struct as the first member within the more refined
object structs.

Use the Py_TYPE() macro when accessing ob_type in order to encapsulate this difference.

python/header-py.c
python/rpmds-py.c
python/rpmfd-py.c
python/rpmfi-py.c
python/rpmkeyring-py.c
python/rpmmi-py.c
python/rpmps-py.c
python/rpmtd-py.c
python/rpmts-py.c
python/spec-py.c

index e51ef0b..18a7e66 100644 (file)
@@ -395,7 +395,7 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
 static void hdr_dealloc(hdrObject * s)
 {
     if (s->h) headerFree(s->h);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static PyObject * hdr_iternext(hdrObject *s)
index 71ef93f..8938cc7 100644 (file)
@@ -199,7 +199,7 @@ rpmds_iternext(rpmdsObject * s)
        rpmTag tagN = rpmdsTagN(s->ds);
        rpmsenseFlags Flags = rpmdsFlags(s->ds);
 
-       result = rpmds_Wrap(s->ob_type, rpmdsSingle(tagN, N, EVR, Flags) );
+       result = rpmds_Wrap(Py_TYPE(s), rpmdsSingle(tagN, N, EVR, Flags) );
     } else
        s->active = 0;
 
@@ -381,7 +381,7 @@ static void
 rpmds_dealloc(rpmdsObject * s)
 {
     s->ds = rpmdsFree(s->ds);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static Py_ssize_t rpmds_length(rpmdsObject * s)
index 077cf9e..193d8e8 100644 (file)
@@ -107,7 +107,7 @@ static void rpmfd_dealloc(rpmfdObject *s)
 {
     PyObject *res = do_close(s);
     Py_XDECREF(res);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static PyObject *rpmfd_fileno(rpmfdObject *s)
index 5894ef4..5484a1b 100644 (file)
@@ -258,7 +258,7 @@ static void
 rpmfi_dealloc(rpmfiObject * s)
 {
     s->fi = rpmfiFree(s->fi);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static int
index 7b57fdb..00be981 100644 (file)
@@ -11,7 +11,7 @@ struct rpmPubkeyObject_s {
 static void rpmPubkey_dealloc(rpmPubkeyObject * s)
 {
     s->pubkey = rpmPubkeyFree(s->pubkey);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static PyObject *rpmPubkey_new(PyTypeObject *subtype, 
@@ -103,7 +103,7 @@ struct rpmKeyringObject_s {
 static void rpmKeyring_dealloc(rpmKeyringObject * s)
 {
     rpmKeyringFree(s->keyring);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static PyObject *rpmKeyring_new(PyTypeObject *subtype, 
index b3cd6d2..0a87153 100644 (file)
@@ -129,7 +129,7 @@ static void rpmmi_dealloc(rpmmiObject * s)
 {
     s->mi = rpmdbFreeIterator(s->mi);
     Py_DECREF(s->ref);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static Py_ssize_t rpmmi_length(rpmmiObject * s)
index dae50e6..1b08e2f 100644 (file)
@@ -175,7 +175,7 @@ static void
 rpmps_dealloc(rpmpsObject * s)
 {
     s->ps = rpmpsFree(s->ps);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static int
index 1911e25..aae4b27 100644 (file)
@@ -117,7 +117,7 @@ static PyObject *rpmtd_new(PyTypeObject * subtype, PyObject *args, PyObject *kwd
 static void rpmtd_dealloc(rpmtdObject * s)
 {
     rpmtdFreeData(&(s->td));
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static int rpmtd_length(rpmtdObject *s)
index e228736..df0f590 100644 (file)
@@ -677,7 +677,7 @@ static void rpmts_dealloc(rpmtsObject * s)
 
     s->ts = rpmtsFree(s->ts);
     Py_XDECREF(s->scriptFd);
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 static PyObject * rpmts_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
index 409db0d..fb362f7 100644 (file)
@@ -40,7 +40,7 @@ spec_dealloc(specObject * s)
     if (s->spec) {
        s->spec=freeSpec(s->spec);
     }
-    s->ob_type->tp_free((PyObject *)s);
+    Py_TYPE(s)->tp_free((PyObject *)s);
 }
 
 /* XXX TODO return something sensible if spec exists but component (eg %clean)