From 1d8af808bfa2b6756375f8e07973495613842521 Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Sat, 23 Sep 2006 05:15:36 +0000 Subject: [PATCH] Piet Delport patches: 3 of 3. --- ChangeLog | 10 +++++++++- psycopg/adapter_list.c | 2 +- psycopg/cursor_type.c | 5 +++-- psycopg/pqpath.c | 3 ++- psycopg/typecast.c | 9 +++++---- psycopg/typecast.h | 2 +- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2aaf0bc2..0afaf34d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2006-09-23 Federico Di Gregorio - + + * Applied patch 1/3 from Piet Delport; from his email: + psycopg2-Py_ssize_t-input.diff adjusts variables used for parameters + and return values. These changes only prevent overflowing on values + greater than 32-bits, so they're not as critical as the other two + patches. I tried to leave places unchanged where the input size is + already constrained to sizeof(int), but i might have missed a few + either way, not being too familiar with the codebase. + * Applied patch 2/3 from Piet Delport; from his email: psycopg2-Py_ssize_t-output.diff adjusts variables used as outputs from CPython API calls: without it the calls try to write 64 bits diff --git a/psycopg/adapter_list.c b/psycopg/adapter_list.c index 29ef1167..c65aac83 100644 --- a/psycopg/adapter_list.c +++ b/psycopg/adapter_list.c @@ -40,7 +40,7 @@ list_quote(listObject *self) /* adapt the list by calling adapt() recursively and then wrapping everything into "ARRAY[]" */ PyObject *tmp = NULL, *str = NULL, *joined = NULL, *res = NULL; - int i, len; + Py_ssize_t i, len; len = PyList_GET_SIZE(self->wrapped); diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index 6d58e872..34e10d57 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -77,7 +77,8 @@ _mogrify(PyObject *var, PyObject *fmt, connectionObject *conn, PyObject **new) { PyObject *key, *value, *n, *item; char *d, *c; - int index = 0, force = 0; + Py_ssize_t index = 0; + int force = 0; /* from now on we'll use n and replace its value in *new only at the end, just before returning. we also init *new to NULL to exit with an error @@ -872,7 +873,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs) { char *procname = NULL, *sql = NULL; long int async = 0; - int i, nparameters = 0, sl = 0; + Py_ssize_t i, nparameters = 0, sl = 0; PyObject *parameters = NULL; PyObject *operation = NULL; PyObject *res = NULL; diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 1ebb569c..561d4f52 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -586,7 +586,8 @@ _pq_copy_in_v3(cursorObject *curs) uses the new PQputCopyData() and can detect errors and set the correct exception */ PyObject *o; - int length = 0, error = 0; + Py_ssize_t length = 0; + int error = 0; while (1) { o = PyObject_CallMethod(curs->copyfile, "read", "i", curs->copysize); diff --git a/psycopg/typecast.c b/psycopg/typecast.c index ef91bfde..625ba1b4 100644 --- a/psycopg/typecast.c +++ b/psycopg/typecast.c @@ -267,7 +267,7 @@ int typecast_add(PyObject *obj, int binary) { PyObject *val; - int len, i; + Py_ssize_t len, i; typecastObject *type = (typecastObject *)obj; @@ -302,7 +302,8 @@ typecast_cmp(PyObject *obj1, PyObject* obj2) typecastObject *self = (typecastObject*)obj1; typecastObject *other = NULL; PyObject *number = NULL; - int i, j, res = -1; + Py_ssize_t i, j; + int res = -1; if (PyObject_TypeCheck(obj2, &typecastType)) { other = (typecastObject*)obj2; @@ -505,7 +506,7 @@ typecast_from_c(typecastObject_initlist *type, PyObject *dict) { PyObject *tuple, *base = NULL; typecastObject *obj; - int i, len = 0; + Py_ssize_t i, len = 0; /* before doing anything else we look for the base */ if (type->base) { @@ -538,7 +539,7 @@ typecast_from_c(typecastObject_initlist *type, PyObject *dict) } PyObject * -typecast_cast(PyObject *obj, char *str, int len, PyObject *curs) +typecast_cast(PyObject *obj, char *str, Py_ssize_t len, PyObject *curs) { PyObject *old, *res = NULL; typecastObject *self = (typecastObject *)obj; diff --git a/psycopg/typecast.h b/psycopg/typecast.h index ec77e5ca..e42dd521 100644 --- a/psycopg/typecast.h +++ b/psycopg/typecast.h @@ -80,6 +80,6 @@ extern PyObject *typecast_from_python( /* the function used to dispatch typecasting calls */ extern PyObject *typecast_cast( - PyObject *self, char *str, int len, PyObject *curs); + PyObject *self, char *str, Py_ssize_t len, PyObject *curs); #endif /* !defined(PSYCOPG_TYPECAST_H) */