Merge branch 'copy-refcount-bug' into devel

This commit is contained in:
Daniele Varrazzo 2011-06-07 01:20:37 +01:00
commit 816b5dda33
2 changed files with 15 additions and 5 deletions

View File

@ -1505,14 +1505,15 @@ psyco_curs_copy_expert(cursorObject *self, PyObject *args, PyObject *kwargs)
self->copyfile = file;
/* At this point, the SQL statement must be str, not unicode */
if (pq_execute(self, Bytes_AS_STRING(sql), 0) != 1) { goto exit; }
if (pq_execute(self, Bytes_AS_STRING(sql), 0) == 1) {
res = Py_None;
Py_INCREF(res);
}
res = Py_None;
Py_INCREF(res);
self->copyfile = NULL;
Py_DECREF(file);
exit:
self->copyfile = NULL;
Py_XDECREF(file);
Py_XDECREF(sql);
return res;

View File

@ -244,6 +244,15 @@ class CopyTests(unittest.TestCase):
self.assertEqual(ntests, len(string.ascii_letters))
def test_copy_expert_file_refcount(self):
class Whatever(object):
pass
f = Whatever()
curs = self.conn.cursor()
self.assertRaises(TypeError,
curs.copy_expert, 'COPY tcopy (data) FROM STDIN', f)
decorate_all_tests(CopyTests, skip_if_green)