mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-29 20:23:45 +03:00
Add more const qualifiers.
This commit is contained in:
parent
eae563ac96
commit
e054004e8f
|
@ -155,7 +155,7 @@ static PyMethodDef listObject_methods[] = {
|
||||||
/* initialization and finalization methods */
|
/* initialization and finalization methods */
|
||||||
|
|
||||||
static int
|
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 = "
|
Dprintf("list_setup: init list object at %p, refcnt = "
|
||||||
FORMAT_CODE_PY_SSIZE_T,
|
FORMAT_CODE_PY_SSIZE_T,
|
||||||
|
@ -198,7 +198,7 @@ static int
|
||||||
list_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
list_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyObject *l;
|
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))
|
if (!PyArg_ParseTuple(args, "O|s", &l, &enc))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -297,7 +297,7 @@ PyObject *
|
||||||
psyco_List(PyObject *module, PyObject *args)
|
psyco_List(PyObject *module, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *str;
|
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))
|
if (!PyArg_ParseTuple(args, "O|s", &str, &enc))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -110,7 +110,7 @@ qstring_quote(qstringObject *self)
|
||||||
/* note that enc is a borrowed reference */
|
/* note that enc is a borrowed reference */
|
||||||
|
|
||||||
if (enc) {
|
if (enc) {
|
||||||
char *s = PyString_AsString(enc);
|
const char *s = PyString_AsString(enc);
|
||||||
Dprintf("qstring_quote: encoding unicode object to %s", s);
|
Dprintf("qstring_quote: encoding unicode object to %s", s);
|
||||||
str = PyUnicode_AsEncodedString(self->wrapped, s, NULL);
|
str = PyUnicode_AsEncodedString(self->wrapped, s, NULL);
|
||||||
Dprintf("qstring_quote: got encoded object at %p", str);
|
Dprintf("qstring_quote: got encoded object at %p", str);
|
||||||
|
@ -267,7 +267,7 @@ static PyMethodDef qstringObject_methods[] = {
|
||||||
/* initialization and finalization methods */
|
/* initialization and finalization methods */
|
||||||
|
|
||||||
static int
|
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 = "
|
Dprintf("qstring_setup: init qstring object at %p, refcnt = "
|
||||||
FORMAT_CODE_PY_SSIZE_T,
|
FORMAT_CODE_PY_SSIZE_T,
|
||||||
|
@ -313,7 +313,7 @@ static int
|
||||||
qstring_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
qstring_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PyObject *str;
|
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))
|
if (!PyArg_ParseTuple(args, "O|s", &str, &enc))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -413,7 +413,7 @@ PyObject *
|
||||||
psyco_QuotedString(PyObject *module, PyObject *args)
|
psyco_QuotedString(PyObject *module, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *str;
|
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))
|
if (!PyArg_ParseTuple(args, "O|s", &str, &enc))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -61,20 +61,20 @@ conn_connect(connectionObject *self)
|
||||||
{
|
{
|
||||||
PGconn *pgconn;
|
PGconn *pgconn;
|
||||||
PGresult *pgres;
|
PGresult *pgres;
|
||||||
char *data, *tmp;
|
const char *data, *tmp;
|
||||||
const char *scs; /* standard-conforming strings */
|
const char *scs; /* standard-conforming strings */
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* we need the initial date style to be ISO, for typecasters; if the user
|
/* we need the initial date style to be ISO, for typecasters; if the user
|
||||||
later change it, she must know what she's doing... */
|
later change it, she must know what she's doing... */
|
||||||
const char *datestyle = "SET DATESTYLE TO 'ISO'";
|
const char datestyle[] = "SET DATESTYLE TO 'ISO'";
|
||||||
const char *encoding = "SHOW client_encoding";
|
const char encoding[] = "SHOW client_encoding";
|
||||||
const char *isolevel = "SHOW default_transaction_isolation";
|
const char isolevel[] = "SHOW default_transaction_isolation";
|
||||||
|
|
||||||
const char *lvl1a = "read uncommitted";
|
const char lvl1a[] = "read uncommitted";
|
||||||
const char *lvl1b = "read committed";
|
const char lvl1b[] = "read committed";
|
||||||
const char *lvl2a = "repeatable read";
|
const char lvl2a[] = "repeatable read";
|
||||||
const char *lvl2b = "serializable";
|
const char lvl2b[] = "serializable";
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS;
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
pgconn = PQconnectdb(self->dsn);
|
pgconn = PQconnectdb(self->dsn);
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
static PyObject *
|
static PyObject *
|
||||||
psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds)
|
psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *keywds)
|
||||||
{
|
{
|
||||||
char *name = NULL;
|
const char *name = NULL;
|
||||||
PyObject *obj, *factory = NULL;
|
PyObject *obj, *factory = NULL;
|
||||||
|
|
||||||
static char *kwlist[] = {"name", "cursor_factory", NULL};
|
static char *kwlist[] = {"name", "cursor_factory", NULL};
|
||||||
|
@ -186,7 +186,8 @@ psyco_conn_set_isolation_level(connectionObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
psyco_conn_set_client_encoding(connectionObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *buffer, *enc = NULL;
|
const char *enc = NULL;
|
||||||
|
char *buffer;
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
|
||||||
EXC_IF_CONN_CLOSED(self);
|
EXC_IF_CONN_CLOSED(self);
|
||||||
|
@ -313,7 +314,7 @@ static struct PyGetSetDef connectionObject_getsets[] = {
|
||||||
/* initialization and finalization methods */
|
/* initialization and finalization methods */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
connection_setup(connectionObject *self, char *dsn)
|
connection_setup(connectionObject *self, const char *dsn)
|
||||||
{
|
{
|
||||||
char *pos;
|
char *pos;
|
||||||
int res;
|
int res;
|
||||||
|
@ -389,7 +390,7 @@ connection_dealloc(PyObject* obj)
|
||||||
static int
|
static int
|
||||||
connection_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
connection_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
char *dsn;
|
const char *dsn;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s", &dsn))
|
if (!PyArg_ParseTuple(args, "s", &dsn))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -371,7 +371,7 @@ _psyco_curs_execute(cursorObject *self,
|
||||||
if (PyObject_HasAttrString(arg, "args")) {
|
if (PyObject_HasAttrString(arg, "args")) {
|
||||||
PyObject *args = PyObject_GetAttrString(arg, "args");
|
PyObject *args = PyObject_GetAttrString(arg, "args");
|
||||||
PyObject *str = PySequence_GetItem(args, 0);
|
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);
|
Dprintf("psyco_curs_execute: -> %s", s);
|
||||||
|
|
||||||
|
@ -586,7 +586,7 @@ psyco_curs_mogrify(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
if (PyObject_HasAttrString(arg, "args")) {
|
if (PyObject_HasAttrString(arg, "args")) {
|
||||||
PyObject *args = PyObject_GetAttrString(arg, "args");
|
PyObject *args = PyObject_GetAttrString(arg, "args");
|
||||||
PyObject *str = PySequence_GetItem(args, 0);
|
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);
|
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 row, int n, int istuple)
|
||||||
{
|
{
|
||||||
int i, len;
|
int i, len;
|
||||||
unsigned char *str;
|
const char *str;
|
||||||
PyObject *val;
|
PyObject *val;
|
||||||
|
|
||||||
for (i=0; i < n; i++) {
|
for (i=0; i < n; i++) {
|
||||||
|
@ -684,14 +684,14 @@ _psyco_curs_buildrow_fill(cursorObject *self, PyObject *res,
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
str = (unsigned char*)PQgetvalue(self->pgres, row, i);
|
str = PQgetvalue(self->pgres, row, i);
|
||||||
len = PQgetlength(self->pgres, row, i);
|
len = PQgetlength(self->pgres, row, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dprintf("_psyco_curs_buildrow: row %ld, element %d, len %d",
|
Dprintf("_psyco_curs_buildrow: row %ld, element %d, len %d",
|
||||||
self->row, i, len);
|
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);
|
(PyObject*)self);
|
||||||
|
|
||||||
if (val) {
|
if (val) {
|
||||||
|
@ -935,7 +935,8 @@ psyco_curs_fetchall(cursorObject *self, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
psyco_curs_callproc(cursorObject *self, PyObject *args, PyObject *kwargs)
|
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;
|
long int async = 0;
|
||||||
Py_ssize_t procname_len, i, nparameters = 0, sl = 0;
|
Py_ssize_t procname_len, i, nparameters = 0, sl = 0;
|
||||||
PyObject *parameters = Py_None;
|
PyObject *parameters = Py_None;
|
||||||
|
@ -1055,7 +1056,7 @@ static PyObject *
|
||||||
psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs)
|
psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
int value, newpos;
|
int value, newpos;
|
||||||
char *mode = "relative";
|
const char *mode = "relative";
|
||||||
|
|
||||||
static char *kwlist[] = {"value", "mode", NULL};
|
static char *kwlist[] = {"value", "mode", NULL};
|
||||||
|
|
||||||
|
@ -1186,8 +1187,8 @@ static PyObject *
|
||||||
psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
|
psyco_curs_copy_from(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
char query[DEFAULT_COPYBUFF];
|
char query[DEFAULT_COPYBUFF];
|
||||||
char *table_name;
|
const char *table_name;
|
||||||
char *sep = "\t", *null = NULL;
|
const char *sep = "\t", *null = NULL;
|
||||||
Py_ssize_t bufsize = DEFAULT_COPYBUFF;
|
Py_ssize_t bufsize = DEFAULT_COPYBUFF;
|
||||||
PyObject *file, *columns = NULL, *res = NULL;
|
PyObject *file, *columns = NULL, *res = NULL;
|
||||||
char columnlist[DEFAULT_COPYBUFF];
|
char columnlist[DEFAULT_COPYBUFF];
|
||||||
|
@ -1260,8 +1261,8 @@ psyco_curs_copy_to(cursorObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
char query[DEFAULT_COPYBUFF];
|
char query[DEFAULT_COPYBUFF];
|
||||||
char columnlist[DEFAULT_COPYBUFF];
|
char columnlist[DEFAULT_COPYBUFF];
|
||||||
char *table_name;
|
const char *table_name;
|
||||||
char *sep = "\t", *null = NULL;
|
const char *sep = "\t", *null = NULL;
|
||||||
PyObject *file, *columns = NULL, *res = NULL;
|
PyObject *file, *columns = NULL, *res = NULL;
|
||||||
|
|
||||||
static char *kwlist[] = {"file", "table", "sep", "null", "columns", NULL};
|
static char *kwlist[] = {"file", "table", "sep", "null", "columns", NULL};
|
||||||
|
@ -1570,7 +1571,7 @@ static struct PyGetSetDef cursorObject_getsets[] = {
|
||||||
/* initialization and finalization methods */
|
/* initialization and finalization methods */
|
||||||
|
|
||||||
static int
|
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: init cursor object at %p", self);
|
||||||
Dprintf("cursor_setup: parameters: name = %s, conn = %p", name, conn);
|
Dprintf("cursor_setup: parameters: name = %s, conn = %p", name, conn);
|
||||||
|
@ -1655,7 +1656,7 @@ cursor_dealloc(PyObject* obj)
|
||||||
static int
|
static int
|
||||||
cursor_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
cursor_init(PyObject *obj, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
char *name = NULL;
|
const char *name = NULL;
|
||||||
PyObject *conn;
|
PyObject *conn;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|s", &conn, &name))
|
if (!PyArg_ParseTuple(args, "O|s", &conn, &name))
|
||||||
|
|
|
@ -93,7 +93,7 @@ int psycopg_debug_enabled = 0;
|
||||||
":rtype: `extensions.connection`"
|
":rtype: `extensions.connection`"
|
||||||
|
|
||||||
static size_t
|
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], kw); i += strlen(kw);
|
||||||
strcpy(&dsn[i], v); i += strlen(v);
|
strcpy(&dsn[i], v); i += strlen(v);
|
||||||
|
@ -108,9 +108,10 @@ psyco_connect(PyObject *self, PyObject *args, PyObject *keywds)
|
||||||
|
|
||||||
size_t idsn=-1;
|
size_t idsn=-1;
|
||||||
int iport=-1;
|
int iport=-1;
|
||||||
char *dsn_static=NULL, *dsn_dynamic=NULL;
|
const char *dsn_static = NULL;
|
||||||
char *database=NULL, *user=NULL, *password=NULL;
|
char *dsn_dynamic=NULL;
|
||||||
char *host=NULL, *sslmode=NULL;
|
const char *database=NULL, *user=NULL, *password=NULL;
|
||||||
|
const char *host=NULL, *sslmode=NULL;
|
||||||
char port[16];
|
char port[16];
|
||||||
|
|
||||||
static char *kwlist[] = {"dsn", "database", "host", "port",
|
static char *kwlist[] = {"dsn", "database", "host", "port",
|
||||||
|
@ -415,7 +416,7 @@ static struct {
|
||||||
char *name;
|
char *name;
|
||||||
PyObject **exc;
|
PyObject **exc;
|
||||||
PyObject **base;
|
PyObject **base;
|
||||||
char *docstr;
|
const char *docstr;
|
||||||
} exctable[] = {
|
} exctable[] = {
|
||||||
{ "psycopg2.Error", &Error, 0, Error_doc },
|
{ "psycopg2.Error", &Error, 0, Error_doc },
|
||||||
{ "psycopg2.Warning", &Warning, 0, Warning_doc },
|
{ "psycopg2.Warning", &Warning, 0, Warning_doc },
|
||||||
|
|
Loading…
Reference in New Issue
Block a user