Permalink
Browse files

3K: fix scipy.optimize._minpack wrapper for py3.

  • Loading branch information...
1 parent 5b47cc5 commit f84c7cf20f7d6c480145808b8e7e1f1d791c721c @pv pv committed Sep 12, 2010
Showing with 44 additions and 2 deletions.
  1. +34 −1 scipy/optimize/_minpackmodule.c
  2. +6 −0 scipy/optimize/minpack.h
  3. +4 −1 tools/py3tool.py
@@ -13,6 +13,39 @@ static struct PyMethodDef minpack_module_methods[] = {
{"_chkder", minpack_chkder, METH_VARARGS, doc_chkder},
{NULL, NULL, 0, NULL}
};
+
+#if PY_VERSION_HEX >= 0x03000000
+static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "_minpack",
+ NULL,
+ -1,
+ minpack_module_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+PyObject *PyInit__minpack(void)
+{
+ PyObject *m, *d, *s;
+
+ m = PyModule_Create(&moduledef);
+ import_array();
+
+ d = PyModule_GetDict(m);
+
+ s = PyUnicode_FromString(" 1.10 ");
+ PyDict_SetItemString(d, "__version__", s);
+ Py_DECREF(s);
+ minpack_error = PyErr_NewException ("minpack.error", NULL, NULL);
+ PyDict_SetItemString(d, "error", minpack_error);
+ if (PyErr_Occurred())
+ Py_FatalError("can't initialize module minpack");
+
+ return m;
+}
+#else
PyMODINIT_FUNC init_minpack(void) {
PyObject *m, *d, *s;
m = Py_InitModule("_minpack", minpack_module_methods);
@@ -27,4 +60,4 @@ PyMODINIT_FUNC init_minpack(void) {
if (PyErr_Occurred())
Py_FatalError("can't initialize module minpack");
}
-
+#endif
@@ -29,6 +29,12 @@ the result tuple when the full_output argument is non-zero.
*/
#include "Python.h"
+#if PY_VERSION_HEX >= 0x03000000
+ #define PyString_FromString PyBytes_FromString
+ #define PyString_ConcatAndDel PyBytes_ConcatAndDel
+ #define PyString_AsString PyBytes_AsString
+ #define PyInt_FromLong PyLong_FromLong
+#endif
#include "numpy/arrayobject.h"
#define PYERR(errobj,message) {PyErr_SetString(errobj,message); goto fail;}
View
@@ -146,6 +146,8 @@ def custom_mangling(filename):
os.path.join('linalg', 'flinalg.py'),
os.path.join('lib', 'blas', '__init__.py'),
os.path.join('lib', 'lapack', '__init__.py'),
+ os.path.join('optimize', 'minpack.py'),
+ os.path.join('optimize', 'zeros.py'),
os.path.join('special', '__init__.py'),
os.path.join('special', 'basic.py'),
os.path.join('special', 'orthogonal.py'),
@@ -160,7 +162,8 @@ def custom_mangling(filename):
for mod in ['_vq', '_hierarchy_wrap', '_fftpack', 'convolve',
'_flinalg', 'fblas', 'flapack', 'cblas', 'clapack',
'calc_lwork', '_cephes', 'specfun', 'orthogonal_eval',
- 'lambertw', 'ckdtree', '_distance_wrap']:
+ 'lambertw', 'ckdtree', '_distance_wrap',
+ '_minpack', '_zeros']:
text = re.sub(r'^(\s*)import %s' % mod,
r'\1from . import %s' % mod,
text, flags=re.M)

0 comments on commit f84c7cf

Please sign in to comment.