Merge ssh://ssh.dcc.fc.up.pt:31064/home/vsc/yap
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
|
||||
YAP_Term TermErrStream, TermOutStream;
|
||||
|
||||
static int py_put(int sno, int ch)
|
||||
{
|
||||
static int py_put(int sno, int ch) {
|
||||
// PyObject *pyw; // buffer
|
||||
// int pyw_kind;
|
||||
// PyObject *pyw_data;
|
||||
@@ -16,13 +15,13 @@ static int py_put(int sno, int ch)
|
||||
if (st->user_name == TermOutStream) {
|
||||
term_t tg = python_acquire_GIL();
|
||||
PySys_WriteStdout("%C", ch);
|
||||
python_release_GIL(tg);
|
||||
return ch;
|
||||
python_release_GIL(tg);
|
||||
return ch;
|
||||
}
|
||||
if (st->user_name == TermErrStream) {
|
||||
term_t tg = python_acquire_GIL();
|
||||
PySys_WriteStderr("%C", ch);
|
||||
python_release_GIL(tg);
|
||||
term_t tg = python_acquire_GIL();
|
||||
PySys_WriteStderr("%C", ch);
|
||||
python_release_GIL(tg);
|
||||
return ch;
|
||||
}
|
||||
char s[2];
|
||||
@@ -33,8 +32,7 @@ static int py_put(int sno, int ch)
|
||||
PyObject_CallMethodObjArgs(st->u.private_data, PyUnicode_FromString("write"),
|
||||
PyUnicode_FromString(s), NULL);
|
||||
python_release_GIL(g0);
|
||||
if ((err = PyErr_Occurred()))
|
||||
{
|
||||
if ((err = PyErr_Occurred())) {
|
||||
PyErr_SetString(
|
||||
err,
|
||||
"Error in put\n"); // %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__);
|
||||
@@ -43,7 +41,8 @@ static int py_put(int sno, int ch)
|
||||
}
|
||||
|
||||
VFS_t pystream;
|
||||
static void *py_open(VFS_t *me, const char *name, const char *io_mode, int sno) {
|
||||
static void *py_open(VFS_t *me, const char *name, const char *io_mode,
|
||||
int sno) {
|
||||
#if HAVE_STRCASESTR
|
||||
if (strcasestr(name, "/python/") == name)
|
||||
name += strlen("/python/");
|
||||
@@ -52,34 +51,36 @@ VFS_t pystream;
|
||||
name += strlen("/python/");
|
||||
#endif
|
||||
term_t ctk = python_acquire_GIL();
|
||||
PyObject *pystream = string_to_python(name, true, NULL);
|
||||
if (pystream == NULL || pystream == Py_None) {
|
||||
python_release_GIL(ctk);
|
||||
return NULL;
|
||||
}
|
||||
PyObject *pystream = string_to_python(name, true, NULL);
|
||||
if (pystream == NULL || pystream == Py_None) {
|
||||
python_release_GIL(ctk);
|
||||
return NULL;
|
||||
}
|
||||
StreamDesc *st = YAP_RepStreamFromId(sno);
|
||||
st->name = YAP_LookupAtom(name);
|
||||
if (strcmp(name,"sys.stdout") == 0) {
|
||||
if (strcmp(name, "sys.stdout") == 0) {
|
||||
st->user_name = TermOutStream;
|
||||
} else if(strcmp(name,"sys.stderr") == 0) {
|
||||
} else if (strcmp(name, "sys.stderr") == 0) {
|
||||
st->user_name = TermErrStream;
|
||||
} else {
|
||||
st->user_name = YAP_MkAtomTerm(st->name);
|
||||
}
|
||||
// we assume object is already open, so there is no need to open it.
|
||||
st->u.private_data = pystream;
|
||||
if (PyCallable_Check(pystream))
|
||||
st->u.private_data = PyObject_Call(pystream, PyTuple_New(0), NULL);
|
||||
else
|
||||
st->u.private_data = pystream;
|
||||
st->vfs = me;
|
||||
python_release_GIL(ctk);
|
||||
python_release_GIL(ctk);
|
||||
return st;
|
||||
}
|
||||
|
||||
static bool py_close(int sno) {
|
||||
StreamDesc *st = YAP_RepStreamFromId(sno);
|
||||
if (strcmp(st->name,"sys.stdout") &&
|
||||
strcmp(st->name,"sys.stderr")) {
|
||||
Py_XDECREF(st->u.private_data);
|
||||
if (strcmp(st->name, "sys.stdout") && strcmp(st->name, "sys.stderr")) {
|
||||
Py_XDECREF(st->u.private_data);
|
||||
}
|
||||
st->u.private_data = NULL;
|
||||
st->u.private_data = NULL;
|
||||
st->vfs = NULL;
|
||||
|
||||
return true;
|
||||
@@ -87,19 +88,20 @@ static bool py_close(int sno) {
|
||||
|
||||
static bool getLine(int inp) {
|
||||
char *myrl_line = NULL;
|
||||
StreamDesc *rl_instream = YAP_RepStreamFromId(inp);
|
||||
term_t ctk = python_acquire_GIL();
|
||||
fprintf(stderr,"in");
|
||||
PyObject*prompt = PyUnicode_FromString( "?- "),
|
||||
*msg = PyUnicode_FromString(" **input** ");
|
||||
StreamDesc *rl_instream = YAP_RepStreamFromId(inp);
|
||||
term_t ctk = python_acquire_GIL();
|
||||
fprintf(stderr, "in");
|
||||
PyObject *prompt = PyUnicode_FromString("?- "),
|
||||
*msg = PyUnicode_FromString(" **input** ");
|
||||
/* window of vulnerability opened */
|
||||
myrl_line = PyUnicode_AsUTF8(PyObject_CallFunctionObjArgs(rl_instream->u.private_data,msg,prompt,NULL));
|
||||
myrl_line = PyUnicode_AsUTF8(PyObject_CallFunctionObjArgs(
|
||||
rl_instream->u.private_data, msg, prompt, NULL));
|
||||
python_release_GIL(ctk);
|
||||
rl_instream->u.irl.ptr = rl_instream->u.irl.buf = (const unsigned char*)myrl_line;
|
||||
rl_instream->u.irl.ptr = rl_instream->u.irl.buf =
|
||||
(const unsigned char *)myrl_line;
|
||||
myrl_line = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static int py_getc(int sno) {
|
||||
StreamDesc *s = YAP_RepStreamFromId(sno);
|
||||
@@ -117,7 +119,7 @@ static int py_getc(int sno) {
|
||||
} else {
|
||||
return EOF;
|
||||
}
|
||||
return ch;
|
||||
return ch;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,23 +153,22 @@ static int py_peek(int sno) {
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
static int64_t py_seek(int sno, int64_t where, int how) {
|
||||
StreamDesc *g0 = YAP_RepStreamFromId(sno);
|
||||
term_t s0 = python_acquire_GIL();
|
||||
term_t s0 = python_acquire_GIL();
|
||||
PyObject *fseek = PyObject_GetAttrString(g0->u.private_data, "seek");
|
||||
PyObject *pyr = PyObject_CallFunctionObjArgs(fseek, PyLong_FromLong(where),
|
||||
PyLong_FromLong(how), NULL);
|
||||
python_release_GIL(s0);
|
||||
return PyLong_AsLong(pyr);
|
||||
python_release_GIL(s0);
|
||||
return PyLong_AsLong(pyr);
|
||||
}
|
||||
|
||||
static void py_flush(int sno) {
|
||||
StreamDesc *s = YAP_GetStreamFromId(sno);
|
||||
term_t tg = python_acquire_GIL();
|
||||
term_t tg = python_acquire_GIL();
|
||||
PyObject *flush = PyObject_GetAttrString(s->u.private_data, "flush");
|
||||
PyObject_CallFunction(flush, NULL);
|
||||
python_release_GIL(tg);
|
||||
python_release_GIL(tg);
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@@ -20,7 +20,6 @@
|
||||
% ]
|
||||
%% ).
|
||||
:- [library(hacks)].
|
||||
|
||||
:- reexport(library(yapi)).
|
||||
:- use_module(library(lists)).
|
||||
:- use_module(library(maplist)).
|
||||
@@ -274,4 +273,21 @@ close_events( Self ) :-
|
||||
fail.
|
||||
close_events( _ ).
|
||||
|
||||
|
||||
:- if( current_prolog_flag(apple, true) ).
|
||||
|
||||
:- putenv( 'LC_ALL', 'en_us:UTF-8').
|
||||
|
||||
plot_inline :-
|
||||
X := self.inline_plotting,
|
||||
nb_setval(inline, X ),
|
||||
X = true,
|
||||
!,
|
||||
:= (
|
||||
import( matplotlib ),
|
||||
matplotlib.use( `nbagg` )
|
||||
).
|
||||
|
||||
:- endif.
|
||||
|
||||
%:- ( start_low_level_trace ).
|
||||
|
Reference in New Issue
Block a user