Skip to content

Refactor module initialization code #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions MySQLdb/_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,7 @@ PyTypeObject _mysql_ConnectionObject_Type = {
0, /* (long) tp_dictoffset */
(initproc)_mysql_ConnectionObject_Initialize, /* tp_init */
NULL, /* tp_alloc */
NULL, /* tp_new */
PyType_GenericNew, /* tp_new */
NULL, /* tp_free Low-level free-memory routine */
0, /* (PyObject *) tp_bases */
0, /* (PyObject *) tp_mro method resolution order */
Expand Down Expand Up @@ -2536,7 +2536,7 @@ PyTypeObject _mysql_ResultObject_Type = {
0, /* (long) tp_dictoffset */
(initproc)_mysql_ResultObject_Initialize, /* tp_init */
NULL, /* tp_alloc */
NULL, /* tp_new */
PyType_GenericNew, /* tp_new */
NULL, /* tp_free Low-level free-memory routine */
0, /* (PyObject *) tp_bases */
0, /* (PyObject *) tp_mro method resolution order */
Expand Down Expand Up @@ -2635,14 +2635,6 @@ init_mysql(void)
{
PyObject *dict, *module, *emod, *edict;

#ifndef IS_PY3K
_mysql_ConnectionObject_Type.ob_type = &PyType_Type;
_mysql_ResultObject_Type.ob_type = &PyType_Type;
#endif
_mysql_ConnectionObject_Type.tp_alloc = PyType_GenericAlloc;
_mysql_ConnectionObject_Type.tp_new = PyType_GenericNew;
_mysql_ResultObject_Type.tp_alloc = PyType_GenericAlloc;
_mysql_ResultObject_Type.tp_new = PyType_GenericNew;
#ifdef IS_PY3K
if (PyType_Ready(&_mysql_ConnectionObject_Type) < 0)
return NULL;
Expand All @@ -2652,8 +2644,10 @@ init_mysql(void)
module = PyModule_Create(&_mysqlmodule);
if (!module) return module; /* this really should never happen */
#else
_mysql_ConnectionObject_Type.tp_free = _PyObject_GC_Del;
_mysql_ResultObject_Type.tp_free = _PyObject_GC_Del;
if (PyType_Ready(&_mysql_ConnectionObject_Type) < 0)
return;
if (PyType_Ready(&_mysql_ResultObject_Type) < 0)
return;
module = Py_InitModule4("_mysql", _mysql_methods, _mysql___doc__,
(PyObject *)NULL, PYTHON_API_VERSION);
if (!module) return; /* this really should never happen */
Expand Down