Refactor extension module initialization (#313)

This commit is contained in:
INADA Naoki
2018-12-13 20:23:46 +09:00
committed by GitHub
parent 0b6c6656f2
commit 911bef988c

View File

@ -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 */
@ -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 */
@ -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;
@ -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 */