From f6ed3fa2cf9cbac6ce396e7d571a23b2868dd38a Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 29 Oct 2013 10:54:41 -0500 Subject: [PATCH] Fix Py3 support involving gmpy --- islpy/__init__.py | 21 +++++++++++++++++++++ setup.py | 2 +- src/wrapper/gmpy.h | 12 +++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/islpy/__init__.py b/islpy/__init__.py index ec1a5ab..c46c43a 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -1,3 +1,24 @@ +from __future__ import division + + +# {{{ check gmpy version + +def _check_gmpy_version(): + import gmpy + gmpy_ver_num = tuple(int(s) for s in gmpy.version().split(".")) + + import sys + if sys.version_info >= (3,) and gmpy_ver_num < (1, 17): + raise ImportError("gmpy 1.17 or newer is required for " + "Python 3 support") + +try: + _check_gmpy_version() +except ValueError: + pass + +# }}} + from islpy._isl import * # noqa from islpy.version import * # noqa diff --git a/setup.py b/setup.py index 0e88db2..611cab1 100644 --- a/setup.py +++ b/setup.py @@ -127,7 +127,7 @@ def main(): install_requires=[ "pytest>=2", - "gmpy>=1,<2", + "gmpy>=1.17,<2", # "Mako>=0.3.6", ], ext_modules=[ diff --git a/src/wrapper/gmpy.h b/src/wrapper/gmpy.h index 276c560..57476de 100644 --- a/src/wrapper/gmpy.h +++ b/src/wrapper/gmpy.h @@ -136,6 +136,7 @@ static Pympf_new_RETURN Pympf_new Pympf_new_PROTO; static Pympf_dealloc_RETURN Pympf_dealloc Pympf_dealloc_PROTO; static Pympf_convert_arg_RETURN Pympf_convert_arg Pympf_convert_arg_PROTO; +#if PY_MAJOR_VERSION < 3 #define export_gmpy(m) { \ PyObject *d; \ static void *Pygmpy_API[Pygmpy_API_pointers]; \ @@ -159,6 +160,7 @@ static Pympf_convert_arg_RETURN Pympf_convert_arg Pympf_convert_arg_PROTO; d = PyModule_GetDict(m);\ PyDict_SetItemString(d, "_C_API", c_api_object);\ } +#endif #else /* This section is used in other C-coded modules that use gmpy's API */ @@ -194,6 +196,7 @@ static void **Pygmpy_API; #define Pympf_convert_arg \ (*(Pympf_convert_arg_RETURN (*)Pympf_convert_arg_PROTO) Pygmpy_API[Pympf_convert_arg_NUM]) +#if PY_MAJOR_VERSION < 3 #define import_gmpy() \ { \ PyObject *module = PyImport_ImportModule("gmpy");\ @@ -205,7 +208,14 @@ static void **Pygmpy_API; } \ } \ } - +#else +static int +import_gmpy(void) +{ + Pygmpy_API = (void **)PyCapsule_Import("gmpy._C_API", 0); + return (Pygmpy_API != NULL) ? 0 : -1; +} +#endif #endif #ifdef __cplusplus -- GitLab