Skip to content

Commit e582929

Browse files
committed
Fixed both Python 2.5 and 64 bit problems.
1 parent fadd1a6 commit e582929

37 files changed

+887
-753
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2007-04-10 Federico Di Gregorio <fog@initd.org>
2+
3+
* Applied super-patch from David Rushby to fix Python 2.5 and 64
4+
bit problems (all of them, kudos!)
5+
16
2007-02-22 Federico Di Gregorio <fog@initd.org>
27

38
* Added support for per-connection and per-cursor typecasters.

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ recursive-include psycopg2da *
66
recursive-include examples *.py somehackers.jpg whereareyou.jpg
77
recursive-include debian *
88
recursive-include doc TODO HACKING SUCCESS ChangeLog-1.x async.txt
9+
recursive-include doc *.rst *.css *.html
910
recursive-include scripts *.py *.sh
1011
include scripts/maketypes.sh scripts/buildtypes.py
1112
include AUTHORS README INSTALL LICENSE ChangeLog
1213
include PKG-INFO MANIFEST.in MANIFEST setup.py setup.cfg
13-
recursive-include doc *.rst *.css *.html

psycopg/adapter_asis.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2020
*/
2121

22+
#define PY_SSIZE_T_CLEAN
2223
#include <Python.h>
2324
#include <structmember.h>
2425
#include <stringobject.h>
@@ -55,14 +56,14 @@ PyObject *
5556
asis_conform(asisObject *self, PyObject *args)
5657
{
5758
PyObject *res, *proto;
58-
59+
5960
if (!PyArg_ParseTuple(args, "O", &proto)) return NULL;
6061

6162
if (proto == (PyObject*)&isqlquoteType)
6263
res = (PyObject*)self;
6364
else
6465
res = Py_None;
65-
66+
6667
Py_INCREF(res);
6768
return res;
6869
}
@@ -90,14 +91,18 @@ static PyMethodDef asisObject_methods[] = {
9091
static int
9192
asis_setup(asisObject *self, PyObject *obj)
9293
{
93-
Dprintf("asis_setup: init asis object at %p, refcnt = %d",
94-
self, ((PyObject *)self)->ob_refcnt);
94+
Dprintf("asis_setup: init asis object at %p, refcnt = "
95+
FORMAT_CODE_PY_SSIZE_T,
96+
self, ((PyObject *)self)->ob_refcnt
97+
);
9598

9699
self->wrapped = obj;
97100
Py_INCREF(self->wrapped);
98-
99-
Dprintf("asis_setup: good asis object at %p, refcnt = %d",
100-
self, ((PyObject *)self)->ob_refcnt);
101+
102+
Dprintf("asis_setup: good asis object at %p, refcnt = "
103+
FORMAT_CODE_PY_SSIZE_T,
104+
self, ((PyObject *)self)->ob_refcnt
105+
);
101106
return 0;
102107
}
103108

@@ -107,18 +112,20 @@ asis_dealloc(PyObject* obj)
107112
asisObject *self = (asisObject *)obj;
108113

109114
Py_XDECREF(self->wrapped);
110-
111-
Dprintf("asis_dealloc: deleted asis object at %p, refcnt = %d",
112-
obj, obj->ob_refcnt);
113-
115+
116+
Dprintf("asis_dealloc: deleted asis object at %p, refcnt = "
117+
FORMAT_CODE_PY_SSIZE_T,
118+
obj, obj->ob_refcnt
119+
);
120+
114121
obj->ob_type->tp_free(obj);
115122
}
116123

117124
static int
118125
asis_init(PyObject *obj, PyObject *args, PyObject *kwds)
119126
{
120127
PyObject *o;
121-
128+
122129
if (!PyArg_ParseTuple(args, "O", &o))
123130
return -1;
124131

@@ -127,7 +134,7 @@ asis_init(PyObject *obj, PyObject *args, PyObject *kwds)
127134

128135
static PyObject *
129136
asis_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
130-
{
137+
{
131138
return type->tp_alloc(type, 0);
132139
}
133140

@@ -159,7 +166,7 @@ PyTypeObject asisType = {
159166
0, /*tp_print*/
160167

161168
0, /*tp_getattr*/
162-
0, /*tp_setattr*/
169+
0, /*tp_setattr*/
163170

164171
0, /*tp_compare*/
165172

@@ -171,14 +178,14 @@ PyTypeObject asisType = {
171178

172179
0, /*tp_call*/
173180
(reprfunc)asis_str, /*tp_str*/
174-
181+
175182
0, /*tp_getattro*/
176183
0, /*tp_setattro*/
177184
0, /*tp_as_buffer*/
178185

179186
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
180187
asisType_doc, /*tp_doc*/
181-
188+
182189
0, /*tp_traverse*/
183190
0, /*tp_clear*/
184191

@@ -195,11 +202,11 @@ PyTypeObject asisType = {
195202
0, /*tp_getset*/
196203
0, /*tp_base*/
197204
0, /*tp_dict*/
198-
205+
199206
0, /*tp_descr_get*/
200207
0, /*tp_descr_set*/
201208
0, /*tp_dictoffset*/
202-
209+
203210
asis_init, /*tp_init*/
204211
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
205212
asis_new, /*tp_new*/
@@ -219,9 +226,9 @@ PyObject *
219226
psyco_AsIs(PyObject *module, PyObject *args)
220227
{
221228
PyObject *obj;
222-
229+
223230
if (!PyArg_ParseTuple(args, "O", &obj))
224231
return NULL;
225-
232+
226233
return PyObject_CallFunction((PyObject *)&asisType, "O", obj);
227234
}

psycopg/adapter_asis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#ifndef PSYCOPG_ASIS_H
2323
#define PSYCOPG_ASIS_H 1
2424

25+
#define PY_SSIZE_T_CLEAN
2526
#include <Python.h>
2627

2728
#ifdef __cplusplus
@@ -39,7 +40,7 @@ typedef struct {
3940
} asisObject;
4041

4142
/* functions exported to psycopgmodule.c */
42-
43+
4344
extern PyObject *psyco_AsIs(PyObject *module, PyObject *args);
4445
#define psyco_AsIs_doc \
4546
"AsIs(obj) -> new AsIs wrapper object"

psycopg/adapter_binary.c

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2020
*/
2121

22+
#define PY_SSIZE_T_CLEAN
2223
#include <Python.h>
2324
#include <structmember.h>
2425
#include <stringobject.h>
@@ -38,8 +39,8 @@
3839

3940
#ifndef PSYCOPG_OWN_QUOTING
4041
static unsigned char *
41-
binary_escape(unsigned char *from, unsigned int from_length,
42-
unsigned int *to_length, PGconn *conn)
42+
binary_escape(unsigned char *from, size_t from_length,
43+
size_t *to_length, PGconn *conn)
4344
{
4445
#if PG_MAJOR_VERSION > 8 || \
4546
(PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION > 1) || \
@@ -52,11 +53,11 @@ binary_escape(unsigned char *from, unsigned int from_length,
5253
}
5354
#else
5455
static unsigned char *
55-
binary_escape(unsigned char *from, unsigned int from_length,
56-
unsigned int *to_length, PGconn *conn)
56+
binary_escape(unsigned char *from, size_t from_length,
57+
size_t *to_length, PGconn *conn)
5758
{
58-
unsigneed char *quoted, *chptr, *newptr;
59-
int i, space, new_space;
59+
unsigned char *quoted, *chptr, *newptr;
60+
size_t i, space, new_space;
6061

6162
space = from_length + 2;
6263

@@ -67,7 +68,7 @@ binary_escape(unsigned char *from, unsigned int from_length,
6768

6869
chptr = quoted;
6970

70-
for (i=0; i < len; i++) {
71+
for (i = 0; i < from_length; i++) {
7172
if (chptr - quoted > space - 6) {
7273
new_space = space * ((space) / (i + 1)) + 2 + 6;
7374
if (new_space - space < 1024) space += 1024;
@@ -102,7 +103,7 @@ binary_escape(unsigned char *from, unsigned int from_length,
102103
}
103104
else {
104105
unsigned char c;
105-
106+
106107
/* escape to octal notation \nnn */
107108
*chptr++ = '\\';
108109
*chptr++ = '\\';
@@ -122,7 +123,7 @@ binary_escape(unsigned char *from, unsigned int from_length,
122123

123124
Py_END_ALLOW_THREADS;
124125

125-
*to_size = chptr - quoted + 1;
126+
*to_length = chptr - quoted + 1;
126127
return quoted;
127128
}
128129
#endif
@@ -142,26 +143,26 @@ binary_quote(binaryObject *self)
142143
/* escape and build quoted buffer */
143144
PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len);
144145

145-
to = (char *)binary_escape((unsigned char*)buffer, buffer_len, &len,
146-
self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
146+
to = (char *)binary_escape((unsigned char*)buffer, (size_t) buffer_len,
147+
&len, self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
147148
if (to == NULL) {
148149
PyErr_NoMemory();
149150
return NULL;
150151
}
151152

152-
if (len > 0)
153-
self->buffer = PyString_FromFormat("'%s'", to);
154-
else
155-
self->buffer = PyString_FromString("''");
153+
if (len > 0)
154+
self->buffer = PyString_FromFormat("'%s'", to);
155+
else
156+
self->buffer = PyString_FromString("''");
156157
PQfreemem(to);
157158
}
158-
159-
/* if the wrapped object is not a string or a buffer, this is an error */
159+
160+
/* if the wrapped object is not a string or a buffer, this is an error */
160161
else {
161162
PyErr_SetString(PyExc_TypeError, "can't escape non-string object");
162163
return NULL;
163164
}
164-
165+
165166
return self->buffer;
166167
}
167168

@@ -206,14 +207,14 @@ PyObject *
206207
binary_conform(binaryObject *self, PyObject *args)
207208
{
208209
PyObject *res, *proto;
209-
210+
210211
if (!PyArg_ParseTuple(args, "O", &proto)) return NULL;
211212

212213
if (proto == (PyObject*)&isqlquoteType)
213214
res = (PyObject*)self;
214215
else
215216
res = Py_None;
216-
217+
217218
Py_INCREF(res);
218219
return res;
219220
}
@@ -244,16 +245,19 @@ static PyMethodDef binaryObject_methods[] = {
244245
static int
245246
binary_setup(binaryObject *self, PyObject *str)
246247
{
247-
Dprintf("binary_setup: init binary object at %p, refcnt = %d",
248-
self, ((PyObject *)self)->ob_refcnt);
248+
Dprintf("binary_setup: init binary object at %p, refcnt = "
249+
FORMAT_CODE_PY_SSIZE_T,
250+
self, ((PyObject *)self)->ob_refcnt
251+
);
249252

250253
self->buffer = NULL;
251254
self->conn = NULL;
252255
self->wrapped = str;
253256
Py_INCREF(self->wrapped);
254-
255-
Dprintf("binary_setup: good binary object at %p, refcnt = %d",
256-
self, ((PyObject *)self)->ob_refcnt);
257+
258+
Dprintf("binary_setup: good binary object at %p, refcnt = "
259+
FORMAT_CODE_PY_SSIZE_T,
260+
self, ((PyObject *)self)->ob_refcnt);
257261
return 0;
258262
}
259263

@@ -265,18 +269,20 @@ binary_dealloc(PyObject* obj)
265269
Py_XDECREF(self->wrapped);
266270
Py_XDECREF(self->buffer);
267271
Py_XDECREF(self->conn);
268-
269-
Dprintf("binary_dealloc: deleted binary object at %p, refcnt = %d",
270-
obj, obj->ob_refcnt);
271-
272+
273+
Dprintf("binary_dealloc: deleted binary object at %p, refcnt = "
274+
FORMAT_CODE_PY_SSIZE_T,
275+
obj, obj->ob_refcnt
276+
);
277+
272278
obj->ob_type->tp_free(obj);
273279
}
274280

275281
static int
276282
binary_init(PyObject *obj, PyObject *args, PyObject *kwds)
277283
{
278284
PyObject *str;
279-
285+
280286
if (!PyArg_ParseTuple(args, "O", &str))
281287
return -1;
282288

@@ -285,7 +291,7 @@ binary_init(PyObject *obj, PyObject *args, PyObject *kwds)
285291

286292
static PyObject *
287293
binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
288-
{
294+
{
289295
return type->tp_alloc(type, 0);
290296
}
291297

@@ -315,7 +321,7 @@ PyTypeObject binaryType = {
315321
binary_dealloc, /*tp_dealloc*/
316322
0, /*tp_print*/
317323
0, /*tp_getattr*/
318-
0, /*tp_setattr*/
324+
0, /*tp_setattr*/
319325

320326
0, /*tp_compare*/
321327
(reprfunc)binary_repr, /*tp_repr*/
@@ -333,7 +339,7 @@ PyTypeObject binaryType = {
333339
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
334340

335341
binaryType_doc, /*tp_doc*/
336-
342+
337343
0, /*tp_traverse*/
338344
0, /*tp_clear*/
339345

@@ -350,11 +356,11 @@ PyTypeObject binaryType = {
350356
0, /*tp_getset*/
351357
0, /*tp_base*/
352358
0, /*tp_dict*/
353-
359+
354360
0, /*tp_descr_get*/
355361
0, /*tp_descr_set*/
356362
0, /*tp_dictoffset*/
357-
363+
358364
binary_init, /*tp_init*/
359365
0, /*tp_alloc will be set to PyType_GenericAlloc in module init*/
360366
binary_new, /*tp_new*/
@@ -374,9 +380,9 @@ PyObject *
374380
psyco_Binary(PyObject *module, PyObject *args)
375381
{
376382
PyObject *str;
377-
383+
378384
if (!PyArg_ParseTuple(args, "O", &str))
379385
return NULL;
380-
386+
381387
return PyObject_CallFunction((PyObject *)&binaryType, "O", str);
382388
}

0 commit comments

Comments
 (0)