From b742c48c6711847ec58a5a6778c372e2ac61df6d Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Sat, 29 Jan 2005 04:16:25 +0000 Subject: [PATCH] The Andrea's-bunch-o-fixes. --- ChangeLog | 13 +++++++++++++ psycopg/cursor_type.c | 19 ++++++++++++------- psycopg/pqpath.c | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0737fd51..8951ab51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-01-29 Federico Di Gregorio + + * psycopg/pqpath.c (_pq_fetch_tuples): fixed scale-related + segfault (*fourth* mail from Andrea. Another couple like this and + psycopg 2 will exit alpha at warp speed.) + + * psycopg/pqpath.c (pq_fetch): _pq_copy_out_3 -> _pq_copy_out_v3 + (second and third mail from Andrea. :/) + + * psycopg/cursor_type.c (_psyco_curs_has_write_check): added check + on .write() attribute, fixed compilation problems (first mail from + Andrea Arcangeli.) + 2005-01-20 Federico Di Gregorio * lib/extensions.py (register_adapter): added register_adapter diff --git a/psycopg/cursor_type.c b/psycopg/cursor_type.c index de32dde6..0c48bbf5 100644 --- a/psycopg/cursor_type.c +++ b/psycopg/cursor_type.c @@ -896,12 +896,17 @@ psyco_curs_scroll(cursorObject *self, PyObject *args, PyObject *kwargs) "copy_from(file, table, sep='\\t', null='NULL') -> copy file to table." static int -_psyco_curs_copy_from_check(PyObject *o) +_psyco_curs_has_write_check(PyObject* o, void* var) { - if (PyObject_GetAttrString(o, "write") + if (PyObject_HasAttrString(o, "write")) { + Py_INCREF(o); + *((PyObject**)var) = o; return 1; - else - + } + else { + PyErr_SetString(TypeError, "argument 1 must have a .write() method"); + return 0; + } } static PyObject * @@ -912,9 +917,9 @@ psyco_curs_copy_from(cursorObject *self, PyObject *args) long int bufsize = DEFAULT_COPYSIZE; PyObject *file, *res = NULL; - if (!PyArg_ParseTuple(args, "O!s|ssi", - &PyFile_Type, &file, &table_name, - &sep, &null, &bufsize)) { + if (!PyArg_ParseTuple(args, "O&s|ssi", + _psyco_curs_has_write_check, &file, + &table_name, &sep, &null, &bufsize)) { return NULL; } diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index c1bfdb12..54f9c4b2 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -749,7 +749,7 @@ pq_fetch(cursorObject *curs) curs->rowcount = 0; #ifdef HAVE_PQPROTOCOL3 if (curs->conn->protocol == 3) - ex = _pq_copy_out_3(curs); + ex = _pq_copy_out_v3(curs); else #endif ex = _pq_copy_out(curs);