From 841d08fe4cbea95da6420f4e27b63461ab816cad Mon Sep 17 00:00:00 2001 From: David Cox <4259949+david-r-cox@users.noreply.github.com> Date: Tue, 3 Jan 2023 13:08:14 -1000 Subject: [PATCH] Support SWI-Prolog versions > 8.5.2 (#133) Support SWI-Prolog versions > 8.5.2 After SWI-Prolog 8.5.2, PL_version was renamed to PL_version_info, causing pyswip to crash when used with SWI-Prolog versions > 8.5.2. --- CONTRIBUTORS.txt | 1 + pyswip/core.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 2ed813c..df0553b 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -26,3 +26,4 @@ Guglielmo Gemignani Vince Jankovics Tobias Grubenmann Arvid Norlander +David Cox diff --git a/pyswip/core.py b/pyswip/core.py index 20a4f6a..725d984 100644 --- a/pyswip/core.py +++ b/pyswip/core.py @@ -587,16 +587,24 @@ def check_and_call(*args): PL_VERSION_VM =6 # VM signature PL_VERSION_BUILT_IN =7 # Built-in predicate signature + +# After SWI-Prolog 8.5.2, PL_version was renamed to PL_version_info +# to avoid a conflict with Perl. For more details, see the following: +# https://github.com/SWI-Prolog/swipl-devel/issues/900 +# https://github.com/SWI-Prolog/swipl-devel/issues/910 try: - PL_version = _lib.PL_version + if _lib.PL_version_info != None: + PL_version = _lib.PL_version_info # swi-prolog > 8.5.2 + else: + PL_version = _lib.PL_version # swi-prolog <= 8.5.2 PL_version.argtypes = [c_int] PL_version.restype = c_uint PL_VERSION = PL_version(PL_VERSION_SYSTEM) if PL_VERSION<80200: - raise Exception("swi-prolog>= 8.2.0 is required") + raise Exception("swi-prolog >= 8.2.0 is required") except AttributeError: - PL_VERSION=70000 # Best guess. When was PL_version introduced? + raise Exception("swi-prolog version number could not be determined") # PySwip constants