Re: Loading database from string (C API)
Edd Barrett <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hello again, On Wed, Dec 11, 2013 at 03:59:09PM +0100, Jan Wielemaker wrote: > On 12/11/2013 03:41 PM, Edd Barrett wrote: > > Search for blob. Basically, if PL_term_type() gives PL_ATOM, it > may be a blob or a real atom. Use PL_is_atom() to find out. > With this workaround applied I am now at the point where I am calling load_files/2, as suggested earlier in this thread. Sadly something is amiss; ideally I would have a C program to demonstrate, but this would be a fairly large piece of code and I would have to translate it from Python CFFI to C. Before I go there let's see if anything obvious springs out. So I have constructed the predicate and arguments needed to call load_files(pl_source, [stream(pl_stream)]), where pl_source is an atom to identify the code in the stream (as described in the docs) and pl_stream is the stream opened using the open_stream C function that we have already discussed. For testing purposes I have passed the theory "f(1)." to the function. The call to load_files/2 (in Python/CFFI) looks like this: pl_qid = self.libpl.PL_open_query(self.ffi.NULL, self.libpl.PL_CATCH_Q_CATCH_EXCEPTION, pl_pred, pl_args) pl_pred is a the result of a PL_predicate() call for load_files of arity 2. pl_args is an 'array'(?) of term refs as given by PL_new_term_refs(). To check these are good I can call PL_get_chars with CVT_WRITE_CANONICAL: Arg 1: swithon_theory -- arbitrary name chosen for the stream Arg 2: '.'(stream(<stream>(0x18ebfd824c00)),[]) -- list with one element, the stream Looks OK. The qid returned looks valid too. The call to open_query is followed by: pl_sol = self.libpl.PL_next_solution(pl_qid); At this point we use PL_exception() to check for an exception etc. The problem is execution never gets past the call to PL_next_solution. The interpreter seems to be stuck in a loop printing: ---8<--- ERROR: Syntax error: Unexpected end of clause ERROR: ERROR: ** here ** ERROR: . ERROR: Syntax error: Unexpected end of clause ERROR: ERROR: ** here ** ERROR: . ERROR: Syntax error: Unexpected end of clause ... ---8<--- Stuff I have tried: * Remove dot on the end of the theory string -- same error. * Varying the theory string in other ways -- no change. * Try different PL_Q_* -- no difference. * Change character encoding on the stream -- same. Is that expected behaviour? -- Best Regards Edd Barrett http://www.theunixzoo.co.uk