Hi,

I am starting a tiny HTTP client library after completing my Redis thing as I 
want to make a server and things like that and as usual, along the way, a 
gremlin has appeared!

Here is the *faulty* code:
        
testing(X) :-
        open_output_codes_stream(Out),
        set_output(Out),
        format("GET /my/slippers/now/jeeves\r\n",[]),
        close_output_codes_stream(Out, X).

when I run this from the REPL it blows when I try to display X in this query:

| ?- testing(V), format(‘~s~n',[V]).

Fatal Error: Segmentation Violation (bad address: 0x10)
I examined my code and I realised that after closing the output stream I had 
not restored the default stream back to user_output. This appears to be the 
cause of the blowout. If I run this modified code:

testing(X) :-
        open_output_codes_stream(Out),
        set_output(Out),
        format("GET /my/slippers/now/jeeves\r\n",[]),
        close_output_codes_stream(Out, X),
        set_output(user_output).

This works as expected:

| ?- testing(C), format('~s~n',[C]).
GET /my/slippers/now/jeeves


C = 
[71,69,84,32,47,109,121,47,115,108,105,112,112,101,114,115,47,110,111,119,47,106,101,101,118,101,115,13,10]

yes

In the documentation for close/2, close/1 it says:
 If SorA is the current output stream the current output stream becomes the 
standard output stream user_output.

I couldn’t determine what close_output_codes_stream/2 does and so it would seem 
that the user_output stream was in some indeterminate value?

Hope that helps track it down.

Many thanks again to Daniel and his Elves for GNU Prolog and a Merry Christmas 
everybody out there that buys into that particular scheme etc.

:)
Sean.

_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to