--- Begin Message ---
- To: Debian Bug Tracking System <submit@bugs.debian.org>
- Subject: [britney2] Port to python2.6 (s/PyFoo_Check/PyFoo_CheckExact/)
- From: Mehdi Dogguy <mehdi@debian.org>
- Date: Sun, 10 Apr 2011 15:36:17 +0200
- Message-id: <20110410133617.4966.82770.reportbug@einsteinium>
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
--- End Message ---
--- Begin Message ---
On Mon, 2011-11-21 at 19:20 +0000, Adam D. Barratt wrote:
> On Sun, 2011-11-20 at 12:51 +0100, Mehdi Dogguy wrote:
> > On 11/20/2011 12:17 AM, Adam D. Barratt wrote:
> > > On Thu, 2011-11-17 at 20:54 +0000, Adam D. Barratt wrote:
> > >> I've finally (!) got to looking at this but have been unable to
> > >> reproduce the problem.  It might be a squeeze versus wheezy issue or
> > >> some oddity which has resolved itself in the meantime, but after
> > >> s/python2.5/python2.6/ in britney-py.c and rebuilding the library on
> > >> franck, everything seems to just work[tm].
> [...]
> > maybe we should close the bug then? (it could be a temporary problem that
> > got fixed somewhere since then…)
> 
> I was planning on running a py2.6 britney live for a couple of days and
> seeing what happened first; what's the worst that could happen? :)
Well, it seems to have worked okay so far, so yeah let's close this.
Regards,
Adam
--- End Message ---