This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
Re: [patch] Python 2.4 compatibility.
- From: "Paul Pluzhnikov" <ppluzhnikov at google dot com>
- To: "Tom Tromey" <tromey at redhat dot com>
- Cc: archer at sourceware dot org
- Date: Mon, 13 Oct 2008 13:30:35 -0700
- Subject: Re: [patch] Python 2.4 compatibility.
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta;t=1223929837; bh=j7W6BPJZApp92hZo+MU3HT/sLWk=;h=DomainKey-Signature:Message-ID:Date:From:To:Subject:Cc: In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-Disposition:References; b=ocC1pB+JrDrlo4U0EYGnRQBKIIGPrM0dkI2Ai8/8mQIez7gn2bxPqDsZbGCdB85GdoeHvk1fKdV5LYlUz6RX2Q==
- Domainkey-signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns;h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references;b=WzBCrl4nMNpolB6XYq0U59Z+FQZ3zb5jcah25F9Y6vdpKodHuixG6hV255vOw0lvmhIgsW0xrt9KhBacXNqlTg==
- References: <20081013181729.103A63A6AF3@localhost> <m3tzbgmje5.fsf@fleche.redhat.com>
On Mon, Oct 13, 2008 at 11:37 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Paul" == Paul Pluzhnikov <ppluzhnikov@google.com> writes:
>
> Paul> Current git source fails to build with python 2.4.
> Paul> Attached patch fixes that, but I am not sure that's the best (or
> Paul> even correct) fix.
>
> Is the problem that Py_ssize_t is not defined?
I see in python-internal.h that Py_ssize_t is already defined for
HAVE_LIBPYTHON2_4, but that's not good enough: PyMappingMethods
uses the "wrong" type:
include/python2.4/object.h
typedef int (*inquiry)(PyObject *);
^^^
typedef struct {
inquiry mp_length;
binaryfunc mp_subscript;
objobjargproc mp_ass_subscript;
} PyMappingMethods;
> Paul> +#if PYTHON_API_VERSION <= 1012
> Paul> + int iter;
> Paul> +#else
> Paul> Py_ssize_t iter;
> Paul> +#endif
>
> Also if not, I suppose this code should just use the length size.
> The fewer conditionals, the better.
In this case, PyDict_Next() is the problem:
include/python2.4/dictobject.h
PyAPI_FUNC(int) PyDict_Next(
PyObject *mp, int *pos, PyObject **key, PyObject **value);
^^^
I am not sure there is a good way to fix this, because we are
working around broken API :(
typedef int gdbpy_int_which_should_have_been_ssize_type; // ???
Ok, how about this (not really sure this is any better :(
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 5896907..ffca87d 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -43,6 +43,14 @@ typedef Py_intptr_t Py_ssize_t;
#error "Unable to find usable Python.h"
#endif
+#if HAVE_LIBPYTHON2_4
+typedef int PyDict_Next_position_type;
+typedef int PyObject_Inquiry_return_type;
+#else
+typedef Py_ssize_t PyDict_Next_position_type;
+typedef Py_ssize_t PyObject_Inquiry_return_type;
+#endif
+
#include "command.h"
struct block;
Perhaps the better solution is to require python >= 2.5 ?
--
Paul Pluzhnikov