fix case where BOM is asked for, and fix case where file with BOM is
consulted, not just read. Also fix some deadlocks when protecting file access. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2066 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
456b4eb6c1
commit
fc2d89a372
@ -3810,7 +3810,7 @@ p_total_erased(void)
|
|||||||
/* only for log upds */
|
/* only for log upds */
|
||||||
while (cl) {
|
while (cl) {
|
||||||
cls++;
|
cls++;
|
||||||
fprintf(stderr,"cl=%p, %x %d\n",cl,cl->ClFlags,cl->ClRefCount);
|
fprintf(stderr,"cl=%p, %lx %lu\n",cl,(unsigned long int)cl->ClFlags,(unsigned long int)cl->ClRefCount);
|
||||||
sz += cl->ClSize;
|
sz += cl->ClSize;
|
||||||
cl = cl->ClNext;
|
cl = cl->ClNext;
|
||||||
}
|
}
|
||||||
|
67
C/iopreds.c
67
C/iopreds.c
@ -2374,7 +2374,7 @@ p_open (void)
|
|||||||
if (open_mode == AtomWrite ) {
|
if (open_mode == AtomWrite ) {
|
||||||
if (needs_bom && !write_bom(sno,st))
|
if (needs_bom && !write_bom(sno,st))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (open_mode == AtomRead &&
|
} else if ((open_mode == AtomRead || open_mode == AtomCsult) &&
|
||||||
!avoid_bom &&
|
!avoid_bom &&
|
||||||
(needs_bom || (st->status & Seekable_Stream_f))) {
|
(needs_bom || (st->status & Seekable_Stream_f))) {
|
||||||
if (!check_bom(sno, st))
|
if (!check_bom(sno, st))
|
||||||
@ -2448,9 +2448,10 @@ static Int p_change_alias_to_stream (void)
|
|||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
at = AtomOfTerm(tname);
|
at = AtomOfTerm(tname);
|
||||||
if ((sno = CheckStream (tstream, Input_Stream_f | Output_Stream_f | Append_Stream_f | Socket_Stream_f, "change_stream_alias/2"))
|
if ((sno = CheckStream (tstream, Input_Stream_f | Output_Stream_f | Append_Stream_f | Socket_Stream_f, "change_stream_alias/2")) == -1) {
|
||||||
== -1)
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
}
|
||||||
SetAlias(at, sno);
|
SetAlias(at, sno);
|
||||||
UNLOCK(Stream[sno].streamlock);
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
@ -3103,7 +3104,7 @@ init_cur_s (void)
|
|||||||
|
|
||||||
i = CheckStream (t3, Input_Stream_f|Output_Stream_f, "current_stream/3");
|
i = CheckStream (t3, Input_Stream_f|Output_Stream_f, "current_stream/3");
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
return(FALSE);
|
return FALSE;
|
||||||
}
|
}
|
||||||
t1 = StreamName(i);
|
t1 = StreamName(i);
|
||||||
t2 = (Stream[i].status & Input_Stream_f ?
|
t2 = (Stream[i].status & Input_Stream_f ?
|
||||||
@ -3125,28 +3126,26 @@ cont_cur_s (void)
|
|||||||
{ /* current_stream */
|
{ /* current_stream */
|
||||||
Term t1, t2, t3;
|
Term t1, t2, t3;
|
||||||
int i = IntOfTerm (EXTRA_CBACK_ARG (3, 1));
|
int i = IntOfTerm (EXTRA_CBACK_ARG (3, 1));
|
||||||
while (i < MaxStreams)
|
while (i < MaxStreams) {
|
||||||
{
|
LOCK(Stream[i].streamlock);
|
||||||
if (Stream[i].status & Free_Stream_f)
|
if (Stream[i].status & Free_Stream_f) {
|
||||||
{
|
++i;
|
||||||
++i;
|
UNLOCK(Stream[i-1].streamlock);
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
t1 = StreamName(i);
|
|
||||||
t2 = (Stream[i].status & Input_Stream_f ?
|
|
||||||
MkAtomTerm (AtomRead) :
|
|
||||||
MkAtomTerm (AtomWrite));
|
|
||||||
t3 = MkStream (i++);
|
|
||||||
EXTRA_CBACK_ARG (3, 1) = Unsigned (MkIntTerm (i));
|
|
||||||
if (Yap_unify (ARG3, t3) && Yap_unify_constant (ARG1, t1) && Yap_unify_constant (ARG2, t2))
|
|
||||||
{
|
|
||||||
return (TRUE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return(FALSE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
t1 = StreamName(i);
|
||||||
|
t2 = (Stream[i].status & Input_Stream_f ?
|
||||||
|
MkAtomTerm (AtomRead) :
|
||||||
|
MkAtomTerm (AtomWrite));
|
||||||
|
t3 = MkStream (i++);
|
||||||
|
UNLOCK(Stream[i-1].streamlock);
|
||||||
|
EXTRA_CBACK_ARG (3, 1) = Unsigned (MkIntTerm (i));
|
||||||
|
if (Yap_unify (ARG3, t3) && Yap_unify_constant (ARG1, t1) && Yap_unify_constant (ARG2, t2)) {
|
||||||
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
cut_fail();
|
cut_fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3296,6 +3295,7 @@ p_past_eof (void)
|
|||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
if (Stream[sno].stream_getc == PlUnGetc) {
|
if (Stream[sno].stream_getc == PlUnGetc) {
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
out = Stream[sno].status & Eof_Stream_f;
|
out = Stream[sno].status & Eof_Stream_f;
|
||||||
@ -3408,7 +3408,7 @@ p_set_input (void)
|
|||||||
return (FALSE);
|
return (FALSE);
|
||||||
Yap_c_input_stream = sno;
|
Yap_c_input_stream = sno;
|
||||||
UNLOCK(Stream[sno].streamlock);
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return (TRUE);
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
@ -3416,7 +3416,7 @@ p_set_output (void)
|
|||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
Int sno = CheckStream (ARG1, Output_Stream_f, "set_output/1");
|
Int sno = CheckStream (ARG1, Output_Stream_f, "set_output/1");
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (FALSE);
|
return FALSE;
|
||||||
Yap_c_output_stream = sno;
|
Yap_c_output_stream = sno;
|
||||||
UNLOCK(Stream[sno].streamlock);
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
@ -3428,6 +3428,7 @@ p_has_bom (void)
|
|||||||
Int sno = CheckStream (ARG1, Input_Stream_f|Output_Stream_f, "has_bom/1");
|
Int sno = CheckStream (ARG1, Input_Stream_f|Output_Stream_f, "has_bom/1");
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return ((Stream[sno].status & HAS_BOM_f));
|
return ((Stream[sno].status & HAS_BOM_f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3440,6 +3441,7 @@ p_representation_error (void)
|
|||||||
Term t = Deref(ARG2);
|
Term t = Deref(ARG2);
|
||||||
|
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
if (Stream[sno].status & RepError_Prolog_f) {
|
if (Stream[sno].status & RepError_Prolog_f) {
|
||||||
return Yap_unify(ARG2, MkIntegerTerm(512));
|
return Yap_unify(ARG2, MkIntegerTerm(512));
|
||||||
}
|
}
|
||||||
@ -3477,14 +3479,14 @@ p_current_input (void)
|
|||||||
if (CellPtr(t1) < H0) Yap_WakeUp(VarOfTerm(t1));
|
if (CellPtr(t1) < H0) Yap_WakeUp(VarOfTerm(t1));
|
||||||
bind_in_current_input:
|
bind_in_current_input:
|
||||||
#endif
|
#endif
|
||||||
return(TRUE);
|
return TRUE;
|
||||||
} else if (!IsApplTerm(t1) ||
|
} else if (!IsApplTerm(t1) ||
|
||||||
FunctorOfTerm(t1) != FunctorStream ||
|
FunctorOfTerm(t1) != FunctorStream ||
|
||||||
!IsIntTerm((t1=ArgOfTerm(1,t1)))) {
|
!IsIntTerm((t1=ArgOfTerm(1,t1)))) {
|
||||||
Yap_Error(DOMAIN_ERROR_STREAM,t1,"current_input/1");
|
Yap_Error(DOMAIN_ERROR_STREAM,t1,"current_input/1");
|
||||||
return(FALSE);
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
return(Yap_c_input_stream == IntOfTerm(t1));
|
return Yap_c_input_stream == IntOfTerm(t1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3500,12 +3502,12 @@ p_current_output (void)
|
|||||||
if (CellPtr(t1) < H0) Yap_WakeUp(VarOfTerm(t1));
|
if (CellPtr(t1) < H0) Yap_WakeUp(VarOfTerm(t1));
|
||||||
bind_in_current_output:
|
bind_in_current_output:
|
||||||
#endif
|
#endif
|
||||||
return(TRUE);
|
return TRUE;
|
||||||
} else if (!IsApplTerm(t1) ||
|
} else if (!IsApplTerm(t1) ||
|
||||||
FunctorOfTerm(t1) != FunctorStream ||
|
FunctorOfTerm(t1) != FunctorStream ||
|
||||||
!IsIntTerm((t1=ArgOfTerm(1,t1)))) {
|
!IsIntTerm((t1=ArgOfTerm(1,t1)))) {
|
||||||
Yap_Error(DOMAIN_ERROR_STREAM,t1,"current_output/1");
|
Yap_Error(DOMAIN_ERROR_STREAM,t1,"current_output/1");
|
||||||
return(FALSE);
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
return(Yap_c_output_stream == IntOfTerm(t1));
|
return(Yap_c_output_stream == IntOfTerm(t1));
|
||||||
}
|
}
|
||||||
@ -5879,6 +5881,7 @@ p_encoding (void)
|
|||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
|
UNLOCK(Stream[sno].streamlock);
|
||||||
return Yap_unify(ARG2, MkIntegerTerm(Stream[sno].encoding));
|
return Yap_unify(ARG2, MkIntegerTerm(Stream[sno].encoding));
|
||||||
}
|
}
|
||||||
Stream[sno].encoding = IntegerOfTerm(Deref(ARG2));
|
Stream[sno].encoding = IntegerOfTerm(Deref(ARG2));
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
<h2>Yap-5.1.3:</h2>
|
<h2>Yap-5.1.3:</h2>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li> FIXED: more BOM trouble (obs from P Moura).</li>
|
||||||
<li> FIXED: testing for BOM forced incorrect execution of gets (obs
|
<li> FIXED: testing for BOM forced incorrect execution of gets (obs
|
||||||
from A N Saravanaraj), also fixed stup call to Ungetc in getc and
|
from A N Saravanaraj), also fixed stup call to Ungetc in getc and
|
||||||
friends.</li>
|
friends.</li>
|
||||||
|
49
pl/yio.yap
49
pl/yio.yap
@ -59,8 +59,9 @@ close(S,Opts) :-
|
|||||||
|
|
||||||
open(F,T,S,Opts) :-
|
open(F,T,S,Opts) :-
|
||||||
'$check_io_opts'(Opts,open(F,T,S,Opts)),
|
'$check_io_opts'(Opts,open(F,T,S,Opts)),
|
||||||
'$process_open_opts'(Opts, 0, N, Aliases, E),
|
'$process_open_opts'(Opts, 0, N, Aliases, E, BOM),
|
||||||
'$open2'(F,T,S,N,E),
|
'$open2'(F,T,S,N,E),
|
||||||
|
'$process_bom'(S, BOM).
|
||||||
'$process_open_aliases'(Aliases,S).
|
'$process_open_aliases'(Aliases,S).
|
||||||
|
|
||||||
'$open2'(Source,M,T,N,_) :- var(Source), !,
|
'$open2'(Source,M,T,N,_) :- var(Source), !,
|
||||||
@ -72,41 +73,53 @@ open(F,T,S,Opts) :-
|
|||||||
'$open2'(File,Mode,Stream,N,Encoding) :-
|
'$open2'(File,Mode,Stream,N,Encoding) :-
|
||||||
'$open'(File,Mode,Stream,N,Encoding).
|
'$open'(File,Mode,Stream,N,Encoding).
|
||||||
|
|
||||||
|
'$process_bom'(S, BOM) :-
|
||||||
|
var(BOM), !,
|
||||||
|
( '$has_bom'(S) -> BOM = true ; BOM = false ).
|
||||||
|
'$process_bom'(_, _).
|
||||||
|
|
||||||
|
|
||||||
'$process_open_aliases'([],_).
|
'$process_open_aliases'([],_).
|
||||||
'$process_open_aliases'([Alias|Aliases],S) :-
|
'$process_open_aliases'([Alias|Aliases],S) :-
|
||||||
'$add_alias_to_stream'(Alias, S),
|
'$add_alias_to_stream'(Alias, S),
|
||||||
'$process_open_aliases'(Aliases,S).
|
'$process_open_aliases'(Aliases,S).
|
||||||
|
|
||||||
'$process_open_opts'([], N, N, [], DefaultEncoding) :-
|
'$process_open_opts'([], N, N, [], DefaultEncoding, []) :-
|
||||||
'$default_encoding'(DefaultEncoding).
|
'$default_encoding'(DefaultEncoding).
|
||||||
'$process_open_opts'([type(T)|L], N0, N, Aliases, Encoding) :-
|
'$process_open_opts'([type(T)|L], N0, N, Aliases, Encoding, BOM) :-
|
||||||
'$value_open_opt'(T,type,I1,I2),
|
'$value_open_opt'(T,type,I1,I2),
|
||||||
N1 is I1\/N0,
|
N1 is I1\/N0,
|
||||||
N2 is I2/\N1,
|
N2 is I2/\N1,
|
||||||
'$process_open_opts'(L,N2,N, Aliases, Encoding).
|
'$process_open_opts'(L,N2,N, Aliases, Encoding, BOM).
|
||||||
'$process_open_opts'([reposition(T)|L], N0, N, Aliases, Encoding) :-
|
'$process_open_opts'([reposition(T)|L], N0, N, Aliases, Encoding, BOM) :-
|
||||||
'$value_open_opt'(T,reposition,I1,I2),
|
'$value_open_opt'(T,reposition,I1,I2),
|
||||||
N1 is I1\/N0,
|
N1 is I1\/N0,
|
||||||
N2 is I2/\N1,
|
N2 is I2/\N1,
|
||||||
'$process_open_opts'(L,N2,N, Aliases, Encoding).
|
'$process_open_opts'(L,N2,N, Aliases, Encoding, BOM).
|
||||||
'$process_open_opts'([encoding(Enc)|L], N0, N, Aliases, EncCode) :-
|
'$process_open_opts'([encoding(Enc)|L], N0, N, Aliases, EncCode, BOM) :-
|
||||||
'$valid_encoding'(Enc, EncCode),
|
'$valid_encoding'(Enc, EncCode),
|
||||||
'$process_open_opts'(L, N0, N, Aliases, _).
|
'$process_open_opts'(L, N0, N, Aliases, _, BOM).
|
||||||
'$process_open_opts'([representation_errors(Mode)|L], N0, N, Aliases, EncCode) :-
|
'$process_open_opts'([representation_errors(Mode)|L], N0, N, Aliases, EncCode, BOM) :-
|
||||||
'$valid_reperrorhandler'(Mode, Flag),
|
'$valid_reperrorhandler'(Mode, Flag),
|
||||||
NI is N0 \/ Flag,
|
NI is N0 \/ Flag,
|
||||||
'$process_open_opts'(L, NI, N, Aliases, EncCode).
|
'$process_open_opts'(L, NI, N, Aliases, EncCode, BOM).
|
||||||
'$process_open_opts'([bom(BOM)|L], N0, N, Aliases, EncCode) :-
|
'$process_open_opts'([bom(BOM)|L], N0, N, Aliases, EncCode, BOM) :-
|
||||||
'$valid_bom'(BOM, Flag),
|
(
|
||||||
NI is N0 \/ Flag,
|
var(BOM)
|
||||||
'$process_open_opts'(L, NI, N, Aliases, EncCode).
|
->
|
||||||
'$process_open_opts'([eof_action(T)|L], N0, N, Aliases, Encoding) :-
|
true
|
||||||
|
;
|
||||||
|
'$valid_bom'(BOM, Flag),
|
||||||
|
NI is N0 \/ Flag
|
||||||
|
),
|
||||||
|
'$process_open_opts'(L, NI, N, Aliases, EncCode, _).
|
||||||
|
'$process_open_opts'([eof_action(T)|L], N0, N, Aliases, Encoding, BOM) :-
|
||||||
'$value_open_opt'(T,eof_action,I1,I2),
|
'$value_open_opt'(T,eof_action,I1,I2),
|
||||||
N1 is I1\/N0,
|
N1 is I1\/N0,
|
||||||
N2 is I2/\N1,
|
N2 is I2/\N1,
|
||||||
'$process_open_opts'(L,N2,N, Aliases, Encoding).
|
'$process_open_opts'(L,N2,N, Aliases, Encoding, BOM).
|
||||||
'$process_open_opts'([alias(Alias)|L], N0, N, [Alias|Aliases], Encoding) :-
|
'$process_open_opts'([alias(Alias)|L], N0, N, [Alias|Aliases], Encoding, BOM) :-
|
||||||
'$process_open_opts'(L,N0,N, Aliases, Encoding).
|
'$process_open_opts'(L,N0,N, Aliases, Encoding, BOM).
|
||||||
|
|
||||||
|
|
||||||
'$value_open_opt'(text,_,1,X) :- X is 128-2. % default
|
'$value_open_opt'(text,_,1,X) :- X is 128-2. % default
|
||||||
|
Reference in New Issue
Block a user