allow SWI Interface to send/receive wide characters.

This commit is contained in:
Vítor Santos Costa 2010-07-21 10:58:24 +01:00
parent 1f3455a656
commit b61d69ffe8
9 changed files with 71 additions and 29 deletions

View File

@ -828,6 +828,30 @@ IOSWIGetc(int sno)
return i;
}
/* static */
static int
IOSWIWidePutc(int sno, int ch)
{
int i;
Yap_StartSlots();
i = (SWIWidePutc)(ch, Stream[sno].u.swi_stream.swi_ptr);
Yap_CloseSlots();
YENV = ENV;
return i;
}
/* static */
static int
IOSWIWideGetc(int sno)
{
int i;
Yap_StartSlots();
i = (SWIWideGetc)(Stream[sno].u.swi_stream.swi_ptr);
Yap_CloseSlots();
YENV = ENV;
return i;
}
#if USE_SOCKET
/* static */
static int
@ -1271,6 +1295,9 @@ EOFGetc(int sno)
s->stream_getc = PlGetc;
s->stream_gets = PlGetsFunc();
}
if (s->status & SWI_Stream_f)
s->stream_wgetc = IOSWIWideGetc;
else
s->stream_wgetc = get_wchar;
if (CharConversionTable != NULL)
s->stream_wgetc_for_read = ISOWGetc;
@ -3156,13 +3183,13 @@ LookupSWIStream (struct io_stream *swi_s)
Stream[i].encoding = DefaultEncoding();
Stream[i].stream_getc = IOSWIGetc;
Stream[i].stream_putc = IOSWIPutc;
Stream[i].stream_wputc = put_wchar;
Stream[i].stream_wgetc = get_wchar;
Stream[i].stream_wputc = IOSWIWidePutc;
Stream[i].stream_wgetc = IOSWIWideGetc;
Stream[i].stream_gets = DefaultGets;
if (CharConversionTable != NULL)
Stream[i].stream_wgetc_for_read = ISOWGetc;
else
Stream[i].stream_wgetc_for_read = get_wchar;
Stream[i].stream_wgetc_for_read = IOSWIWideGetc;
return i;
}
@ -4575,9 +4602,9 @@ p_get (void)
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "get/2");
return FALSE;
}
while ((ch = get_wchar(sno)) <= 32 && ch >= 0);
while ((ch = Stream[sno].stream_wgetc(sno)) <= 32 && ch >= 0);
UNLOCK(Stream[sno].streamlock);
return (Yap_unify_constant (ARG2, MkIntTerm (ch)));
return (Yap_unify_constant (ARG2, MkIntegerTerm (ch)));
}
static Int
@ -4595,7 +4622,7 @@ p_get0 (void)
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "get0/2");
return FALSE;
}
out = get_wchar(sno);
out = Stream[sno].stream_wgetc(sno);
UNLOCK(Stream[sno].streamlock);
return (Yap_unify_constant (ARG2, MkIntegerTerm (out)) );
}
@ -5698,7 +5725,7 @@ p_skip (void)
UNLOCK(Stream[sno].streamlock);
return (FALSE);
}
while ((ch = get_wchar(sno)) != n && ch != -1);
while ((ch = Stream[sno].stream_wgetc(sno)) != n && ch != -1);
UNLOCK(Stream[sno].streamlock);
return (TRUE);
}

View File

@ -24,6 +24,8 @@
typedef int (*SWI_PutFunction)(int, void *);
typedef int (*SWI_GetFunction)(void *);
typedef int (*SWI_PutWideFunction)(int, void *);
typedef int (*SWI_GetWideFunction)(void *);
typedef int (*SWI_CloseFunction)(void *);
#include "../include/dswiatoms.h"

View File

@ -91,10 +91,6 @@
#define TotGcRecovered WL->tot_gc_recovered
#define LastGcTime WL->last_gc_time
#define LastSSTime WL->last_ss_time
#define FSWIStream WL->f_swi_stream
#define SWIGetc WL->swi_getc
#define SWIPutc WL->swi_putc
#define SWIClose WL->swi_close
#if defined(YAPOR) || defined(THREADS)
#define SignalLock WL->signal_lock
@ -177,6 +173,12 @@
#define BGL Yap_global->bgl
#endif
#define FSWIStream Yap_global->f_swi_stream
#define SWIGetc Yap_global->swi_getc
#define SWIPutc Yap_global->swi_putc
#define SWIWideGetc Yap_global->swi_wgetc
#define SWIWidePutc Yap_global->swi_wputc
#define SWIClose Yap_global->swi_close
#define Yap_AllowLocalExpansion Yap_global->allow_local_expansion
#define Yap_AllowGlobalExpansion Yap_global->allow_global_expansion

View File

@ -93,10 +93,6 @@ typedef struct worker_local {
YAP_ULONG_LONG tot_gc_recovered;
Int last_gc_time;
Int last_ss_time;
Functor f_swi_stream;
SWI_GetFunction swi_getc;
SWI_PutFunction swi_putc;
SWI_CloseFunction swi_close;
#if defined(YAPOR) || defined(THREADS)
lockvar signal_lock;
@ -179,6 +175,12 @@ typedef struct worker_shared {
lockvar bgl;
#endif
Functor f_swi_stream;
SWI_GetFunction swi_getc;
SWI_PutFunction swi_putc;
SWI_GetWideFunction swi_wgetc;
SWI_PutWideFunction swi_wputc;
SWI_CloseFunction swi_close;
int allow_local_expansion;
int allow_global_expansion;

View File

@ -91,10 +91,6 @@ static void InitWorker(int wid) {
FOREIGN_WL(wid)->tot_gc_recovered = 0L;
FOREIGN_WL(wid)->last_gc_time = 0L;
FOREIGN_WL(wid)->last_ss_time = 0L;
FOREIGN_WL(wid)->f_swi_stream = NULL;
FOREIGN_WL(wid)->swi_getc = NULL;
FOREIGN_WL(wid)->swi_putc = NULL;
FOREIGN_WL(wid)->swi_close = NULL;
#if defined(YAPOR) || defined(THREADS)
INIT_LOCK(FOREIGN_WL(wid)->signal_lock);
@ -177,6 +173,12 @@ static void InitGlobal(void) {
INIT_LOCK(Yap_global->bgl);
#endif
Yap_global->f_swi_stream = NULL;
Yap_global->swi_getc = NULL;
Yap_global->swi_putc = NULL;
Yap_global->swi_wgetc = NULL;
Yap_global->swi_wputc = NULL;
Yap_global->swi_close = NULL;
Yap_global->allow_local_expansion = TRUE;
Yap_global->allow_global_expansion = TRUE;

View File

@ -92,10 +92,6 @@ static void RestoreWorker(int wid) {
#if defined(YAPOR) || defined(THREADS)
REINIT_LOCK(FOREIGN_WL(wid)->signal_lock);
@ -188,6 +184,12 @@ static void RestoreGlobal(void) {
#if HAVE_LIBREADLINE

View File

@ -3097,6 +3097,8 @@ PL_YAP_InitSWIIO(struct SWI_IO *swio)
FSWIStream = SWIFunctorToFunctor(swio->f);
SWIGetc = swio->get_c;
SWIPutc = swio->put_c;
SWIWideGetc = swio->get_w;
SWIWidePutc = swio->put_w;
SWIClose = swio->close_s;
}

View File

@ -99,11 +99,6 @@ YAP_ULONG_LONG tot_gc_recovered TotGcRecovered =0L
Int last_gc_time LastGcTime =0L
Int last_ss_time LastSSTime =0L
Functor f_swi_stream FSWIStream =NULL
SWI_GetFunction swi_getc SWIGetc =NULL
SWI_PutFunction swi_putc SWIPutc =NULL
SWI_CloseFunction swi_close SWIClose =NULL
// global variables that cannot be global in a thread/or-p implementation
#if defined(YAPOR) || defined(THREADS)
lockvar signal_lock SignalLock MkLock
@ -199,6 +194,13 @@ UInt threads_total_time ThreadsTotalTime =0L
lockvar bgl BGL MkLock
#endif
Functor f_swi_stream FSWIStream =NULL
SWI_GetFunction swi_getc SWIGetc =NULL
SWI_PutFunction swi_putc SWIPutc =NULL
SWI_GetWideFunction swi_wgetc SWIWideGetc =NULL
SWI_PutWideFunction swi_wputc SWIWidePutc =NULL
SWI_CloseFunction swi_close SWIClose =NULL
// stack overflow expansion/gc control
int allow_local_expansion Yap_AllowLocalExpansion =TRUE
int allow_global_expansion Yap_AllowGlobalExpansion =TRUE

View File

@ -4316,6 +4316,7 @@ static void
init_yap_extras()
{
swi_io_struct swiio;
swiio.f = FUNCTOR_dstream1;
swiio.get_c = pl_Sgetc;
swiio.put_c = Sputc;