SWI seems to use t=0 for user_input/output. Not very clear why...

This commit is contained in:
Vítor Santos Costa 2010-12-15 20:03:22 +00:00
parent d1665c7462
commit 4546a22101
4 changed files with 24 additions and 11 deletions

View File

@ -3490,7 +3490,7 @@ CheckStream (Term arg, int kind, char *msg)
if (kind & SWI_Stream_f) {
struct io_stream *swi_stream;
if (Yap_get_stream_handle(arg, &swi_stream)) {
if (Yap_get_stream_handle(arg, kind & Input_Stream_f, kind & Output_Stream_f, &swi_stream)) {
sno = LookupSWIStream(swi_stream);
return sno;
}
@ -3690,9 +3690,11 @@ Yap_CloseStreams (int loud)
} else {
free(Stream[sno].u.mem_string.buf);
}
} else if (!(Stream[sno].status & Null_Stream_f))
} else if (Stream[sno].status & (SWI_Stream_f)) {
SWIClose(Stream[sno].u.swi_stream.swi_ptr);
} else if (!(Stream[sno].status & Null_Stream_f)) {
YP_fclose (Stream[sno].u.file.file);
else {
} else {
if (loud)
fprintf (Yap_stderr, "%% YAP Error: while closing stream: %s\n", RepAtom (Stream[sno].u.file.name)->StrOfAE);
}

View File

@ -461,7 +461,7 @@ void STD_PROTO(Yap_InitMYDDAS_TopLevelPreds,(void));
/* yap2swi.c */
void STD_PROTO(Yap_swi_install,(void));
void STD_PROTO(Yap_InitSWIHash,(void));
int STD_PROTO(Yap_get_stream_handle,(Term, void *));
int STD_PROTO(Yap_get_stream_handle,(Term, int, int, void *));
/* ypsocks.c */
void STD_PROTO(Yap_InitSockets,(void));

View File

@ -3098,13 +3098,20 @@ PL_YAP_InitSWIIO(struct SWI_IO *swio)
SWIGetStream = swio->get_stream_handle;
}
typedef int (*GetStreamF)(term_t, IOSTREAM **s);
typedef int (*GetStreamF)(term_t, int, int, IOSTREAM **s);
int
Yap_get_stream_handle(Term t0, void *s){
term_t t = (term_t)YAP_InitSlot(t0);
Yap_get_stream_handle(Term t0, int read_mode, int write_mode, void *s){
term_t t;
GetStreamF f = (GetStreamF)SWIGetStream;
return (*f)(t,s);
if (t0 == MkAtomTerm(AtomUserOut) && write_mode && !read_mode) {
t = 0;
} else if (t0 == MkAtomTerm(AtomUserIn) && !write_mode && read_mode) {
t = 0;
} else {
t = (term_t)YAP_InitSlot(t0);
}
return (*f)(t, read_mode, write_mode, s);
}

View File

@ -4340,12 +4340,16 @@ static const PL_extension foreigns[] = {
};
static int
get_stream_handle_no_errors(term_t t, IOSTREAM **s)
get_stream_handle_no_errors(term_t t, int read, int write, IOSTREAM **s)
{ GET_LD
if ( t == 0 )
{ if (write) *s = getStream(Scurout);
else *s = getStream(Scurout);
return TRUE;
}
return get_stream_handle(t, s, SH_ALIAS);
}
static void
init_yap_extras(void)
{
@ -4357,7 +4361,7 @@ init_yap_extras(void)
swiio.get_w = Sgetcode;
swiio.put_w = Sputcode;
swiio.flush_s = Sflush;
swiio.close_s = Sclose;
swiio.close_s = closeStream;
swiio.get_stream_handle = get_stream_handle_no_errors;
PL_YAP_InitSWIIO(&swiio);
initCharTypes();