summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Henstridge <james@jamesh.id.au>2008-01-21 21:01:08 +0000
committerJames Henstridge <james@jamesh.id.au>2008-01-21 21:01:08 +0000
commite054004e8fbf083f730a624bff9c48ca29460898 (patch)
treeee3fca339303acc0637393c1b6e4ea84fe067535
parenteae563ac96342e35b9f7373871ff8b13ff45127d (diff)
downloadpsycopg2-e054004e8fbf083f730a624bff9c48ca29460898.tar.gz
Add more const qualifiers.
-rw-r--r--psycopg/adapter_list.c6
-rw-r--r--psycopg/adapter_qstring.c8
-rw-r--r--psycopg/connection_int.c18
-rw-r--r--psycopg/connection_type.c9
-rw-r--r--psycopg/cursor_type.c27
-rw-r--r--psycopg/psycopgmodule.c11
6 files changed, 41 insertions, 38 deletions
diff --git a/psycopg/adapter_list.c b/psycopg/adapter_list.c
index 2ce2e60..b6022bd 100644
--- a/psycopg/adapter_list.c
+++ b/psycopg/adapter_list.c
@@ -155,7 +155,7 @@ static PyMethodDef listObject_methods[] = {
/* initialization and finalization methods */
static int
-list_setup(listObject *self, PyObject *obj, char *enc)
+list_setup(listObject *self, PyObject *obj, const char *enc)
{
Dprintf("list_setup: init list object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
@@ -198,7 +198,7 @@ static int
list_init(PyObject *obj, PyObject *args, PyObject *kwds)
{
PyObject *l;
- char *enc = "latin-1"; /* default encoding as in Python */
+ const char *enc = "latin-1"; /* default encoding as in Python */
if (!PyArg_ParseTuple(args, "O|s", &l, &enc))
return -1;
@@ -297,7 +297,7 @@ PyObject *
psyco_List(PyObject *module, PyObject *args)
{
PyObject *str;
- char *enc = "latin-1"; /* default encoding as in Python */
+ const char *enc = "latin-1"; /* default encoding as in Python */
if (!PyArg_ParseTuple(args, "O|s", &str, &enc))
return NULL;
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index cebb521..3684039 100644
--- a/psycopg/adapter_qstring.c
+++ b/psycopg/adapter_qstring.c
@@ -110,7 +110,7 @@ qstring_quote(qstringObject *self)
/* note that enc is a borrowed reference */
if (enc) {
- char *s = PyString_AsString(enc);
+ const char *s = PyString_AsString(enc);
Dprintf("qstring_quote: encoding unicode object to %s", s);
str = PyUnicode_AsEncodedString(self->wrapped, s, NULL);
Dprintf("qstring_quote: got encoded object at %p", str);
@@ -267,7 +267,7 @@ static PyMethodDef qstringObject_methods[] = {
/* initialization and finalization methods */
static int
-qstring_setup(qstringObject *self, PyObject *str, char *enc)
+qstring_setup(qstringObject *self, PyObject *str, const char *enc)
{
Dprintf("qstring_setup: init qstring object at %p, refcnt = "
FORMAT_CODE_PY_SSIZE_T,
@@ -313,7 +313,7 @@ static int
qstring_init(PyObject *obj, PyObject *args, PyObject *kwds)
{
PyObject *str;
- char *enc = "latin-1"; /* default encoding as in Python */
+ const char *enc = "latin-1"; /* default encoding as in Python */
if (!PyArg_ParseTuple(args, "O|s", &str, &enc))
return -1;
@@ -413,7 +413,7 @@ PyObject *
psyco_QuotedString(PyObject *module, PyObject *args)
{
PyObject *str;
- char *enc = "latin-1"; /* default encoding as in Python */
+ const char *enc = "latin-1"; /* default encoding as in Python */
if (!PyArg_ParseTuple(args, "O|s", &str, &enc))
return NULL;
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c
index 2cc7818..c5ba1ec 100644
--- a/psycopg/connection_int.c
+++ b/psycopg/connection_int.c
@@ -61,20 +61,20 @@ conn_connect(connectionObject *self)
{
PGconn *pgconn;
PGresult *pgres;
- char *data, *tmp;
+ const char *data, *tmp;
const char *scs; /* standard-conforming strings */
size_t i;
/* we need the initial date style to be ISO, for typecasters; if the user
later change it, she must know what she's doing... */
- const char *datestyle = "SET DATESTYLE TO 'ISO'";
- const char *encoding = "SHOW client_encoding";
- const char *isolevel = "SHOW default_transaction_isolation";
-
- const char *lvl1a = "read uncommitted";
- const char *lvl1b = "read committed";
- const char *lvl2a = "repeatable read";
- const char *lvl2b = "serializable";
+ const char datestyle[] = "SET DATESTYLE TO 'ISO'";
+ const char encoding[] = "SHOW client_encoding";
+ const char isolevel[] = "SHOW default_transaction_isolation";
+
+ const char lvl1a[] = "read uncommitted";
+ const char lvl1b[] = "read committed";
+ const char lvl2a[] = "repeatable read";
+ const char lvl2b[] = "serializable";
Py_BEGIN_ALLOW_THREADS;
pgconn = PQconnectdb(self->dsn);
diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c
index 92a0686..38ca5f9 100644
--- a/psycopg/connection_type.c
+++ b/psycopg/connection_type.c
@@ -49,7 +49,7 @@
static PyObject *
psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds)
{
- char *name = NULL;
+ const char *name = NULL;
PyObject *obj, *factory = NULL;
static char *kwlist[] = {"name", "cursor_factory", NULL};
@@ -186,7 +186,8 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args)
static PyObject *
psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
{
- char *buffer, *enc = NULL;
+ const char *enc = NULL;
+ char *buffer;
size_t i, j;
EXC_IF_CONN_CLOSED(self);
@@ -313,7 +314,7 @@ static struct PyGetSetDef connectionObject_getsets[] = {
/* initialization and finalization methods */
static int
-connection_setup(connectionObject *self, char *dsn)
+connection_setup(connectionObject *self, const char *dsn)
{
char *pos;
int res;
@@ -389,7 +390,7 @@ connection_dealloc(PyObject* obj)
static int
connection_init(PyObject *obj, PyObject *args, PyObject *kwds)
{
- char *dsn;
+ const char *dsn;
if (!PyArg_ParseTuple(args, "s", &dsn))
return -1;
diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c
index 083826f..a17847e 100644
--- a/psycopg/cursor_type.c
+++ b/psycopg/cursor_type.c
@@ -371,7 +371,7 @@ _psyco_curs_execute(cursorObject *self,
if (PyObject_HasAttrString(arg, "args")) {
PyObject *args = PyObject_GetAttrString(arg, "args");
PyObject *str = PySequence_GetItem(args, 0);
- char *s = PyString_AS_STRING(str);
+ const char *s = PyString_AS_STRING(str);
Dprintf("psyco_curs_execute: -> %s", s);
@@ -586,7 +586,7 @@ psyco_curs_mogrify(cursorObject *self, PyObject *args, PyObject *kwargs)
if (PyObject_HasAttrString(arg, "args")) {
PyObject *args = PyObject_GetAttrString(arg, "args");
PyObject *str = PySequence_GetItem(args, 0);
- char *s = PyString_AS_STRING(str);
+ const char *s = PyString_AS_STRING(str);
Dprintf("psyco_curs_execute: -> %s", s);
@@ -675,7 +675,7 @@ _psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
int row, int n, int istuple)
{
int i, len;
- unsigned char *str;
+ const char *str;
PyObject *val;
for (i=0; i < n; i++) {
@@ -684,14 +684,14 @@ _psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
len = 0;
}
else {
- str = (unsigned char*)PQgetvalue(self->pgres, row, i);
+ str = PQgetvalue(self->pgres, row, i);
len = PQgetlength(self->pgres, row, i);
}
Dprintf("_psyco_curs_buildrow: row %ld, element %d, len %d",
self->row, i, len);
- val = typecast_cast(PyTuple_GET_ITEM(self->casts, i), (char*)str, len,
+ val = typecast_cast(PyTuple_GET_ITEM(self->casts, i), str, len,
(PyObject*)self);
if (val) {
@@ -935,7 +935,8 @@ psyco_curs_fetchall(cursorObject *self, PyObject *args)
static PyObject *
psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs)
{
- char *procname = NULL, *sql = NULL;
+ const char *procname = NULL;
+ char *sql = NULL;
long int async = 0;
Py_ssize_t procname_len, i, nparameters = 0, sl = 0;
PyObject *parameters = Py_None;
@@ -1055,7 +1056,7 @@ static PyObject *
psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs)
{
int value, newpos;
- char *mode = "relative";
+ const char *mode = "relative";
static char *kwlist[] = {"value", "mode", NULL};
@@ -1186,8 +1187,8 @@ static PyObject *
psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
{
char query[DEFAULT_COPYBUFF];
- char *table_name;
- char *sep = "\t", *null = NULL;
+ const char *table_name;
+ const char *sep = "\t", *null = NULL;
Py_ssize_t bufsize = DEFAULT_COPYBUFF;
PyObject *file, *columns = NULL, *res = NULL;
char columnlist[DEFAULT_COPYBUFF];
@@ -1260,8 +1261,8 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
{
char query[DEFAULT_COPYBUFF];
char columnlist[DEFAULT_COPYBUFF];
- char *table_name;
- char *sep = "\t", *null = NULL;
+ const char *table_name;
+ const char *sep = "\t", *null = NULL;
PyObject *file, *columns = NULL, *res = NULL;
static char *kwlist[] = {"file", "table", "sep", "null", "columns", NULL};
@@ -1570,7 +1571,7 @@ static struct PyGetSetDef cursorObject_getsets[] = {
/* initialization and finalization methods */
static int
-cursor_setup(cursorObject *self, connectionObject *conn, char *name)
+cursor_setup(cursorObject *self, connectionObject *conn, const char *name)
{
Dprintf("cursor_setup: init cursor object at %p", self);
Dprintf("cursor_setup: parameters: name = %s, conn = %p", name, conn);
@@ -1655,7 +1656,7 @@ cursor_dealloc(PyObject* obj)
static int
cursor_init(PyObject *obj, PyObject *args, PyObject *kwds)
{
- char *name = NULL;
+ const char *name = NULL;
PyObject *conn;
if (!PyArg_ParseTuple(args, "O|s", &conn, &name))
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index a212ba4..b74abdc 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -93,7 +93,7 @@ int psycopg_debug_enabled = 0;
":rtype: `extensions.connection`"
static size_t
-_psyco_connect_fill_dsn(char *dsn, char *kw, char *v, size_t i)
+_psyco_connect_fill_dsn(char *dsn, const char *kw, const char *v, size_t i)
{
strcpy(&dsn[i], kw); i += strlen(kw);
strcpy(&dsn[i], v); i += strlen(v);
@@ -108,9 +108,10 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
size_t idsn=-1;
int iport=-1;
- char *dsn_static=NULL, *dsn_dynamic=NULL;
- char *database=NULL, *user=NULL, *password=NULL;
- char *host=NULL, *sslmode=NULL;
+ const char *dsn_static = NULL;
+ char *dsn_dynamic=NULL;
+ const char *database=NULL, *user=NULL, *password=NULL;
+ const char *host=NULL, *sslmode=NULL;
char port[16];
static char *kwlist[] = {"dsn", "database", "host", "port",
@@ -415,7 +416,7 @@ static struct {
char *name;
PyObject **exc;
PyObject **base;
- char *docstr;
+ const char *docstr;
} exctable[] = {
{ "psycopg2.Error", &Error, 0, Error_doc },
{ "psycopg2.Warning", &Warning, 0, Warning_doc },