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,17 +143,17 @@ 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;
} }
if (len > 0) if (len > 0)
self->buffer = PyString_FromFormat("'%s'", to); self->buffer = PyString_FromFormat("'%s'", to);
else else
self->buffer = PyString_FromString("''"); self->buffer = PyString_FromString("''");
PQfreemem(to); PQfreemem(to);
} }
@ -244,16 +245,19 @@ 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 = "
self, ((PyObject *)self)->ob_refcnt); FORMAT_CODE_PY_SSIZE_T,
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);
} }
@ -255,13 +260,13 @@ PyTypeObject pydatetimeType = {
PyObject * PyObject *
psyco_Date(PyObject *self, PyObject *args) psyco_Date(PyObject *self, PyObject *args)
{ {
PyObject *res = NULL; PyObject *res = NULL;
int year, month, day; int year, month, day;
PyObject* obj = NULL; PyObject* obj = NULL;
if (!PyArg_ParseTuple(args, "iii", &year, &month, &day)) if (!PyArg_ParseTuple(args, "iii", &year, &month, &day))
return NULL; return NULL;
obj = PyObject_CallFunction(pyDateTypeP, "iii", year, month, day); obj = PyObject_CallFunction(pyDateTypeP, "iii", year, month, day);
@ -286,7 +291,7 @@ psyco_Time(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "iid|O", &hours, &minutes, &second, if (!PyArg_ParseTuple(args, "iid|O", &hours, &minutes, &second,
&tzinfo)) &tzinfo))
return NULL; return NULL;
micro = (second - floor(second)) * 1000000.0; micro = (second - floor(second)) * 1000000.0;
second = floor(second); second = floor(second);
@ -320,7 +325,7 @@ psyco_Timestamp(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "lii|iidO", &year, &month, &day, if (!PyArg_ParseTuple(args, "lii|iidO", &year, &month, &day,
&hour, &minute, &second, &tzinfo)) &hour, &minute, &second, &tzinfo))
return NULL; return NULL;
micro = (second - floor(second)) * 1000000.0; micro = (second - floor(second)) * 1000000.0;
second = floor(second); second = floor(second);
@ -380,7 +385,7 @@ psyco_TimeFromTicks(PyObject *self, PyObject *args)
ticks -= (double)t; ticks -= (double)t;
if (localtime_r(&t, &tm)) { if (localtime_r(&t, &tm)) {
args = Py_BuildValue("iid", tm.tm_hour, tm.tm_min, args = Py_BuildValue("iid", tm.tm_hour, tm.tm_min,
(double)tm.tm_sec + ticks); (double)tm.tm_sec + ticks);
if (args) { if (args) {
res = psyco_Time(self, args); res = psyco_Time(self, args);
Py_DECREF(args); Py_DECREF(args);
@ -406,7 +411,7 @@ psyco_TimestampFromTicks(PyObject *self, PyObject *args)
args = Py_BuildValue("iiiiidO", args = Py_BuildValue("iiiiidO",
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_hour, tm.tm_min,
(double)tm.tm_sec + ticks, (double)tm.tm_sec + ticks,
pyPsycopgTzLOCAL); pyPsycopgTzLOCAL);
if (args) { if (args) {
res = psyco_Timestamp(self, args); res = psyco_Timestamp(self, args);

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>
@ -52,11 +53,11 @@ list_quote(listObject *self)
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
PyObject *quoted; PyObject *quoted;
PyObject *wrapped = PyList_GET_ITEM(self->wrapped, i); PyObject *wrapped = PyList_GET_ITEM(self->wrapped, i);
if (wrapped == Py_None) if (wrapped == Py_None)
quoted = PyString_FromString("NULL"); quoted = PyString_FromString("NULL");
else else
quoted = microprotocol_getquoted(wrapped, quoted = microprotocol_getquoted(wrapped,
(connectionObject*)self->connection); (connectionObject*)self->connection);
if (quoted == NULL) goto error; if (quoted == NULL) goto error;
@ -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);
} }
@ -276,13 +283,13 @@ PyTypeObject mxdatetimeType = {
PyObject * PyObject *
psyco_Date(PyObject *self, PyObject *args) psyco_Date(PyObject *self, PyObject *args)
{ {
PyObject *res, *mx; PyObject *res, *mx;
int year, month, day; int year, month, day;
if (!PyArg_ParseTuple(args, "iii", &year, &month, &day)) if (!PyArg_ParseTuple(args, "iii", &year, &month, &day))
return NULL; return NULL;
mx = mxDateTimeP->DateTime_FromDateAndTime(year, month, day, 0, 0, 0.0); mx = mxDateTimeP->DateTime_FromDateAndTime(year, month, day, 0, 0, 0.0);
if (mx == NULL) return NULL; if (mx == NULL) return NULL;
res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx, res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx,
@ -294,14 +301,14 @@ psyco_Date(PyObject *self, PyObject *args)
PyObject * PyObject *
psyco_Time(PyObject *self, PyObject *args) psyco_Time(PyObject *self, PyObject *args)
{ {
PyObject *res, *mx; PyObject *res, *mx;
int hours, minutes=0; int hours, minutes=0;
double seconds=0.0; double seconds=0.0;
if (!PyArg_ParseTuple(args, "iid", &hours, &minutes, &seconds)) if (!PyArg_ParseTuple(args, "iid", &hours, &minutes, &seconds))
return NULL; return NULL;
mx = mxDateTimeP->DateTimeDelta_FromTime(hours, minutes, seconds); mx = mxDateTimeP->DateTimeDelta_FromTime(hours, minutes, seconds);
if (mx == NULL) return NULL; if (mx == NULL) return NULL;
res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx, res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx,
@ -313,14 +320,14 @@ psyco_Time(PyObject *self, PyObject *args)
PyObject * PyObject *
psyco_Timestamp(PyObject *self, PyObject *args) psyco_Timestamp(PyObject *self, PyObject *args)
{ {
PyObject *res, *mx; PyObject *res, *mx;
int year, month, day; int year, month, day;
int hour=0, minute=0; /* default to midnight */ int hour=0, minute=0; /* default to midnight */
double second=0.0; double second=0.0;
if (!PyArg_ParseTuple(args, "lii|iid", &year, &month, &day, if (!PyArg_ParseTuple(args, "lii|iid", &year, &month, &day,
&hour, &minute, &second)) &hour, &minute, &second))
return NULL; return NULL;
mx = mxDateTimeP->DateTime_FromDateAndTime(year, month, day, mx = mxDateTimeP->DateTime_FromDateAndTime(year, month, day,
hour, minute, second); hour, minute, second);

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;
} }
@ -191,14 +194,14 @@ psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
buffer = PyMem_Malloc(strlen(enc)); buffer = PyMem_Malloc(strlen(enc));
for (i=j=0 ; i < strlen(enc) ; i++) { for (i=j=0 ; i < strlen(enc) ; i++) {
if (enc[i] == '_' || enc[i] == '-') if (enc[i] == '_' || enc[i] == '-')
continue; continue;
else else
buffer[j++] = toupper(enc[i]); buffer[j++] = toupper(enc[i]);
} }
buffer[j] = '\0'; buffer[j] = '\0';
if (conn_set_client_encoding(self, buffer) == 0) { if (conn_set_client_encoding(self, buffer) == 0) {
PyMem_Free(buffer); PyMem_Free(buffer);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
@ -274,9 +277,9 @@ 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,
"A set of typecasters to convert textual values."}, "A set of typecasters to convert textual values."},
{"binary_types", T_OBJECT, offsetof(connectionObject, binary_types), RO, {"binary_types", T_OBJECT, offsetof(connectionObject, binary_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;
} }
@ -251,7 +256,7 @@ _psyco_curs_execute(cursorObject *self,
if (!PyObject_IsTrue(operation)) { if (!PyObject_IsTrue(operation)) {
psyco_set_error(ProgrammingError, (PyObject*)self, psyco_set_error(ProgrammingError, (PyObject*)self,
"can't execute an empty query", NULL, NULL); "can't execute an empty query", NULL, NULL);
return 0; return 0;
} }
if (PyUnicode_Check(operation)) { if (PyUnicode_Check(operation)) {
@ -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;
} }
@ -892,7 +903,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs)
if(parameters && parameters != Py_None) { if(parameters && parameters != Py_None) {
nparameters = PyObject_Length(parameters); nparameters = PyObject_Length(parameters);
if (nparameters < 0) nparameters = 0; if (nparameters < 0) nparameters = 0;
} }
/* allocate some memory, build the SQL and create a PyString from it */ /* allocate some memory, build the SQL and create a PyString from it */
@ -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;
} }
@ -1102,7 +1115,7 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
Py_DECREF(col); Py_DECREF(col);
Py_DECREF(collistiter); Py_DECREF(collistiter);
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"Elements in column list must be strings"); "Elements in column list must be strings");
return NULL; return NULL;
} }
PyString_AsStringAndSize(col, &colname, &colitemlen); PyString_AsStringAndSize(col, &colname, &colitemlen);
@ -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
@ -144,16 +145,16 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
} }
if (pyport && PyString_Check(pyport)) { if (pyport && PyString_Check(pyport)) {
PyObject *pyint = PyInt_FromString(PyString_AsString(pyport), NULL, 10); PyObject *pyint = PyInt_FromString(PyString_AsString(pyport), NULL, 10);
if (!pyint) return NULL; if (!pyint) return NULL;
iport = PyInt_AsLong(pyint); iport = PyInt_AsLong(pyint);
} }
else if (pyport && PyInt_Check(pyport)) { else if (pyport && PyInt_Check(pyport)) {
iport = PyInt_AsLong(pyport); iport = PyInt_AsLong(pyport);
} }
else if (pyport != NULL) { else if (pyport != NULL) {
PyErr_SetString(PyExc_TypeError, "port must be a string or int"); PyErr_SetString(PyExc_TypeError, "port must be a string or int");
return NULL; return NULL;
} }
if (iport > 0) if (iport > 0)
@ -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;
@ -529,7 +530,7 @@ psyco_set_error(PyObject *exc, PyObject *curs, char *msg,
PyObject_SetAttrString(err, "cursor", Py_None); PyObject_SetAttrString(err, "cursor", Py_None);
PyErr_SetObject(exc, err); PyErr_SetObject(exc, err);
Py_DECREF(err); Py_DECREF(err);
} }
} }

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

@ -122,7 +122,7 @@ typecast_array_tokenize(char *str, int strlength,
if (str[*pos] == '"') { if (str[*pos] == '"') {
*pos += 1; *pos += 1;
l -= 2; l -= 2;
*quotes = 1; *quotes = 1;
} }
if (res == ASCAN_QUOTED) { if (res == ASCAN_QUOTED) {
@ -166,18 +166,18 @@ typecast_array_scan(char *str, int strlength,
while (1) { while (1) {
token = NULL; token = NULL;
state = typecast_array_tokenize(str, strlength, state = typecast_array_tokenize(str, strlength,
&pos, &token, &length, &quotes); &pos, &token, &length, &quotes);
Dprintf("typecast_array_scan: state = %d, length = %d, token = '%s'", Dprintf("typecast_array_scan: state = %d, length = %d, token = '%s'",
state, length, token); state, length, token);
if (state == ASCAN_TOKEN || state == ASCAN_QUOTED) { if (state == ASCAN_TOKEN || state == ASCAN_QUOTED) {
PyObject *obj; PyObject *obj;
if (!quotes && length == 4 if (!quotes && length == 4
&& (token[0] == 'n' || token[0] == 'N') && (token[0] == 'n' || token[0] == 'N')
&& (token[1] == 'u' || token[1] == 'U') && (token[1] == 'u' || token[1] == 'U')
&& (token[2] == 'l' || token[2] == 'L') && (token[2] == 'l' || token[2] == 'L')
&& (token[3] == 'l' || token[3] == 'L')) && (token[3] == 'l' || token[3] == 'L'))
obj = typecast_cast(base, NULL, 0, curs); obj = typecast_cast(base, NULL, 0, curs);
else else
obj = typecast_cast(base, token, length, curs); obj = typecast_cast(base, token, length, curs);
/* before anything else we free the memory */ /* before anything else we free the memory */

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

@ -59,7 +59,7 @@ typecast_PYDATE_cast(char *str, int len, PyObject *curs)
PyErr_SetString(DataError, "unable to parse date"); PyErr_SetString(DataError, "unable to parse date");
} }
else { else {
if (y > 9999) y = 9999; if (y > 9999) y = 9999;
obj = PyObject_CallFunction(pyDateTypeP, "iii", y, m, d); obj = PyObject_CallFunction(pyDateTypeP, "iii", y, m, d);
} }
} }
@ -113,7 +113,7 @@ typecast_PYDATETIME_cast(char *str, int len, PyObject *curs)
ss -= 60; ss -= 60;
} }
if (y > 9999) if (y > 9999)
y = 9999; y = 9999;
if (n == 5 && ((cursorObject*)curs)->tzinfo_factory != Py_None) { if (n == 5 && ((cursorObject*)curs)->tzinfo_factory != Py_None) {
/* we have a time zone, calculate minutes and create /* we have a time zone, calculate minutes and create
@ -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 {