yuce / pyswip

PySwip is a Python-Prolog interface that enables querying SWI-Prolog in your Python programs.
https://pyswip.org
MIT License
482 stars 98 forks source link

C assert since swi-prolog 8.2.0? #92

Closed allComputableThings closed 4 years ago

allComputableThings commented 4 years ago

I've been having this issue for a week or more:

[Thread 1 (main) at Wed Jun 17 16:21:50 2020] /build/swi-prolog-IR7kdY/swi-prolog-8.2.0-1-g7c05cf19b/src/pl-fli.c:2510: PL_put_chars: Assertion failed: 0
C-stack trace labeled "assert_fail":
  [0] PL_strtod() at ??:? [0x7f819362d4b8]
  [1] __assert_fail() at ??:? [0x7f81935eb7d7]
  [2] PL_put_chars() at ??:? [0x7f8193549ec9]
  [3] ffi_call_unix64() at ??:? [0x7f81947b9dae]
  [4] ffi_call() at ??:? [0x7f81947b971f]
  [5] _ctypes_callproc() at ??:? [0x7f81949cd944]
  [6] _ctypes_callproc() at ??:? [0x7f81949ce0d4]
  [7] python(_PyObject_FastCallKeywords+0x4eb) [0x5d96db]
  [8] python(_PyEval_EvalFrameDefault+0x4679) [0x551e89]
  [9] python(+0xd2165) [0x4d2165]
...

I've checked out the latest pyswip master and:

pip install -e .

... gets the above error. I was having the same error also with earlier versions. I suspect SWI-Prolog.h has somehow become incompatible with core.py. It suspect if has been happening since the apt swi-prolog version went to 8.2.0. I don't seem to be able to load earlier versions from the ppa either.

Can anyone confirm this? I should be straightforward to reproduce

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:swi-prolog/stable
sudo apt-get update
sudo apt-get install swi-prolog
md5sum /usr/lib/swi-prolog/include/SWI-Prolog.h 
# 175575c766582b0020c7c7d5050adad7  /usr/lib/swi-prolog/include/SWI-Prolog.h
sudo pip install pyswip
python -c 'import pyswip; p = pyswip.Prolog(); p.assertz("father(michael,john)")' 
# explosion #
allComputableThings commented 4 years ago

I'm sorry. There's a mistake above. The latest master checkout has the error. The latest pip package seems fine:

$ pip install pyswip
Collecting pyswip
  Using cached https://files.pythonhosted.org/packages/e4/f3/2b1462c4379b089426dbedb29d8d903e63baf37857ccf6e87f168b786019/pyswip-0.2.9-py2.py3-none-any.whl
Installing collected packages: pyswip
Successfully installed pyswip-0.2.9

$ python -c 'import pyswip; p = pyswip.Prolog(); p.assertz("father(michael,john)")'
# Success

# Go to latest clone of master
$ cd soft/pyswip/
$ python -c 'import pyswip; p = pyswip.Prolog(); p.assertz("father(michael,john)")'
[Thread 1 (main) at Wed Jun 17 19:49:26 2020] /build/swi-prolog-IR7kdY/swi-prolog-8.2.0-1-g7c05cf19b/src/pl-fli.c:2510: PL_put_chars: Assertion failed: 0
C-stack trace labeled "assert_fail":
  [0] PL_strtod() at ??:? [0x7fc4306a44b8]
  [1] __assert_fail() at ??:? [0x7fc4306627d7]
  [2] PL_put_chars() at ??:? [0x7fc4305c0ec9]
  [3] ffi_call_unix64() at ??:? [0x7fc4318f9dae]
  [4] ffi_call() at ??:? [0x7fc4318f971f]
  [5] _ctypes_callproc() at ??:? [0x7fc431b0d944]
  [6] _ctypes_callproc() at ??:? [0x7fc431b0e0d4]
  [7] python(_PyObject_FastCallKeywords+0x4eb) [0x5d96db]
  [8] python(_PyEval_EvalFrameDefault+0x4679) [0x551e89]
  [9] python(+0xd2165) [0x4d2165]
  [10] python(+0x155976) [0x555976]
  [11] python(_PyMethodDef_RawFastCallKeywords+0x1b3) [0x5d7ef3]
  [12] python(_PyEval_EvalFrameDefault+0x42a4) [0x551ab4]
  [13] python(_PyEval_EvalCodeWithName+0x252) [0x54b302]
  [14] python(_PyFunction_FastCallKeywords+0x482) [0x5d8bd2]
  [15] python(+0x14a880) [0x54a880]
  [16] python(_PyEval_EvalFrameDefault+0x43f8) [0x551c08]
  [17] python(_PyEval_EvalCodeWithName+0x252) [0x54b302]
  [18] python(PyRun_StringFlags+0xaf) [0x530aef]
  [19] python(PyRun_SimpleStringFlags+0x3d) [0x63138d]
  [20] python(+0x25473d) [0x65473d]
  [21] python(_Py_UnixMain+0x2e) [0x65486e]
  [22] __libc_start_main() at /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344 [0x7fc43369eb97]
  [23] python(_start+0x2a) [0x5df80a]
Aborted (core dumped)
allComputableThings commented 4 years ago

Its turns our there are breaking changed in SWI-Prolog.h with PL_STRING (!) I'll submit a PR.

NB. The 8.xxx apt prior to 8.2.0 seems to be no-longer available. There's no option to stay compatible with that release, so upgrade is mandatory!

allComputableThings commented 4 years ago

Resolved here: https://github.com/yuce/pyswip/pull/93

yuce commented 4 years ago

@stuz5000 Thanks for the fix for 8.2.0. Both Ubuntu 18.04 and 20.04 seem to be on SWI 7.6.4 in the official repos, so accepting the PR will break it for users (at least) on those platforms. So, we have to either (1) support both SWI 7 and 8 in the same package or (2) maintain another fork/package for SWI 8.There is a refactored PySwip living in a private repo which makes it easier to do (1), but it's notready for prime time yet.

Is using SWI 7 for the time being an option for you? What are the most important features you use from SWI 8?

allComputableThings commented 4 years ago

Hmm... that makes sense. I followed the SWI instructions and installed from the ppa. I’m using tabling and dict’s from 8.

On Thu, Jun 18, 2020 at 8:24 PM Yüce Tekol notifications@github.com wrote:

@stuz5000 https://github.com/stuz5000 Thanks for the fix for 8.2.0. Both Ubuntu 18.04 and 20.04 seem to be on SWI 7.6.4 in the official repos, so accepting the PR will break it for users (at least) on those platforms. So, we have to either (1) support both SWI 7 and 8 in the same package or (2) maintain another fork/package for SWI 8.There is a refactored PySwip living in a private repo which makes it easier to do (1), but it's notready for prime time yet.

Is using SWI 7 for the time being an option for you? What are the most important features you use from SWI 8?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yuce/pyswip/issues/92#issuecomment-646413955, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3QJLGYQBWC5EGL3MGOGHTRXLK53ANCNFSM4OBB3FPA .

allComputableThings commented 4 years ago

I could refactor the PR so it detects the version and correctly sets the constants. Is it worth if there’s another version cooking?

On Thu, Jun 18, 2020 at 8:29 PM Stuart Reynolds stuart@stuartreynolds.net wrote:

Hmm... that makes sense. I followed the SWI instructions and installed from the ppa. I’m using tabling and dict’s from 8.

On Thu, Jun 18, 2020 at 8:24 PM Yüce Tekol notifications@github.com wrote:

@stuz5000 https://github.com/stuz5000 Thanks for the fix for 8.2.0. Both Ubuntu 18.04 and 20.04 seem to be on SWI 7.6.4 in the official repos, so accepting the PR will break it for users (at least) on those platforms. So, we have to either (1) support both SWI 7 and 8 in the same package or (2) maintain another fork/package for SWI 8.There is a refactored PySwip living in a private repo which makes it easier to do (1), but it's notready for prime time yet.

Is using SWI 7 for the time being an option for you? What are the most important features you use from SWI 8?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yuce/pyswip/issues/92#issuecomment-646413955, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3QJLGYQBWC5EGL3MGOGHTRXLK53ANCNFSM4OBB3FPA .

yuce commented 4 years ago

I think it definitely worths it. The other version is not coming out soon, and when it does it will still need to check for the version.

allComputableThings commented 4 years ago

OK -- I've checked in a fix to provide back compatibility.