diff --git a/C/write.c b/C/write.c index dcf68f7fd..8c094676f 100644 --- a/C/write.c +++ b/C/write.c @@ -1136,7 +1136,7 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags, rwt.parent = NULL; wglb.Ignore_ops = flags & Ignore_ops_f; wglb.Write_strings = flags & BackQuote_String_f; - if (false && !(flags & Ignore_cyclics_f)) { + if (!(flags & Ignore_cyclics_f) && false) { Term ts[2]; ts[0] = Yap_BreakRational(t, 0, ts+1, TermNil PASS_REGS); //fprintf(stderr, "%lx %lx %lx\n", t, ts[0], ts[1]); diff --git a/packages/python/pl2py.c b/packages/python/pl2py.c index e20b6d08d..0aa023f59 100644 --- a/packages/python/pl2py.c +++ b/packages/python/pl2py.c @@ -1,4 +1,5 @@ + #include "Yap.h" #include "py4yap.h" @@ -259,8 +260,6 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) { return out; } else { PyObject *no = find_term_obj(o, &t0, false); - if (no == o) - return NULL; return yap_to_python(t0, eval, no, cvt); } } else { @@ -418,7 +417,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) { PL_reset_term_refs(arg); YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "t(...)->python"); } - PyObject *a = term_to_python(arg, eval, o, cvt); + PyObject *a = term_to_python(arg, eval, NULL, cvt); if (a) { if (PyTuple_SetItem(rc, i, a) < 0) { PL_reset_term_refs(arg); diff --git a/packages/python/py2pl.c b/packages/python/py2pl.c index 46ba1f7df..91e5eaf2b 100644 --- a/packages/python/py2pl.c +++ b/packages/python/py2pl.c @@ -226,7 +226,7 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) { return python_to_term(exp, t); } - case PL_STRING: { + case PL_STRING: { char *s = NULL; size_t l; PL_get_string_chars(t, &s,&l); diff --git a/packages/python/pybips.c b/packages/python/pybips.c index 01ef55862..6b1e088a2 100644 --- a/packages/python/pybips.c +++ b/packages/python/pybips.c @@ -12,21 +12,29 @@ #include "py4yap.h" static PyObject *finalLookup(PyObject *i, const char *s) { - PyObject *rc; + PyObject *os = PyUnicode_FromString(s), *rc = NULL; if (i == NULL) return NULL; + if (strcmp(s, "none") == 0) return Py_None; - if (PyDict_Check(i)) { - if ((rc = PyDict_GetItemString(i, s))) - return rc; - } if (PyModule_Check(i)) { - if ((rc = PyDict_GetItemString(i, s))) - return rc; + i = PyModule_GetDict(i); + } + + if (PyDict_Check(i)) + { + if (PyDict_Contains(i, os) == 1) { + rc = PyDict_GetItem(i, os); } - if (PyObject_HasAttrString(i, s)) { - return PyObject_GetAttrString(i, s); + } + if (!rc && PyObject_HasAttr(i, os)) { + rc = PyObject_GetAttr(i, os); + } + if (rc) + { + Py_IncRef(rc); + return rc; } return NULL; } @@ -69,6 +77,10 @@ PyObject *lookupPySymbol(const char *sp, PyObject *pContext, PyObject **duc) { if ((out = finalLookup(py_Builtin, sp))) { return out; } + if ((out = finalLookup(py_Atoms, sp))) + { + return out; + } PyObject *py_Local = PyEval_GetLocals(); if ((out = finalLookup(py_Local, sp)) && out != Py_None) { return out; @@ -479,7 +491,7 @@ static PyObject *bip_sum(term_t t) { } #if PY_MAJOR_VERSION < 3 if (PyInt_CheckExact(item)) { - 764PyFPE_START_PROTECT("add", Py_DECREF(item); Py_DECREF(iter); + PyFPE_START_PROTECT("add", Py_DECREF(item); Py_DECREF(iter); return 0)f_result += (double)PyInt_AS_LONG(item); PyFPE_END_PROTECT(f_result) Py_DECREF(item); continue; @@ -1079,6 +1091,8 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) { PyObject *key = PyUnicode_FromString(sk); AOK(PL_get_arg(2, tleft, tleft), NULL); PyObject *val = term_to_python(tleft, true, o, cvt); + if (val == NULL) + return NULL; PyDict_SetItem(pyDict, key, val); } else { indict = false; @@ -1110,9 +1124,9 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) { PyObject *rc; if (ys && PyCallable_Check(ys)) { - PyObject_Print(ys, stderr, 0); - PyObject_Print(pArgs, stderr, 0); - PyObject_Print(pyDict, stderr, 0); + //PyObject_Print(ys, stderr, 0); + // PyObject_Print(pArgs, stderr, 0); + // PyObject_Print(pyDict, stderr, 0); // PyObject_Print(pArgs, stderr, 0); // PyObject_Print(o, stderr, 0); diff --git a/packages/python/pyio.c b/packages/python/pyio.c index 8869e4d7c..79258248a 100644 --- a/packages/python/pyio.c +++ b/packages/python/pyio.c @@ -131,7 +131,7 @@ static bool py_close(int sno) { static bool pygetLine(StreamDesc *rl_iostream, int sno) { // term_t ctk = python_acquire_GIL(); const char *myrl_line; - PyObject *user_line; + PyObject *user_line, *prompt; StreamDesc *s = YAP_GetStreamFromId(sno); //term_t tg = python_acquire_GIL(); if (!strcmp(RepAtom(s->name)->StrOfAE,"input") ) { @@ -144,10 +144,10 @@ static bool pygetLine(StreamDesc *rl_iostream, int sno) { Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err); } } - user_line = PyObject_CallFunctionObjArgs(pystream, NULL); + user_line = PyObject_CallFunctionObjArgs(pystream, PyUnicode_FromString("?- ") , NULL); } else { PyObject *readl = PyObject_GetAttrString(s->u.private_data, "readline"); - user_line = PyObject_CallFunction(readl, NULL); + user_line = PyObject_CallFunction(readl, PyUnicode_FromString("?- ") , NULL); } myrl_line = PyUnicode_AsUTF8(user_line); if (myrl_line == NULL) diff --git a/packages/python/pypreds.c b/packages/python/pypreds.c index 52aa94297..14e23dd62 100644 --- a/packages/python/pypreds.c +++ b/packages/python/pypreds.c @@ -648,7 +648,7 @@ static int python_import(term_t mname, term_t mod) { foreign_t rc = address_to_term(pModule, mod); if (do_as) { - PyObject_SetAttrString(py_Main, as, pModule); + PyModule_AddObject(py_Main, as, pModule); } python_release_GIL(t0); pyErrorAndReturn(rc); diff --git a/packages/python/yap_kernel/yap_ipython/yapi.py b/packages/python/yap_kernel/yap_ipython/yapi.py index 4808e18f4..55a54ed49 100644 --- a/packages/python/yap_kernel/yap_ipython/yapi.py +++ b/packages/python/yap_kernel/yap_ipython/yapi.py @@ -648,6 +648,7 @@ class YAPRun: raw_cell, store_history, silent, shell_futures) self.result = interactiveshell.ExecutionResult(info) + self.result.error_before_exec = None if (raw_cell == "") or raw_cell.isspace(): self.shell.last_execution_succeeded = True diff --git a/packages/swig/yap.i b/packages/swig/yap.i index 85b6b92cb..e1c04863f 100644 --- a/packages/swig/yap.i +++ b/packages/swig/yap.i @@ -35,7 +35,7 @@ class YAPEngine; #if defined(SWIGPYTHON) %pythoncode %{ -YAPError = _yap.YAPError +# YAPError = _yap.YAPError %} %typemap(typecheck) Term* {