# Ann: SWI-Prolog 9.1.0

**URL:** <https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964>\
**Category:** Releases\
**Created:** [November 24, 2022, 2:30pm UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964 "2022-11-24T14:30:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 24, 2022, 2:31pm UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964/1 "2022-11-24T14:31:00Z")

</div>

Dear SWI-Prolog user,

SWI-Prolog 9.1.0 is ready for download. This version starts a new  
development cycle and is practically identical to 9.0.0. Highlights:

- Many new features and fixes to the new Emacs sweeprolog mode by  
@oskardrums

- Almost final version of the new C++ interface SWI-cpp2,h by  
@peter.ludemann. There are still a few discussions going on  
about part of the API. Anyone working in C++ is kindly  
requested to review the current state.

- Pretty stable GMP replacement using LibBF is included. Should  
work fine for most applications, but can be slow, notably for  
handling larger rational numbers (\> 64 bits).

- Lots of small stuff, notably about configuration, etc.

# SWI-Prolog Changelog since version 8.5.20

- SNAP: CMAKE\_INSTALL\_LIBDIR seems undefined inside snapcraft, causing  
the build to fail.

- SNAP: Latest snapcraft sets LD\_LIBRARY\_PATH to provide access to the  
“parts”. We should not consider this a broken environment.

- DOC: Fixed LaTeX issues blocking the generation of the PDF manual.

- TEST: Avoid name conflict between two tests to make test\_installation/0  
work again.

- ENHANCED: library(main) to delay looking for tspy/1 or gspy/1 until  
the option is activated.

- FIXED: Make X11 event dispatching work in single threaded version.

- TEST: Avoid testing stuff that requires threads in the single threaded  
version.

- CLEANUP: Do not compile code required for multi-threaded loading in  
the single threaded version.

- DOC: format/1-3: document behavior of `~0f`.

- CONFIG: Do not install thread libraries for single threaded version.

- MODIFIED: When ISO mode is enabled, unknown options are result in a  
domain error. This now also holds if the option argument is a dict.

- MODIFIED: Ssprintf() and Ssnprintf() functions now use UTF-8 encoding  
(used to be ISO Latin 1), so they can handle Unicode.

- ENHANCED: Use xref\_source/2 for fetching PlDoc comments from loaded  
sources. Patch by @swi.

- PORT: Provide backtrace with line numbers on MacOS using `atos`  
as replacement for `addr2line`.

- ADDED: prolog\_interrupt/0 to make a thread behave as if SIGINT is  
received using thread\_signal/2.

- FIXED: Do not reload system files to get their documentation.

- PORT: More integer passing problems over vararg functions.

- FIXED: Prolog flag `pid` on some 64 bit platforms.

- PORT: Use CMake to test for \<threads.h\> support.

- MAINTENANCE: Provide a Prolog flag `asan` when the system is compiled  
with AddressSanitizer.

- INSTALL: When using `-DSWIPL_INSTALL_IN_LIB`, make sure that the  
CMake export files can be relocated.

- WASM: Avoid undefined HTMLCollection.toList(). Emacs whitespace update

- MODIFIED: pack\_install/1 and friends to pass all environment variables  
to the tools that may be executed to build the pack.

- PORT: Issue#1070: pack\_install/1: Pass `PKG_CONFIG_PATH` to build  
tools

- FIXED: format/2,3: manage proper arithmetic environment for  
expressions.

- PORT: Make LibBF code compile for Clang

- FIXED: fetch/restore of Mersenne Twister random state. Also reduced  
the size of the state.

- MODIFIED: \*\*/2 and ^/2: If the power can be done using rational  
arithmetic but the numbers are too big, make the behaviour depend on  
`max_rational_size_action`. When `float`, try to continue after float  
conversion, else raise a resource error.

- FIXED: \*\*/2 and ^/2 overflow checking when computing the power of  
two rational numbers.

- ENHANCED: Prefer mpz\_sgn() over mpz\_cmp\_ui() to 0.

- ENHANCED: Key generation for bignum and rational clause indexing

- ADDED: BF\_FTOA\_PL\_QUIRKS for correct float formatting.

- MODIFIED: CMake `target_link_swipl()` now removes the `lib` prefix.

- PORT: Updated MacOS dependencies

- FIXED: swipl.cmake outside pack\_rebuild/2 context gets linking against  
libswipl wrong.

- FIXED: Issue#163: -s and -l files were loaded before the argv Prolog  
flag is cleaned.

- ADDED: prolog\_walk\_code/1: option walk\_meta\_predicates(+Boolean) to  
prevent the code walker from considering meta-predicates. There are  
few cases where this is interesting, but it was needed for constructing  
a s(CASP) dependency graph.

- DOC: Document (part of) the PL\_cvt\_i\__() functions and improve  
documentation for several of the PL\_get\__() and PL\_get\_\*\_ex()  
functions.

- ADDED: PL\_get\_bool() now also accepts the integers (0,1)

- PORT: set RPATH correctly on MacOS for native libs in packages

- ADDED: PL\_cvt\_i\_llong() PL\_cvt\_i\_ulong() and PL\_cvt\_i\_bool().  
This completes the types supported by these functions.

- ADDED: listing/1,2 to also accept a clause reference as entity to list.

## Package clib

- TEST: Disable tests that require threads on the single threaded  
version.

## Package cpp

- TEST: Fixed C interface PL\_scan\_options() tests.

- TEST: Renamed foreign function test module to `test_ffi`. This avoids  
a conflict (and confusion) with the ffi pack to run the tests  
interactively.

- TEST: Added PL\_scan\_options example

## Package http

- CONFIG: Reorganise installation and docs to distinguish core part we  
always want, the HTTP client and HTTP server libraries.

## Package odbc

- PORT: Allow compiling in single threaded mode.

## Package pldoc

- CONFIG: Make most of PlDoc work in the single threaded version.

- CONFIG: Make PlDoc work if the HTTP server components are not part  
of the configuration.

- ENHANCED: Source button to prefer loaded code over xref data.

## Package semweb

- FIXED: rdfa.pl: Avoid dependency oin development tools

## Package ssl

- TEST: Drop tests when single threaded.

## Package sweep

- ADDED: PlUnit tests block skeleton and command for inserting it \*  
sweeprolog.el (sweeprolog-format-string-as-atom): new function.  
(sweeprolog-module-header-skeleton): use define-skeleton, making it a  
command instead of a defconst. (sweeprolog-plunit-testset-skeleton):  
new skeleton and command. \* sweeprolog-tests: test it. \* [README.org](http://README.org)  
(“Writing Tests”): new section. (“Using templates for creating new  
modules”): rename to “Creating New Modules”.

- FIXED: instantiation error in color term normalization

- FIXED: sweeprolog-beginning-of-next-top-term: other possible loop \*  
sweeprolog.el (sweeprolog-beginning-of-next-top-term): don’t loop  
when called in the last term of the buffer \* sweeprolog-tests.el  
(beginning-of-next-top-term-at-last-clause): new test case

- FIXED: possible infinite loop looking for next term \* sweeprolog.el  
(sweeprolog-beginning-of-next-top-term): handle comments more reliably

- FIXED: exporting predicates in presence of exported  
operators \* sweep.pl (sweep\_exportable\_predicates/2): new  
predicate. \* sweeprolog.el (sweeprolog–module-term)  
(sweeprolog–exportable-predicates)  
(sweeprolog-analyze-start-exportable)  
(sweeprolog-analyze-fragment-exportable): no longer  
used, deleted. (sweeprolog-exportable-predicates): new  
function. (sweeprolog-read-exportable-predicate): use it.  
(sweeprolog-export-predicate): handle exported operators.

- ENHANCED: allow sweeprolog-forward-hole to wrap around \* sweeprolog.el  
(sweeprolog–next-hole, sweeprolog–previous-hole): new functions.  
(sweeprolog–forward-hole, sweeprolog–backward-hole): add WRAP arg.

- ENHANCED: conditional syntax error highlighting

- DOC: mention sweeprolog-swipl-path in the manual

- ADDED: minor mode for automatic whitespace insertion \* sweep.pl  
(sweep\_context\_callable/2): only consider the context to be  
callable if a neck is present up the tree, i.e. not in the head.

- ENHANCED: revise predicate completion at point Completion at point now  
detects whether predicate completion is appropriate, by parsing Prolog  
code back from point to determine the context of point. If predicate  
completion is not appropriate, fallback to atom completion.

- ADDED: user option specifying where to define new predicates

- FIXED: possible error in sweeprolog-describe-predicate

- DOC: document sweeprolog-xref-project-source-files in the manual

- ADDED: new command sweeprolog-xref-project-source-files

- FIXED: find user predicate definitions more reliably

- TEST: add test for updating syntax error faces

- FIXED: clear syntax error face after fix more aggressively

- FIXED: properly update query highlighting in the toplevel

- FIXED: simplify & make variable highlighting more reliable

- FIXED: only consider backslash as an escape inside strings

- FIXED: restrict variable underlining to current clause

- FIXED: variable name completion on Emacs 27 \* sweeprolog.el  
(sweeprolog-variable-completion-at-point): don’t rely on  
char-uppercase-p \* sweeprolog-tests.el (complete-variable): new test.

- ADDED: sweeprolog-forward/backward/mark-predicate

- REFACTOR: Simplify and deduplicate code all around \* sweeprolog.el  
(sweeprolog-colourise-_): rename to sweeprolog-analyze-_

- FIXED: correctly recognize “public” head terms

- TEST: add two test cases

- FIXED: sweeprolog-identifier-at-point could return unbound module

- FIXED: write\_sweep\_module\_location/0 for Windows.

- DOC: added section “Code Completion” to the manual

- ADDED: completion-at-point for variable names \*  
sweeprolog.el (sweeprolog-local-variables-collection,  
sweeprolog-variable-completion-at-point):  
new functions. (sweeprolog-mode): add to  
completion-at-point-functions. (sweeprolog-mode-syntax-table): update  
according to char\_type(Char, prolog\_symbol).

- ADDED: context-based command for inserting new clauses or terms \*  
sweeprolog.el (sweeprolog–forward-hole, sweeprolog–backward-hole):  
new functions. (sweeprolog-forward-hole): new command.  
(sweeprolog-end-of-predicate-definition,sweeprolog-insert-clause,  
sweeprolog-maybe-insert-next-clause,  
sweeprolog-maybe-define-predicate): new functions.  
(sweeprolog-insert-term-functions): new hook.  
(sweeprolog-insert-term-dwim): new command. (sweeprolog-mode-map):  
bind new commands. \* sweeprolog-tests.el (dwim-define-predicate): new  
test case. \* [README.org](http://README.org) (Context-Based Term Insertion): new section.

- ENHANCED: render refs to Prolog library in help buffers \* sweeprolog.el  
(sweeprolog-render-html-a): recognize and render references to Prolog  
library files.

- FIXED: handling of operators as predicate completion candidates

- FIXED: don’t include irrelevant candidates in apropos results \*  
sweep.pl (sweep\_predicate\_apropos/2): filter candidates by minimum  
match quality.

- ENHANCED: add predicate properties list in help buffers \* sweep.pl  
(sweep\_predicate\_properties/2): new predicate. \* sweeprolog.el  
(sweeprolog–render-predicate-properties): new function.  
(sweeprolog–describe-predicate): use it.

- ENHANCED: load and initialize sweep-module just-in-time Instead  
of loading sweep-module and initializing Prolog as part of loading  
sweeprolog.el (subject to the user option sweeprolog-init-on-load),  
this commit introduces just-in-time loading and initialization  
of Prolog. Suggested by Stefan Monnier.

- ENHANCED: teach sweep to jump to C code for built-in predicates

## Package swipl-win

- FIXED: Check return codes of many operations on lists.

- PORT: Changes for SWI-cpp.h API Version 2

## Package windows

- PORT: add libname to install() routine
- PORT: add libname to install() routine From this discussion:  
[Static executable (-DSTATIC\_EXTENSIONS) - #2 by jan](https://swi-prolog.discourse.group/t/static-executable-dstatic-extensions/5710/2)

“the install function of a library must be called install\_  
and the Prolog side must use use\_foreign\_library/1”

## Package xpce

- CONFIG: Avoid dependency on threads.

- FIXED: replace internal expand\_path/2 with absolute\_file\_name/3  
old code could not handle aliases like swi(library/clp) only  
swi(‘library/clp’)

## Package zlib

- TEST: Disable tests that requires threads

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [November 26, 2022, 2:02pm UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964/2 "2022-11-26T14:02:48Z")

</div>

I encountered problems while running the test suite under MSYS2. Two of the failures are already known (semweb:turtle and ntriples), I think this would require support for Unicode code points \> 0xFFFF which isn’t yet there. But the other two failures are new, cpp and mqi, and I think these may be fixed. Consider cpp, the error is at c:/msys64/home/c7201178/swipl-devel/packages/cpp/test\_cpp.pl:84

```prolog
test(as_string, S == "ä¸\u0096ç\u0095\u008Cå\u009B\u009B") :-
    error:current_encoding(Enc),
    writeln(Enc),
    atom_to_string(世界四, S).

```

I added the two lines with the encoding, they write “octet” on the screen. [On Linux, it says the same, though].

The error says

```prolog
Test project C:/msys64/home/c7201178/swipl-devel/build
    Start 43: cpp:cpp
1/4 Test #43: cpp:cpp ..........................***Failed 3.51 sec
% PL-Unit: cpp ...........octet
ERROR: c:/msys64/home/c7201178/swipl-devel/packages/cpp/test_cpp.pl:84:
        test as_string: received error: atom_to_string/2: Cannot represent due to `encoding' (Cannot represent char U4e16 using current locale encoding)

```

Still, I am wondering if the error just results from the test suite not loading test\_cpp.pl properly. If I reduce the file to the minimum, like this:

```prolog
$ cat test_cpp2.pl
% -*- mode: Prolog; coding: utf-8 -*-

test :-
    atom_string(世界四, S),
    writeln(S).

```

and then invoke swipl, I need to explicitly state the encoding of the file:

```prolog
c7201178@PC105-C720 MINGW64 ~/swipl-devel/packages/cpp
$ ~/swipl/bin/swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.1.0-7-g039a75912-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

1 ?- [test_cpp2].
ERROR: c:/msys64/home/c7201178/swipl-devel/packages/cpp/test_cpp2.pl:4:17: Syntax error: Operator expected
true.

2 ?- load_files(test_cpp2).
ERROR: c:/msys64/home/c7201178/swipl-devel/packages/cpp/test_cpp2.pl:4:17: Syntax error: Operator expected
true.

3 ?- load_files(test_cpp2, [encoding(utf8)]).
true.

4 ?- test.
世界四
true.

5 ?- halt.

```

Any idea how I could isolate this better?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 26, 2022, 4:02pm UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964/3 "2022-11-26T16:02:44Z")

</div>

> [@mgondan1](#):
>
> (semweb:turtle and ntriples), I think this would require support for Unicode code points \> 0xFFFF which isn’t yet there.

Well, since some time the core supports the full Unicode range on Windows. These external libraries consider wide strings UCS-2 encoded (on Windows), while they should use UTF-16.

> [@mgondan1](#):
>
> [mqi](https://www.swi-prolog.org/pldoc/doc_for?object=section(%27packages/mqi.html%27))

What is the problem here? Could be that the JSON libraries cannot handle the full Unicode range for the same reason as the semweb libraries.

> [@mgondan1](#):
>
> `ERROR: c:/msys64/home/c7201178/swipl-devel/packages/cpp/test_cpp.pl:84:`

The test is invalid. The code extracts the raw data from a (wide) atom and translates this into a byte string. The raw data format is different in Windows (UTF-16) than on non-Windows (UCS-4). For now I disabled these two tests for Windows. I think `as_string()` should better raise an exception when applied to wide-character arrays as the result is basically undefined.

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [November 26, 2022, 5:48pm UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964/4 "2022-11-26T17:48:17Z")

</div>

The failures in cpp and mqi have disappeared after updating.

> [@jan](#):
>
> Well, since some time the core supports the full Unicode range on Windows.

Ah, I wasn’t sure about this. Great!

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [November 26, 2022, 8:35pm UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964/5 "2022-11-26T20:35:40Z")

</div>

> [@jan](#):
>
> These external libraries consider wide strings UCS-2 encoded (on Windows), while they should use UTF-16.

Indeed, addBuf in ntriples.c “cuts” the upper bits away,

```prolog
static inline int
addBuf(string_buffer *b, int c)
{
  if ( b->in < b->end )
  { *b->in++ = c; // here, \\U00012345 becomes \\u2345
    return TRUE;
  }

  return growBuffer(b, c);
}

```

It’s a bit disturbing that gcc does not even issue a warning. (EDIT: -Wconversion would do so)

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 27, 2022, 9:10am UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964/6 "2022-11-27T09:10:28Z")

</div>

For the core we have some support functions and macros in `src/os/pl-utf-8.[c,h]` (name of the file is a bit misleading now as it support both UTF-8 and UTF-16). I don’t really like the idea of providing support for processing encoding to SWI-Prolog.h as that has nothing to do with Prolog.

Possibly we should have a reusable header/library to support the packages with stuff that is not related to Prolog directly, but still required for multiple packages?

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [November 27, 2022, 6:51pm UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964/7 "2022-11-27T18:51:27Z")

</div>

> [@mgondan1](#):
>
> -Wconversion would do so

I use these flags – they’ve caught a few problems (and also some in included libraries):  
`-Wall -Wextra -Wconversion -Wsign-conversion -Wfloat-conversion -Wno-unused-parameter`  
and `-Warith-conversion` (which doesn’t work with Clang)

I’d use `-Werror` as well, but there were a few “bogus” warnings unfortunately.

---

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [December 7, 2022, 6:44pm UTC](https://swi-prolog.discourse.group/t/ann-swi-prolog-9-1-0/5964/8 "2022-12-07T18:44:14Z")

</div>

A quick fix would thus be

```prolog
static inline int
addBuf_old(string_buffer *b, int c)
{ if ( b->in < b->end )
  { *b->in++ = c;
    return TRUE;
  }

  return growBuffer(b, c);
}

static inline int
addBuf(string_buffer *b, int c)
{ if ( c <= 0xffff )
    return addBuf_old(b, c) ;

  int l, t ;
  utf16_encode(c, &l, &t);
  return addBuf_old(b, l) && addBuf_old(b, t) ;
}

```

Does this make sense?
