]> Repositorios git - scryer-prolog.git/commit
fix type_error with instantiated EOF -1 byte literal in get_byte/2
authorManos Pitsidianakis <[email protected]>
Wed, 26 Oct 2022 10:49:38 +0000 (13:49 +0300)
committerManos Pitsidianakis <[email protected]>
Wed, 26 Oct 2022 10:49:38 +0000 (13:49 +0300)
commitb905d2758d1251004011a9fbf06987120551b042
treea33bd10d245c58ef9e9ba579c832f5cdebacd496
parent311d9851455c42bd3ee2fdf93b850a60482ce09e
fix type_error with instantiated EOF -1 byte literal in get_byte/2

According to ISO Prolog, get_byte/2 predicate can receive an
instantiated input byte:

http://www.gprolog.org/manual/html_node/gprolog037.html#sec156

    get_byte(+stream_or_alias, ?in_byte)

Since in_byte can be -1 if EOF is reached, instantiating it with -1
should work but does not because the implementation is trying to convert
it to a u8 which is unsigned:

?- open("/dev/null", read, S, [type(binary)]), get_byte(S, -1).
   error(type_error(in_byte,-1),get_byte/2).

This commit adds an extra check for -1 before checking for a valid u8
instantiated value if in_byte is an input:

?- open("/dev/null", read, S, [type(binary)]), get_byte(S, -1).
   S = '$stream'(0x55601e65c998).

Closes #1625
src/machine/system_calls.rs