This commit is contained in:
Vitor Santos Costa 2018-06-05 11:20:39 +01:00
parent 40096b3fdc
commit 2d55f41ef6
19 changed files with 84 additions and 83 deletions

View File

@ -33,8 +33,9 @@ static char SccsId[] = "%W% %G%";
/** @defgroup Internal_Database Internal Data Base
@ingroup builtins
@{
@ingroup builtins
@{
Some programs need global information for, e.g. counting or collecting
data obtained by backtracking. As a rule, to keep this information, the

View File

@ -1237,10 +1237,11 @@ static Int do_open(Term file_name, Term t2, Term tlist USES_REGS) {
encoding_t encoding;
Term tenc;
char io_mode[8];
file_name = Deref( file_name);
if (IsVarTerm(file_name)) {
Yap_ThrowError(INSTANTIATION_ERROR, file_name, "while opening a list of options");
}
file_name = Deref(file_name);
if (IsVarTerm(file_name)) {
Yap_ThrowError(INSTANTIATION_ERROR, file_name,
"while opening a list of options");
}
// open mode
if (IsVarTerm(t2)) {
Yap_Error(INSTANTIATION_ERROR, t2, "open/3");
@ -1583,18 +1584,19 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
vfsp->open(vfsp, fname, io_mode, sno)) {
// read, write, append
user_name = st->user_name;
st->vfs = vfsp;
UNLOCK(st->streamlock);
} else {
st->file = fopen(fname, io_mode);
if (st->file == NULL) {
UNLOCK(st->streamlock);
if (errno == ENOENT && !strchr(io_mode, 'r')) {
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname,
strerror(errno));
} else {
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname,
strerror(errno));
}
UNLOCK(st->streamlock);
if (errno == ENOENT && !strchr(io_mode, 'r')) {
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname,
strerror(errno));
} else {
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname,
strerror(errno));
}
}
st->vfs = NULL;
}
@ -1644,9 +1646,9 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open");
}
}
if (!strchr(io_mode, 'b') && binary_file(fname)) {
flags |= Binary_Stream_f;
}
if (!strchr(io_mode, 'b') && binary_file(fname)) {
flags |= Binary_Stream_f;
}
Yap_initStream(sno, st->file, fname, io_mode, user_name, LOCAL_encoding,
flags, vfsp);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exists %s <%d>", fname,
@ -1761,8 +1763,8 @@ int Yap_CheckTextStream__(const char *file, const char *f, int line, Term arg,
return sno;
}
int Yap_CheckTextWriteStream__(const char *file, const char *f, int line, Term arg,
const char *msg) {
int Yap_CheckTextWriteStream__(const char *file, const char *f, int line,
Term arg, const char *msg) {
int sno, kind = Output_Stream_f;
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
return -1;
@ -1779,8 +1781,8 @@ int Yap_CheckTextWriteStream__(const char *file, const char *f, int line, Term a
return sno;
}
int Yap_CheckTextReadStream__(const char *file, const char *f, int line, Term arg,
const char *msg) {
int Yap_CheckTextReadStream__(const char *file, const char *f, int line,
Term arg, const char *msg) {
int sno, kind = Input_Stream_f;
if ((sno = CheckStream__(file, f, line, arg, kind, msg)) < 0)
return -1;

View File

@ -10,9 +10,8 @@ YAP_Term TermErrStream, TermOutStream;
static unsigned char *outbuf, *errbuf;
static void pyflush( StreamDesc *st)
{
#if 0
static void pyflush(StreamDesc *st) {
#if 0
st->u.w_irl.ptr[0] = '\0';
fprintf(stderr,"%s\n", st->u.w_irl.buf);
term_t tg = python_acquire_GIL();
@ -20,12 +19,11 @@ static void pyflush( StreamDesc *st)
PySys_WriteStdout("%s", st->u.w_irl.buf);
} else {
PySys_WriteStderr("%s", st->u.w_irl.buf);
}
python_release_GIL(tg);
st->u.w_irl.ptr = st->u.w_irl.buf;
#endif
#endif
}
static int py_putc(int sno, int ch) {
@ -43,7 +41,7 @@ static int py_putc(int sno, int ch) {
}
return ch;
}
#endif
#endif
char s[2];
PyObject *err;
s[0] = ch;
@ -96,31 +94,27 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
// } else if (strcmp(name, "input") == 0) {
//pystream = PyObject_Call(pystream, PyTuple_New(0), NULL);
} else */
{
st->user_name = YAP_MkAtomTerm(st->name);
}
st->u.private_data = pystream;
{ st->user_name = YAP_MkAtomTerm(st->name); }
st->u.private_data = pystream;
st->vfs = me;
st->file = NULL;
python_release_GIL(ctk);
return st;
}
static void py_flush(int sno) {
StreamDesc *s = YAP_GetStreamFromId(sno);
term_t tg = python_acquire_GIL();
PyObject *flush = PyObject_GetAttrString(s->u.private_data, "flush");
pyflush(s);
pyflush(s);
PyObject_CallFunction(flush, NULL);
python_release_GIL(tg);
}
static bool py_close(int sno) {
StreamDesc *st = YAP_RepStreamFromId(sno);
if (st->status & (Output_Stream_f|Append_Stream_f))
py_flush(sno);
if (st->status & (Output_Stream_f | Append_Stream_f))
py_flush(sno);
if (strcmp(st->name, "sys.stdout") && strcmp(st->name, "sys.stderr")) {
Py_XDECREF(st->u.private_data);
st->u.w_irl.buf = st->u.w_irl.ptr = NULL;
@ -137,13 +131,14 @@ static bool getLine(int inp) {
term_t ctk = python_acquire_GIL();
Py_ssize_t size;
PyObject *prompt = PyUnicode_FromString("?- "),
*msg = PyUnicode_FromString(" **input** ");
*msg = PyUnicode_FromString(" **input** "),
*o = PyObject_GetAttrString(rl_iostream->u.private_data, "read");
/* window of vulnerability opened */
myrl_line = PyUnicode_AsUTF8AndSize(PyObject_CallFunctionObjArgs(
rl_instream->u.private_data, msg, prompt, NULL), &size);
myrl_line = PyUnicode_AsUTF8AndSize(
PyObject_CallFunctionObjArgs(o, msg, prompt, NULL), &size);
python_release_GIL(ctk);
rl_instream->u.irl.ptr = rl_instream->u.irl.buf =
(const unsigned char *)malloc(size);
(const unsigned char *)malloc(size);
memcpy((void *)rl_instream->u.irl.buf, myrl_line, size);
return true;
}

View File

@ -26,13 +26,13 @@
jupyter_query(Caller, Cell, Line ) :-
jupyter_cell(Caller, Cell, Line).
jupyter_cell(_Caller, Cell, _) :-
jupyter_cell(_Caller, Cell, _Line) :-
jupyter_consult(Cell), %stack_dump,
fail.
jupyter_cell( _Caller, _, '' ) :- !.
jupyter_cell( _Caller, _, Line ) :-
blank( Line ),
!.
jupyter_cell( _Caller, _, '' ) :- !.
jupyter_cell( Caller, _, Line ) :-
Self := Caller.query,
python_query(Self,Line).
@ -54,19 +54,13 @@ jupyter_consult(Text) :-
jupyter_consult(Cell) :-
% Name = 'Inp',
% stream_property(Stream, file_name(Name) ),
setup_call_cleanup(
% setup_call_cleanup(
open_mem_read_stream( Cell, Stream),
load_files(user:'jupyter cell',[stream(Stream)]),
close(Stream)
).
load_files(user:'jupyter cell',[stream(Stream)]).
blank(Text) :-
atom_codes(Text, L),
maplist( blankc, L).
blankc(' ').
blankc('\n').
blankc('\t').
maplist( code_type(space), L).
:- dynamic cell_stream/1.

View File

@ -36,6 +36,7 @@
/** @defgroup CompilerAnalysis Internal Clause Rewriting
@ingroup YAPCompilerSettings
@{
YAP supports several clause optimisation mechanisms, that
are designed to improve execution of arithmetic
@ -59,7 +60,6 @@
*/
%% @{
/** @pred expand_exprs(- _O_,+ _N_)
Control term expansion during compilation.

View File

@ -15,14 +15,13 @@
* *
*************************************************************************/
%% @{
/**
@file arithpreds.yap
@addtogroup arithmetic_preds
@{
*/
:- system_module(arithmetic_predicates, [

View File

@ -26,7 +26,7 @@
/**
* @addtogroup Predicates_on_Atoms
*
* @{
*/
/** @pred atom_concat(+ As, ? A)

View File

@ -19,11 +19,11 @@
@file boot.yap
@brief YAP bootstrap
@{
@addtogroup TopLevel Top-Level and Boot Predicates
@ingroup builtins
@{
*/

View File

@ -3,6 +3,7 @@
@short utilities
@addtogroup Internal_Database
@{
*/
/** @pred recordaifnot(+ _K_, _T_,- _R_)
@ -41,3 +42,4 @@ recordzifnot(K,T,R) :-
recordzifnot(K,T,R) :-
recordz(K,T,R).
%% @}

View File

@ -21,8 +21,7 @@
@addtogroup YAPControl Control Predicates
@ingroup builtins
@{
@{
*/

View File

@ -39,11 +39,11 @@ implementation.
*/
%% @{
/** @defgroup Call_Counting Counting Calls
@ingroup Profiling
/**
@defgroup Call_Counting Counting Calls
@ingroup Profiling
@{
Predicates compiled with YAP's flag call_counting set to
`on` update counters on the numbers of calls and of
retries. Counters are actually decreasing counters, so that they can be

View File

@ -22,12 +22,11 @@
'$syntax_check_multiple'/2,
'$syntax_check_single_var'/2]).
%% @{
/**
@defgroup YAPStyle Checker
@ingroup YAPCompilerSettings
@defgroup YAPStyle Checker
@ingroup YAPCompilerSettings
@{
YAP implements a style-checker thay currently verifies whether:

View File

@ -83,11 +83,9 @@
@addtogroup YAPControl
@ingroup builtins
@{
*/
%% @{
/** @pred forall(: _Cond_,: _Action_)

View File

@ -30,10 +30,9 @@
%%
% @defgroup YAPBigLoad Loading Large Tables
% @ingroup YAPConsulting
%
% @{
% @brief Fast and Exo Loading
%
% @{
/*!
* @pred load_mega_clause( +Stream ) is detail

View File

@ -24,6 +24,7 @@
/**
@defgroup Deb_Interaction Interacting with the debugger
@{
@ingroup YAPProgramming
Debugging with YAP is similar to debugging with C-Prolog. Both systems
@ -237,6 +238,8 @@ be lost.
*/
/*-----------------------------------------------------------------------------
spy

View File

@ -18,6 +18,7 @@
/**
@defgroup DepthLimited Depth Limited Search
@{
@ingroup extensions
YAP implements various extensions to the default Prolog search. One of
@ -27,9 +28,12 @@ the most iseful s restricting the maximum search depth.
:-
system_module( '$_depth_bound', [depth_bound_call/2], []).
%depth_bound_call(A,D) :-
%write(depth_bound_call(A,D)), nl, fail.
%% @pred depth_bound_call(A,D)
%
% CallError _A_ with maximum stack_el depth_reduction _B_.
%
depth_bound_call(A,D) :-
'$execute_under_depth_limit'(A,D).
%% @}

View File

@ -23,6 +23,7 @@
*
* @brief Extended Abstract Machine
* @defgroup EAM Extended Abstract Machine
* @{
* @ingroup extensions
*
*
@ -54,3 +55,5 @@ eamconsult(File):- eam, eam, %fails if eam is disable
assert((user:term_expansion((A :- B),(A :- C)):- eamtrans(B,C))),
eam, ( consult(File) ; true), eam,
abolish(user:term_expansion,2).
%% @}

View File

@ -32,6 +32,7 @@
code_location/3]).
/**
* @namespace yap_hacks
*
* @defgroup Hacks Low-level access
* @ingroup builtins

View File

@ -25,27 +25,27 @@
*/
:- system_module( '$_listing', [listing/0,
/*:- system_module( '$_listing', [listing/0,
listing/1,
portray_clause/1,
portray_clause/2], []).
*/
/**
* @defgroup Listing List predicates in a module
* @{
* @defgroup listingGroup List predicates in a module
*
* @ingroup builtins
*
* @{
*/
:- use_system_module( '$_errors', ['$do_error'/2]).
:- use_system_module( '$_preds', ['$clause'/4,
'$current_predicate'/4]).
/* listing : Listing clauses in the database
*/
/** @brief listing : Listing clauses in the database
*
*/
/** @pred listing
@ -347,3 +347,5 @@ portray_clause(Clause) :-
'$list_transform'(L,M).
'$list_transform'([_|L],M) :-
'$list_transform'(L,M).
%% @}