SWI getc and putc may call prolog: protect them with slots.
allow format to codes/2 and terminate memory stream.
This commit is contained in:
parent
68a1ab6ce7
commit
d6bd81ce81
28
C/iopreds.c
28
C/iopreds.c
@ -810,14 +810,24 @@ MemPutc(int sno, int ch)
|
|||||||
static int
|
static int
|
||||||
IOSWIPutc(int sno, int ch)
|
IOSWIPutc(int sno, int ch)
|
||||||
{
|
{
|
||||||
return (SWIPutc)(ch, Stream[sno].u.swi_stream.swi_ptr);
|
int i;
|
||||||
|
Yap_StartSlots();
|
||||||
|
i = (SWIPutc)(ch, Stream[sno].u.swi_stream.swi_ptr);
|
||||||
|
Yap_CloseSlots();
|
||||||
|
YENV = ENV;
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
static int
|
static int
|
||||||
IOSWIGetc(int sno, int ch)
|
IOSWIGetc(int sno, int ch)
|
||||||
{
|
{
|
||||||
return (SWIGetc)(Stream[sno].u.swi_stream.swi_ptr);
|
int i;
|
||||||
|
Yap_StartSlots();
|
||||||
|
i = (SWIGetc)(Stream[sno].u.swi_stream.swi_ptr);
|
||||||
|
Yap_CloseSlots();
|
||||||
|
YENV = ENV;
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_SOCKET
|
#if USE_SOCKET
|
||||||
@ -5627,7 +5637,7 @@ static Int
|
|||||||
p_format2(void)
|
p_format2(void)
|
||||||
{ /* 'format'(Stream,Control,Args) */
|
{ /* 'format'(Stream,Control,Args) */
|
||||||
int old_c_stream = Yap_c_output_stream;
|
int old_c_stream = Yap_c_output_stream;
|
||||||
int mem_stream = FALSE;
|
int mem_stream = FALSE, codes_stream = FALSE;
|
||||||
Int out;
|
Int out;
|
||||||
Term tin = Deref(ARG1);
|
Term tin = Deref(ARG1);
|
||||||
|
|
||||||
@ -5638,6 +5648,10 @@ p_format2(void)
|
|||||||
if (IsApplTerm(tin) && FunctorOfTerm(tin) == FunctorAtom) {
|
if (IsApplTerm(tin) && FunctorOfTerm(tin) == FunctorAtom) {
|
||||||
Yap_c_output_stream = OpenBufWriteStream();
|
Yap_c_output_stream = OpenBufWriteStream();
|
||||||
mem_stream = TRUE;
|
mem_stream = TRUE;
|
||||||
|
} else if (IsApplTerm(tin) && FunctorOfTerm(tin) == FunctorCodes) {
|
||||||
|
Yap_c_output_stream = OpenBufWriteStream();
|
||||||
|
codes_stream = TRUE;
|
||||||
|
mem_stream = TRUE;
|
||||||
} else {
|
} else {
|
||||||
/* needs to change Yap_c_output_stream for write */
|
/* needs to change Yap_c_output_stream for write */
|
||||||
Yap_c_output_stream = CheckStream (ARG1, Output_Stream_f, "format/3");
|
Yap_c_output_stream = CheckStream (ARG1, Output_Stream_f, "format/3");
|
||||||
@ -5650,12 +5664,18 @@ p_format2(void)
|
|||||||
out = format(Deref(ARG2),Deref(ARG3),Yap_c_output_stream);
|
out = format(Deref(ARG2),Deref(ARG3),Yap_c_output_stream);
|
||||||
if (mem_stream) {
|
if (mem_stream) {
|
||||||
Term tat;
|
Term tat;
|
||||||
|
Term inp = Deref(ARG1);
|
||||||
int stream = Yap_c_output_stream;
|
int stream = Yap_c_output_stream;
|
||||||
Yap_c_output_stream = old_c_stream;
|
Yap_c_output_stream = old_c_stream;
|
||||||
if (out) {
|
if (out) {
|
||||||
|
Stream[stream].u.mem_string.buf[Stream[stream].u.mem_string.pos] = '\0';
|
||||||
|
if (codes_stream) {
|
||||||
|
tat = Yap_StringToDiffList(Stream[stream].u.mem_string.buf, ArgOfTerm(2,inp));
|
||||||
|
} else {
|
||||||
tat = MkAtomTerm(Yap_LookupAtom(Stream[stream].u.mem_string.buf));
|
tat = MkAtomTerm(Yap_LookupAtom(Stream[stream].u.mem_string.buf));
|
||||||
|
}
|
||||||
CloseStream(stream);
|
CloseStream(stream);
|
||||||
if (!Yap_unify(tat,ArgOfTerm(1,ARG1)))
|
if (!Yap_unify(tat,ArgOfTerm(1,inp)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
CloseStream(stream);
|
CloseStream(stream);
|
||||||
|
Reference in New Issue
Block a user