Use the PyModule_*() API instead of manipulating the module dictionary
directly.
This commit is contained in:
parent
7829335763
commit
f4e3484692
|
@ -1731,12 +1731,14 @@ static PyMethodDef a_methods[] = {
|
||||||
DL_EXPORT(void)
|
DL_EXPORT(void)
|
||||||
initarray(void)
|
initarray(void)
|
||||||
{
|
{
|
||||||
PyObject *m, *d;
|
PyObject *m;
|
||||||
|
|
||||||
Arraytype.ob_type = &PyType_Type;
|
Arraytype.ob_type = &PyType_Type;
|
||||||
m = Py_InitModule3("array", a_methods, module_doc);
|
m = Py_InitModule3("array", a_methods, module_doc);
|
||||||
d = PyModule_GetDict(m);
|
|
||||||
PyDict_SetItemString(d, "ArrayType", (PyObject *)&Arraytype);
|
Py_INCREF((PyObject *)&Arraytype);
|
||||||
PyDict_SetItemString(d, "array", (PyObject *)&Arraytype);
|
PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype);
|
||||||
|
Py_INCREF((PyObject *)&Arraytype);
|
||||||
|
PyModule_AddObject(m, "array", (PyObject *)&Arraytype);
|
||||||
/* No need to check the error here, the caller will do that */
|
/* No need to check the error here, the caller will do that */
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,13 +394,11 @@ static PyMethodDef cmath_methods[] = {
|
||||||
DL_EXPORT(void)
|
DL_EXPORT(void)
|
||||||
initcmath(void)
|
initcmath(void)
|
||||||
{
|
{
|
||||||
PyObject *m, *d, *v;
|
PyObject *m;
|
||||||
|
|
||||||
m = Py_InitModule3("cmath", cmath_methods, module_doc);
|
m = Py_InitModule3("cmath", cmath_methods, module_doc);
|
||||||
d = PyModule_GetDict(m);
|
|
||||||
PyDict_SetItemString(d, "pi",
|
PyModule_AddObject(m, "pi",
|
||||||
v = PyFloat_FromDouble(atan(1.0) * 4.0));
|
PyFloat_FromDouble(atan(1.0) * 4.0));
|
||||||
Py_DECREF(v);
|
PyModule_AddObject(m, "e", PyFloat_FromDouble(exp(1.0)));
|
||||||
PyDict_SetItemString(d, "e", v = PyFloat_FromDouble(exp(1.0)));
|
|
||||||
Py_DECREF(v);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue