Re: Loading database from string (C API)

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 12/12/2013 06:10 PM, Edd Barrett wrote:
> On Thu, Dec 12, 2013 at 05:30:36PM +0100, Jan Wielemaker wrote:
>> I'd replace the call to load_files/2 by something else and
>> then dump the content of the stream.  E.g.
>>
>> test_files(_Id, [stream(Stream)]) :-
>> 	copy_stream_data(Stream, user_output),
>> 	flush_output(user_output).
>>
>> That should print f(1). to the user output.  Most likely it will not
>> do that.  The precise output might give you a hint what is wrong.
> 
> It does indeed print 'f(1).'. We didn't want that to happen did we?

It might have been easier if it had printed something else ...

> I also checked if loading from a stream works, it does:
> 
> ---8<---
> ?- open('a.pl', read, Stream).                    
> Stream = <stream>(0x166c275e0e00).
> ?- load_files(blah, [stream(Stream)]).
> % blah compiled 0.00 sec, 2 clauses
> true.
> ---8<---
> 
> Hmm, this is mysterious. I will think a bit more, but in the interest of
> moving on I may just write the database text to a file and consult it.

Just a guess.  Is the string properly allocated, such that it won't move
or be overwritten or whatever if Prolog and or Python are going to
do garbage collection or malloc() reuses the freed address, or ...

	Cheers --- Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.