From 76c7f4a0b5f3ff69499239917fb0aec8b0da6adf Mon Sep 17 00:00:00 2001 From: Oleksandr Shulgin Date: Thu, 22 Oct 2015 16:17:08 +0200 Subject: [PATCH] Use direct call to consume() callable in pq_copy_both() --- psycopg/pqpath.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index d6886981..30a3d394 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -1737,12 +1737,11 @@ pq_copy_both(replicationCursorObject *repl, PyObject *consume, int decode, connectionObject *conn = curs->conn; PGconn *pgconn = conn->pgconn; PyObject *msg, *tmp = NULL; - PyObject *consume_func = NULL; int fd, sel, ret = -1; fd_set fds; struct timeval keep_intr, curr_time, ping_time, timeout; - if (!(consume_func = PyObject_GetAttrString(consume, "__call__"))) { + if (!PyCallable_Check(consume)) { Dprintf("pq_copy_both: expected callable consume object"); goto exit; } @@ -1804,11 +1803,11 @@ pq_copy_both(replicationCursorObject *repl, PyObject *consume, int decode, continue; } else { - tmp = PyObject_CallFunctionObjArgs(consume_func, msg, NULL); + tmp = PyObject_CallFunctionObjArgs(consume, msg, NULL); Py_DECREF(msg); if (tmp == NULL) { - Dprintf("pq_copy_both: consume_func returned NULL"); + Dprintf("pq_copy_both: consume returned NULL"); goto exit; } Py_DECREF(tmp); @@ -1818,7 +1817,6 @@ pq_copy_both(replicationCursorObject *repl, PyObject *consume, int decode, ret = 1; exit: - Py_XDECREF(consume_func); return ret; }