mathgl/mathgl-2.4.2-lang.patch
Orion Poplawski 62eff8cf24 Update to 2.4.2.1
Rebuild for octave 4.4
2018-11-13 09:10:38 -07:00

434 lines
18 KiB
Diff

diff -up mathgl-2.4.2/lang/CMakeLists.txt.lang mathgl-2.4.2/lang/CMakeLists.txt
--- mathgl-2.4.2/lang/CMakeLists.txt.lang 2018-03-21 10:48:17.000000000 -0600
+++ mathgl-2.4.2/lang/CMakeLists.txt 2018-11-07 21:47:46.663647687 -0700
@@ -17,52 +17,6 @@ if(NOT SWIG_FOUND)
endif(NOT SWIG_FOUND)
INCLUDE(${SWIG_USE_FILE})
-if(enable-python)
- set(Python_ADDITIONAL_VERSIONS 2.7)
- FIND_PACKAGE(PythonInterp)
- if(NOT PYTHONINTERP_FOUND)
- message(SEND_ERROR "Couldn't find python interpreter.")
- endif(NOT PYTHONINTERP_FOUND)
- FIND_PACKAGE(PythonLibs)
- if(NOT PYTHONLIBS_FOUND)
- message(SEND_ERROR "Couldn't find python development libraries.")
- endif(NOT PYTHONLIBS_FOUND)
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.get_include()"
- OUTPUT_VARIABLE NUMPY_INCLUDE_PATH
- RESULT_VARIABLE NUMPY_ERR
- OUTPUT_STRIP_TRAILING_WHITESPACE
- )
- if(NOT NUMPY_INCLUDE_PATH)
- message(SEND_ERROR "Couldn't find numpy.")
- endif(NOT NUMPY_INCLUDE_PATH)
-
- include_directories(${PYTHON_INCLUDE_DIR} ${NUMPY_INCLUDE_PATH})
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}')"
- OUTPUT_VARIABLE MGL_PYTHON_SITE_PACKAGES
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- set(SWIG_MODULE_mathgl_EXTRA_DEPS numpy.i ${src_imp_dep})
- if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
- SWIG_ADD_MODULE(mathgl python mathgl.i)
- else(${CMAKE_VERSION} VERSION_LESS "3.8.0")
- SWIG_ADD_LIBRARY(mathgl LANGUAGE python SOURCES mathgl.i)
- endif(${CMAKE_VERSION} VERSION_LESS "3.8.0")
- SWIG_LINK_LIBRARIES(mathgl mgl ${PYTHON_LIBRARIES})
- set_target_properties(_mathgl PROPERTIES BUILD_WITH_INSTALL_RPATH ON)
- add_custom_command(OUTPUT mathgl.pyc
- COMMAND ${PYTHON_EXECUTABLE}
- ARGS -c \"from py_compile import compile\; compile('mathgl.py') \"
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/lang
- DEPENDS _mathgl
- )
- add_custom_target(mgl_python_module ALL DEPENDS _mathgl mathgl.pyc)
-
- install(FILES ${MathGL2_BINARY_DIR}/lang/mathgl.py ${MathGL2_BINARY_DIR}/lang/mathgl.pyc DESTINATION ${MGL_PYTHON_SITE_PACKAGES})
- install (TARGETS _mathgl LIBRARY DESTINATION ${MGL_PYTHON_SITE_PACKAGES})
- set(mgl_clean_files ${mgl_clean_files} mathgl.py)
-endif(enable-python)
-
if(enable-lua)
INCLUDE(FindLua51)
if(NOT LUA51_FOUND)
@@ -145,4 +99,8 @@ message(STATUS "${oct_prog} ${oct_host}
endif(enable-octave-install)
set(mgl_clean_files ${mgl_clean_files} mathgl)
endif(enable-octave)
+
+#add_subdirectory( python2 )
+add_subdirectory( python3 )
+
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${mgl_clean_files}")
diff -up mathgl-2.4.2/lang/numpy.i.lang mathgl-2.4.2/lang/numpy.i
--- mathgl-2.4.2/lang/numpy.i.lang 2018-03-21 10:48:17.000000000 -0600
+++ mathgl-2.4.2/lang/numpy.i 2018-11-07 21:45:40.490389470 -0700
@@ -97,7 +97,7 @@
{
/* Given a PyObject, return a string describing its type.
*/
- char* pytype_string(PyObject* py_obj) {
+ const char* pytype_string(PyObject* py_obj) {
if (py_obj == NULL ) return "C NULL value";
if (py_obj == Py_None ) return "Python None" ;
if (PyCallable_Check(py_obj)) return "callable" ;
@@ -107,17 +107,18 @@
if (PyDict_Check( py_obj)) return "dict" ;
if (PyList_Check( py_obj)) return "list" ;
if (PyTuple_Check( py_obj)) return "tuple" ;
- if (PyFile_Check( py_obj)) return "file" ;
if (PyModule_Check( py_obj)) return "module" ;
+%#if PY_MAJOR_VERSION < 3
+ if (PyFile_Check( py_obj)) return "file" ;
if (PyInstance_Check(py_obj)) return "instance" ;
-
- return "unknow type";
+%#endif
+ return "unkown type";
}
/* Given a NumPy typecode, return a string describing the type.
*/
- char* typecode_string(int typecode) {
- static char* type_names[25] = {"bool", "byte", "unsigned byte",
+ const char* typecode_string(int typecode) {
+ static const char* type_names[25] = {"bool", "byte", "unsigned byte",
"short", "unsigned short", "int",
"unsigned int", "long", "unsigned long",
"long long", "unsigned long long",
@@ -159,8 +160,8 @@
}
else if is_array(input)
{
- char* desired_type = typecode_string(typecode);
- char* actual_type = typecode_string(array_type(input));
+ const char* desired_type = typecode_string(typecode);
+ const char* actual_type = typecode_string(array_type(input));
PyErr_Format(PyExc_TypeError,
"Array of type '%s' required. Array of type '%s' given",
desired_type, actual_type);
@@ -168,8 +169,8 @@
}
else
{
- char * desired_type = typecode_string(typecode);
- char * actual_type = pytype_string(input);
+ const char * desired_type = typecode_string(typecode);
+ const char * actual_type = pytype_string(input);
PyErr_Format(PyExc_TypeError,
"Array of type '%s' required. A '%s' was given",
desired_type, actual_type);
@@ -307,6 +308,95 @@
return ary1;
}
+ /* The following code was added by Ilmar M. Wilbers for forcing a copy of the
+ * object even when it is a NumPy array. This is meant for use with the
+ * IN_ARRAY typemaps, and allows the user to perform changes on an array
+ * without these chenges being reflected in the calling code.
+ */
+
+ /* Convert the given PyObject to a NumPy array with the given
+ * typecode as a copy. On success, return a valid PyArrayObject* with the
+ * correct type. On failure, the python error string will be set and
+ * the routine returns NULL.
+ */
+ PyArrayObject* obj_to_array_force_conversion(PyObject* input, int typecode,
+ int* is_new_object)
+ {
+ PyArrayObject* ary = NULL;
+ PyObject* py_obj;
+ if (is_array(input) && (typecode == NPY_NOTYPE ||
+ PyArray_EquivTypenums(array_type(input),typecode)))
+ {
+ py_obj = PyArray_Copy((PyArrayObject*) input);
+ ary = (PyArrayObject*) py_obj;
+ *is_new_object = 1;
+ }
+ else
+ {
+ py_obj = PyArray_FROMANY(input, typecode, 0, 0, NPY_DEFAULT);
+ /* If NULL, PyArray_FromObject will have set python error value.*/
+ ary = (PyArrayObject*) py_obj;
+ *is_new_object = 1;
+ }
+ return ary;
+ }
+
+ /* Convert a given PyObject to a contiguous PyArrayObject of the
+ * specified type. If the input object is not a contiguous
+ * PyArrayObject, a new one will be created and the new object flag
+ * will be set.
+ */
+ PyArrayObject* obj_to_array_contiguous_force_conversion(PyObject* input,
+ int typecode,
+ int* is_new_object)
+ {
+ int is_new1 = 0;
+ int is_new2 = 0;
+ PyArrayObject* ary2;
+ PyArrayObject* ary1 = obj_to_array_force_conversion(input, typecode,
+ &is_new1);
+ if (ary1)
+ {
+ ary2 = make_contiguous(ary1, &is_new2, 0, 0);
+ if ( is_new1 && is_new2)
+ {
+ Py_DECREF(ary1);
+ }
+ ary1 = ary2;
+ }
+ *is_new_object = is_new1 || is_new2;
+ return ary1;
+ }
+
+ /* Convert a given PyObject to a Fortran-ordered PyArrayObject of the
+ * specified type. If the input object is not a Fortran-ordered
+ * PyArrayObject, a new one will be created and the new object flag
+ * will be set.
+ */
+ PyArrayObject* obj_to_array_fortran_force_conversion(PyObject* input,
+ int typecode,
+ int* is_new_object)
+ {
+ int is_new1 = 0;
+ int is_new2 = 0;
+ PyArrayObject* ary2;
+ PyArrayObject* ary1 = obj_to_array_force_conversion(input, typecode,
+ &is_new1);
+ if (ary1)
+ {
+ ary2 = make_fortran(ary1, &is_new2, 0, 0);
+ if (is_new1 && is_new2)
+ {
+ Py_DECREF(ary1);
+ }
+ ary1 = ary2;
+ }
+ *is_new_object = is_new1 || is_new2;
+ return ary1;
+ }
+ /* End modifications by Ilmar M. Wilbers
+ */
+
} /* end fragment */
@@ -601,7 +691,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[1] = { $1_dim0 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 1) ||
!require_size(array, size, 1)) SWIG_fail;
@@ -628,7 +718,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[1] = { -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 1) ||
!require_size(array, size, 1)) SWIG_fail;
@@ -656,7 +746,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[1] = {-1};
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 1) ||
!require_size(array, size, 1)) SWIG_fail;
@@ -684,7 +774,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[2] = { $1_dim0, $1_dim1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 2) ||
!require_size(array, size, 2)) SWIG_fail;
@@ -711,7 +801,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[2] = { -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 2) ||
!require_size(array, size, 2)) SWIG_fail;
@@ -740,7 +830,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[2] = { -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 2) ||
!require_size(array, size, 2)) SWIG_fail;
@@ -769,7 +859,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[2] = { -1, -1 };
- array = obj_to_array_fortran_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_fortran_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 2) ||
!require_size(array, size, 2) || !require_fortran(array)) SWIG_fail;
@@ -798,7 +888,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[2] = { -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 2) ||
!require_size(array, size, 2) || !require_fortran(array)) SWIG_fail;
@@ -827,7 +917,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[3] = { $1_dim0, $1_dim1, $1_dim2 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 3) ||
!require_size(array, size, 3)) SWIG_fail;
@@ -855,7 +945,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[3] = { -1, -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 3) ||
!require_size(array, size, 3)) SWIG_fail;
@@ -886,7 +976,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[3] = { -1, -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 3) ||
!require_size(array, size, 3)) SWIG_fail;
@@ -917,7 +1007,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[3] = { -1, -1, -1 };
- array = obj_to_array_fortran_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_fortran_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 3) ||
!require_size(array, size, 3) | !require_fortran(array)) SWIG_fail;
@@ -948,7 +1038,7 @@
(PyArrayObject* array=NULL, int is_new_object=0)
{
npy_intp size[3] = { -1, -1, -1 };
- array = obj_to_array_contiguous_allow_conversion($input, DATA_TYPECODE,
+ array = obj_to_array_contiguous_force_conversion($input, DATA_TYPECODE,
&is_new_object);
if (!array || !require_dimensions(array, 3) ||
!require_size(array, size, 3) || !require_fortran(array)) SWIG_fail;
@@ -1291,7 +1381,7 @@
npy_intp dims[1];
if (!PyInt_Check($input))
{
- char* typestring = pytype_string($input);
+ const char* typestring = pytype_string($input);
PyErr_Format(PyExc_TypeError,
"Int dimension expected. '%s' given.",
typestring);
@@ -1319,7 +1409,7 @@
npy_intp dims[1];
if (!PyInt_Check($input))
{
- char* typestring = pytype_string($input);
+ const char* typestring = pytype_string($input);
PyErr_Format(PyExc_TypeError,
"Int dimension expected. '%s' given.",
typestring);
diff -up mathgl-2.4.2/lang/python3/CMakeLists.txt.lang mathgl-2.4.2/lang/python3/CMakeLists.txt
--- mathgl-2.4.2/lang/python3/CMakeLists.txt.lang 2018-11-07 21:45:40.441388976 -0700
+++ mathgl-2.4.2/lang/python3/CMakeLists.txt 2018-11-07 21:45:40.503389601 -0700
@@ -0,0 +1,75 @@
+set(src_imp_dep
+../../include/mgl2/type.h
+../../include/mgl2/data.h
+../../include/mgl2/mgl.h
+../mgl.i
+../data.i
+../type.i
+)
+
+set(mgl_clean_files "")
+
+SET_SOURCE_FILES_PROPERTIES(../mathgl.i ../numpy.i PROPERTIES CPLUSPLUS ON)
+
+if(enable-python)
+ set(Python_ADDITIONAL_VERSIONS 3.6)
+ unset(PYTHONINTERP_FOUND)
+ unset(PYTHON_EXECUTABLE CACHE)
+ FIND_PACKAGE(PythonInterp 3.6 REQUIRED)
+ if(NOT PYTHONINTERP_FOUND)
+ message(SEND_ERROR "Couldn't find python interpreter.")
+ endif(NOT PYTHONINTERP_FOUND)
+
+ unset(PYTHONLIBS_FOUND)
+ unset(PYTHON_LIBRARIES CACHE)
+ unset(PYTHON_INCLUDE_PATH CACHE)
+ unset(PYTHON_INCLUDE_DIRS CACHE)
+ unset(PYTHON_DEBUG_LIBRARIES CACHE)
+ unset(PYTHONLIBS_VERSION_STRING CACHE)
+ unset(PYTHON_LIBRARY CACHE)
+ unset(PYTHON_INCLUDE_DIR CACHE)
+ FIND_PACKAGE(PythonLibs 3.6)
+ if(NOT PYTHONLIBS_FOUND)
+ message(SEND_ERROR "Couldn't find python development libraries.")
+ endif(NOT PYTHONLIBS_FOUND)
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print(numpy.get_include())"
+ OUTPUT_VARIABLE NUMPY_INCLUDE_PATH
+ RESULT_VARIABLE NUMPY_ERR
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ if(NOT NUMPY_INCLUDE_PATH)
+ message(SEND_ERROR "Couldn't find numpy.")
+ endif(NOT NUMPY_INCLUDE_PATH)
+
+ include_directories(${PYTHON_INCLUDE_DIR} ${NUMPY_INCLUDE_PATH})
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'))"
+ OUTPUT_VARIABLE MGL_PYTHON_SITE_PACKAGES
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ set(SWIG_MODULE_mathglp3_EXTRA_DEPS ../numpy.i ${src_imp_dep})
+ SWIG_ADD_MODULE(mathglp3 python ../mathgl.i)
+ SWIG_LINK_LIBRARIES(mathglp3 mgl ${PYTHON_LIBRARIES})
+ execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('SO'))"
+ OUTPUT_VARIABLE MGL_PYTHON_LIB_SUFFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ set_target_properties(_mathglp3 PROPERTIES
+ BUILD_WITH_INSTALL_RPATH ON
+ OUTPUT_NAME _mathgl
+ SUFFIX ${MGL_PYTHON_LIB_SUFFIX})
+ add_custom_command(OUTPUT mathgl.pyc
+ COMMAND ${PYTHON_EXECUTABLE}
+ ARGS -c \"from py_compile import compile\; compile('mathgl.py') \"
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/lang/python3
+ DEPENDS _mathglp3
+ )
+ add_custom_target(mgl_python_modulep3 ALL DEPENDS _mathglp3 mathgl.pyc)
+
+ install(FILES ${MathGL2_BINARY_DIR}/lang/python3/mathgl.py DESTINATION ${MGL_PYTHON_SITE_PACKAGES})
+# harcoded for now. another way is to make glob search on *pyc in __pycache__ dir
+ install(FILES ${MathGL2_BINARY_DIR}/lang/python3/__pycache__/mathgl.cpython-36.pyc DESTINATION ${MGL_PYTHON_SITE_PACKAGES}/__pycache__)
+ install (TARGETS _mathglp3 LIBRARY DESTINATION ${MGL_PYTHON_SITE_PACKAGES})
+ set(mgl_clean_files ${mgl_clean_files} mathgl.py)
+endif(enable-python)
+
+set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${mgl_clean_files}")