From 96a950d3eb188803164d748aaf61d81b9bb985c5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 30 Dec 2010 01:30:09 +0100 Subject: [PATCH] Fixed 2-phase commit support in Python 3. --- psycopg/connection_int.c | 2 +- psycopg/xid_type.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 6d281b36..83c77ad0 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -1050,7 +1050,7 @@ conn_tpc_command(connectionObject *self, const char *cmd, XidObject *xid) Dprintf("conn_tpc_command: %s", cmd); /* convert the xid into PostgreSQL transaction id while keeping the GIL */ - if (!(tid = xid_get_tid(xid))) { goto exit; } + if (!(tid = psycopg_ensure_bytes(xid_get_tid(xid)))) { goto exit; } if (!(ctid = Bytes_AsString(tid))) { goto exit; } Py_BEGIN_ALLOW_THREADS; diff --git a/psycopg/xid_type.c b/psycopg/xid_type.c index 51cd4490..29577492 100644 --- a/psycopg/xid_type.c +++ b/psycopg/xid_type.c @@ -399,7 +399,11 @@ _xid_base64_enc_dec(const char *funcname, PyObject *s) if (!(base64 = PyImport_ImportModule("base64"))) { goto exit; } if (!(func = PyObject_GetAttrString(base64, funcname))) { goto exit; } - rv = PyObject_CallFunctionObjArgs(func, s, NULL); + + Py_INCREF(s); + if (!(s = psycopg_ensure_bytes(s))) { goto exit; } + rv = psycopg_ensure_text(PyObject_CallFunctionObjArgs(func, s, NULL)); + Py_DECREF(s); exit: Py_XDECREF(func);