Skip to content

Commit 369810d

Browse files
committed
PyPy fixes, and probably some reference issues for CPython too.
Derived from a patch at https://bitbucket.org/pypy/compatibility/wiki/edit/mysql-python
1 parent c9b282f commit 369810d

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

MySQLdb/converters.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848

4949
import array
5050

51+
try:
52+
ArrayType = array.ArrayType
53+
except AttributeError:
54+
ArrayType = array.array
55+
5156
try:
5257
set
5358
except NameError:
@@ -133,7 +138,7 @@ def array2Str(o, d):
133138
ListType: escape_sequence,
134139
DictType: escape_dict,
135140
InstanceType: Instance2Str,
136-
array.ArrayType: array2Str,
141+
ArrayType: array2Str,
137142
StringType: Thing2Literal, # default
138143
UnicodeType: Unicode2Str,
139144
ObjectType: Instance2Str,

_mysql.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ _mysql_ResultObject_Initialize(
481481
PyObject *pmask=NULL;
482482
pmask = PyTuple_GET_ITEM(t, 0);
483483
fun2 = PyTuple_GET_ITEM(t, 1);
484+
Py_XINCREF(fun2);
484485
if (PyInt_Check(pmask)) {
485486
mask = PyInt_AS_LONG(pmask);
486487
flags = fields[i].flags;
@@ -501,8 +502,10 @@ _mysql_ResultObject_Initialize(
501502
}
502503
Py_DECREF(t);
503504
}
504-
if (!fun2) fun2 = Py_None;
505-
Py_INCREF(fun2);
505+
if (!fun2) {
506+
fun2 = Py_None;
507+
Py_INCREF(fun2);
508+
}
506509
Py_DECREF(fun);
507510
fun = fun2;
508511
}
@@ -1190,7 +1193,9 @@ _escape_item(
11901193
"no default type converter defined");
11911194
goto error;
11921195
}
1196+
Py_INCREF(d);
11931197
quoted = PyObject_CallFunction(itemconv, "OO", item, d);
1198+
Py_DECREF(d);
11941199
Py_DECREF(itemconv);
11951200
error:
11961201
return quoted;
@@ -2985,6 +2990,9 @@ _mysql_NewException(
29852990
if (!(e = PyDict_GetItemString(edict, name)))
29862991
return NULL;
29872992
if (PyDict_SetItemString(dict, name, e)) return NULL;
2993+
#ifdef PYPY_VERSION
2994+
Py_INCREF(e);
2995+
#endif
29882996
return e;
29892997
}
29902998

tests/test_MySQLdb_capabilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import MySQLdb
55
import warnings
66

7-
warnings.filterwarnings('error')
7+
warnings.filterwarnings('ignore')
88

99
class test_MySQLdb(capabilities.DatabaseTest):
1010

tests/test_MySQLdb_dbapi20.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import unittest
44
import MySQLdb
55
from configdb import connection_kwargs
6+
import warnings
7+
warnings.simplefilter("ignore")
68

79
class test_MySQLdb(dbapi20.DatabaseAPI20Test):
810
driver = MySQLdb

tests/test_MySQLdb_nonstandard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import MySQLdb
55
from MySQLdb.constants import FIELD_TYPE
66
from configdb import connection_factory
7-
7+
import warnings
8+
warnings.simplefilter("ignore")
89

910
class TestDBAPISet(unittest.TestCase):
1011
def test_set_equality(self):

0 commit comments

Comments
 (0)