modernize for ghc 9.4.7 & swi-prolog 9.0.4 - #2
Open
gravermistakes wants to merge 2 commits into
Open
Conversation
The binding built against GHC 7.10 / SWI-Prolog 5.10 but segfaults or returns garbage against modern SWI-Prolog because several parts of the foreign API drifted. Fixes, all verified against a parent/child backtracking smoke test on SWI-Prolog 9.0.4 + GHC 9.4.7: * Handle types CULong -> CUIntPtr. term_t is uintptr_t and qid_t/fid_t are pointers; CULong only coincides with pointer width on LP64 and is wrong on LLP64 (Windows). CUIntPtr is correct everywhere and keeps the `swiplArgs + 1` term arithmetic in HSwip.hs working (Num instance). * PL_term_type constants: the enum shifted. FLOAT 4->5, STRING 5->6, TERM 6->7, with new PL_NIL(8)/PL_BLOB(9)/PL_LIST_PAIR(10)/PL_DICT(44). The old table mapped a compound term (now 7) to `undefined`, crashing every query that returned a structure. Rewrote against SWI-Prolog.h and made the default branch fail safe to TTerm instead of bottom. * PL_get_chars flags: the old `BUF_ALLOC 0x200` is now CVT_WRITEQ, and CVT_FLOAT moved 0x10->0x20. The stale flag asked the engine to allocate with PL_malloc and the binding then free()d an engine-owned buffer -> "double free detected in tcache". Now uses real CVT_ALL | BUF_STACK and does not free the engine buffer. * cabal: default-language Haskell98 -> Haskell2010, tested-with bumped to GHC==9.4.7, version 0.3 -> 0.4. (pkgconfig-depends: swipl retained.) Verified: asserta of six parent/2 facts; parent(X,Y) returns all six bindings; parent(bob, Who) correctly returns only pat and ann.
exitcode-stdio test-suite that asserts six parent/2 facts and checks parent(X,Y) yields six solutions and parent(bob, Who) yields pat and ann. Fails nonzero on any regression. Run with SWI_HOME_DIR set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
modernized hswip to ghc 9.4.7 & swi-prolog 9.0.4
prev fixes crashed modern swip from api drift
ffi fixes:
cabal: haskell2010, ghc 9.4.7, v0.4
added smoke test, verified ghc 9.4.7 + swi-prolog 9.0.4