fix locks
This commit is contained in:
parent
1c06bfdc05
commit
f5b50a4179
@ -2641,6 +2641,7 @@ YAP_InitConsult(int mode, const char *filename)
|
|||||||
return -1;
|
return -1;
|
||||||
sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f );
|
sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f );
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return sno;
|
return sno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2964,7 +2965,7 @@ YAP_Init(YAP_init_args *yap_init)
|
|||||||
*/
|
*/
|
||||||
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG, yap_init->HaltAfterConsult );
|
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG, yap_init->HaltAfterConsult );
|
||||||
}
|
}
|
||||||
/* tell the system who should cope with interruptions */
|
/* tell the system who should cope with interrupts */
|
||||||
Yap_ExecutionMode = yap_init->ExecutionMode;
|
Yap_ExecutionMode = yap_init->ExecutionMode;
|
||||||
if (do_bootstrap) {
|
if (do_bootstrap) {
|
||||||
restore_result = YAP_BOOT_FROM_PROLOG;
|
restore_result = YAP_BOOT_FROM_PROLOG;
|
||||||
|
6
C/qlyr.c
6
C/qlyr.c
@ -741,6 +741,7 @@ p_get_header( USES_REGS1 )
|
|||||||
FILE *stream;
|
FILE *stream;
|
||||||
Term t1 = Deref(ARG1);
|
Term t1 = Deref(ARG1);
|
||||||
Atom at;
|
Atom at;
|
||||||
|
Int rc;
|
||||||
|
|
||||||
if (IsVarTerm(t1)) {
|
if (IsVarTerm(t1)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3");
|
Yap_Error(INSTANTIATION_ERROR,t1,"read_program/3");
|
||||||
@ -750,8 +751,9 @@ p_get_header( USES_REGS1 )
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if ((at = get_header( stream )) == NIL)
|
if ((at = get_header( stream )) == NIL)
|
||||||
return FALSE;
|
rc = FALSE;
|
||||||
return Yap_unify( ARG2, MkAtomTerm( at ) );
|
else rc = Yap_unify( ARG2, MkAtomTerm( at ) );
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -52,7 +52,7 @@ blob_type_t PL_Message_Queue = {
|
|||||||
#if DEBUG_LOCKS||DEBUG_PE_LOCKS
|
#if DEBUG_LOCKS||DEBUG_PE_LOCKS
|
||||||
|
|
||||||
int debug_locks = FALSE, debug_pe_locks = FALSE;
|
int debug_locks = FALSE, debug_pe_locks = FALSE;
|
||||||
static Int p_debug_locks( USES_REGS1 ) { debugf=stdout; debug_pe_locks = 1; return TRUE; }
|
static Int p_debug_locks( USES_REGS1 ) { debug_pe_locks = 1; return TRUE; }
|
||||||
|
|
||||||
static Int p_nodebug_locks( USES_REGS1 ) { debug_locks = 0; debug_pe_locks = 0; return TRUE; }
|
static Int p_nodebug_locks( USES_REGS1 ) { debug_locks = 0; debug_pe_locks = 0; return TRUE; }
|
||||||
|
|
||||||
@ -1590,8 +1590,6 @@ Yap_InitFirstWorkerThreadHandle(void)
|
|||||||
LOCAL_ThreadHandle.ref_count = 1;
|
LOCAL_ThreadHandle.ref_count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *debugf;
|
|
||||||
|
|
||||||
void Yap_InitThreadPreds(void)
|
void Yap_InitThreadPreds(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
13
C/tracer.c
13
C/tracer.c
@ -97,10 +97,19 @@ check_trail_consistency(void) {
|
|||||||
|
|
||||||
CELL old_value = 0L, old_value2 = 0L;
|
CELL old_value = 0L, old_value2 = 0L;
|
||||||
|
|
||||||
void jmp_deb(int);
|
void jmp_deb(int), jmp_deb2(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
jmp_deb(int i) {if (i) printf("Here we go\n"); else jmp_deb(0);}
|
jmp_deb2( void )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Here\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
jmp_deb(int i) {
|
||||||
|
if (i) printf("Here we go %ld\n", old_value++);
|
||||||
|
if (old_value == 716) jmp_deb2();
|
||||||
|
}
|
||||||
|
|
||||||
struct various_codes *sc;
|
struct various_codes *sc;
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
//#define DEBUG_PE_LOCKS 1
|
//#define DEBUG_PE_LOCKS 1
|
||||||
#define DEBUG_LOCKS 1
|
//#define DEBUG_LOCKS 1
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int Yap_ThreadID( void );
|
int Yap_ThreadID( void );
|
||||||
#define debugf stdout
|
#define debugf ( stderr ? stderr : stdout )
|
||||||
|
|
||||||
#define INIT_LOCK(LOCK_VAR) (void)(fprintf(debugf, "[%d] %s:%d: LOCK(%p)\n", Yap_ThreadID(),__BASE_FILE__, __LINE__,&(LOCK_VAR)) && pthread_mutex_init(&(LOCK_VAR), NULL) )
|
#define INIT_LOCK(LOCK_VAR) pthread_mutex_init(&(LOCK_VAR), NULL)
|
||||||
#define DESTROY_LOCK(LOCK_VAR) pthread_mutex_destroy(&(LOCK_VAR))
|
#define DESTROY_LOCK(LOCK_VAR) pthread_mutex_destroy(&(LOCK_VAR))
|
||||||
#define TRY_LOCK(LOCK_VAR) pthread_mutex_trylock(&(LOCK_VAR))
|
#define TRY_LOCK(LOCK_VAR) pthread_mutex_trylock(&(LOCK_VAR))
|
||||||
#if DEBUG_LOCKS
|
#if DEBUG_LOCKS
|
||||||
|
@ -808,11 +808,12 @@ peek_code ( USES_REGS1 )
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
if (GLOBAL_Stream[sno].status & Binary_Stream_f) {
|
if (GLOBAL_Stream[sno].status & Binary_Stream_f) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "peek_code/2");
|
PlIOError(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "peek_code/2");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if ((ch = dopeek( sno )) < 0)
|
if ((ch = dopeek( sno )) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return(Yap_unify_constant(ARG2,MkIntTerm(ch)));
|
return(Yap_unify_constant(ARG2,MkIntTerm(ch)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -841,6 +842,7 @@ peek_code_1 ( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
if ((ch = dopeek( sno )) < 0)
|
if ((ch = dopeek( sno )) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return(Yap_unify_constant(ARG2,MkIntTerm(ch)));
|
return(Yap_unify_constant(ARG2,MkIntTerm(ch)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -857,7 +859,7 @@ peek_byte ( USES_REGS1 )
|
|||||||
{ /* at_end_of_stream */
|
{ /* at_end_of_stream */
|
||||||
/* the next character is a EOF */
|
/* the next character is a EOF */
|
||||||
int sno = Yap_CheckStream (ARG1, Input_Stream_f, "peek/2");
|
int sno = Yap_CheckStream (ARG1, Input_Stream_f, "peek/2");
|
||||||
Int ch;
|
Int ch;
|
||||||
|
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
@ -868,6 +870,7 @@ peek_byte ( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
if ((ch = dopeek( sno )) < 0)
|
if ((ch = dopeek( sno )) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return(Yap_unify_constant(ARG2,MkIntTerm(ch)));
|
return(Yap_unify_constant(ARG2,MkIntTerm(ch)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,13 +347,15 @@ file_size(USES_REGS1)
|
|||||||
// there
|
// there
|
||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
if (fstat(fileno(GLOBAL_Stream[sno].file), &file_stat) < 0) {
|
if (fstat(fileno(GLOBAL_Stream[sno].file), &file_stat) < 0) {
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
PlIOError( PERMISSION_ERROR_INPUT_STREAM, ARG1, "%s in file_size/2", strerror(errno));
|
PlIOError( PERMISSION_ERROR_INPUT_STREAM, ARG1, "%s in file_size/2", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// and back again
|
// and back again
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return Yap_unify_constant( ARG2, MkIntegerTerm( file_stat.st_size) );
|
return Yap_unify_constant( ARG2, MkIntegerTerm( file_stat.st_size) );
|
||||||
}
|
}
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1650,7 +1650,7 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
|
|||||||
if (sname == AtomUser) {
|
if (sname == AtomUser) {
|
||||||
if (kind & Input_Stream_f) {
|
if (kind & Input_Stream_f) {
|
||||||
if (kind & (Output_Stream_f|Append_Stream_f)) {
|
if (kind & (Output_Stream_f|Append_Stream_f)) {
|
||||||
Yap_Error(PERMISSION_ERROR_INPUT_STREAM, arg,
|
PlIOError(PERMISSION_ERROR_INPUT_STREAM, arg,
|
||||||
"ambiguous use of 'user' as a stream");
|
"ambiguous use of 'user' as a stream");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@ -1690,6 +1690,7 @@ Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags)
|
|||||||
Yap_Error(PERMISSION_ERROR_OUTPUT_STREAM, arg, msg);
|
Yap_Error(PERMISSION_ERROR_OUTPUT_STREAM, arg, msg);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
jmp_deb(1);
|
||||||
return (sno);
|
return (sno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,8 +824,8 @@ read2 ( USES_REGS1 )
|
|||||||
if (inp_stream == -1) {
|
if (inp_stream == -1) {
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
|
||||||
out = Yap_read_term(inp_stream, TermNil, 1);
|
out = Yap_read_term(inp_stream, TermNil, 1);
|
||||||
|
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
||||||
return out && Yap_unify(ARG2, out);
|
return out && Yap_unify(ARG2, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -938,7 +938,8 @@ Yap_StringToTerm(const char *s, size_t len, encoding_t enc, int prio, Term *bind
|
|||||||
|
|
||||||
rval = Yap_read_term(stream, ctl, 3);
|
rval = Yap_read_term(stream, ctl, 3);
|
||||||
Yap_CloseStream(stream);
|
Yap_CloseStream(stream);
|
||||||
if (bindings) {
|
UNLOCK(GLOBAL_Stream[stream].streamlock);
|
||||||
|
if (rval && bindings) {
|
||||||
*bindings = Yap_GetFromSlot( sl );
|
*bindings = Yap_GetFromSlot( sl );
|
||||||
Yap_RecoverSlots( sl, 1 PASS_REGS);
|
Yap_RecoverSlots( sl, 1 PASS_REGS);
|
||||||
}
|
}
|
||||||
|
60
os/streams.c
60
os/streams.c
@ -102,29 +102,35 @@ static void CloseStream(int sno);
|
|||||||
FILE *Yap_GetInputStream(Term t, const char *msg)
|
FILE *Yap_GetInputStream(Term t, const char *msg)
|
||||||
{
|
{
|
||||||
int sno = Yap_CheckStream (t, Input_Stream_f, msg);
|
int sno = Yap_CheckStream (t, Input_Stream_f, msg);
|
||||||
|
FILE *rc;
|
||||||
|
|
||||||
if(!(GLOBAL_Stream[sno].status & (Tty_Stream_f|Socket_Stream_f|Pipe_Stream_f)))
|
if(!(GLOBAL_Stream[sno].status & (Tty_Stream_f|Socket_Stream_f|Pipe_Stream_f)))
|
||||||
return GLOBAL_Stream[sno].file;
|
rc = GLOBAL_Stream[sno].file;
|
||||||
return NULL;
|
else
|
||||||
|
rc = NULL;
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *Yap_GetOutputStream(Term t, const char *msg)
|
FILE *Yap_GetOutputStream(Term t, const char *msg)
|
||||||
{
|
{
|
||||||
int sno = Yap_CheckStream (t, Output_Stream_f, msg);
|
int sno = Yap_CheckStream (t, Output_Stream_f, msg);
|
||||||
|
FILE *rc;
|
||||||
|
|
||||||
if(!(GLOBAL_Stream[sno].status & (Tty_Stream_f|Socket_Stream_f)))
|
if(!(GLOBAL_Stream[sno].status & (Tty_Stream_f|Socket_Stream_f)))
|
||||||
return GLOBAL_Stream[sno].file;
|
rc = GLOBAL_Stream[sno].file;
|
||||||
|
else
|
||||||
return NULL;
|
rc = NULL;
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
GetFreeStreamD(void)
|
GetFreeStreamD(void)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
|
for (sno = 0; sno < MaxStreams; ++sno) {
|
||||||
for (sno = 0; sno < MaxStreams; ++sno) {
|
|
||||||
LOCK(GLOBAL_Stream[sno].streamlock);
|
LOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
if (GLOBAL_Stream[sno].status & Free_Stream_f) {
|
if (GLOBAL_Stream[sno].status & Free_Stream_f) {
|
||||||
break;
|
break;
|
||||||
@ -208,7 +214,6 @@ static Int
|
|||||||
is_input ( int sno USES_REGS )
|
is_input ( int sno USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
bool rc = GLOBAL_Stream[sno].status & Input_Stream_f;
|
bool rc = GLOBAL_Stream[sno].status & Input_Stream_f;
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,14 +221,12 @@ static Int
|
|||||||
is_output ( int sno USES_REGS )
|
is_output ( int sno USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
bool rc = GLOBAL_Stream[sno].status & (Output_Stream_f|Append_Stream_f);
|
bool rc = GLOBAL_Stream[sno].status & (Output_Stream_f|Append_Stream_f);
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
has_bom ( int sno, Term t2 USES_REGS )
|
has_bom ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
bool rc = GLOBAL_Stream[sno].status & Seekable_Stream_f;
|
bool rc = GLOBAL_Stream[sno].status & Seekable_Stream_f;
|
||||||
if (!IsVarTerm(t2) && !boolean(t2)) {
|
if (!IsVarTerm(t2) && !boolean(t2)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -234,11 +237,11 @@ has_bom ( int sno, Term t2 USES_REGS )
|
|||||||
return Yap_unify_constant(t2, TermFalse);
|
return Yap_unify_constant(t2, TermFalse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
has_reposition ( int sno, Term t2 USES_REGS )
|
has_reposition ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
bool rc = GLOBAL_Stream[sno].status & Seekable_Stream_f;
|
bool rc = GLOBAL_Stream[sno].status & Seekable_Stream_f;
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !boolean(t2)) {
|
if (!IsVarTerm(t2) && !boolean(t2)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -284,7 +287,6 @@ representation_error ( int sno, Term t2 USES_REGS )
|
|||||||
{
|
{
|
||||||
stream_flags_t flags = GLOBAL_Stream[sno].status & (RepError_Xml_f|RepError_Prolog_f);
|
stream_flags_t flags = GLOBAL_Stream[sno].status & (RepError_Xml_f|RepError_Prolog_f);
|
||||||
/* '$representation_error'(+Stream,-ErrorMessage) */
|
/* '$representation_error'(+Stream,-ErrorMessage) */
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && isatom(t2)) {
|
if (!IsVarTerm(t2) && isatom(t2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -308,7 +310,6 @@ file_name ( int sno, Term t2 USES_REGS )
|
|||||||
rc = MkAtomTerm(Yap_LookupAtom(name));
|
rc = MkAtomTerm(Yap_LookupAtom(name));
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !isatom(t2)) {
|
if (!IsVarTerm(t2) && !isatom(t2)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -320,7 +321,6 @@ file_no ( int sno, Term t2 USES_REGS )
|
|||||||
{
|
{
|
||||||
int f = Yap_GetStreamFd(sno);
|
int f = Yap_GetStreamFd(sno);
|
||||||
Term rc = MkIntTerm(f) ;
|
Term rc = MkIntTerm(f) ;
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !IsIntTerm(t2)) {
|
if (!IsVarTerm(t2) && !IsIntTerm(t2)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -355,7 +355,6 @@ has_close_on_abort ( int sno, Term t2 USES_REGS )
|
|||||||
static bool
|
static bool
|
||||||
has_encoding ( int sno, Term t2 USES_REGS )
|
has_encoding ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -375,7 +374,6 @@ static bool
|
|||||||
found_eof ( int sno, Term t2 USES_REGS )
|
found_eof ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
stream_flags_t flags = GLOBAL_Stream[sno].status & (Past_Eof_Stream_f|Eof_Stream_f);
|
stream_flags_t flags = GLOBAL_Stream[sno].status & (Past_Eof_Stream_f|Eof_Stream_f);
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -391,7 +389,6 @@ static bool
|
|||||||
stream_mode ( int sno, Term t2 USES_REGS )
|
stream_mode ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
stream_flags_t flags = GLOBAL_Stream[sno].status & (Input_Stream_f|Output_Stream_f|Append_Stream_f);
|
stream_flags_t flags = GLOBAL_Stream[sno].status & (Input_Stream_f|Output_Stream_f|Append_Stream_f);
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -408,7 +405,6 @@ static bool
|
|||||||
stream_tty ( int sno, Term t2 USES_REGS )
|
stream_tty ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
stream_flags_t flags = GLOBAL_Stream[sno].status & (Tty_Stream_f);
|
stream_flags_t flags = GLOBAL_Stream[sno].status & (Tty_Stream_f);
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -421,7 +417,6 @@ static bool
|
|||||||
stream_type ( int sno, Term t2 USES_REGS )
|
stream_type ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
stream_flags_t flags = GLOBAL_Stream[sno].status & (Binary_Stream_f);
|
stream_flags_t flags = GLOBAL_Stream[sno].status & (Binary_Stream_f);
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -434,7 +429,6 @@ static bool
|
|||||||
stream_position ( int sno, Term t2 USES_REGS )
|
stream_position ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
Term tout = StreamPosition(sno);
|
Term tout = StreamPosition(sno);
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
return Yap_unify (t2, tout);
|
return Yap_unify (t2, tout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,7 +468,6 @@ static bool
|
|||||||
eof_action ( int sno, Term t2 USES_REGS )
|
eof_action ( int sno, Term t2 USES_REGS )
|
||||||
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
{ /* '$set_output'(+Stream,-ErrorMessage) */
|
||||||
stream_flags_t flags = GLOBAL_Stream[sno].status & (Eof_Error_Stream_f|Reset_Eof_Stream_f|Push_Eof_Stream_f);
|
stream_flags_t flags = GLOBAL_Stream[sno].status & (Eof_Error_Stream_f|Reset_Eof_Stream_f|Push_Eof_Stream_f);
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
|
||||||
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
if (!IsVarTerm(t2) && !(isatom(t2))) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -706,6 +699,7 @@ do_set_stream (int sno, Term opts USES_REGS)
|
|||||||
|
|
||||||
args = Yap_ArgListToVector ( opts, set_stream_defs, SET_STREAM_END );
|
args = Yap_ArgListToVector ( opts, set_stream_defs, SET_STREAM_END );
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (i=0; i < SET_STREAM_END; i ++) {
|
for (i=0; i < SET_STREAM_END; i ++) {
|
||||||
@ -747,7 +741,7 @@ do_set_stream (int sno, Term opts USES_REGS)
|
|||||||
} else {
|
} else {
|
||||||
LOCAL_Error_TYPE = DOMAIN_ERROR_OUT_OF_RANGE;
|
LOCAL_Error_TYPE = DOMAIN_ERROR_OUT_OF_RANGE;
|
||||||
LOCAL_ErrorMessage = "in set_stream/2:eof_action";
|
LOCAL_ErrorMessage = "in set_stream/2:eof_action";
|
||||||
return false;
|
rc = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SET_STREAM_FILE_NAME:
|
case SET_STREAM_FILE_NAME:
|
||||||
@ -780,7 +774,7 @@ do_set_stream (int sno, Term opts USES_REGS)
|
|||||||
} else {
|
} else {
|
||||||
LOCAL_Error_TYPE = DOMAIN_ERROR_OUT_OF_RANGE;
|
LOCAL_Error_TYPE = DOMAIN_ERROR_OUT_OF_RANGE;
|
||||||
LOCAL_ErrorMessage = "in set_stream/2:eof_action";
|
LOCAL_ErrorMessage = "in set_stream/2:eof_action";
|
||||||
return false;
|
rc = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1265,13 +1259,13 @@ set_stream_position ( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
if (!(GLOBAL_Stream[sno].status & Seekable_Stream_f) ) {
|
if (!(GLOBAL_Stream[sno].status & Seekable_Stream_f) ) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
Yap_Error(PERMISSION_ERROR_REPOSITION_STREAM, ARG1,"set_stream_position/2");
|
PlIOError(PERMISSION_ERROR_REPOSITION_STREAM, ARG1,"set_stream_position/2");
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
if (fseek (GLOBAL_Stream[sno].file, 0L, SEEK_END) == -1) {
|
if (fseek (GLOBAL_Stream[sno].file, 0L, SEEK_END) == -1) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
Yap_Error(SYSTEM_ERROR, tp,
|
PlIOError(SYSTEM_ERROR, tp,
|
||||||
"fseek failed for set_stream_position/2");
|
"fseek failed for set_stream_position/2: %s", strerror(errno));
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
GLOBAL_Stream[sno].stream_getc = PlGetc;
|
GLOBAL_Stream[sno].stream_getc = PlGetc;
|
||||||
@ -1431,7 +1425,7 @@ Yap_StreamToFileNo(Term t)
|
|||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return(GLOBAL_Stream[sno].u.socket.fd);
|
return(GLOBAL_Stream[sno].u.socket.fd);
|
||||||
#endif
|
#endif
|
||||||
} else if (GLOBAL_Stream[sno].status & (Null_Stream_f|InMemory_Stream_f)) {
|
} else if (GLOBAL_Stream[sno].status & (Null_Stream_f)) {
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return(-1);
|
return(-1);
|
||||||
} else {
|
} else {
|
||||||
@ -1458,15 +1452,17 @@ FILE *
|
|||||||
Yap_FileDescriptorFromStream(Term t)
|
Yap_FileDescriptorFromStream(Term t)
|
||||||
{
|
{
|
||||||
int sno = Yap_CheckStream (t, Input_Stream_f|Output_Stream_f, "FileDescriptorFromStream");
|
int sno = Yap_CheckStream (t, Input_Stream_f|Output_Stream_f, "FileDescriptorFromStream");
|
||||||
|
FILE *rc;
|
||||||
if (sno < 0)
|
if (sno < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (GLOBAL_Stream[sno].status & (Null_Stream_f|
|
if (GLOBAL_Stream[sno].status & (Null_Stream_f|
|
||||||
InMemory_Stream_f|
|
|
||||||
Socket_Stream_f|
|
Socket_Stream_f|
|
||||||
Pipe_Stream_f|
|
Pipe_Stream_f|
|
||||||
Free_Stream_f))
|
Free_Stream_f))
|
||||||
return NULL;
|
rc = NULL;
|
||||||
return GLOBAL_Stream[sno].file;
|
else rc = GLOBAL_Stream[sno].file;
|
||||||
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user