Rev 4737: Py_ssize_t and its associated function typedefs are not available w/ python 2.4 in lp:///~jameinel/bzr/2.1-static-tuple-py2.4-compat
John Arbash Meinel
john at arbash-meinel.com
Mon Oct 12 22:45:19 BST 2009
At lp:///~jameinel/bzr/2.1-static-tuple-py2.4-compat
------------------------------------------------------------
revno: 4737
revision-id: john at arbash-meinel.com-20091012214427-zddi1kmc2jlf7v31
parent: pqm at pqm.ubuntu.com-20091012195159-n0de3utv1q92agvg
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-static-tuple-py2.4-compat
timestamp: Mon 2009-10-12 16:44:27 -0500
message:
Py_ssize_t and its associated function typedefs are not available w/ python 2.4
So we define them in python-compat.h
Even further, gcc issued a warning for:
static int
_workaround_pyrex_096()
So we changed it to:
_workaround_pyrex_096(void)
Also, some python api funcs were incorrectly defined as 'char *' when they meant
'const char *'. Work around that with a (char *) cast, to avoid compiler warnings.
-------------- next part --------------
=== modified file 'bzrlib/_export_c_api.h'
--- a/bzrlib/_export_c_api.h 2009-10-02 02:21:12 +0000
+++ b/bzrlib/_export_c_api.h 2009-10-12 21:44:27 +0000
@@ -45,14 +45,17 @@
PyObject *d = NULL;
PyObject *c_obj = NULL;
- d = PyObject_GetAttrString(module, _C_API_NAME);
+ /* (char *) is because python2.4 declares this api as 'char *' rather than
+ * const char* which it really is.
+ */
+ d = PyObject_GetAttrString(module, (char *)_C_API_NAME);
if (!d) {
PyErr_Clear();
d = PyDict_New();
if (!d)
goto bad;
Py_INCREF(d);
- if (PyModule_AddObject(module, _C_API_NAME, d) < 0)
+ if (PyModule_AddObject(module, (char *)_C_API_NAME, d) < 0)
goto bad;
}
c_obj = PyCObject_FromVoidPtrAndDesc(func, signature, 0);
=== modified file 'bzrlib/_import_c_api.h'
--- a/bzrlib/_import_c_api.h 2009-10-01 21:34:36 +0000
+++ b/bzrlib/_import_c_api.h 2009-10-12 21:44:27 +0000
@@ -47,7 +47,10 @@
PyObject *c_obj = NULL;
const char *desc = NULL;
- d = PyObject_GetAttrString(module, _C_API_NAME);
+ /* (char *) because Python2.4 defines this as (char *) rather than
+ * (const char *)
+ */
+ d = PyObject_GetAttrString(module, (char *)_C_API_NAME);
if (!d) {
// PyObject_GetAttrString sets an appropriate exception
goto bad;
@@ -94,7 +97,7 @@
{
PyObject *type = NULL;
- type = PyObject_GetAttrString(module, class_name);
+ type = PyObject_GetAttrString(module, (char *)class_name);
if (!type) {
goto bad;
}
@@ -149,7 +152,7 @@
struct type_description *cur_type;
int ret_code;
- module = PyImport_ImportModule(module_name);
+ module = PyImport_ImportModule((char *)module_name);
if (!module)
goto bad;
if (functions != NULL) {
=== modified file 'bzrlib/_static_tuple_c.c'
--- a/bzrlib/_static_tuple_c.c 2009-10-12 19:05:34 +0000
+++ b/bzrlib/_static_tuple_c.c 2009-10-12 21:44:27 +0000
@@ -20,6 +20,9 @@
*/
#define STATIC_TUPLE_MODULE
+#include <Python.h>
+#include "python-compat.h"
+
#include "_static_tuple_c.h"
#include "_export_c_api.h"
@@ -31,8 +34,6 @@
#define import__simple_set_pyx import_bzrlib___simple_set_pyx
#include "_simple_set_pyx_api.h"
-#include "python-compat.h"
-
#if defined(__GNUC__)
# define inline __inline__
#elif defined(_MSC_VER)
@@ -689,7 +690,7 @@
static int
-_workaround_pyrex_096()
+_workaround_pyrex_096(void)
{
/* Work around an incompatibility in how pyrex 0.9.6 exports a module,
* versus how pyrex 0.9.8 and cython 0.11 export it.
=== modified file 'bzrlib/python-compat.h'
--- a/bzrlib/python-compat.h 2009-10-12 18:59:22 +0000
+++ b/bzrlib/python-compat.h 2009-10-12 21:44:27 +0000
@@ -28,6 +28,9 @@
/* http://www.python.org/dev/peps/pep-0353/ */
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
typedef int Py_ssize_t;
+ typedef Py_ssize_t (*lenfunc)(PyObject *);
+ typedef PyObject * (*ssizeargfunc)(PyObject *, Py_ssize_t);
+ typedef PyObject * (*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#define PyInt_FromSsize_t(z) PyInt_FromLong(z)
More information about the bazaar-commits
mailing list