Existance error only when calling through C API. UTF-8 characters.

11 views
Skip to first unread message

kalmen...@gmail.com

unread,
Apr 10, 2016, 4:23:14 PM4/10/16
to SWI-Prolog
Hey I could use some help tackling this issue.
I was given a prolog source file and tasked with querying it through A C++ program.
The file is UTF-8 encoded.

When running swipl in the terminal i do the following:
consult('file').
sõnad([aja,leht],B).
B = [ajaleht].
Everything works as expected.

Through the C API however, I get the following error:
Prolog query failed: Failure to generate solution: error(existence_error(procedure,s??nad/2),context(system:call/1,_G42))
The problem goes away, if i remove the 'õ' character.

querying current_prolog_flag(encoding,X) returns X = 'utf8'.

The code i'm using to query in c++ can be found here:
https://github.com/ethz-asl/ros-prolog/blob/master/prolog_swi/src/Query.cpp

take a look at Query::Impl::open()

Really hit the wall with this problem, any help is greatly appreciated.

Oliver

Jan Wielemaker

unread,
Apr 11, 2016, 2:53:58 AM4/11/16
to kalmen...@gmail.com, SWI-Prolog
The C(++) interface has two string APIs. The one using char* is
always interpreted as ISO Latin 1. If you need something else
you must use the wchar_t* functions/methods and translate to
unicode yourself.

There is one exception, the PL_unify_chars() and variation functions.
They take a flag arg that may include REP_MB to indicate locale
specific multibyte encoding.

Cheers --- Jan
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages