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 911bef9

Browse filesBrowse files
authored
Refactor extension module initialization (PyMySQL#313)
1 parent 0b6c665 commit 911bef9
Copy full SHA for 911bef9

File tree

Expand file treeCollapse file tree

1 file changed

+6
-12
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-12
lines changed

‎MySQLdb/_mysql.c

Copy file name to clipboardExpand all lines: MySQLdb/_mysql.c
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,7 @@ PyTypeObject _mysql_ConnectionObject_Type = {
24682468
0, /* (long) tp_dictoffset */
24692469
(initproc)_mysql_ConnectionObject_Initialize, /* tp_init */
24702470
NULL, /* tp_alloc */
2471-
NULL, /* tp_new */
2471+
PyType_GenericNew, /* tp_new */
24722472
NULL, /* tp_free Low-level free-memory routine */
24732473
0, /* (PyObject *) tp_bases */
24742474
0, /* (PyObject *) tp_mro method resolution order */
@@ -2536,7 +2536,7 @@ PyTypeObject _mysql_ResultObject_Type = {
25362536
0, /* (long) tp_dictoffset */
25372537
(initproc)_mysql_ResultObject_Initialize, /* tp_init */
25382538
NULL, /* tp_alloc */
2539-
NULL, /* tp_new */
2539+
PyType_GenericNew, /* tp_new */
25402540
NULL, /* tp_free Low-level free-memory routine */
25412541
0, /* (PyObject *) tp_bases */
25422542
0, /* (PyObject *) tp_mro method resolution order */
@@ -2635,14 +2635,6 @@ init_mysql(void)
26352635
{
26362636
PyObject *dict, *module, *emod, *edict;
26372637

2638-
#ifndef IS_PY3K
2639-
_mysql_ConnectionObject_Type.ob_type = &PyType_Type;
2640-
_mysql_ResultObject_Type.ob_type = &PyType_Type;
2641-
#endif
2642-
_mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc;
2643-
_mysql_ConnectionObject_Type.tp_new = PyType_GenericNew;
2644-
_mysql_ResultObject_Type.tp_alloc = PyType_GenericAlloc;
2645-
_mysql_ResultObject_Type.tp_new = PyType_GenericNew;
26462638
#ifdef IS_PY3K
26472639
if (PyType_Ready(&_mysql_ConnectionObject_Type) < 0)
26482640
return NULL;
@@ -2652,8 +2644,10 @@ init_mysql(void)
26522644
module = PyModule_Create(&_mysqlmodule);
26532645
if (!module) return module; /* this really should never happen */
26542646
#else
2655-
_mysql_ConnectionObject_Type.tp_free = _PyObject_GC_Del;
2656-
_mysql_ResultObject_Type.tp_free = _PyObject_GC_Del;
2647+
if (PyType_Ready(&_mysql_ConnectionObject_Type) < 0)
2648+
return;
2649+
if (PyType_Ready(&_mysql_ResultObject_Type) < 0)
2650+
return;
26572651
module = Py_InitModule4("_mysql", _mysql_methods, _mysql___doc__,
26582652
(PyObject *)NULL, PYTHON_API_VERSION);
26592653
if (!module) return; /* this really should never happen */

0 commit comments

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