From 2046ae34fbeb32a6ed38fa829df809c34aa4344f Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Tue, 6 May 2008 17:09:43 +0800 Subject: [PATCH] * psycopg/lobject*: const'ify the code. --- ChangeLog | 2 ++ psycopg/lobject.h | 10 ++++++---- psycopg/lobject_int.c | 6 +++--- psycopg/lobject_type.c | 8 ++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c132555..d755d18b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2008-05-06 James Henstridge + * psycopg/lobject*: const'ify the code. + * tests/test_lobject.py (LargeObjectTests): add more tests, including behaviour on closed lobjects and stale lobjects. diff --git a/psycopg/lobject.h b/psycopg/lobject.h index 9f6bce32..d6dd9793 100644 --- a/psycopg/lobject.h +++ b/psycopg/lobject.h @@ -42,7 +42,7 @@ typedef struct { int closed; /* 1 if the lobject is closed */ int mode; /* numeric mode, tells if lobject was opened */ - char *smode; /* string mode if lobject was opened */ + const char *smode; /* string mode if lobject was opened */ long int mark; /* copied from conn->mark */ @@ -53,12 +53,14 @@ typedef struct { /* functions exported from lobject_int.c */ HIDDEN int lobject_open(lobjectObject *self, connectionObject *conn, - Oid oid, int mode, Oid new_oid, char *new_file); + Oid oid, int mode, Oid new_oid, + const char *new_file); HIDDEN int lobject_unlink(lobjectObject *self); -HIDDEN int lobject_export(lobjectObject *self, char *filename); +HIDDEN int lobject_export(lobjectObject *self, const char *filename); HIDDEN Py_ssize_t lobject_read(lobjectObject *self, char *buf, size_t len); -HIDDEN Py_ssize_t lobject_write(lobjectObject *self, char *buf, size_t len); +HIDDEN Py_ssize_t lobject_write(lobjectObject *self, const char *buf, + size_t len); HIDDEN int lobject_seek(lobjectObject *self, int pos, int whence); HIDDEN int lobject_tell(lobjectObject *self); HIDDEN int lobject_close(lobjectObject *self); diff --git a/psycopg/lobject_int.c b/psycopg/lobject_int.c index 476f236d..13f30bd6 100644 --- a/psycopg/lobject_int.c +++ b/psycopg/lobject_int.c @@ -45,7 +45,7 @@ collect_error(connectionObject *conn, char **error) int lobject_open(lobjectObject *self, connectionObject *conn, - Oid oid, int mode, Oid new_oid, char *new_file) + Oid oid, int mode, Oid new_oid, const char *new_file) { int retvalue = -1; PGresult *pgres = NULL; @@ -198,7 +198,7 @@ lobject_unlink(lobjectObject *self) /* lobject_write - write bytes to a lo */ Py_ssize_t -lobject_write(lobjectObject *self, char *buf, size_t len) +lobject_write(lobjectObject *self, const char *buf, size_t len) { Py_ssize_t written; PGresult *pgres = NULL; @@ -301,7 +301,7 @@ lobject_tell(lobjectObject *self) /* lobject_export - export to a local file */ int -lobject_export(lobjectObject *self, char *filename) +lobject_export(lobjectObject *self, const char *filename) { PGresult *pgres = NULL; char *error = NULL; diff --git a/psycopg/lobject_type.c b/psycopg/lobject_type.c index 690e4b6a..e191bdf1 100644 --- a/psycopg/lobject_type.c +++ b/psycopg/lobject_type.c @@ -74,7 +74,7 @@ static PyObject * psyco_lobj_write(lobjectObject *self, PyObject *args) { int len, res=0; - char *buffer; + const char *buffer; if (!PyArg_ParseTuple(args, "s#", &buffer, &len)) return NULL; @@ -191,7 +191,7 @@ psyco_lobj_unlink(lobjectObject *self, PyObject *args) static PyObject * psyco_lobj_export(lobjectObject *self, PyObject *args) { - char *filename; + const char *filename; if (!PyArg_ParseTuple(args, "s", &filename)) return NULL; @@ -244,7 +244,7 @@ static struct PyMemberDef lobjectObject_members[] = { static int lobject_setup(lobjectObject *self, connectionObject *conn, - Oid oid, int mode, Oid new_oid, char *new_file) + Oid oid, int mode, Oid new_oid, const char *new_file) { Dprintf("lobject_setup: init lobject object at %p", self); @@ -292,7 +292,7 @@ lobject_init(PyObject *obj, PyObject *args, PyObject *kwds) { Oid oid=InvalidOid, new_oid=InvalidOid; int mode=0; - char *new_file = NULL; + const char *new_file = NULL; PyObject *conn; if (!PyArg_ParseTuple(args, "O|iiis",