yuce / pyswip

PySwip is a Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.
MIT License
464 stars 97 forks source link

Avoid AttributeError with PL_version_info in swipl <= 8.4.2 #154

Closed DestyNova closed 3 months ago

DestyNova commented 1 year ago

In older versions of libswipl.so, pyswip produced this error:

Traceback (most recent call last):                                                                       
  File "/home/omf/.local/lib/python3.10/site-packages/pyswip/core.py", line 597, in <module>
    if _lib.PL_version_info != None:                                                                     
  File "/usr/lib/python3.10/ctypes/__init__.py", line 387, in __getattr__                                
    func = self.__getitem__(name)                                                                        
  File "/usr/lib/python3.10/ctypes/__init__.py", line 392, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))                                                        
AttributeError: /lib/libswipl.so.8: undefined symbol: PL_version_info

This happened on my system with libswipl 8.4.2. We can avoid this by using hasattr instead of comparing the property to None.

yuce commented 3 months ago

@DestyNova Looks good, thanks. Could you add your name to CONTRIBUTORS.txt?