Fixed both Python 2.5 and 64 bit problems.

This commit is contained in:
Federico Di Gregorio 2007-04-10 06:36:18 +00:00
parent fadd1a6938
commit e5829292cd
37 changed files with 887 additions and 753 deletions

View File

@ -1,3 +1,8 @@
2007-04-10 Federico Di Gregorio <fog@initd.org>
* Applied super-patch from David Rushby to fix Python 2.5 and 64
bit problems (all of them, kudos!)
2007-02-22 Federico Di Gregorio <fog@initd.org> 2007-02-22 Federico Di Gregorio <fog@initd.org>
* Added support for per-connection and per-cursor typecasters. * Added support for per-connection and per-cursor typecasters.

View File

@ -6,8 +6,8 @@ recursive-include psycopg2da *
recursive-include examples *.py somehackers.jpg whereareyou.jpg recursive-include examples *.py somehackers.jpg whereareyou.jpg
recursive-include debian * recursive-include debian *
recursive-include doc TODO HACKING SUCCESS ChangeLog-1.x async.txt recursive-include doc TODO HACKING SUCCESS ChangeLog-1.x async.txt
recursive-include doc *.rst *.css *.html
recursive-include scripts *.py *.sh recursive-include scripts *.py *.sh
include scripts/maketypes.sh scripts/buildtypes.py include scripts/maketypes.sh scripts/buildtypes.py
include AUTHORS README INSTALL LICENSE ChangeLog include AUTHORS README INSTALL LICENSE ChangeLog
include PKG-INFO MANIFEST.in MANIFEST setup.py setup.cfg include PKG-INFO MANIFEST.in MANIFEST setup.py setup.cfg
recursive-include doc *.rst *.css *.html

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>
@ -90,14 +91,18 @@ static PyMethodDef asisObject_methods[] = {
static int static int
asis_setup(asisObject *self, PyObject *obj) asis_setup(asisObject *self, PyObject *obj)
{ {
Dprintf("asis_setup: init asis object at %p, refcnt = %d", Dprintf("asis_setup: init asis object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
self->wrapped = obj; self->wrapped = obj;
Py_INCREF(self->wrapped); Py_INCREF(self->wrapped);
Dprintf("asis_setup: good asis object at %p, refcnt = %d", Dprintf("asis_setup: good asis object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
return 0; return 0;
} }
@ -108,8 +113,10 @@ asis_dealloc(PyObject* obj)
Py_XDECREF(self->wrapped); Py_XDECREF(self->wrapped);
Dprintf("asis_dealloc: deleted asis object at %p, refcnt = %d", Dprintf("asis_dealloc: deleted asis object at %p, refcnt = "
obj, obj->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_ASIS_H #ifndef PSYCOPG_ASIS_H
#define PSYCOPG_ASIS_H 1 #define PSYCOPG_ASIS_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>
@ -38,8 +39,8 @@
#ifndef PSYCOPG_OWN_QUOTING #ifndef PSYCOPG_OWN_QUOTING
static unsigned char * static unsigned char *
binary_escape(unsigned char *from, unsigned int from_length, binary_escape(unsigned char *from, size_t from_length,
unsigned int *to_length, PGconn *conn) size_t *to_length, PGconn *conn)
{ {
#if PG_MAJOR_VERSION > 8 || \ #if PG_MAJOR_VERSION > 8 || \
(PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION > 1) || \ (PG_MAJOR_VERSION == 8 && PG_MINOR_VERSION > 1) || \
@ -52,11 +53,11 @@ binary_escape(unsigned char *from, unsigned int from_length,
} }
#else #else
static unsigned char * static unsigned char *
binary_escape(unsigned char *from, unsigned int from_length, binary_escape(unsigned char *from, size_t from_length,
unsigned int *to_length, PGconn *conn) size_t *to_length, PGconn *conn)
{ {
unsigneed char *quoted, *chptr, *newptr; unsigned char *quoted, *chptr, *newptr;
int i, space, new_space; size_t i, space, new_space;
space = from_length + 2; space = from_length + 2;
@ -67,7 +68,7 @@ binary_escape(unsigned char *from, unsigned int from_length,
chptr = quoted; chptr = quoted;
for (i=0; i < len; i++) { for (i = 0; i < from_length; i++) {
if (chptr - quoted > space - 6) { if (chptr - quoted > space - 6) {
new_space = space * ((space) / (i + 1)) + 2 + 6; new_space = space * ((space) / (i + 1)) + 2 + 6;
if (new_space - space < 1024) space += 1024; if (new_space - space < 1024) space += 1024;
@ -122,7 +123,7 @@ binary_escape(unsigned char *from, unsigned int from_length,
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
*to_size = chptr - quoted + 1; *to_length = chptr - quoted + 1;
return quoted; return quoted;
} }
#endif #endif
@ -142,8 +143,8 @@ binary_quote(binaryObject *self)
/* escape and build quoted buffer */ /* escape and build quoted buffer */
PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len); PyObject_AsCharBuffer(self->wrapped, &buffer, &buffer_len);
to = (char *)binary_escape((unsigned char*)buffer, buffer_len, &len, to = (char *)binary_escape((unsigned char*)buffer, (size_t) buffer_len,
self->conn ? ((connectionObject*)self->conn)->pgconn : NULL); &len, self->conn ? ((connectionObject*)self->conn)->pgconn : NULL);
if (to == NULL) { if (to == NULL) {
PyErr_NoMemory(); PyErr_NoMemory();
return NULL; return NULL;
@ -244,15 +245,18 @@ static PyMethodDef binaryObject_methods[] = {
static int static int
binary_setup(binaryObject *self, PyObject *str) binary_setup(binaryObject *self, PyObject *str)
{ {
Dprintf("binary_setup: init binary object at %p, refcnt = %d", Dprintf("binary_setup: init binary object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
self->buffer = NULL; self->buffer = NULL;
self->conn = NULL; self->conn = NULL;
self->wrapped = str; self->wrapped = str;
Py_INCREF(self->wrapped); Py_INCREF(self->wrapped);
Dprintf("binary_setup: good binary object at %p, refcnt = %d", Dprintf("binary_setup: good binary object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt); self, ((PyObject *)self)->ob_refcnt);
return 0; return 0;
} }
@ -266,8 +270,10 @@ binary_dealloc(PyObject* obj)
Py_XDECREF(self->buffer); Py_XDECREF(self->buffer);
Py_XDECREF(self->conn); Py_XDECREF(self->conn);
Dprintf("binary_dealloc: deleted binary object at %p, refcnt = %d", Dprintf("binary_dealloc: deleted binary object at %p, refcnt = "
obj, obj->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_BINARY_H #ifndef PSYCOPG_BINARY_H
#define PSYCOPG_BINARY_H 1 #define PSYCOPG_BINARY_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <libpq-fe.h> #include <libpq-fe.h>

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>
@ -125,15 +126,19 @@ static PyMethodDef pydatetimeObject_methods[] = {
static int static int
pydatetime_setup(pydatetimeObject *self, PyObject *obj, int type) pydatetime_setup(pydatetimeObject *self, PyObject *obj, int type)
{ {
Dprintf("pydatetime_setup: init datetime object at %p, refcnt = %d", Dprintf("pydatetime_setup: init datetime object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
self->type = type; self->type = type;
self->wrapped = obj; self->wrapped = obj;
Py_INCREF(self->wrapped); Py_INCREF(self->wrapped);
Dprintf("pydatetime_setup: good pydatetime object at %p, refcnt = %d", Dprintf("pydatetime_setup: good pydatetime object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
return 0; return 0;
} }
@ -145,7 +150,7 @@ pydatetime_dealloc(PyObject* obj)
Py_XDECREF(self->wrapped); Py_XDECREF(self->wrapped);
Dprintf("mpydatetime_dealloc: deleted pydatetime object at %p, " Dprintf("mpydatetime_dealloc: deleted pydatetime object at %p, "
"refcnt = %d", obj, obj->ob_refcnt); "refcnt = " FORMAT_CODE_PY_SSIZE_T, obj, obj->ob_refcnt);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_DATETIME_H #ifndef PSYCOPG_DATETIME_H
#define PSYCOPG_DATETIME_H 1 #define PSYCOPG_DATETIME_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>
@ -156,8 +157,10 @@ static PyMethodDef listObject_methods[] = {
static int static int
list_setup(listObject *self, PyObject *obj, char *enc) list_setup(listObject *self, PyObject *obj, char *enc)
{ {
Dprintf("list_setup: init list object at %p, refcnt = %d", Dprintf("list_setup: init list object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
if (!PyList_Check(obj)) if (!PyList_Check(obj))
return -1; return -1;
@ -169,8 +172,10 @@ list_setup(listObject *self, PyObject *obj, char *enc)
self->wrapped = obj; self->wrapped = obj;
Py_INCREF(self->wrapped); Py_INCREF(self->wrapped);
Dprintf("list_setup: good list object at %p, refcnt = %d", Dprintf("list_setup: good list object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
return 0; return 0;
} }
@ -184,7 +189,7 @@ list_dealloc(PyObject* obj)
if (self->encoding) free(self->encoding); if (self->encoding) free(self->encoding);
Dprintf("list_dealloc: deleted list object at %p, " Dprintf("list_dealloc: deleted list object at %p, "
"refcnt = %d", obj, obj->ob_refcnt); "refcnt = " FORMAT_CODE_PY_SSIZE_T, obj, obj->ob_refcnt);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_LIST_H #ifndef PSYCOPG_LIST_H
#define PSYCOPG_LIST_H 1 #define PSYCOPG_LIST_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>
@ -146,15 +147,19 @@ static PyMethodDef mxdatetimeObject_methods[] = {
static int static int
mxdatetime_setup(mxdatetimeObject *self, PyObject *obj, int type) mxdatetime_setup(mxdatetimeObject *self, PyObject *obj, int type)
{ {
Dprintf("mxdatetime_setup: init mxdatetime object at %p, refcnt = %d", Dprintf("mxdatetime_setup: init mxdatetime object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
self->type = type; self->type = type;
self->wrapped = obj; self->wrapped = obj;
Py_INCREF(self->wrapped); Py_INCREF(self->wrapped);
Dprintf("mxdatetime_setup: good mxdatetime object at %p, refcnt = %d", Dprintf("mxdatetime_setup: good mxdatetime object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
return 0; return 0;
} }
@ -165,8 +170,10 @@ mxdatetime_dealloc(PyObject* obj)
Py_XDECREF(self->wrapped); Py_XDECREF(self->wrapped);
Dprintf("mxdatetime_dealloc: deleted mxdatetime object at %p, refcnt = %d", Dprintf("mxdatetime_dealloc: deleted mxdatetime object at %p, refcnt = "
obj, obj->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_MXDATETIME_H #ifndef PSYCOPG_MXDATETIME_H
#define PSYCOPG_MXDATETIME_H 1 #define PSYCOPG_MXDATETIME_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>
@ -100,14 +101,18 @@ static PyMethodDef pbooleanObject_methods[] = {
static int static int
pboolean_setup(pbooleanObject *self, PyObject *obj) pboolean_setup(pbooleanObject *self, PyObject *obj)
{ {
Dprintf("pboolean_setup: init pboolean object at %p, refcnt = %d", Dprintf("pboolean_setup: init pboolean object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
self->wrapped = obj; self->wrapped = obj;
Py_INCREF(self->wrapped); Py_INCREF(self->wrapped);
Dprintf("pboolean_setup: good pboolean object at %p, refcnt = %d", Dprintf("pboolean_setup: good pboolean object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
return 0; return 0;
} }
@ -118,8 +123,10 @@ pboolean_dealloc(PyObject* obj)
Py_XDECREF(self->wrapped); Py_XDECREF(self->wrapped);
Dprintf("pboolean_dealloc: deleted pboolean object at %p, refcnt = %d", Dprintf("pboolean_dealloc: deleted pboolean object at %p, refcnt = "
obj, obj->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_PBOOLEAN_H #ifndef PSYCOPG_PBOOLEAN_H
#define PSYCOPG_PBOOLEAN_H 1 #define PSYCOPG_PBOOLEAN_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>
@ -248,8 +249,10 @@ static PyMethodDef qstringObject_methods[] = {
static int static int
qstring_setup(qstringObject *self, PyObject *str, char *enc) qstring_setup(qstringObject *self, PyObject *str, char *enc)
{ {
Dprintf("qstring_setup: init qstring object at %p, refcnt = %d", Dprintf("qstring_setup: init qstring object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
self->buffer = NULL; self->buffer = NULL;
self->conn = NULL; self->conn = NULL;
@ -260,8 +263,10 @@ qstring_setup(qstringObject *self, PyObject *str, char *enc)
self->wrapped = str; self->wrapped = str;
Py_INCREF(self->wrapped); Py_INCREF(self->wrapped);
Dprintf("qstring_setup: good qstring object at %p, refcnt = %d", Dprintf("qstring_setup: good qstring object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
return 0; return 0;
} }
@ -276,8 +281,10 @@ qstring_dealloc(PyObject* obj)
if (self->encoding) free(self->encoding); if (self->encoding) free(self->encoding);
Dprintf("qstring_dealloc: deleted qstring object at %p, refcnt = %d", Dprintf("qstring_dealloc: deleted qstring object at %p, refcnt = "
obj, obj->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_QSTRING_H #ifndef PSYCOPG_QSTRING_H
#define PSYCOPG_QSTRING_H 1 #define PSYCOPG_QSTRING_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -28,7 +28,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#define Dprintf(fmt, args...) \ #define Dprintf(fmt, args...) \
fprintf(stderr, "[%d] " fmt "\n", getpid() , ## args) fprintf(stderr, "[%d] " fmt "\n", (int) getpid() , ## args)
#else #else
#define Dprintf(fmt, args...) #define Dprintf(fmt, args...)
#endif #endif

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_CONNECTION_H #ifndef PSYCOPG_CONNECTION_H
#define PSYCOPG_CONNECTION_H 1 #define PSYCOPG_CONNECTION_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <libpq-fe.h> #include <libpq-fe.h>

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <string.h> #include <string.h>

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>
@ -77,8 +78,10 @@ psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds)
return NULL; return NULL;
} }
Dprintf("psyco_conn_cursor: new cursor at %p: refcnt = %d", Dprintf("psyco_conn_cursor: new cursor at %p: refcnt = "
obj, obj->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
return obj; return obj;
} }
@ -274,7 +277,7 @@ static struct PyMemberDef connectionObject_members[] = {
{"notifies", T_OBJECT, offsetof(connectionObject, notifies), RO}, {"notifies", T_OBJECT, offsetof(connectionObject, notifies), RO},
{"dsn", T_STRING, offsetof(connectionObject, dsn), RO, {"dsn", T_STRING, offsetof(connectionObject, dsn), RO,
"The current connection string."}, "The current connection string."},
{"status", T_LONG, {"status", T_INT,
offsetof(connectionObject, status), RO, offsetof(connectionObject, status), RO,
"The current transaction status."}, "The current transaction status."},
{"string_types", T_OBJECT, offsetof(connectionObject, string_types), RO, {"string_types", T_OBJECT, offsetof(connectionObject, string_types), RO,
@ -293,8 +296,10 @@ connection_setup(connectionObject *self, char *dsn)
char *pos; char *pos;
int res; int res;
Dprintf("connection_setup: init connection object at %p, refcnt = %d", Dprintf("connection_setup: init connection object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
self->dsn = strdup(dsn); self->dsn = strdup(dsn);
self->notice_list = PyList_New(0); self->notice_list = PyList_New(0);
@ -315,8 +320,10 @@ connection_setup(connectionObject *self, char *dsn)
res = -1; res = -1;
} }
else { else {
Dprintf("connection_setup: good connection object at %p, refcnt = %d", Dprintf("connection_setup: good connection object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
res = 0; res = 0;
} }
@ -349,8 +356,10 @@ connection_dealloc(PyObject* obj)
pthread_mutex_destroy(&(self->lock)); pthread_mutex_destroy(&(self->lock));
Dprintf("connection_dealloc: deleted connection object at %p, refcnt = %d", Dprintf("connection_dealloc: deleted connection object at %p, refcnt = "
obj, obj->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_CURSOR_H #ifndef PSYCOPG_CURSOR_H
#define PSYCOPG_CURSOR_H 1 #define PSYCOPG_CURSOR_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <libpq-fe.h> #include <libpq-fe.h>
@ -60,7 +61,7 @@ typedef struct {
PyObject *caster; /* the current typecaster object */ PyObject *caster; /* the current typecaster object */
PyObject *copyfile; /* file-like used during COPY TO/FROM ops */ PyObject *copyfile; /* file-like used during COPY TO/FROM ops */
long int copysize; /* size of the copy buffer during COPY TO/FROM ops */ Py_ssize_t copysize; /* size of the copy buffer during COPY TO/FROM ops */
#define DEFAULT_COPYSIZE 16384 #define DEFAULT_COPYSIZE 16384
PyObject *tuple_factory; /* factory for result tuples */ PyObject *tuple_factory; /* factory for result tuples */

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <string.h> #include <string.h>

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <string.h> #include <string.h>
@ -116,7 +117,8 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new)
return -1; return -1;
} }
Dprintf("_mogrify: value refcnt: %d (+1)", value->ob_refcnt); Dprintf("_mogrify: value refcnt: "
FORMAT_CODE_PY_SSIZE_T " (+1)", value->ob_refcnt);
if (n == NULL) { if (n == NULL) {
n = PyDict_New(); n = PyDict_New();
@ -167,7 +169,10 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new)
Py_DECREF(item); Py_DECREF(item);
} }
Py_DECREF(key); /* key has the original refcnt now */ Py_DECREF(key); /* key has the original refcnt now */
Dprintf("_mogrify: after value refcnt: %d",value->ob_refcnt); Dprintf("_mogrify: after value refcnt: "
FORMAT_CODE_PY_SSIZE_T,
value->ob_refcnt
);
} }
c = d; c = d;
} }
@ -367,7 +372,8 @@ _psyco_curs_execute(cursorObject *self,
self->query = fquery; self->query = fquery;
} }
Dprintf("psyco_curs_execute: cvt->refcnt = %d", cvt->ob_refcnt); Dprintf("psyco_curs_execute: cvt->refcnt = " FORMAT_CODE_PY_SSIZE_T,
cvt->ob_refcnt);
Py_DECREF(cvt); Py_DECREF(cvt);
} }
else { else {
@ -399,7 +405,7 @@ psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs)
static char *kwlist[] = {"query", "vars", "async", NULL}; static char *kwlist[] = {"query", "vars", "async", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Oi", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Ol", kwlist,
&operation, &vars, &async)) { &operation, &vars, &async)) {
return NULL; return NULL;
} }
@ -557,8 +563,10 @@ psyco_curs_mogrify(cursorObject *self, PyObject *args, PyObject *kwargs)
return NULL; return NULL;
} }
Dprintf("psyco_curs_execute: cvt->refcnt = %d, fquery->refcnt = %d", Dprintf("psyco_curs_execute: cvt->refcnt = " FORMAT_CODE_PY_SSIZE_T
cvt->ob_refcnt, fquery->ob_refcnt); ", fquery->refcnt = " FORMAT_CODE_PY_SSIZE_T,
cvt->ob_refcnt, fquery->ob_refcnt
);
Py_DECREF(cvt); Py_DECREF(cvt);
} }
else { else {
@ -634,7 +642,10 @@ _psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
(PyObject*)self); (PyObject*)self);
if (val) { if (val) {
Dprintf("_psyco_curs_buildrow: val->refcnt = %d", val->ob_refcnt); Dprintf("_psyco_curs_buildrow: val->refcnt = "
FORMAT_CODE_PY_SSIZE_T,
val->ob_refcnt
);
if (istuple) { if (istuple) {
PyTuple_SET_ITEM(res, i, val); PyTuple_SET_ITEM(res, i, val);
} }
@ -878,7 +889,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs)
PyObject *operation = NULL; PyObject *operation = NULL;
PyObject *res = NULL; PyObject *res = NULL;
if (!PyArg_ParseTuple(args, "s|Oi", &procname, &parameters, &async)) { if (!PyArg_ParseTuple(args, "s|Ol", &procname, &parameters, &async)) {
return NULL; return NULL;
} }
@ -1073,17 +1084,19 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
char query[1024]; char query[1024];
char *table_name; char *table_name;
char *sep = "\t", *null = NULL; char *sep = "\t", *null = NULL;
long int bufsize = DEFAULT_COPYSIZE; Py_ssize_t bufsize = DEFAULT_COPYSIZE;
PyObject *file, *columns = NULL, *res = NULL; PyObject *file, *columns = NULL, *res = NULL;
char columnlist[1024] = ""; char columnlist[1024] = "";
static char *kwlist[] = {"file", "table", "sep", "null", "size", static char *kwlist[] = {"file", "table", "sep", "null", "size",
"columns", NULL}; "columns", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&s|ssiO", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwargs,
_psyco_curs_has_read_check, &file, "O&s|ss" CONV_CODE_PY_SSIZE_T "O", kwlist,
&table_name, &sep, &null, &bufsize, _psyco_curs_has_read_check, &file, &table_name, &sep, &null, &bufsize,
&columns)) { &columns)
)
{
return NULL; return NULL;
} }
@ -1429,8 +1442,10 @@ cursor_setup(cursorObject *self, connectionObject *conn, char *name)
self->tzinfo_factory = pyPsycopgTzFixedOffsetTimezone; self->tzinfo_factory = pyPsycopgTzFixedOffsetTimezone;
Py_INCREF(self->tzinfo_factory); Py_INCREF(self->tzinfo_factory);
Dprintf("cursor_setup: good cursor object at %p, refcnt = %d", Dprintf("cursor_setup: good cursor object at %p, refcnt = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
self, ((PyObject *)self)->ob_refcnt
);
return 0; return 0;
} }
@ -1453,8 +1468,10 @@ cursor_dealloc(PyObject* obj)
IFCLEARPGRES(self->pgres); IFCLEARPGRES(self->pgres);
Dprintf("cursor_dealloc: deleted cursor object at %p, refcnt = %d", Dprintf("cursor_dealloc: deleted cursor object at %p, refcnt = "
obj, obj->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt
);
obj->ob_type->tp_free(obj); obj->ob_type->tp_free(obj);
} }

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_MICROPROTOCOLS_H #ifndef PSYCOPG_MICROPROTOCOLS_H
#define PSYCOPG_MICROPROTOCOLS_H 1 #define PSYCOPG_MICROPROTOCOLS_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include "psycopg/connection.h" #include "psycopg/connection.h"
#include "psycopg/cursor.h" #include "psycopg/cursor.h"

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include <stringobject.h> #include <stringobject.h>

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_ISQLQUOTE_H #ifndef PSYCOPG_ISQLQUOTE_H
#define PSYCOPG_ISQLQUOTE_H 1 #define PSYCOPG_ISQLQUOTE_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <libpq-fe.h> #include <libpq-fe.h>

View File

@ -25,6 +25,7 @@
connection. connection.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <string.h> #include <string.h>
@ -358,7 +359,7 @@ pq_is_busy(connectionObject *conn)
PyObject *notify; PyObject *notify;
Dprintf("curs_is_busy: got NOTIFY from pid %d, msg = %s", Dprintf("curs_is_busy: got NOTIFY from pid %d, msg = %s",
pgn->be_pid, pgn->relname); (int) pgn->be_pid, pgn->relname);
notify = PyTuple_New(2); notify = PyTuple_New(2);
PyTuple_SET_ITEM(notify, 0, PyInt_FromLong((long)pgn->be_pid)); PyTuple_SET_ITEM(notify, 0, PyInt_FromLong((long)pgn->be_pid));
@ -600,7 +601,9 @@ _pq_copy_in_v3(cursorObject *curs)
int error = 0; int error = 0;
while (1) { while (1) {
o = PyObject_CallMethod(curs->copyfile, "read", "i", curs->copysize); o = PyObject_CallMethod(curs->copyfile, "read",
CONV_CODE_PY_SSIZE_T, curs->copysize
);
if (!o || !PyString_Check(o) || (length = PyString_Size(o)) == -1) { if (!o || !PyString_Check(o) || (length = PyString_Size(o)) == -1) {
error = 1; error = 1;
} }
@ -682,7 +685,7 @@ _pq_copy_out_v3(cursorObject *curs)
PyObject *tmp = NULL; PyObject *tmp = NULL;
char *buffer; char *buffer;
int len; Py_ssize_t len;
while (1) { while (1) {
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
@ -726,7 +729,8 @@ _pq_copy_out(cursorObject *curs)
PyObject *tmp = NULL; PyObject *tmp = NULL;
char buffer[4096]; char buffer[4096];
int status, len, ll=0; int status, ll=0;
Py_ssize_t len;
while (1) { while (1) {
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
@ -735,7 +739,7 @@ _pq_copy_out(cursorObject *curs)
if (status == 0) { if (status == 0) {
if (!ll && buffer[0] == '\\' && buffer[1] == '.') break; if (!ll && buffer[0] == '\\' && buffer[1] == '.') break;
len = strlen(buffer); len = (Py_ssize_t) strlen(buffer);
buffer[len++] = '\n'; buffer[len++] = '\n';
ll = 0; ll = 0;
} }

View File

@ -22,17 +22,42 @@
#ifndef PSYCOPG_H #ifndef PSYCOPG_H
#define PSYCOPG_H 1 #define PSYCOPG_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* Python 2.5 ssize_t compatibility */ /* Python 2.5+ Py_ssize_t compatibility: */
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) #ifndef PY_FORMAT_SIZE_T
typedef int Py_ssize_t; #define PY_FORMAT_SIZE_T ""
#define PY_SSIZE_T_MAX INT_MAX #endif
#define PY_SSIZE_T_MIN INT_MIN
/* FORMAT_CODE_SIZE_T is for plain size_t, not for Py_ssize_t: */
#ifdef _MSC_VER
/* For MSVC: */
#define FORMAT_CODE_SIZE_T "%Iu"
#else
/* C99 standard format code: */
#define FORMAT_CODE_SIZE_T "%zu"
#endif
/* FORMAT_CODE_PY_SSIZE_T is for Py_ssize_t: */
#define FORMAT_CODE_PY_SSIZE_T "%" PY_FORMAT_SIZE_T "d"
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5
#define CONV_CODE_PY_SSIZE_T "n"
#else
#define CONV_CODE_PY_SSIZE_T "d"
typedef int Py_ssize_t;
#define PY_SSIZE_T_MIN INT_MIN
#define PY_SSIZE_T_MAX INT_MAX
#define readbufferproc getreadbufferproc
#define writebufferproc getwritebufferproc
#define segcountproc getsegcountproc
#define charbufferproc getcharbufferproc
#endif #endif
/* DBAPI compliance parameters */ /* DBAPI compliance parameters */

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#define PSYCOPG_MODULE #define PSYCOPG_MODULE
@ -239,7 +240,7 @@ _psyco_register_type_set(PyObject **dict, PyObject *type)
static PyObject * static PyObject *
psyco_register_type(PyObject *self, PyObject *args) psyco_register_type(PyObject *self, PyObject *args)
{ {
PyObject *type, *obj; PyObject *type, *obj = NULL;
if (!PyArg_ParseTuple(args, "O!|O", &typecastType, &type, &obj)) { if (!PyArg_ParseTuple(args, "O!|O", &typecastType, &type, &obj)) {
return NULL; return NULL;

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_PYTHON_H #ifndef PSYCOPG_PYTHON_H
#define PSYCOPG_PYTHON_H 1 #define PSYCOPG_PYTHON_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>

View File

@ -19,6 +19,7 @@
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
@ -271,8 +272,10 @@ typecast_add(PyObject *obj, PyObject *dict, int binary)
typecastObject *type = (typecastObject *)obj; typecastObject *type = (typecastObject *)obj;
Dprintf("typecast_add: object at %p, values refcnt = %d", Dprintf("typecast_add: object at %p, values refcnt = "
obj, type->values->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
obj, type->values->ob_refcnt
);
if (dict == NULL) if (dict == NULL)
dict = (binary ? psyco_binary_types : psyco_types); dict = (binary ? psyco_binary_types : psyco_types);
@ -451,7 +454,8 @@ typecast_new(PyObject *name, PyObject *values, PyObject *cast, PyObject *base)
obj = PyObject_NEW(typecastObject, &typecastType); obj = PyObject_NEW(typecastObject, &typecastType);
if (obj == NULL) return NULL; if (obj == NULL) return NULL;
Dprintf("typecast_new: new type at = %p, refcnt = %d", obj, obj->ob_refcnt); Dprintf("typecast_new: new type at = %p, refcnt = " FORMAT_CODE_PY_SSIZE_T,
obj, obj->ob_refcnt);
Py_INCREF(values); Py_INCREF(values);
obj->values = values; obj->values = values;
@ -485,7 +489,7 @@ typecast_new(PyObject *name, PyObject *values, PyObject *cast, PyObject *base)
PyObject * PyObject *
typecast_from_python(PyObject *self, PyObject *args, PyObject *keywds) typecast_from_python(PyObject *self, PyObject *args, PyObject *keywds)
{ {
PyObject *v, *name, *cast = NULL, *base = NULL; PyObject *v, *name = NULL, *cast = NULL, *base = NULL;
static char *kwlist[] = {"values", "name", "castobj", "baseobj", NULL}; static char *kwlist[] = {"values", "name", "castobj", "baseobj", NULL};

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_TYPECAST_H #ifndef PSYCOPG_TYPECAST_H
#define PSYCOPG_TYPECAST_H 1 #define PSYCOPG_TYPECAST_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -33,8 +33,10 @@
static void static void
chunk_dealloc(chunkObject *self) chunk_dealloc(chunkObject *self)
{ {
Dprintf("chunk_dealloc: deallocating memory at %p, size %d", Dprintf("chunk_dealloc: deallocating memory at %p, size "
self->base, self->len); FORMAT_CODE_PY_SSIZE_T,
self->base, self->len
);
free(self->base); free(self->base);
self->ob_type->tp_free((PyObject *) self); self->ob_type->tp_free((PyObject *) self);
} }
@ -42,12 +44,14 @@ chunk_dealloc(chunkObject *self)
static PyObject * static PyObject *
chunk_repr(chunkObject *self) chunk_repr(chunkObject *self)
{ {
return PyString_FromFormat("<memory chunk at %p size %d>", return PyString_FromFormat(
self->base, self->len); "<memory chunk at %p size " FORMAT_CODE_PY_SSIZE_T ">",
self->base, self->len
);
} }
static int static Py_ssize_t
chunk_getreadbuffer(chunkObject *self, int segment, void **ptr) chunk_getreadbuffer(chunkObject *self, Py_ssize_t segment, void **ptr)
{ {
if (segment != 0) if (segment != 0)
{ {
@ -59,8 +63,8 @@ chunk_getreadbuffer(chunkObject *self, int segment, void **ptr)
return self->len; return self->len;
} }
static int static Py_ssize_t
chunk_getsegcount(chunkObject *self, int *lenp) chunk_getsegcount(chunkObject *self, Py_ssize_t *lenp)
{ {
if (lenp != NULL) if (lenp != NULL)
*lenp = self->len; *lenp = self->len;
@ -69,10 +73,10 @@ chunk_getsegcount(chunkObject *self, int *lenp)
static PyBufferProcs chunk_as_buffer = static PyBufferProcs chunk_as_buffer =
{ {
(getreadbufferproc) chunk_getreadbuffer, (readbufferproc) chunk_getreadbuffer,
(getwritebufferproc) NULL, (writebufferproc) NULL,
(getsegcountproc) chunk_getsegcount, (segcountproc) chunk_getsegcount,
(getcharbufferproc) NULL (charbufferproc) NULL
}; };
#define chunk_doc "memory chunk" #define chunk_doc "memory chunk"
@ -172,7 +176,8 @@ typecast_BINARY_cast(char *s, int l, PyObject *curs)
s = buffer; s = buffer;
} }
str = (char*)PQunescapeBytea((unsigned char*)s, &len); str = (char*)PQunescapeBytea((unsigned char*)s, &len);
Dprintf("typecast_BINARY_cast: unescaped %d bytes", len); Dprintf("typecast_BINARY_cast: unescaped " FORMAT_CODE_SIZE_T " bytes",
len);
if (buffer) PyMem_Free(buffer); if (buffer) PyMem_Free(buffer);
chunk = (chunkObject *) PyObject_New(chunkObject, &chunkType); chunk = (chunkObject *) PyObject_New(chunkObject, &chunkType);

View File

@ -22,6 +22,7 @@
#ifndef PSYCOPG_TYPECAST_BINARY_H #ifndef PSYCOPG_TYPECAST_BINARY_H
#define PSYCOPG_TYPECAST_BINARY_H 1 #define PSYCOPG_TYPECAST_BINARY_H 1
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -36,7 +37,7 @@ typedef struct {
PyObject_HEAD PyObject_HEAD
void *base; /* Pointer to the memory chunk. */ void *base; /* Pointer to the memory chunk. */
int len; /* Size in bytes of the memory chunk. */ Py_ssize_t len; /* Size in bytes of the memory chunk. */
} chunkObject; } chunkObject;

View File

@ -124,8 +124,10 @@ typecast_PYDATETIME_cast(char *str, int len, PyObject *curs)
((cursorObject*)curs)->tzinfo_factory, "i", tz); ((cursorObject*)curs)->tzinfo_factory, "i", tz);
obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiiiO", obj = PyObject_CallFunction(pyDateTimeTypeP, "iiiiiiiO",
y, m, d, hh, mm, ss, us, tzinfo); y, m, d, hh, mm, ss, us, tzinfo);
Dprintf("typecast_PYDATETIME_cast: tzinfo: %p, refcnt = %d", Dprintf("typecast_PYDATETIME_cast: tzinfo: %p, refcnt = "
tzinfo, tzinfo->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
tzinfo, tzinfo->ob_refcnt
);
Py_XDECREF(tzinfo); Py_XDECREF(tzinfo);
} }
else { else {