diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-05 02:48:11 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2012-03-05 02:48:11 +0000 |
commit | b8c75d9de0874481ebbe6bd39ba16399ef7b3995 (patch) | |
tree | 4b1e7ee931329dace42df4a46ab6d98a21969f6f /psycopg/adapter_binary.c | |
parent | 37aa62ca52149360331e54740a2f70567343710e (diff) | |
parent | 2c309dfdb46cce51ff17688c97b391e39f2a392e (diff) | |
download | psycopg2-b8c75d9de0874481ebbe6bd39ba16399ef7b3995.tar.gz |
Merge branch 'gcc-python-plugin' into devel
Diffstat (limited to 'psycopg/adapter_binary.c')
-rw-r--r-- | psycopg/adapter_binary.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/psycopg/adapter_binary.c b/psycopg/adapter_binary.c index 2574c60..b08c144 100644 --- a/psycopg/adapter_binary.c +++ b/psycopg/adapter_binary.c @@ -65,6 +65,13 @@ binary_quote(binaryObject *self) int got_view = 0; #endif + /* Allow Binary(None) to work */ + if (self->wrapped == Py_None) { + Py_INCREF(psyco_null); + rv = psyco_null; + goto exit; + } + /* if we got a plain string or a buffer we escape it and save the buffer */ #if HAS_MEMORYVIEW @@ -93,7 +100,7 @@ binary_quote(binaryObject *self) /* escape and build quoted buffer */ - to = (char *)binary_escape((unsigned char*)buffer, (size_t) buffer_len, + to = (char *)binary_escape((unsigned char*)buffer, (size_t)buffer_len, &len, self->conn ? ((connectionObject*)self->conn)->pgconn : NULL); if (to == NULL) { PyErr_NoMemory(); @@ -113,12 +120,6 @@ exit: if (got_view) { PyBuffer_Release(&view); } #endif - /* Allow Binary(None) to work */ - if (self->wrapped == Py_None) { - Py_INCREF(psyco_null); - rv = psyco_null; - } - /* if the wrapped object is not bytes or a buffer, this is an error */ if (!rv && !PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "can't escape %s to binary", @@ -149,16 +150,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; |