Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b5780d2

Browse filesBrowse files
committed
self of module-level function is not NULL on Python 3.
1 parent c66b43c commit b5780d2
Copy full SHA for b5780d2

File tree

Expand file treeCollapse file tree

1 file changed

+26
-9
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-9
lines changed

‎_mysql.c

Copy file name to clipboardExpand all lines: _mysql.c
+26-9Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,9 @@ _mysql_escape_string(
10741074
len = mysql_escape_string(out, in, size);
10751075
#else
10761076
check_server_init(NULL);
1077+
1078+
if (PyModule_Check((PyObject*)self))
1079+
self = NULL;
10771080
if (self && self->open)
10781081
len = mysql_real_escape_string(&(self->connection), out, in, size);
10791082
else
@@ -1101,21 +1104,31 @@ _mysql_string_literal(
11011104
PyObject *str, *s, *o, *d;
11021105
char *in, *out;
11031106
int len, size;
1107+
if (PyModule_Check((PyObject*)self))
1108+
self = NULL;
11041109
if (!PyArg_ParseTuple(args, "O|O:string_literal", &o, &d)) return NULL;
1105-
s = PyObject_Str(o);
1106-
if (!s) return NULL;
1110+
if (PyBytes_Check(o)) {
1111+
s = o;
1112+
Py_INCREF(s);
1113+
} else {
1114+
s = PyObject_Str(o);
1115+
if (!s) return NULL;
11071116
#ifdef IS_PY3K
1108-
{
1109-
PyObject *t = PyUnicode_AsASCIIString(s);
1110-
if (!t) return NULL;
1111-
Py_DECREF(s);
1112-
s = t;
1113-
}
1117+
{
1118+
PyObject *t = PyUnicode_AsASCIIString(s);
1119+
Py_DECREF(s);
1120+
if (!t) return NULL;
1121+
s = t;
1122+
}
11141123
#endif
1124+
}
11151125
in = PyBytes_AsString(s);
11161126
size = PyBytes_GET_SIZE(s);
11171127
str = PyBytes_FromStringAndSize((char *) NULL, size*2+3);
1118-
if (!str) return PyErr_NoMemory();
1128+
if (!str) {
1129+
Py_DECREF(s);
1130+
return PyErr_NoMemory();
1131+
}
11191132
out = PyBytes_AS_STRING(str);
11201133
#if MYSQL_VERSION_ID < 32321
11211134
len = mysql_escape_string(out+1, in, size);
@@ -1336,7 +1349,11 @@ _mysql_field_to_python(
13361349
if (rowitem) {
13371350
if (converter != Py_None) {
13381351
v = PyObject_CallFunction(converter,
1352+
#ifdef IS_PY3K
1353+
"y#",
1354+
#else
13391355
"s#",
1356+
#endif
13401357
rowitem,
13411358
(int)length);
13421359
} else {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.