From 369810dff7d2e9d7371776f9dc58cedf5b794567 Mon Sep 17 00:00:00 2001 From: farcepest Date: Wed, 17 Oct 2012 18:30:19 -0400 Subject: PyPy fixes, and probably some reference issues for CPython too. Derived from a patch at https://bitbucket.org/pypy/compatibility/wiki/edit/mysql-python --- MySQLdb/converters.py | 7 ++++++- _mysql.c | 12 ++++++++++-- tests/test_MySQLdb_capabilities.py | 2 +- tests/test_MySQLdb_dbapi20.py | 2 ++ tests/test_MySQLdb_nonstandard.py | 3 ++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/MySQLdb/converters.py b/MySQLdb/converters.py index 14b1f52..953c4e5 100644 --- a/MySQLdb/converters.py +++ b/MySQLdb/converters.py @@ -48,6 +48,11 @@ except ImportError: import array +try: + ArrayType = array.ArrayType +except AttributeError: + ArrayType = array.array + try: set except NameError: @@ -133,7 +138,7 @@ conversions = { ListType: escape_sequence, DictType: escape_dict, InstanceType: Instance2Str, - array.ArrayType: array2Str, + ArrayType: array2Str, StringType: Thing2Literal, # default UnicodeType: Unicode2Str, ObjectType: Instance2Str, diff --git a/_mysql.c b/_mysql.c index 5fee5ce..c0ffddb 100644 --- a/_mysql.c +++ b/_mysql.c @@ -481,6 +481,7 @@ _mysql_ResultObject_Initialize( PyObject *pmask=NULL; pmask = PyTuple_GET_ITEM(t, 0); fun2 = PyTuple_GET_ITEM(t, 1); + Py_XINCREF(fun2); if (PyInt_Check(pmask)) { mask = PyInt_AS_LONG(pmask); flags = fields[i].flags; @@ -501,8 +502,10 @@ _mysql_ResultObject_Initialize( } Py_DECREF(t); } - if (!fun2) fun2 = Py_None; - Py_INCREF(fun2); + if (!fun2) { + fun2 = Py_None; + Py_INCREF(fun2); + } Py_DECREF(fun); fun = fun2; } @@ -1190,7 +1193,9 @@ _escape_item( "no default type converter defined"); goto error; } + Py_INCREF(d); quoted = PyObject_CallFunction(itemconv, "OO", item, d); + Py_DECREF(d); Py_DECREF(itemconv); error: return quoted; @@ -2985,6 +2990,9 @@ _mysql_NewException( if (!(e = PyDict_GetItemString(edict, name))) return NULL; if (PyDict_SetItemString(dict, name, e)) return NULL; +#ifdef PYPY_VERSION + Py_INCREF(e); +#endif return e; } diff --git a/tests/test_MySQLdb_capabilities.py b/tests/test_MySQLdb_capabilities.py index 60bbfad..ebec1e6 100644 --- a/tests/test_MySQLdb_capabilities.py +++ b/tests/test_MySQLdb_capabilities.py @@ -4,7 +4,7 @@ import unittest import MySQLdb import warnings -warnings.filterwarnings('error') +warnings.filterwarnings('ignore') class test_MySQLdb(capabilities.DatabaseTest): diff --git a/tests/test_MySQLdb_dbapi20.py b/tests/test_MySQLdb_dbapi20.py index 44830e0..2832e32 100644 --- a/tests/test_MySQLdb_dbapi20.py +++ b/tests/test_MySQLdb_dbapi20.py @@ -3,6 +3,8 @@ import dbapi20 import unittest import MySQLdb from configdb import connection_kwargs +import warnings +warnings.simplefilter("ignore") class test_MySQLdb(dbapi20.DatabaseAPI20Test): driver = MySQLdb diff --git a/tests/test_MySQLdb_nonstandard.py b/tests/test_MySQLdb_nonstandard.py index 92fcbdc..a5c0e84 100644 --- a/tests/test_MySQLdb_nonstandard.py +++ b/tests/test_MySQLdb_nonstandard.py @@ -4,7 +4,8 @@ import _mysql import MySQLdb from MySQLdb.constants import FIELD_TYPE from configdb import connection_factory - +import warnings +warnings.simplefilter("ignore") class TestDBAPISet(unittest.TestCase): def test_set_equality(self): -- cgit v1.2.1