Proper type check in prepare() methods for list, binary, qstring

This commit is contained in:
Daniele Varrazzo 2012-03-04 17:59:51 +00:00
parent 76cc838a93
commit 0e832b97ea
3 changed files with 13 additions and 17 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;