[issue9928] weird oddity with bz2 context manager
Antoine Pitrou
report at bugs.python.org
Thu Sep 23 19:56:18 CEST 2010
Antoine Pitrou <pitrou at free.fr> added the comment:
Actually, it is because bz2 doesn't call PyType_Ready() but instead sets some field manually. Perhaps we could have a guard somewhere that raises a fatal error when a C extension type hasn't been properly readied?
In the meantime, this patch seems to solve the issue:
diff -r 843be379fb26 Modules/bz2module.c
--- a/Modules/bz2module.c Thu Sep 23 18:45:17 2010 +0200
+++ b/Modules/bz2module.c Thu Sep 23 19:55:19 2010 +0200
@@ -2155,9 +2155,12 @@ PyInit_bz2(void)
{
PyObject *m;
- Py_TYPE(&BZ2File_Type) = &PyType_Type;
- Py_TYPE(&BZ2Comp_Type) = &PyType_Type;
- Py_TYPE(&BZ2Decomp_Type) = &PyType_Type;
+ if (PyType_Ready(&BZ2File_Type) < 0)
+ return NULL;
+ if (PyType_Ready(&BZ2Comp_Type) < 0)
+ return NULL;
+ if (PyType_Ready(&BZ2Decomp_Type) < 0)
+ return NULL;
m = PyModule_Create(&bz2module);
if (m == NULL)
----------
versions: +Python 2.7, Python 3.1
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9928>
_______________________________________
More information about the Python-bugs-list
mailing list