diff --git a/ChangeLog b/ChangeLog index fbf7cc83..bb7014df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-01-22 James Henstridge + + * psycopg/*.[ch]: add const qualifier to various string arguments + to functions (typecast functions and conn_switch_isolation_level). + 2008-01-21 James Henstridge * setup.cfg (define): remove PSYCOPG_DISPLAY_SIZE from default diff --git a/psycopg/connection.h b/psycopg/connection.h index e4ef2f11..18674643 100644 --- a/psycopg/connection.h +++ b/psycopg/connection.h @@ -83,7 +83,7 @@ HIDDEN void conn_close(connectionObject *self); HIDDEN int conn_commit(connectionObject *self); HIDDEN int conn_rollback(connectionObject *self); HIDDEN int conn_switch_isolation_level(connectionObject *self, int level); -HIDDEN int conn_set_client_encoding(connectionObject *self, char *enc); +HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc); /* exception-raising macros */ #define EXC_IF_CONN_CLOSED(self) if ((self)->closed > 0) { \ diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index bf72df3e..2cc7818e 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -296,7 +296,7 @@ conn_switch_isolation_level(connectionObject *self, int level) /* conn_set_client_encoding - switch client encoding on connection */ int -conn_set_client_encoding(connectionObject *self, char *enc) +conn_set_client_encoding(connectionObject *self, const char *enc) { PGresult *pgres = NULL; char *error = NULL; diff --git a/psycopg/typecast.c b/psycopg/typecast.c index 8d6df5bf..75ab293a 100644 --- a/psycopg/typecast.c +++ b/psycopg/typecast.c @@ -32,15 +32,15 @@ /* usefull function used by some typecasters */ -static char * -skip_until_space(char *s) +static const char * +skip_until_space(const char *s) { while (*s && *s != ' ') s++; return s; } -static char * -skip_until_space2(char *s, Py_ssize_t *len) +static const char * +skip_until_space2(const char *s, Py_ssize_t *len) { while (*len > 0 && *s && *s != ' ') { s++; (*len)--; @@ -49,7 +49,7 @@ skip_until_space2(char *s, Py_ssize_t *len) } static int -typecast_parse_date(char* s, char** t, Py_ssize_t* len, +typecast_parse_date(const char* s, const char** t, Py_ssize_t* len, int* year, int* month, int* day) { int acc = -1, cz = 0; @@ -92,7 +92,7 @@ typecast_parse_date(char* s, char** t, Py_ssize_t* len, } static int -typecast_parse_time(char* s, char** t, Py_ssize_t* len, +typecast_parse_time(const char* s, const char** t, Py_ssize_t* len, int* hh, int* mm, int* ss, int* us, int* tz) { int acc = -1, cz = 0; @@ -556,7 +556,7 @@ typecast_from_c(typecastObject_initlist *type, PyObject *dict) } PyObject * -typecast_cast(PyObject *obj, char *str, Py_ssize_t len, PyObject *curs) +typecast_cast(PyObject *obj, const 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 c64bc309..17e5486f 100644 --- a/psycopg/typecast.h +++ b/psycopg/typecast.h @@ -32,7 +32,8 @@ extern "C" { #endif /* type of type-casting functions (both C and Python) */ -typedef PyObject *(*typecast_function)(char *, Py_ssize_t len, PyObject *); +typedef PyObject *(*typecast_function)(const char *str, Py_ssize_t len, + PyObject *cursor); /** typecast type **/ @@ -83,6 +84,6 @@ HIDDEN PyObject *typecast_from_python( /* the function used to dispatch typecasting calls */ HIDDEN PyObject *typecast_cast( - PyObject *self, char *str, Py_ssize_t len, PyObject *curs); + PyObject *self, const char *str, Py_ssize_t len, PyObject *curs); #endif /* !defined(PSYCOPG_TYPECAST_H) */ diff --git a/psycopg/typecast_array.c b/psycopg/typecast_array.c index 4a792266..b05c6345 100644 --- a/psycopg/typecast_array.c +++ b/psycopg/typecast_array.c @@ -24,7 +24,7 @@ /** typecast_array_cleanup - remove the horrible [...]= stuff **/ static int -typecast_array_cleanup(char **str, Py_ssize_t *len) +typecast_array_cleanup(const char **str, Py_ssize_t *len) { Py_ssize_t i, depth = 1; @@ -53,7 +53,7 @@ typecast_array_cleanup(char **str, Py_ssize_t *len) #define ASCAN_QUOTED 4 static int -typecast_array_tokenize(char *str, Py_ssize_t strlength, +typecast_array_tokenize(const char *str, Py_ssize_t strlength, Py_ssize_t *pos, char** token, Py_ssize_t *length, int *quotes) { @@ -148,7 +148,7 @@ typecast_array_tokenize(char *str, Py_ssize_t strlength, *length = (Py_ssize_t) (buffer - *token); } else { - *token = &str[*pos]; + *token = (char *)&str[*pos]; *length = l; } @@ -161,7 +161,7 @@ typecast_array_tokenize(char *str, Py_ssize_t strlength, } static int -typecast_array_scan(char *str, Py_ssize_t strlength, +typecast_array_scan(const char *str, Py_ssize_t strlength, PyObject *curs, PyObject *base, PyObject *array) { int state, quotes = 0; @@ -235,7 +235,7 @@ typecast_array_scan(char *str, Py_ssize_t strlength, have to be taken on the single items **/ static PyObject * -typecast_GENERIC_ARRAY_cast(char *str, Py_ssize_t len, PyObject *curs) +typecast_GENERIC_ARRAY_cast(const char *str, Py_ssize_t len, PyObject *curs) { PyObject *obj = NULL; PyObject *base = ((typecastObject*)((cursorObject*)curs)->caster)->bcast; diff --git a/psycopg/typecast_basic.c b/psycopg/typecast_basic.c index eeb96be9..c4f3cf62 100644 --- a/psycopg/typecast_basic.c +++ b/psycopg/typecast_basic.c @@ -22,7 +22,7 @@ /** INTEGER - cast normal integers (4 bytes) to python int **/ static PyObject * -typecast_INTEGER_cast(char *s, Py_ssize_t len, PyObject *curs) +typecast_INTEGER_cast(const char *s, Py_ssize_t len, PyObject *curs) { char buffer[12]; @@ -31,13 +31,13 @@ typecast_INTEGER_cast(char *s, Py_ssize_t len, PyObject *curs) strncpy(buffer, s, (size_t) len); buffer[len] = '\0'; s = buffer; } - return PyInt_FromString(s, NULL, 0); + return PyInt_FromString((char *)s, NULL, 0); } /** LONGINTEGER - cast long integers (8 bytes) to python long **/ static PyObject * -typecast_LONGINTEGER_cast(char *s, Py_ssize_t len, PyObject *curs) +typecast_LONGINTEGER_cast(const char *s, Py_ssize_t len, PyObject *curs) { char buffer[24]; @@ -46,13 +46,13 @@ typecast_LONGINTEGER_cast(char *s, Py_ssize_t len, PyObject *curs) strncpy(buffer, s, (size_t) len); buffer[len] = '\0'; s = buffer; } - return PyLong_FromString(s, NULL, 0); + return PyLong_FromString((char *)s, NULL, 0); } /** FLOAT - cast floating point numbers to python float **/ static PyObject * -typecast_FLOAT_cast(char *s, Py_ssize_t len, PyObject *curs) +typecast_FLOAT_cast(const char *s, Py_ssize_t len, PyObject *curs) { PyObject *str = NULL, *flo = NULL; char *pend; @@ -67,7 +67,7 @@ typecast_FLOAT_cast(char *s, Py_ssize_t len, PyObject *curs) /** STRING - cast strings of any type to python string **/ static PyObject * -typecast_STRING_cast(char *s, Py_ssize_t len, PyObject *curs) +typecast_STRING_cast(const char *s, Py_ssize_t len, PyObject *curs) { if (s == NULL) {Py_INCREF(Py_None); return Py_None;} return PyString_FromStringAndSize(s, len); @@ -76,7 +76,7 @@ typecast_STRING_cast(char *s, Py_ssize_t len, PyObject *curs) /** UNICODE - cast strings of any type to a python unicode object **/ static PyObject * -typecast_UNICODE_cast(char *s, Py_ssize_t len, PyObject *curs) +typecast_UNICODE_cast(const char *s, Py_ssize_t len, PyObject *curs) { PyObject *enc; @@ -98,7 +98,7 @@ typecast_UNICODE_cast(char *s, Py_ssize_t len, PyObject *curs) /** BOOLEAN - cast boolean value into right python object **/ static PyObject * -typecast_BOOLEAN_cast(char *s, Py_ssize_t len, PyObject *curs) +typecast_BOOLEAN_cast(const char *s, Py_ssize_t len, PyObject *curs) { PyObject *res; @@ -117,7 +117,7 @@ typecast_BOOLEAN_cast(char *s, Py_ssize_t len, PyObject *curs) #ifdef HAVE_DECIMAL static PyObject * -typecast_DECIMAL_cast(char *s, Py_ssize_t len, PyObject *curs) +typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs) { PyObject *res = NULL; PyObject *decimalType; diff --git a/psycopg/typecast_binary.c b/psycopg/typecast_binary.c index 52674dda..47fff1ee 100644 --- a/psycopg/typecast_binary.c +++ b/psycopg/typecast_binary.c @@ -156,7 +156,7 @@ typecast_BINARY_cast_unescape(unsigned char *str, size_t *to_length) #endif static PyObject * -typecast_BINARY_cast(char *s, Py_ssize_t l, PyObject *curs) +typecast_BINARY_cast(const char *s, Py_ssize_t l, PyObject *curs) { chunkObject *chunk = NULL; PyObject *res = NULL; diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c index f8b4f1fb..6748c6a6 100644 --- a/psycopg/typecast_datetime.c +++ b/psycopg/typecast_datetime.c @@ -34,7 +34,7 @@ extern PyObject *pyDeltaTypeP; /** DATE - cast a date into a date python object **/ static PyObject * -typecast_PYDATE_cast(char *str, Py_ssize_t len, PyObject *curs) +typecast_PYDATE_cast(const char *str, Py_ssize_t len, PyObject *curs) { PyObject* obj = NULL; int n, y=0, m=0, d=0; @@ -70,12 +70,12 @@ typecast_PYDATE_cast(char *str, Py_ssize_t len, PyObject *curs) /** DATETIME - cast a timestamp into a datetime python object **/ static PyObject * -typecast_PYDATETIME_cast(char *str, Py_ssize_t len, PyObject *curs) +typecast_PYDATETIME_cast(const char *str, Py_ssize_t len, PyObject *curs) { PyObject* obj = NULL; int n, y=0, m=0, d=0; int hh=0, mm=0, ss=0, us=0, tz=0; - char *tp = NULL; + const char *tp = NULL; if (str == NULL) {Py_INCREF(Py_None); return Py_None;} @@ -144,7 +144,7 @@ typecast_PYDATETIME_cast(char *str, Py_ssize_t len, PyObject *curs) /** TIME - parse time into a time object **/ static PyObject * -typecast_PYTIME_cast(char *str, Py_ssize_t len, PyObject *curs) +typecast_PYTIME_cast(const char *str, Py_ssize_t len, PyObject *curs) { PyObject* obj = NULL; int n, hh=0, mm=0, ss=0, us=0, tz=0; @@ -172,7 +172,7 @@ typecast_PYTIME_cast(char *str, Py_ssize_t len, PyObject *curs) /** INTERVAL - parse an interval into a timedelta object **/ static PyObject * -typecast_PYINTERVAL_cast(char *str, Py_ssize_t len, PyObject *curs) +typecast_PYINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs) { long years = 0, months = 0, days = 0; double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0; diff --git a/psycopg/typecast_mxdatetime.c b/psycopg/typecast_mxdatetime.c index 85809da4..bdd2955b 100644 --- a/psycopg/typecast_mxdatetime.c +++ b/psycopg/typecast_mxdatetime.c @@ -28,11 +28,11 @@ extern mxDateTimeModule_APIObject *mxDateTimeP; /** DATE - cast a date into mx.DateTime python object **/ static PyObject * -typecast_MXDATE_cast(char *str, Py_ssize_t len, PyObject *curs) +typecast_MXDATE_cast(const char *str, Py_ssize_t len, PyObject *curs) { int n, y=0, m=0, d=0; int hh=0, mm=0, ss=0, us=0, tz=0; - char *tp = NULL; + const char *tp = NULL; if (str == NULL) {Py_INCREF(Py_None); return Py_None;} @@ -76,7 +76,7 @@ typecast_MXDATE_cast(char *str, Py_ssize_t len, PyObject *curs) /** TIME - parse time into an mx.DateTime object **/ static PyObject * -typecast_MXTIME_cast(char *str, Py_ssize_t len, PyObject *curs) +typecast_MXTIME_cast(const char *str, Py_ssize_t len, PyObject *curs) { int n, hh=0, mm=0, ss=0, us=0, tz=0; @@ -103,7 +103,7 @@ typecast_MXTIME_cast(char *str, Py_ssize_t len, PyObject *curs) /** INTERVAL - parse an interval into an mx.DateTimeDelta **/ static PyObject * -typecast_MXINTERVAL_cast(char *str, Py_ssize_t len, PyObject *curs) +typecast_MXINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs) { long years = 0, months = 0, days = 0, denominator = 1; double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0;