Use the abstract object interfaces when digging around in module objects
instead of directly manipulating the underlying dictionary.
This commit is contained in:
parent
94a7eba9db
commit
13130bc5b1
|
@ -2828,44 +2828,42 @@ DL_EXPORT(void) initparser(void); /* supply a prototype */
|
||||||
DL_EXPORT(void)
|
DL_EXPORT(void)
|
||||||
initparser(void)
|
initparser(void)
|
||||||
{
|
{
|
||||||
PyObject* module;
|
PyObject *module, *copyreg;
|
||||||
PyObject* dict;
|
|
||||||
|
|
||||||
PyST_Type.ob_type = &PyType_Type;
|
PyST_Type.ob_type = &PyType_Type;
|
||||||
module = Py_InitModule("parser", parser_functions);
|
module = Py_InitModule("parser", parser_functions);
|
||||||
dict = PyModule_GetDict(module);
|
|
||||||
|
|
||||||
if (parser_error == 0)
|
if (parser_error == 0)
|
||||||
parser_error = PyErr_NewException("parser.ParserError", NULL, NULL);
|
parser_error = PyErr_NewException("parser.ParserError", NULL, NULL);
|
||||||
|
|
||||||
if ((parser_error == 0)
|
if ((parser_error == 0)
|
||||||
|| (PyDict_SetItemString(dict, "ParserError", parser_error) != 0)) {
|
|| (PyModule_AddObject(module, "ParserError", parser_error) != 0)) {
|
||||||
/* caller will check PyErr_Occurred() */
|
/* caller will check PyErr_Occurred() */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Py_INCREF(&PyST_Type);
|
Py_INCREF(&PyST_Type);
|
||||||
PyDict_SetItemString(dict, "ASTType", (PyObject*)&PyST_Type);
|
PyModule_AddObject(module, "ASTType", (PyObject*)&PyST_Type);
|
||||||
Py_INCREF(&PyST_Type);
|
Py_INCREF(&PyST_Type);
|
||||||
PyDict_SetItemString(dict, "STType", (PyObject*)&PyST_Type);
|
PyModule_AddObject(module, "STType", (PyObject*)&PyST_Type);
|
||||||
|
|
||||||
PyDict_SetItemString(dict, "__copyright__",
|
PyModule_AddStringConstant(module, "__copyright__",
|
||||||
PyString_FromString(parser_copyright_string));
|
parser_copyright_string);
|
||||||
PyDict_SetItemString(dict, "__doc__",
|
PyModule_AddStringConstant(module, "__doc__",
|
||||||
PyString_FromString(parser_doc_string));
|
parser_doc_string);
|
||||||
PyDict_SetItemString(dict, "__version__",
|
PyModule_AddStringConstant(module, "__version__",
|
||||||
PyString_FromString(parser_version_string));
|
parser_version_string);
|
||||||
|
|
||||||
/* Register to support pickling.
|
/* Register to support pickling.
|
||||||
* If this fails, the import of this module will fail because an
|
* If this fails, the import of this module will fail because an
|
||||||
* exception will be raised here; should we clear the exception?
|
* exception will be raised here; should we clear the exception?
|
||||||
*/
|
*/
|
||||||
module = PyImport_ImportModule("copy_reg");
|
copyreg = PyImport_ImportModule("copy_reg");
|
||||||
if (module != NULL) {
|
if (copyreg != NULL) {
|
||||||
PyObject *func, *pickler;
|
PyObject *func, *pickler;
|
||||||
|
|
||||||
func = PyObject_GetAttrString(module, "pickle");
|
func = PyObject_GetAttrString(copyreg, "pickle");
|
||||||
pickle_constructor = PyDict_GetItemString(dict, "sequence2st");
|
pickle_constructor = PyObject_GetAttrString(module, "sequence2st");
|
||||||
pickler = PyDict_GetItemString(dict, "_pickler");
|
pickler = PyObject_GetAttrString(module, "_pickler");
|
||||||
Py_XINCREF(pickle_constructor);
|
Py_XINCREF(pickle_constructor);
|
||||||
if ((func != NULL) && (pickle_constructor != NULL)
|
if ((func != NULL) && (pickle_constructor != NULL)
|
||||||
&& (pickler != NULL)) {
|
&& (pickler != NULL)) {
|
||||||
|
@ -2876,6 +2874,8 @@ initparser(void)
|
||||||
Py_XDECREF(res);
|
Py_XDECREF(res);
|
||||||
}
|
}
|
||||||
Py_XDECREF(func);
|
Py_XDECREF(func);
|
||||||
Py_DECREF(module);
|
Py_XDECREF(pickle_constructor);
|
||||||
|
Py_XDECREF(pickler);
|
||||||
|
Py_DECREF(copyreg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue