summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-03-04 17:59:51 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2012-03-04 17:59:51 +0000
commit0e832b97ea7a84220f2148db3746e10f85eadef2 (patch)
tree747b74dfaa8bc058227ce56b965d14aad28bcf15
parent76cc838a93dc2e55c6ddd101a543bda61cba4550 (diff)
downloadpsycopg2-0e832b97ea7a84220f2148db3746e10f85eadef2.tar.gz
Proper type check in prepare() methods for list, binary, qstring
-rw-r--r--psycopg/adapter_binary.c10
-rw-r--r--psycopg/adapter_list.c6
-rw-r--r--psycopg/adapter_qstring.c14
3 files changed, 13 insertions, 17 deletions
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c
index 2574c60..da3bec6 100644
--- a/psycopg/adapter_binary.c
+++ b/psycopg/adapter_binary.c
@@ -149,16 +149,14 @@ binary_str(binaryObject *self)
static PyObject *
binary_prepare(binaryObject *self, PyObject *args)
{
- connectionObject *conn;
+ PyObject *conn;
- if (!PyArg_ParseTuple(args, "O", &conn))
+ if (!PyArg_ParseTuple(args, "O!", &connectionType, &conn))
return NULL;
Py_XDECREF(self->conn);
- if (conn) {
- self->conn = (PyObject*)conn;
- Py_INCREF(self->conn);
- }
+ self->conn = conn;
+ Py_INCREF(self->conn);
Py_INCREF(Py_None);
return Py_None;
diff --git a/psycopg/adapter_list.c b/psycopg/adapter_list.c
index cbb7542..d97ecfb 100644
--- a/psycopg/adapter_list.c
+++ b/psycopg/adapter_list.c
@@ -98,9 +98,9 @@ list_getquoted(listObject *self, PyObject *args)
static PyObject *
list_prepare(listObject *self, PyObject *args)
{
- connectionObject *conn;
+ PyObject *conn;
- if (!PyArg_ParseTuple(args, "O", &conn))
+ if (!PyArg_ParseTuple(args, "O!", &connectionType, &conn))
return NULL;
/* note that we don't copy the encoding from the connection, but take a
@@ -109,7 +109,7 @@ list_prepare(listObject *self, PyObject *args)
work even without a connection to the backend. */
Py_CLEAR(self->connection);
Py_INCREF(conn);
- self->connection = (PyObject*)conn;
+ self->connection = conn;
Py_INCREF(Py_None);
return Py_None;
diff --git a/psycopg/adapter_qstring.c b/psycopg/adapter_qstring.c
index 4240d38..773cfa0 100644
--- a/psycopg/adapter_qstring.c
+++ b/psycopg/adapter_qstring.c
@@ -124,24 +124,22 @@ qstring_str(qstringObject *self)
static PyObject *
qstring_prepare(qstringObject *self, PyObject *args)
{
- connectionObject *conn;
+ PyObject *conn;
- if (!PyArg_ParseTuple(args, "O", &conn))
+ if (!PyArg_ParseTuple(args, "O!", &connectionType, &conn))
return NULL;
/* we bother copying the encoding only if the wrapped string is unicode,
we don't need the encoding if that's not the case */
if (PyUnicode_Check(self->wrapped)) {
if (self->encoding) free(self->encoding);
- self->encoding = strdup(conn->codec);
- Dprintf("qstring_prepare: set encoding to %s", conn->codec);
+ self->encoding = strdup(((connectionObject *)conn)->codec);
+ Dprintf("qstring_prepare: set encoding to %s", self->encoding);
}
Py_CLEAR(self->conn);
- if (conn) {
- Py_INCREF(conn);
- self->conn = (PyObject*)conn;
- }
+ Py_INCREF(conn);
+ self->conn = conn;
Py_INCREF(Py_None);
return Py_None;