[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#622152: [britney2] Port to python2.6 (s/PyFoo_Check/PyFoo_CheckExact/)



Package: release.debian.org
Severity: normal
Tags: patch
User: release.debian.org@packages.debian.org
Usertags: britney

Hi.

It seems that britney2 segfaults at every run when compiled for Python
2.6. After some quick investigation, the problem boils down to the
following:

Britney2 uses PyFoo_Check to check that some structure has the correct
type. That class of functions changed between Python 2.5 and 2.6. The
(relevant part of the) diff is as follows:

In Include/dictobject.h:

-#define PyDict_Check(op) PyObject_TypeCheck(op, &PyDict_Type)
+#define PyDict_Check(op) \
+                 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)
-#define PyDict_CheckExact(op) ((op)->ob_type == &PyDict_Type)
+#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)

In Include/object.h

 #define PyObject_TypeCheck(ob, tp) \
-       ((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))
+    (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))

 #define PyType_HasFeature(t,f)  (((t)->tp_flags & (f)) != 0)
+#define PyType_FastSubclass(t,f)  PyType_HasFeature(t,f)

I (personally) don't care much about (how) python (does it) (tbh)
because in our case, we know that those structures have exactly the
type we are testing against. So, we can use PyFoo_CheckExact variants
instead (btw, that was winning test even with Python 2.5).

Attached is a simple patch that performs the described substitution.
Using this patch, I've been able to run britney2 on my machines
wihtout seeing any problem.

Regards,

-- System Information:
Debian Release: 6.0
  APT prefers stable
  APT policy: (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
>From e022f5f39203486c875e06ed47c73fbaf9f5aeeb Mon Sep 17 00:00:00 2001
From: Mehdi Dogguy <mehdi@debian.org>
Date: Fri, 11 Mar 2011 18:37:00 +0100
Subject: [PATCH 1/2] Use Py{Dict,List}_CheckExact instead of Py{Dict,List}_Check

---
 lib/britney-py.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/britney-py.c b/lib/britney-py.c
index 69de370..8037e32 100644
--- a/lib/britney-py.c
+++ b/lib/britney-py.c
@@ -1,4 +1,4 @@
-#include <python2.5/Python.h>
+#include <python2.6/Python.h>
 
 #include "dpkg.h"
 
@@ -269,7 +269,7 @@ static PyObject *dpkgpackages_add_binary(dpkgpackages *self, PyObject *args) {
 	(void)self; /* unused */
 
     if (!PyArg_ParseTuple(args, "sO", &pkg_name, &value) ||
-        !PyList_Check(value)) return NULL;
+        !PyList_CheckExact(value)) return NULL;
 
     /* initialize the new package */
     dpkg_package *pkg;
@@ -950,7 +950,7 @@ static PyObject *build_system(PyObject *self, PyObject *args) {
 	(void)self; /* unused */
 
     if (!PyArg_ParseTuple(args, "sO", &arch, &pkgs) ||
-        !PyDict_Check(pkgs)) return NULL;
+        !PyDict_CheckExact(pkgs)) return NULL;
 
     /* Fields and positions for the binary package:
        # VERSION = 0
-- 
1.7.2.5


Reply to: