Merge branch 'master' of gitosis@yap.dcc.fc.up.pt:yap-6
This commit is contained in:
commit
42bdf4f50b
@ -2039,8 +2039,12 @@ YAP_GoalHasException(Term *t)
|
||||
BACKUP_MACHINE_REGS();
|
||||
if (EX) {
|
||||
do {
|
||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||
*t = Yap_FetchTermFromDB(EX);
|
||||
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
||||
if (Yap_Error_TYPE == YAP_NO_ERROR) {
|
||||
RECOVER_MACHINE_REGS();
|
||||
return TRUE;
|
||||
} else if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
|
||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||
if (!Yap_growglobal(NULL)) {
|
||||
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
|
||||
@ -2107,7 +2111,7 @@ YAP_Read(int (*mygetc)(void))
|
||||
BACKUP_MACHINE_REGS();
|
||||
|
||||
do_getf = mygetc;
|
||||
sno = Yap_GetFreeStreamDForReading();
|
||||
sno = Yap_GetFreeStreamDForReading();
|
||||
if (sno < 0) {
|
||||
Yap_Error(SYSTEM_ERROR,TermNil, "new stream not available for YAP_Read");
|
||||
return TermNil;
|
||||
@ -2116,6 +2120,7 @@ YAP_Read(int (*mygetc)(void))
|
||||
Stream[sno].status |= Tty_Stream_f;
|
||||
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(sno, &tpos);
|
||||
Stream[sno].status = Free_Stream_f;
|
||||
UNLOCK(Stream[sno].streamlock);
|
||||
if (Yap_ErrorMessage)
|
||||
{
|
||||
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
|
||||
|
5
C/exec.c
5
C/exec.c
@ -948,10 +948,12 @@ p_pred_goal_expansion_on(void) {
|
||||
return PRED_GOAL_EXPANSION_ON;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
exec_absmi(int top)
|
||||
{
|
||||
int lval, out;
|
||||
|
||||
if (top && (lval = sigsetjmp (Yap_RestartEnv, 1)) != 0) {
|
||||
switch(lval) {
|
||||
case 1:
|
||||
@ -965,6 +967,9 @@ exec_absmi(int top)
|
||||
restore_B();
|
||||
/* H is not so important, because we're gonna backtrack */
|
||||
restore_H();
|
||||
/* set stack */
|
||||
ASP = B;
|
||||
Yap_StartSlots();
|
||||
LOCK(SignalLock);
|
||||
CreepFlag = CalculateStackGap();
|
||||
Yap_PrologMode = UserMode;
|
||||
|
2
C/init.c
2
C/init.c
@ -165,8 +165,6 @@ int Yap_CritLocks = 0;
|
||||
|
||||
/********* streams ********************************************/
|
||||
|
||||
int Yap_c_input_stream, Yap_c_output_stream, Yap_c_error_stream;
|
||||
|
||||
YP_FILE *Yap_stdin;
|
||||
YP_FILE *Yap_stdout;
|
||||
YP_FILE *Yap_stderr;
|
||||
|
29
C/iopreds.c
29
C/iopreds.c
@ -208,14 +208,17 @@ GetFreeStreamD(void)
|
||||
{
|
||||
int sno;
|
||||
|
||||
for (sno = 0; sno < MaxStreams; ++sno)
|
||||
if (Stream[sno].status & Free_Stream_f)
|
||||
for (sno = 0; sno < MaxStreams; ++sno) {
|
||||
LOCK(Stream[sno].streamlock);
|
||||
if (Stream[sno].status & Free_Stream_f) {
|
||||
break;
|
||||
}
|
||||
UNLOCK(Stream[sno].streamlock);
|
||||
}
|
||||
if (sno == MaxStreams) {
|
||||
return -1;
|
||||
}
|
||||
Stream[sno].encoding = DefaultEncoding();
|
||||
INIT_LOCK(Stream[sno].streamlock);
|
||||
return sno;
|
||||
}
|
||||
|
||||
@ -244,6 +247,7 @@ Yap_GetFreeStreamDForReading(void)
|
||||
s->stream_wgetc_for_read = ISOWGetc;
|
||||
else
|
||||
s->stream_wgetc_for_read = s->stream_wgetc;
|
||||
UNLOCK(s->streamlock);
|
||||
return sno;
|
||||
}
|
||||
|
||||
@ -2120,6 +2124,7 @@ Yap_InitSocketStream(int fd, socket_info flags, socket_domain domain) {
|
||||
st->stream_wgetc_for_read = ISOWGetc;
|
||||
else
|
||||
st->stream_wgetc_for_read = st->stream_wgetc;
|
||||
UNLOCK(st->streamlock);
|
||||
return(MkStream(sno));
|
||||
}
|
||||
|
||||
@ -2409,8 +2414,10 @@ p_open (void)
|
||||
st = &Stream[sno];
|
||||
/* can never happen */
|
||||
tenc = Deref(ARG5);
|
||||
if (IsVarTerm(tenc) || !IsIntegerTerm(tenc))
|
||||
if (IsVarTerm(tenc) || !IsIntegerTerm(tenc)) {
|
||||
UNLOCK(st->streamlock);
|
||||
return FALSE;
|
||||
}
|
||||
encoding = IntegerOfTerm(tenc);
|
||||
#ifdef _WIN32
|
||||
if (opts & 2) {
|
||||
@ -2422,6 +2429,7 @@ p_open (void)
|
||||
if ((st->u.file.file = YP_fopen (Yap_FileNameBuf, io_mode)) == YAP_ERROR ||
|
||||
(!(opts & 2 /* binary */) && binary_file(Yap_FileNameBuf)))
|
||||
{
|
||||
UNLOCK(st->streamlock);
|
||||
if (open_mode == AtomCsult)
|
||||
{
|
||||
if (!find_csult_file (Yap_FileNameBuf, Yap_FileNameBuf2, st, io_mode))
|
||||
@ -2494,6 +2502,7 @@ p_open (void)
|
||||
st->stream_getc = PlGetc;
|
||||
st->stream_gets = PlGetsFunc();
|
||||
}
|
||||
UNLOCK(st->streamlock);
|
||||
ta[1] = MkAtomTerm(AtomTrue);
|
||||
t = Yap_MkApplTerm(Yap_MkFunctor(AtomReposition,1),1,ta);
|
||||
Yap_Error(PERMISSION_ERROR_OPEN_SOURCE_SINK,t,"open/4");
|
||||
@ -2537,6 +2546,7 @@ p_open (void)
|
||||
st->stream_wgetc_for_read = ISOWGetc;
|
||||
else
|
||||
st->stream_wgetc_for_read = st->stream_wgetc;
|
||||
UNLOCK(st->streamlock);
|
||||
t = MkStream (sno);
|
||||
if (open_mode == AtomWrite ) {
|
||||
if (needs_bom && !write_bom(sno,st))
|
||||
@ -2693,6 +2703,7 @@ p_open_null_stream (void)
|
||||
st->stream_wgetc = get_wchar;
|
||||
st->stream_wgetc_for_read = get_wchar;
|
||||
st->u.file.user_name = MkAtomTerm (st->u.file.name = AtomDevNull);
|
||||
UNLOCK(st->streamlock);
|
||||
t = MkStream (sno);
|
||||
return (Yap_unify (ARG1, t));
|
||||
}
|
||||
@ -2754,6 +2765,7 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
|
||||
st->stream_wgetc_for_read = ISOWGetc;
|
||||
else
|
||||
st->stream_wgetc_for_read = st->stream_wgetc;
|
||||
UNLOCK(st->streamlock);
|
||||
t = MkStream (sno);
|
||||
return t;
|
||||
}
|
||||
@ -2806,6 +2818,7 @@ p_open_pipe_stream (void)
|
||||
#else
|
||||
st->u.pipe.fd = filedes[0];
|
||||
#endif
|
||||
UNLOCK(st->streamlock);
|
||||
sno = GetFreeStreamD();
|
||||
if (sno < 0)
|
||||
return (PlIOError (RESOURCE_ERROR_MAX_STREAMS,TermNil, "new stream not available for open_pipe_stream/2"));
|
||||
@ -2828,6 +2841,7 @@ p_open_pipe_stream (void)
|
||||
#else
|
||||
st->u.pipe.fd = filedes[1];
|
||||
#endif
|
||||
UNLOCK(st->streamlock);
|
||||
t2 = MkStream (sno);
|
||||
return
|
||||
Yap_unify (ARG1, t1) &&
|
||||
@ -2864,6 +2878,7 @@ open_buf_read_stream(char *nbuf, Int nchars)
|
||||
st->u.mem_string.max_size = nchars;
|
||||
st->u.mem_string.error_handler = NULL;
|
||||
st->u.mem_string.src = MEM_BUF_CODE;
|
||||
UNLOCK(st->streamlock);
|
||||
return sno;
|
||||
}
|
||||
|
||||
@ -2942,6 +2957,7 @@ open_buf_write_stream(char *nbuf, UInt sz)
|
||||
st->u.mem_string.buf = nbuf;
|
||||
st->u.mem_string.max_size = sz;
|
||||
st->u.mem_string.src = MEM_BUF_CODE;
|
||||
UNLOCK(st->streamlock);
|
||||
return sno;
|
||||
}
|
||||
|
||||
@ -3190,6 +3206,7 @@ LookupSWIStream (struct io_stream *swi_s)
|
||||
Stream[i].stream_wgetc_for_read = ISOWGetc;
|
||||
else
|
||||
Stream[i].stream_wgetc_for_read = IOSWIWideGetc;
|
||||
UNLOCK(Stream[i].streamlock);
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -3240,20 +3257,22 @@ CheckStream (Term arg, int kind, char *msg)
|
||||
Yap_Error(DOMAIN_ERROR_STREAM_OR_ALIAS, arg, msg);
|
||||
return (-1);
|
||||
}
|
||||
LOCK(Stream[sno].streamlock);
|
||||
if (Stream[sno].status & Free_Stream_f)
|
||||
{
|
||||
UNLOCK(Stream[sno].streamlock);
|
||||
Yap_Error(EXISTENCE_ERROR_STREAM, arg, msg);
|
||||
return (-1);
|
||||
}
|
||||
if ((Stream[sno].status & kind) == 0)
|
||||
{
|
||||
UNLOCK(Stream[sno].streamlock);
|
||||
if (kind & Input_Stream_f)
|
||||
Yap_Error(PERMISSION_ERROR_INPUT_STREAM, arg, msg);
|
||||
else
|
||||
Yap_Error(PERMISSION_ERROR_OUTPUT_STREAM, arg, msg);
|
||||
return (-1);
|
||||
}
|
||||
LOCK(Stream[sno].streamlock);
|
||||
return (sno);
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,9 @@ store_specs(int new_worker_id, UInt ssize, UInt tsize, UInt sysize, Term *tpgoal
|
||||
FOREIGN_ThreadHandle(new_worker_id).ssize = ssize;
|
||||
FOREIGN_ThreadHandle(new_worker_id).tsize = tsize;
|
||||
FOREIGN_ThreadHandle(new_worker_id).sysize = sysize;
|
||||
FOREIGN_WL(new_worker_id)->c_input_stream = Yap_c_input_stream;
|
||||
FOREIGN_WL(new_worker_id)->c_output_stream = Yap_c_output_stream;
|
||||
FOREIGN_WL(new_worker_id)->c_error_stream = Yap_c_error_stream;
|
||||
pm = (ssize + tsize)*1024;
|
||||
if (!(FOREIGN_ThreadHandle(new_worker_id).stack_address = malloc(pm))) {
|
||||
return FALSE;
|
||||
|
@ -21,6 +21,10 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#define Yap_c_input_stream WL->c_input_stream
|
||||
#define Yap_c_output_stream WL->c_output_stream
|
||||
#define Yap_c_error_stream WL->c_error_stream
|
||||
|
||||
#define OldASP WL->rinfo.old_ASP
|
||||
#define OldLCL0 WL->rinfo.old_LCL0
|
||||
|
@ -22,6 +22,10 @@
|
||||
|
||||
typedef struct worker_local {
|
||||
|
||||
int c_input_stream;
|
||||
int c_output_stream;
|
||||
int c_error_stream;
|
||||
|
||||
restoreinfo rinfo;
|
||||
|
||||
|
||||
|
@ -22,6 +22,10 @@
|
||||
|
||||
static void InitWorker(int wid) {
|
||||
|
||||
FOREIGN_WL(wid)->c_input_stream = 0;
|
||||
FOREIGN_WL(wid)->c_output_stream = 1;
|
||||
FOREIGN_WL(wid)->c_error_stream = 2;
|
||||
|
||||
FOREIGN_WL(wid)->rinfo.old_ASP = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_LCL0 = NULL;
|
||||
FOREIGN_WL(wid)->rinfo.old_TR = NULL;
|
||||
|
@ -54,6 +54,10 @@ static void RestoreWorker(int wid) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -322,11 +322,6 @@ Term STD_PROTO(Yap_WStringToList,(wchar_t *));
|
||||
Term STD_PROTO(Yap_WStringToListOfAtoms,(wchar_t *));
|
||||
Atom STD_PROTO(Yap_LookupWideAtom,(wchar_t *));
|
||||
|
||||
extern int
|
||||
Yap_c_input_stream,
|
||||
Yap_c_output_stream,
|
||||
Yap_c_error_stream;
|
||||
|
||||
#define YAP_INPUT_STREAM 0x01
|
||||
#define YAP_OUTPUT_STREAM 0x02
|
||||
#define YAP_APPEND_STREAM 0x04
|
||||
|
@ -20,6 +20,11 @@
|
||||
// Stuff that must be considered local to a thread or worker
|
||||
START_WORKER_LOCAL
|
||||
|
||||
// Streams
|
||||
int c_input_stream Yap_c_input_stream =0
|
||||
int c_output_stream Yap_c_output_stream =1
|
||||
int c_error_stream Yap_c_error_stream =2
|
||||
|
||||
/* shifts and restore: per local data-structure */
|
||||
restoreinfo rinfo
|
||||
. rinfo.old_ASP OldASP =NULL
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 7c9456b5c9c60ab227674f7653dc226e13973484
|
||||
Subproject commit 6e7c68cdcc5d781d218b57d04f2a16b3e0bcbfca
|
Reference in New Issue
Block a user