Skip to content

Commit eae563a

Browse files
committed
* psycopg/*.[ch]: add const qualifier to various string arguments
to functions (typecast functions and conn_switch_isolation_level).
1 parent 9fa0393 commit eae563a

File tree

10 files changed

+41
-35
lines changed

10 files changed

+41
-35
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2008-01-22 James Henstridge <james@jamesh.id.au>
2+
3+
* psycopg/*.[ch]: add const qualifier to various string arguments
4+
to functions (typecast functions and conn_switch_isolation_level).
5+
16
2008-01-21 James Henstridge <james@jamesh.id.au>
27

38
* setup.cfg (define): remove PSYCOPG_DISPLAY_SIZE from default

psycopg/connection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ HIDDEN void conn_close(connectionObject *self);
8383
HIDDEN int conn_commit(connectionObject *self);
8484
HIDDEN int conn_rollback(connectionObject *self);
8585
HIDDEN int conn_switch_isolation_level(connectionObject *self, int level);
86-
HIDDEN int conn_set_client_encoding(connectionObject *self, char *enc);
86+
HIDDEN int conn_set_client_encoding(connectionObject *self, const char *enc);
8787

8888
/* exception-raising macros */
8989
#define EXC_IF_CONN_CLOSED(self) if ((self)->closed > 0) { \

psycopg/connection_int.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ conn_switch_isolation_level(connectionObject *self, int level)
296296
/* conn_set_client_encoding - switch client encoding on connection */
297297

298298
int
299-
conn_set_client_encoding(connectionObject *self, char *enc)
299+
conn_set_client_encoding(connectionObject *self, const char *enc)
300300
{
301301
PGresult *pgres = NULL;
302302
char *error = NULL;

psycopg/typecast.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232

3333
/* usefull function used by some typecasters */
3434

35-
static char *
36-
skip_until_space(char *s)
35+
static const char *
36+
skip_until_space(const char *s)
3737
{
3838
while (*s && *s != ' ') s++;
3939
return s;
4040
}
4141

42-
static char *
43-
skip_until_space2(char *s, Py_ssize_t *len)
42+
static const char *
43+
skip_until_space2(const char *s, Py_ssize_t *len)
4444
{
4545
while (*len > 0 && *s && *s != ' ') {
4646
s++; (*len)--;
@@ -49,7 +49,7 @@ skip_until_space2(char *s, Py_ssize_t *len)
4949
}
5050

5151
static int
52-
typecast_parse_date(char* s, char** t, Py_ssize_t* len,
52+
typecast_parse_date(const char* s, const char** t, Py_ssize_t* len,
5353
int* year, int* month, int* day)
5454
{
5555
int acc = -1, cz = 0;
@@ -92,7 +92,7 @@ typecast_parse_date(char* s, char** t, Py_ssize_t* len,
9292
}
9393

9494
static int
95-
typecast_parse_time(char* s, char** t, Py_ssize_t* len,
95+
typecast_parse_time(const char* s, const char** t, Py_ssize_t* len,
9696
int* hh, int* mm, int* ss, int* us, int* tz)
9797
{
9898
int acc = -1, cz = 0;
@@ -556,7 +556,7 @@ typecast_from_c(typecastObject_initlist *type, PyObject *dict)
556556
}
557557

558558
PyObject *
559-
typecast_cast(PyObject *obj, char *str, Py_ssize_t len, PyObject *curs)
559+
typecast_cast(PyObject *obj, const char *str, Py_ssize_t len, PyObject *curs)
560560
{
561561
PyObject *old, *res = NULL;
562562
typecastObject *self = (typecastObject *)obj;

psycopg/typecast.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ extern "C" {
3232
#endif
3333

3434
/* type of type-casting functions (both C and Python) */
35-
typedef PyObject *(*typecast_function)(char *, Py_ssize_t len, PyObject *);
35+
typedef PyObject *(*typecast_function)(const char *str, Py_ssize_t len,
36+
PyObject *cursor);
3637

3738
/** typecast type **/
3839

@@ -83,6 +84,6 @@ HIDDEN PyObject *typecast_from_python(
8384

8485
/* the function used to dispatch typecasting calls */
8586
HIDDEN PyObject *typecast_cast(
86-
PyObject *self, char *str, Py_ssize_t len, PyObject *curs);
87+
PyObject *self, const char *str, Py_ssize_t len, PyObject *curs);
8788

8889
#endif /* !defined(PSYCOPG_TYPECAST_H) */

psycopg/typecast_array.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/** typecast_array_cleanup - remove the horrible [...]= stuff **/
2525

2626
static int
27-
typecast_array_cleanup(char **str, Py_ssize_t *len)
27+
typecast_array_cleanup(const char **str, Py_ssize_t *len)
2828
{
2929
Py_ssize_t i, depth = 1;
3030

@@ -53,7 +53,7 @@ typecast_array_cleanup(char **str, Py_ssize_t *len)
5353
#define ASCAN_QUOTED 4
5454

5555
static int
56-
typecast_array_tokenize(char *str, Py_ssize_t strlength,
56+
typecast_array_tokenize(const char *str, Py_ssize_t strlength,
5757
Py_ssize_t *pos, char** token,
5858
Py_ssize_t *length, int *quotes)
5959
{
@@ -148,7 +148,7 @@ typecast_array_tokenize(char *str, Py_ssize_t strlength,
148148
*length = (Py_ssize_t) (buffer - *token);
149149
}
150150
else {
151-
*token = &str[*pos];
151+
*token = (char *)&str[*pos];
152152
*length = l;
153153
}
154154

@@ -161,7 +161,7 @@ typecast_array_tokenize(char *str, Py_ssize_t strlength,
161161
}
162162

163163
static int
164-
typecast_array_scan(char *str, Py_ssize_t strlength,
164+
typecast_array_scan(const char *str, Py_ssize_t strlength,
165165
PyObject *curs, PyObject *base, PyObject *array)
166166
{
167167
int state, quotes = 0;
@@ -235,7 +235,7 @@ typecast_array_scan(char *str, Py_ssize_t strlength,
235235
have to be taken on the single items **/
236236

237237
static PyObject *
238-
typecast_GENERIC_ARRAY_cast(char *str, Py_ssize_t len, PyObject *curs)
238+
typecast_GENERIC_ARRAY_cast(const char *str, Py_ssize_t len, PyObject *curs)
239239
{
240240
PyObject *obj = NULL;
241241
PyObject *base = ((typecastObject*)((cursorObject*)curs)->caster)->bcast;

psycopg/typecast_basic.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/** INTEGER - cast normal integers (4 bytes) to python int **/
2323

2424
static PyObject *
25-
typecast_INTEGER_cast(char *s, Py_ssize_t len, PyObject *curs)
25+
typecast_INTEGER_cast(const char *s, Py_ssize_t len, PyObject *curs)
2626
{
2727
char buffer[12];
2828

@@ -31,13 +31,13 @@ typecast_INTEGER_cast(char *s, Py_ssize_t len, PyObject *curs)
3131
strncpy(buffer, s, (size_t) len); buffer[len] = '\0';
3232
s = buffer;
3333
}
34-
return PyInt_FromString(s, NULL, 0);
34+
return PyInt_FromString((char *)s, NULL, 0);
3535
}
3636

3737
/** LONGINTEGER - cast long integers (8 bytes) to python long **/
3838

3939
static PyObject *
40-
typecast_LONGINTEGER_cast(char *s, Py_ssize_t len, PyObject *curs)
40+
typecast_LONGINTEGER_cast(const char *s, Py_ssize_t len, PyObject *curs)
4141
{
4242
char buffer[24];
4343

@@ -46,13 +46,13 @@ typecast_LONGINTEGER_cast(char *s, Py_ssize_t len, PyObject *curs)
4646
strncpy(buffer, s, (size_t) len); buffer[len] = '\0';
4747
s = buffer;
4848
}
49-
return PyLong_FromString(s, NULL, 0);
49+
return PyLong_FromString((char *)s, NULL, 0);
5050
}
5151

5252
/** FLOAT - cast floating point numbers to python float **/
5353

5454
static PyObject *
55-
typecast_FLOAT_cast(char *s, Py_ssize_t len, PyObject *curs)
55+
typecast_FLOAT_cast(const char *s, Py_ssize_t len, PyObject *curs)
5656
{
5757
PyObject *str = NULL, *flo = NULL;
5858
char *pend;
@@ -67,7 +67,7 @@ typecast_FLOAT_cast(char *s, Py_ssize_t len, PyObject *curs)
6767
/** STRING - cast strings of any type to python string **/
6868

6969
static PyObject *
70-
typecast_STRING_cast(char *s, Py_ssize_t len, PyObject *curs)
70+
typecast_STRING_cast(const char *s, Py_ssize_t len, PyObject *curs)
7171
{
7272
if (s == NULL) {Py_INCREF(Py_None); return Py_None;}
7373
return PyString_FromStringAndSize(s, len);
@@ -76,7 +76,7 @@ typecast_STRING_cast(char *s, Py_ssize_t len, PyObject *curs)
7676
/** UNICODE - cast strings of any type to a python unicode object **/
7777

7878
static PyObject *
79-
typecast_UNICODE_cast(char *s, Py_ssize_t len, PyObject *curs)
79+
typecast_UNICODE_cast(const char *s, Py_ssize_t len, PyObject *curs)
8080
{
8181
PyObject *enc;
8282

@@ -98,7 +98,7 @@ typecast_UNICODE_cast(char *s, Py_ssize_t len, PyObject *curs)
9898
/** BOOLEAN - cast boolean value into right python object **/
9999

100100
static PyObject *
101-
typecast_BOOLEAN_cast(char *s, Py_ssize_t len, PyObject *curs)
101+
typecast_BOOLEAN_cast(const char *s, Py_ssize_t len, PyObject *curs)
102102
{
103103
PyObject *res;
104104

@@ -117,7 +117,7 @@ typecast_BOOLEAN_cast(char *s, Py_ssize_t len, PyObject *curs)
117117

118118
#ifdef HAVE_DECIMAL
119119
static PyObject *
120-
typecast_DECIMAL_cast(char *s, Py_ssize_t len, PyObject *curs)
120+
typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs)
121121
{
122122
PyObject *res = NULL;
123123
PyObject *decimalType;

psycopg/typecast_binary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ typecast_BINARY_cast_unescape(unsigned char *str, size_t *to_length)
156156
#endif
157157

158158
static PyObject *
159-
typecast_BINARY_cast(char *s, Py_ssize_t l, PyObject *curs)
159+
typecast_BINARY_cast(const char *s, Py_ssize_t l, PyObject *curs)
160160
{
161161
chunkObject *chunk = NULL;
162162
PyObject *res = NULL;

psycopg/typecast_datetime.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern PyObject *pyDeltaTypeP;
3434
/** DATE - cast a date into a date python object **/
3535

3636
static PyObject *
37-
typecast_PYDATE_cast(char *str, Py_ssize_t len, PyObject *curs)
37+
typecast_PYDATE_cast(const char *str, Py_ssize_t len, PyObject *curs)
3838
{
3939
PyObject* obj = NULL;
4040
int n, y=0, m=0, d=0;
@@ -70,12 +70,12 @@ typecast_PYDATE_cast(char *str, Py_ssize_t len, PyObject *curs)
7070
/** DATETIME - cast a timestamp into a datetime python object **/
7171

7272
static PyObject *
73-
typecast_PYDATETIME_cast(char *str, Py_ssize_t len, PyObject *curs)
73+
typecast_PYDATETIME_cast(const char *str, Py_ssize_t len, PyObject *curs)
7474
{
7575
PyObject* obj = NULL;
7676
int n, y=0, m=0, d=0;
7777
int hh=0, mm=0, ss=0, us=0, tz=0;
78-
char *tp = NULL;
78+
const char *tp = NULL;
7979

8080
if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
8181

@@ -144,7 +144,7 @@ typecast_PYDATETIME_cast(char *str, Py_ssize_t len, PyObject *curs)
144144
/** TIME - parse time into a time object **/
145145

146146
static PyObject *
147-
typecast_PYTIME_cast(char *str, Py_ssize_t len, PyObject *curs)
147+
typecast_PYTIME_cast(const char *str, Py_ssize_t len, PyObject *curs)
148148
{
149149
PyObject* obj = NULL;
150150
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)
172172
/** INTERVAL - parse an interval into a timedelta object **/
173173

174174
static PyObject *
175-
typecast_PYINTERVAL_cast(char *str, Py_ssize_t len, PyObject *curs)
175+
typecast_PYINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs)
176176
{
177177
long years = 0, months = 0, days = 0;
178178
double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0;

psycopg/typecast_mxdatetime.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ extern mxDateTimeModule_APIObject *mxDateTimeP;
2828
/** DATE - cast a date into mx.DateTime python object **/
2929

3030
static PyObject *
31-
typecast_MXDATE_cast(char *str, Py_ssize_t len, PyObject *curs)
31+
typecast_MXDATE_cast(const char *str, Py_ssize_t len, PyObject *curs)
3232
{
3333
int n, y=0, m=0, d=0;
3434
int hh=0, mm=0, ss=0, us=0, tz=0;
35-
char *tp = NULL;
35+
const char *tp = NULL;
3636

3737
if (str == NULL) {Py_INCREF(Py_None); return Py_None;}
3838

@@ -76,7 +76,7 @@ typecast_MXDATE_cast(char *str, Py_ssize_t len, PyObject *curs)
7676
/** TIME - parse time into an mx.DateTime object **/
7777

7878
static PyObject *
79-
typecast_MXTIME_cast(char *str, Py_ssize_t len, PyObject *curs)
79+
typecast_MXTIME_cast(const char *str, Py_ssize_t len, PyObject *curs)
8080
{
8181
int n, hh=0, mm=0, ss=0, us=0, tz=0;
8282

@@ -103,7 +103,7 @@ typecast_MXTIME_cast(char *str, Py_ssize_t len, PyObject *curs)
103103
/** INTERVAL - parse an interval into an mx.DateTimeDelta **/
104104

105105
static PyObject *
106-
typecast_MXINTERVAL_cast(char *str, Py_ssize_t len, PyObject *curs)
106+
typecast_MXINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs)
107107
{
108108
long years = 0, months = 0, days = 0, denominator = 1;
109109
double hours = 0.0, minutes = 0.0, seconds = 0.0, hundredths = 0.0;

0 commit comments

Comments
 (0)