Skip to content

modernize for ghc 9.4.7 & swi-prolog 9.0.4 - #2

Open
gravermistakes wants to merge 2 commits into
aartamonau:masterfrom
gravermistakes:modernize-ghc9-swipl9
Open

modernize for ghc 9.4.7 & swi-prolog 9.0.4#2
gravermistakes wants to merge 2 commits into
aartamonau:masterfrom
gravermistakes:modernize-ghc9-swipl9

Conversation

@gravermistakes

Copy link
Copy Markdown

modernized hswip to ghc 9.4.7 & swi-prolog 9.0.4
prev fixes crashed modern swip from api drift

ffi fixes:

  • types CULong to CUIntPtr. term_t is uintptr_t, qid_t/fid_t are pointers. CULong correct for linux 64bit not win llp64. CUIntPtr good cross-platform & math in HSwip.hs still functions
  • PL_term_type constants: FLOAT 4 -> 5, STRING 5 -> 6, TERM 6 -> 7, w/ new NIL/BLOB/LIST_PAIR/DICT. prev table had TERM 7 as undefined, crashed on query
  • old BUF_ALLOC flag in PL_get_chars was 0x200, now CVT_WRITEQ. CVT_FLOAT moved 0x10 -> 0x20. stale flag caused a double free on an engine-owned buffer. now uses BUF_STACK and CVT_ALL, no free

cabal: haskell2010, ghc 9.4.7, v0.4
added smoke test, verified ghc 9.4.7 + swi-prolog 9.0.4

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.

@gravermistakes gravermistakes left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant