smallbugs

This commit is contained in:
Vitor Santos Costa 2017-06-18 11:14:55 +01:00
parent 31f1c25ee7
commit 6b545c8f71
7 changed files with 338 additions and 373 deletions

View File

@ -1427,7 +1427,7 @@ OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate, CELL *ATrail,
char fname[YAP_FILENAME_MAX +1];
if (!Yap_findFile( inpf, YAP_STARTUP, YapLibDir, fname, true, YAP_SAVED_STATE, true, true))
return false;
return FAIL_RESTORE;
if (fname[0] &&
(mode = try_open(fname,Astate,ATrail,AStack,AHeap,streamp)) != FAIL_RESTORE) {
return mode;

View File

@ -1,17 +1,17 @@
/*************************************************************************
* *
* YAP Prolog %W% %G% *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2012 *
* *
**************************************************************************
* *
* File: YapCompounTerm.h *
* mods: *
* comments: main header file for YAP *
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
*************************************************************************/
* *
* YAP Prolog %W% %G% *
* Yap Prolog was developed at NCCUP - Universidade do Porto *
* *
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2012 *
* *
**************************************************************************
* *
* File: YapCompounTerm.h *
* mods: *
* comments: main header file for YAP *
* version: $Id: Yap.h,v 1.38 2008-06-18 10:02:27 vsc Exp $ *
*************************************************************************/
/*************************************************************************************************
High level macros to access arguments
@ -23,7 +23,7 @@
#include "inline-only.h"
EXTERN Int Yap_unify(Term a, Term b);
EXTERN bool Yap_unify(Term a, Term b);
INLINE_ONLY EXTERN inline Term Deref(Term a);
@ -39,7 +39,6 @@ INLINE_ONLY EXTERN inline Term Deref(Term a) {
INLINE_ONLY EXTERN inline CELL *GetTermAdress(Term a);
INLINE_ONLY EXTERN inline Term Derefa(CELL *b);
INLINE_ONLY EXTERN inline Term Derefa(CELL *b) {

View File

@ -374,19 +374,19 @@ close_attvar_chain(CELL *dvarsmin, CELL *dvarsmax) {
}
INLINE_ONLY EXTERN inline
Int Yap_unify(Term t0, Term t1);
bool Yap_unify(Term t0, Term t1);
INLINE_ONLY EXTERN inline
Int Yap_unify(Term t0, Term t1)
bool Yap_unify(Term t0, Term t1)
{
CACHE_REGS
tr_fr_ptr TR0 = TR;
if (Yap_IUnify(t0,t1)) {
return TRUE;
return true;
} else {
reset_trail(TR0);
return FALSE;
return false;
}
}

View File

@ -4,42 +4,37 @@
extern PyObject *py_Local, *py_Global;
PyObject *YE(term_t t, int line, const char *file, const char *code)
{
PyObject *YE(term_t t, int line, const char *file, const char *code) {
char buf[1024];
YAP_WriteBuffer(YAP_GetFromSlot(t), buf, 1023, 0);
fprintf(stderr, "**** Warning,%s@%s:%d: failed on expression %s\n", code, file, line, buf);
fprintf(stderr, "**** Warning,%s@%s:%d: failed on expression %s\n", code,
file, line, buf);
return NULL;
}
void YEM(const char *exp, int line, const char *file, const char *code)
{
fprintf(stderr, "**** Warning,%s@%s:%d: failed while executing %s\n", code, file, line, exp);
void YEM(const char *exp, int line, const char *file, const char *code) {
fprintf(stderr, "**** Warning,%s@%s:%d: failed while executing %s\n", code,
file, line, exp);
}
static PyObject *s_to_python( const char *s, bool eval, PyObject *p0)
{
static PyObject *s_to_python(const char *s, bool eval, PyObject *p0) {
PyObject *o;
if (eval)
{
o = PythonLookup(s,p0);
/* if (!o)
return o;
*/
}
else
{
o = PythonLookupSpecial(s);
}
if (o)
{
Py_INCREF(o);
return CHECKNULL(YAP_MkStringTerm(s), o);
} else {
PyObject *pobj = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
return pobj;
}
if (eval) {
o = PythonLookup(s, p0);
/* if (!o)
return o;
*/
} else {
o = PythonLookupSpecial(s);
}
if (o) {
Py_INCREF(o);
return CHECKNULL(YAP_MkStringTerm(s), o);
} else {
PyObject *pobj = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
return pobj;
}
}
/**
@ -50,19 +45,18 @@ static PyObject *s_to_python( const char *s, bool eval, PyObject *p0)
*
* @return a Python object descriptor or NULL if failed
*/
X_API PyObject *string_to_python( const char *s, bool eval, PyObject *p0)
{
char *buf = malloc(strlen(s)+1), *child;
while((child = strchr(s,'.')) != NULL ) {
X_API PyObject *string_to_python(const char *s, bool eval, PyObject *p0) {
char *buf = malloc(strlen(s) + 1), *child;
while ((child = strchr(s, '.')) != NULL) {
size_t len = child - s;
strncpy(buf,s,len);
buf[len]='\0';
strncpy(buf, s, len);
buf[len] = '\0';
p0 = s_to_python(buf, eval, p0);
s = child+1;
s = child + 1;
}
return s_to_python(s, eval, p0);
}
/**
* term_to_python translates and evaluates from Prolog to Python
*
@ -71,77 +65,58 @@ X_API PyObject *string_to_python( const char *s, bool eval, PyObject *p0)
*
* @return a Python object descriptor or NULL if failed
*/
PyObject *term_to_python(term_t t, bool eval, PyObject *o)
{
PyObject *term_to_python(term_t t, bool eval, PyObject *o) {
// o≈
YAP_Term yt = YAP_GetFromSlot(t);
// Yap_DebugPlWriteln(yt);
switch (PL_term_type(t))
{
case PL_VARIABLE:
{
if (t == 0)
{
switch (PL_term_type(t)) {
case PL_VARIABLE: {
if (t == 0) {
Yap_ThrowError(SYSTEM_ERROR_INTERNAL, yt, "in term_to_python");
}
PyObject *out = PyTuple_New(1);
PyTuple_SET_ITEM(out, 0, PyLong_FromLong(t));
return term_to_nametuple("v", 1, out);
};
case PL_ATOM:
{
case PL_ATOM: {
YAP_Atom at = YAP_AtomOfTerm(yt);
const char *s;
s = YAP_AtomName(at);
if (eval)
{
if (eval) {
o = PythonLookup(s, o);
/* if (!o)
return o;
return o;
*/
}
else
{
} else {
o = PythonLookupSpecial(s);
}
if (o)
{
if (o) {
Py_INCREF(o);
return CHECKNULL(t, o);
}
}
case PL_STRING:
{
case PL_STRING: {
const char *s = NULL;
if (YAP_IsAtomTerm(yt))
{
if (YAP_IsAtomTerm(yt)) {
s = YAP_AtomName(YAP_AtomOfTerm(yt));
}
else if (YAP_IsStringTerm(yt))
{
} else if (YAP_IsStringTerm(yt)) {
s = YAP_StringOfTerm(yt);
}
else
{
} else {
return CHECKNULL(t, NULL);
}
#if PY_MAJOR_VERSION < 3
if (proper_ascii_string(s))
{
if (proper_ascii_string(s)) {
PyObject *o = PyString_FromStringAndSize(s, strlen(s));
return CHECKNULL(t, o);
}
else
} else
#endif
{
PyObject *pobj = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
return CHECKNULL(t, pobj);
}
}
break;
case PL_INTEGER:
{
} break;
case PL_INTEGER: {
int64_t j;
if (!PL_get_int64_ex(t, &j))
return CHECKNULL(t, NULL);
@ -154,8 +129,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o)
#endif
}
case PL_FLOAT:
{
case PL_FLOAT: {
PyObject *out;
double fl;
if (!PL_get_float(t, &fl))
@ -163,45 +137,39 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o)
out = PyFloat_FromDouble(fl);
return CHECKNULL(t, out);
}
default:
{
default: {
term_t tail = PL_new_term_ref(), arg;
size_t len, i;
if (PL_skip_list(t, tail, &len) && PL_get_nil(tail))
{
if (PL_skip_list(t, tail, &len) && PL_get_nil(tail)) {
PyObject *out, *a;
arg = tail;
out = PyList_New(len);
if (!out)
if (!out) {
PL_reset_term_refs(tail);
return CHECKNULL(t, Py_None);
}
for (i = 0; i < len; i++)
{
if (!PL_get_list(t, arg, t))
{
for (i = 0; i < len; i++) {
if (!PL_get_list(t, arg, t)) {
PL_reset_term_refs(tail);
return Py_None;
}
a = term_to_python(arg, eval, o);
if (a )
{
if (PyList_SetItem(out, i, a) < 0)
{
return Py_None;
if (a) {
if (PyList_SetItem(out, i, a) < 0) {
PL_reset_term_refs(tail);
return Py_None;
}
}
}
PL_reset_term_refs(tail);
return CHECKNULL(t, out);
}
else
{
} else {
functor_t fun;
PyObject *rc;
if (!PL_get_functor(t, &fun))
{
if (!PL_get_functor(t, &fun)) {
PL_reset_term_refs(tail);
return CHECKNULL(t, Py_None);
}
@ -217,8 +185,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o)
return CHECKNULL(t, Py_None);
}
PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o)
{
PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o) {
if (t == 0)
return NULL;
term_t yt = YAP_InitSlot(t);
@ -227,13 +194,11 @@ PyObject *yap_to_python(YAP_Term t, bool eval, PyObject *o)
return o;
}
PyObject *deref_term_to_python(term_t t)
{
PyObject *deref_term_to_python(term_t t) {
// Yap_DebugPlWrite(YAP_GetFromSlot(t)); fprintf(stderr, " here I
// am\n");
YAP_Term yt = YAP_GetFromSlot(t);
if (YAP_IsVarTerm(yt))
{
if (YAP_IsVarTerm(yt)) {
char s[32];
char *o = YAP_WriteBuffer(yt, s, 31, 0);
PyObject *p = PyUnicode_FromString(o);

View File

@ -1,6 +1,6 @@
#include "py4yap.h"
static foreign_t repr_term(PyObject *pVal, term_t t) {
term_t to = PL_new_term_ref(), t1 = PL_new_term_ref();
PL_put_pointer(t1, pVal);
@ -25,11 +25,14 @@ foreign_t assign_to_symbol(term_t t, PyObject *e) {
foreign_t python_to_term(PyObject *pVal, term_t t) {
bool rc = true;
term_t to = PL_new_term_ref();
// fputs(" <<*** ",stderr); PyObject_Print(pVal,stderr,0); fputs("<<***\n",stderr);
// fputs(" <<*** ",stderr); PyObject_Print(pVal,stderr,0);
// fputs("<<***\n",stderr);
if (pVal == Py_None) {
//fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs(" >>***\n",stderr);
rc= PL_unify_atom(t, ATOM_none);
//fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs(" >>***\n",stderr);
// fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
// >>***\n",stderr);
rc = PL_unify_atom(t, ATOM_none);
// fputs("<<*** ",stderr);Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
// >>***\n",stderr);
} else if (PyBool_Check(pVal)) {
rc = rc && PL_unify_bool(t, PyObject_IsTrue(pVal));
} else if (PyLong_Check(pVal)) {
@ -41,8 +44,7 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
} else if (PyFloat_Check(pVal)) {
rc = rc && PL_unify_float(t, PyFloat_AsDouble(pVal));
} else if (PyComplex_Check(pVal)) {
term_t t1 = PL_new_term_ref(),
t2 = PL_new_term_ref();
term_t t1 = PL_new_term_ref(), t2 = PL_new_term_ref();
if (!PL_put_float(t1, PyComplex_RealAsDouble(pVal)) ||
!PL_put_float(t2, PyComplex_ImagAsDouble(pVal)) ||
!PL_cons_functor(to, FUNCTOR_complex2, t1, t2)) {
@ -61,7 +63,7 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
free(ptr);
#else
const char *s = PyUnicode_AsUTF8(pVal);
tmp_atom = PL_new_atom( s);
tmp_atom = PL_new_atom(s);
#endif
rc = rc && PL_unify_atom(t, tmp_atom);
} else if (PyByteArray_Check(pVal)) {
@ -80,63 +82,63 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
rc = rc && PL_unify_atom(t, ATOM_brackets);
} else {
if ((s = (Py_TYPE(pVal)->tp_name))) {
if (!strcmp(s, "H")) {
pVal = PyTuple_GetItem(pVal, 0);
if (pVal==NULL) {
pVal = Py_None;
PyErr_Clear();
}
}
if (s[0] == '$') {
char *ns = malloc(strlen(s) + 5);
strcpy(ns, "__");
strcat(ns, s + 1);
strcat(ns, "__");
f = PL_new_functor(PL_new_atom(ns), sz);
} else {
f = PL_new_functor(PL_new_atom(s), sz);
}
if (!strcmp(s, "H")) {
pVal = PyTuple_GetItem(pVal, 0);
if (pVal == NULL) {
pVal = Py_None;
PyErr_Clear();
}
}
if (s[0] == '$') {
char *ns = malloc(strlen(s) + 5);
strcpy(ns, "__");
strcat(ns, s + 1);
strcat(ns, "__");
f = PL_new_functor(PL_new_atom(ns), sz);
} else {
f = PL_new_functor(PL_new_atom(s), sz);
}
} else {
f = PL_new_functor(ATOM_t, sz);
f = PL_new_functor(ATOM_t, sz);
}
if (PL_unify_functor(t, f)) {
for (i = 0; i < sz; i++) {
if (!PL_get_arg(i + 1, t, to))
rc = false;
PyObject *p = PyTuple_GetItem(pVal, i);
if (p==NULL) {
PyErr_Clear();
p = Py_None;
}
rc = rc && python_to_term(p, to);
if (PL_unify_functor(t, f)) {
for (i = 0; i < sz; i++) {
if (!PL_get_arg(i + 1, t, to))
rc = false;
PyObject *p = PyTuple_GetItem(pVal, i);
if (p == NULL) {
PyErr_Clear();
p = Py_None;
}
rc = rc && python_to_term(p, to);
}
} else {
rc = false;
}
} else {
rc = false;
}
//fputs(" ||*** ",stderr); Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs(" ||***\n",stderr);
// fputs(" ||*** ",stderr); Yap_DebugPlWrite(YAP_GetFromSlot(t)); fputs("
// ||***\n",stderr);
}
} else if (PyList_Check(pVal)) {
Py_ssize_t i, sz = PyList_GET_SIZE(pVal);
Py_ssize_t i, sz = PyList_GET_SIZE(pVal);
if (sz == 0) {
rc = rc && PL_unify_nil(t);
} else {
for (i = 0; i < sz; i++) {
PyObject *obj;
if (!PL_unify_list(t, to, t)) {
rc = false;
break;
}
if ((obj = PyList_GetItem(pVal, i)) == NULL) {
obj = Py_None;
}
rc = rc && python_to_term(obj, to);
}
if (sz == 0) {
rc = rc && PL_unify_nil(t);
} else {
for (i = 0; i < sz; i++) {
PyObject *obj;
if (!PL_unify_list(t, to, t)) {
rc = false;
break;
}
if ((obj = PyList_GetItem(pVal, i)) == NULL) {
obj = Py_None;
}
rc = rc && python_to_term(obj, to);
}
//fputs("[***] ", stderr);
//Yap_DebugPlWrite(yt); fputs("[***]\n", stderr);
rc = rc && PL_unify_nil(t);
}
// fputs("[***] ", stderr);
// Yap_DebugPlWrite(yt); fputs("[***]\n", stderr);
} else if (PyDict_Check(pVal)) {
Py_ssize_t pos = 0;
term_t to = PL_new_term_ref(), ti = to;
@ -147,30 +149,31 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
rc = rc && PL_unify_atom(t, ATOM_curly_brackets);
} else {
while (PyDict_Next(pVal, &pos, &key, &value)) {
term_t tkey = PL_new_term_ref(), tval = PL_new_term_ref(), tint,
tnew = PL_new_term_ref();
/* do something interesting with the values... */
if (!python_to_term(key, tkey)) {
continue;
}
if (!python_to_term(value, tval)) {
continue;
}
/* reuse */
tint = tkey;
if (!PL_cons_functor(tint, FUNCTOR_colon2, tkey, tval)) {
rc = false;
continue;
}
if (--left) {
if (!PL_cons_functor(tint, FUNCTOR_comma2, tint, tnew))
PL_reset_term_refs(tkey);
rc = false;
}
if (!PL_unify(ti, tint)) {
rc = false; }
ti = tnew;
PL_reset_term_refs(tkey);
term_t tkey = PL_new_term_ref(), tval = PL_new_term_ref(), tint,
tnew = PL_new_term_ref();
/* do something interesting with the values... */
if (!python_to_term(key, tkey)) {
continue;
}
if (!python_to_term(value, tval)) {
continue;
}
/* reuse */
tint = tkey;
if (!PL_cons_functor(tint, FUNCTOR_colon2, tkey, tval)) {
rc = false;
continue;
}
if (--left) {
if (!PL_cons_functor(tint, FUNCTOR_comma2, tint, tnew))
PL_reset_term_refs(tkey);
rc = false;
}
if (!PL_unify(ti, tint)) {
rc = false;
}
ti = tnew;
PL_reset_term_refs(tkey);
}
rc = rc && PL_unify(t, to);
}
@ -183,9 +186,10 @@ foreign_t python_to_term(PyObject *pVal, term_t t) {
X_API YAP_Term pythonToYAP(PyObject *pVal) {
term_t t = PL_new_term_ref();
if (pVal == NULL ||
!python_to_term(pVal, t))
if (pVal == NULL || !python_to_term(pVal, t)) {
PL_reset_term_refs(t);
return 0;
}
YAP_Term tt = YAP_GetFromSlot(t);
PL_reset_term_refs(t);
Py_DECREF(pVal);
@ -238,25 +242,25 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
if (PL_skip_list(t, tail, &len) &&
PL_get_nil(tail)) { // true list
bool o = true;
if (PySequence_Check(exp) && PySequence_Length(exp) == len)
bool o = true;
if (PySequence_Check(exp) && PySequence_Length(exp) == len)
for (i = 0; i < len; i++) {
PyObject *p;
if (!PL_get_list(t, arg, t)) {
PL_reset_term_refs(tail);
o = false;
p = Py_None;
}
if ((p = PySequence_GetItem(exp, i)) == NULL)
p = Py_None;
if (!python_assign(arg, p, context)) {
PL_reset_term_refs(tail);
o = false;
}
}
PL_reset_term_refs(tail);
return o;
for (i = 0; i < len; i++) {
PyObject *p;
if (!PL_get_list(t, arg, t)) {
PL_reset_term_refs(tail);
o = false;
p = Py_None;
}
if ((p = PySequence_GetItem(exp, i)) == NULL)
p = Py_None;
if (!python_assign(arg, p, context)) {
PL_reset_term_refs(tail);
o = false;
}
}
PL_reset_term_refs(tail);
return o;
} else {
functor_t fun;
@ -287,8 +291,8 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
}
if (PyList_Check(i)) {
i = PyList_GetItem(i, 0);
if (i==NULL)
i = Py_None;
if (i == NULL)
i = Py_None;
long int j;
if (PyList_Check(o)) {
#if PY_MAJOR_VERSION < 3

View File

@ -14,7 +14,7 @@ static PyObject *finalLookup(PyObject *i, const char *s) {
PyObject *rc;
if (i == NULL)
return NULL;
if (strcmp(s,"none") == 0)
if (strcmp(s, "none") == 0)
return Py_None;
if (PyDict_Check(i)) {
if ((rc = PyDict_GetItemString(i, s)))
@ -68,14 +68,14 @@ PyObject *lookupPySymbol(const char *sp, PyObject *pContext, PyObject **duc) {
return out;
}
PyObject *py_Global = PyEval_GetGlobals();
if ((out = finalLookup(py_Global, sp)) ) {
return out;
if ((out = finalLookup(py_Global, sp))) {
return out;
}
if ((out = finalLookup(py_ModDict, sp))) {
return out;
return out;
}
if ((out = finalLookup(py_Main, sp)) ) {
return out;
if ((out = finalLookup(py_Main, sp))) {
return out;
}
return NULL;
}
@ -101,12 +101,11 @@ PyObject *find_obj(PyObject *ob, term_t l, bool eval) {
hd = YAP_HeadOfTerm(yt);
ob = yap_to_python(hd, true, ob);
ob = CHECKNULL(yt, ob);
if (!ob){
if (!ob) {
return Py_None;
}
yt = YAP_TailOfTerm(yt);
}
}
YAP_PutInSlot(l, yt);
return ob;
}
@ -122,9 +121,9 @@ PyObject *find_obj(PyObject *ob, term_t l, bool eval) {
static PyObject *bip_abs(term_t t) {
PyObject *pVal, *nVal;
AOK( PL_get_arg(1, t, t), NULL);
AOK(PL_get_arg(1, t, t), NULL);
pVal = term_to_python(t, true, NULL);
pVal = CHECKNULL( t, pVal );
pVal = CHECKNULL(t, pVal);
nVal = PyNumber_Absolute(pVal);
Py_DecRef(pVal);
return nVal;
@ -143,11 +142,11 @@ static PyObject *bip_all(term_t t) {
PyObject *(*iternext)(PyObject *);
int cmp;
AOK( PL_get_arg(1, t, t), NULL );
(v = term_to_python(t, true, NULL) );
v = CHECKNULL( t, v);
AOK(PL_get_arg(1, t, t), NULL);
(v = term_to_python(t, true, NULL));
v = CHECKNULL(t, v);
it = PyObject_GetIter(v);
if (CHECKNULL( t, it) == NULL)
if (CHECKNULL(t, it) == NULL)
return Py_None;
iternext = *Py_TYPE(it)->tp_iternext;
@ -160,7 +159,7 @@ static PyObject *bip_all(term_t t) {
// PyObject_Print(v, stderr, 0);
for (;;) {
item = iternext(it);
if (CHECKNULL(t,item) == NULL)
if (CHECKNULL(t, item) == NULL)
break;
cmp = PyObject_IsTrue(item);
Py_DECREF(item);
@ -190,16 +189,16 @@ static PyObject *bip_any(term_t t) {
PyObject *(*iternext)(PyObject *);
int cmp;
AOK( PL_get_arg(1, t, t), NULL );
AOK(PL_get_arg(1, t, t), NULL);
v = term_to_python(t, true, NULL);
it = PyObject_GetIter(v);
if (CHECKNULL(t,it) == NULL)
if (CHECKNULL(t, it) == NULL)
return Py_None;
iternext = *Py_TYPE(it)->tp_iternext;
for (;;) {
item = iternext(it);
if (CHECKNULL(t,item) == NULL)
if (CHECKNULL(t, item) == NULL)
break;
cmp = PyObject_IsTrue(item);
Py_DECREF(item);
@ -217,7 +216,7 @@ static PyObject *bip_any(term_t t) {
if (PyErr_ExceptionMatches(PyExc_StopIteration))
PyErr_Clear();
else
return CHECKNULL(t,NULL);
return CHECKNULL(t, NULL);
}
Py_RETURN_FALSE;
}
@ -225,7 +224,7 @@ static PyObject *bip_any(term_t t) {
static PyObject *bip_bin(term_t t) {
PyObject *v;
AOK ( PL_get_arg(1, t, t), NULL);
AOK(PL_get_arg(1, t, t), NULL);
v = term_to_python(t, true, NULL);
return PyNumber_ToBase(v, 2);
}
@ -233,7 +232,7 @@ static PyObject *bip_bin(term_t t) {
static PyObject *bip_float(term_t t, bool eval) {
PyObject *pVal, *o;
AOK( PL_get_arg(1, t, t), NULL );
AOK(PL_get_arg(1, t, t), NULL);
pVal = term_to_python(t, eval, NULL);
if (PyLong_Check(pVal)) {
o = PyFloat_FromDouble(PyLong_AsLong(pVal));
@ -252,7 +251,7 @@ static PyObject *bip_float(term_t t, bool eval) {
static PyObject *bip_int(term_t t) {
PyObject *pVal, *o;
AOK( PL_get_arg(1, t, t), NULL );
AOK(PL_get_arg(1, t, t), NULL);
pVal = term_to_python(t, true, NULL);
#if PY_MAJOR_VERSION < 3
if (PyLong_Check(pVal)) {
@ -278,7 +277,7 @@ static PyObject *bip_int(term_t t) {
static PyObject *bip_long(term_t t) {
PyObject *pVal, *o;
AOK( PL_get_arg(1, t, t), NULL );
AOK(PL_get_arg(1, t, t), NULL);
pVal = term_to_python(t, true, NULL);
if (PyLong_Check(pVal)) {
return pVal;
@ -297,8 +296,8 @@ static PyObject *bip_long(term_t t) {
static PyObject *bip_iter(term_t t) {
PyObject *v;
AOK( PL_get_arg(1, t, t), NULL );
v = term_to_python(t, true, NULL);
AOK(PL_get_arg(1, t, t), NULL);
v = term_to_python(t, true, NULL);
return PyObject_GetIter(v);
}
@ -306,8 +305,8 @@ static PyObject *bip_ord(term_t t) {
PyObject *pVal;
Py_ssize_t size;
AOK( PL_get_arg(1, t, t), NULL );
pVal = term_to_python(t, true, NULL);
AOK(PL_get_arg(1, t, t), NULL);
pVal = term_to_python(t, true, NULL);
if (PyUnicode_Check(pVal)) {
#if PY_MAJOR_VERSION < 3
size = PyUnicode_GET_SIZE(pVal);
@ -349,7 +348,7 @@ static PyObject *bip_sum(term_t t) {
PyObject *result = NULL;
PyObject *temp, *item, *iter;
AOK( PL_get_arg(1, t, t), NULL );
AOK(PL_get_arg(1, t, t), NULL);
seq = term_to_python(t, true, NULL);
iter = PyObject_GetIter(seq);
if (iter == NULL)
@ -456,8 +455,8 @@ 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); return 0)
f_result += (double)PyInt_AS_LONG(item);
764PyFPE_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;
}
@ -561,15 +560,14 @@ static long get_len_of_range(long lo, long hi, long step) {
#if PY_MAJOR_VERSION >= 3
static PyStructSequence_Field pnull[] = {
{"A1", NULL}, {"A2", NULL}, {"A3", NULL}, {"A4", NULL},
{"A5", NULL}, {"A6", NULL}, {"A7", NULL}, {"A8", NULL},
{"A9", NULL}, {"A9", NULL}, {"A10", NULL}, {"A11", NULL},
{"A12", NULL}, {"A13", NULL}, {"A14", NULL}, {"A15", NULL},
{"A16", NULL}, {"A17", NULL}, {"A18", NULL}, {"A19", NULL},
{"A19", NULL}, {"A20", NULL}, {"A21", NULL}, {"A22", NULL},
{"A23", NULL}, {"A24", NULL}, {"A25", NULL}, {"A26", NULL},
{"A27", NULL}, {"A28", NULL}, {"A29", NULL}, {"A29", NULL},
{"A30", NULL}, {"A31", NULL}, {"A32", NULL}, {NULL,NULL}};
{"A1", NULL}, {"A2", NULL}, {"A3", NULL}, {"A4", NULL}, {"A5", NULL},
{"A6", NULL}, {"A7", NULL}, {"A8", NULL}, {"A9", NULL}, {"A9", NULL},
{"A10", NULL}, {"A11", NULL}, {"A12", NULL}, {"A13", NULL}, {"A14", NULL},
{"A15", NULL}, {"A16", NULL}, {"A17", NULL}, {"A18", NULL}, {"A19", NULL},
{"A19", NULL}, {"A20", NULL}, {"A21", NULL}, {"A22", NULL}, {"A23", NULL},
{"A24", NULL}, {"A25", NULL}, {"A26", NULL}, {"A27", NULL}, {"A28", NULL},
{"A29", NULL}, {"A29", NULL}, {"A30", NULL}, {"A31", NULL}, {"A32", NULL},
{NULL, NULL}};
static PyObject *structseq_str(PyObject *iobj) {
@ -698,10 +696,9 @@ static PyObject *structseq_repr(PyObject *iobj) {
}
#endif
PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
PyObject *o;
#if PY_MAJOR_VERSION >= 3
#if PY_MAJOR_VERSION >= 3
PyTypeObject *typp;
PyObject *key = PyUnicode_FromString(s);
if (py_F2P && PyDict_Contains(py_F2P, key)) {
@ -711,7 +708,7 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
typp = calloc(sizeof(PyTypeObject), 1);
PyStructSequence_Desc *desc = calloc(sizeof(PyStructSequence_Desc), 1);
desc->name = PyMem_Malloc(strlen(s)+1);
desc->name = PyMem_Malloc(strlen(s) + 1);
strcpy(desc->name, s);
Py_DECREF(key);
desc->doc = "YAPTerm";
@ -724,22 +721,22 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
typp->tp_repr = structseq_repr;
// typp = PyStructSequence_NewType(desc);
// don't do this: we cannot add a type as an atribute.
//PyModule_AddObject(py_Main, s, (PyObject *)typp);
// PyModule_AddObject(py_Main, s, (PyObject *)typp);
if (py_F2P)
PyDict_SetItem(py_F2P, key, (PyObject *)typp);
Py_INCREF(typp);
}
o = PyStructSequence_New(typp);
arity_t i;
for (i=0; i < arity; i++) {
PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
Py_INCREF(pArg);
if (pArg)
PyStructSequence_SET_ITEM(o, i, pArg);
//PyObject_Print(pArg,stderr,0);fputc('\n',stderr);
}
for (i = 0; i < arity; i++) {
PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
Py_INCREF(pArg);
if (pArg)
PyStructSequence_SET_ITEM(o, i, pArg);
// PyObject_Print(pArg,stderr,0);fputc('\n',stderr);
}
//((PyStructSequence *)o)->ob_base.ob_size = arity;
//PyObject_Print(o,stderr,0);fputc('\n',stderr);
// PyObject_Print(o,stderr,0);fputc('\n',stderr);
return o;
#else
PyObject *o1;
@ -762,16 +759,16 @@ static PyObject *bip_range(term_t t) {
if (!PL_get_name_arity(t, &name, &arity))
return NULL;
AOK( PL_get_arg(1, t, arg), NULL);
AOK(PL_get_arg(1, t, arg), NULL);
ilow = get_int(arg, true);
if (arity == 1) {
ihigh = ilow;
ilow = 0;
} else {
AOK( PL_get_arg(2, t, arg), NULL );
AOK(PL_get_arg(2, t, arg), NULL);
ihigh = get_int(arg, true);
if (arity == 3) {
AOK( PL_get_arg(3, t, arg), NULL );
AOK(PL_get_arg(3, t, arg), NULL);
istep = get_int(arg, true);
}
}
@ -784,7 +781,8 @@ static PyObject *bip_range(term_t t) {
else
bign = get_len_of_range(ihigh, ilow, -istep);
n = (Py_ssize_t)bign;
AOK ( ( (bign >= 0 && (long)n == bign) || "range() result has too many items" ), NULL );
AOK(((bign >= 0 && (long)n == bign) || "range() result has too many items"),
NULL);
v = PyList_New(n);
if (v == NULL)
@ -807,53 +805,52 @@ static PyObject *bip_range(term_t t) {
}
static bool copy_to_dictionary(PyObject *dict, term_t targ, term_t taux,
bool eval) {
bool eval) {
PyObject *lhs, *rhs;
term_t tleft = PL_new_term_ref(), tright = PL_new_term_ref();
functor_t fun;
AOK (PL_get_functor(targ, &fun), false);
while (fun == FUNCTOR_comma2) {
AOK( PL_get_arg(1, targ, tleft), false);
if (! copy_to_dictionary(dict, tleft, taux, eval) )
return false;
AOK ( PL_get_arg(2, targ, targ), false);
return copy_to_dictionary(dict, tright, taux, eval);
}
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
// Py_DECREF(lhs);
// Py_DECREF(rhs);
functor_t fun;
AOK(PL_get_functor(targ, &fun), false);
while (fun == FUNCTOR_comma2) {
AOK(PL_get_arg(1, targ, tleft), false);
lhs = atom_to_python_string(tleft);
if (lhs == NULL) {
return FALSE;
}
AOK(PL_get_arg(2, targ, tright), false);
rhs = term_to_python(tright, eval, NULL);
if (rhs == NULL) {
PyErr_Print();
if (!copy_to_dictionary(dict, tleft, taux, eval))
return false;
}
return PyDict_SetItem(dict, lhs, rhs) >= 0;
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
// Py_DECREF(lhs);
// Py_DECREF(rhs);
AOK(PL_get_arg(2, targ, targ), false);
return copy_to_dictionary(dict, tright, taux, eval);
}
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
// Py_DECREF(lhs);
// Py_DECREF(rhs);
AOK(PL_get_arg(1, targ, tleft), false);
lhs = atom_to_python_string(tleft);
if (lhs == NULL) {
return FALSE;
}
AOK(PL_get_arg(2, targ, tright), false);
rhs = term_to_python(tright, eval, NULL);
if (rhs == NULL) {
PyErr_Print();
return false;
}
return PyDict_SetItem(dict, lhs, rhs) >= 0;
// PyObject_Print(dict, stderr, 0); fprintf(stderr,"\n");
// Py_DECREF(lhs);
// Py_DECREF(rhs);
}
PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
atom_t name;
int len;
AOK (PL_get_name_arity(t, &name, &len), o);
AOK(PL_get_name_arity(t, &name, &len), o);
if (fun == FUNCTOR_pointer1) {
void *ptr;
AOK (PL_get_arg(1, t, t), NULL);
AOK (PL_get_pointer(t, &ptr), NULL)
AOK(PL_get_arg(1, t, t), NULL);
AOK(PL_get_pointer(t, &ptr), NULL)
/* return __main__,s */
return (PyObject *)ptr;
}
@ -868,7 +865,7 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
if (!out)
return NULL;
for (i = 0; i < len; i++) {
AOK ( PL_get_arg(i + 1, t, targ), NULL);
AOK(PL_get_arg(i + 1, t, targ), NULL);
PyErr_Clear();
PyObject *oa = term_to_python(targ, true, o);
bool rc = PyTuple_SET_ITEM(out, i, oa) == 0;
@ -882,11 +879,11 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
AOK ( PL_get_arg(1, t, targ), NULL );
AOK(PL_get_arg(1, t, targ), NULL);
lhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(lhs))
return NULL;
AOK ( PL_get_arg(2, t, targ), NULL );
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
if (!PyNumber_Check(rhs))
return NULL;
@ -900,16 +897,16 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
term_t targ = PL_new_term_ref(), trhs = PL_new_term_ref();
PyObject *v;
Py_ssize_t min, max;
AOK (PL_get_arg(2, t, targ), NULL);
AOK(PL_get_arg(2, t, targ), NULL);
v = term_to_python(targ, true, o);
AOK (PL_get_arg(1, t, targ), NULL );
AOK (PL_get_list(targ, trhs, targ) , NULL);
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_get_list(targ, trhs, targ), NULL);
if (PL_is_functor(trhs, FUNCTOR_colon2)) {
if (!PySequence_Check(v))
return NULL;
min = get_p_int(term_to_python(targ, true, NULL), 0);
AOK (PL_get_arg(1, trhs, targ), NULL);
AOK(PL_get_arg(1, trhs, targ), NULL);
if (PL_is_functor(targ, FUNCTOR_colon2)) {
return NULL;
}
@ -927,18 +924,18 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
#else
if (PyLong_Check(ip)) {
PyObject *o = PySequence_GetItem(v, PyLong_AsLong(ip));
if (o == NULL)
o = Py_None;
if (CHECKNULL(t,o) == NULL)
return NULL;
if (o == NULL)
o = Py_None;
if (CHECKNULL(t, o) == NULL)
return NULL;
Py_INCREF(o);
return o;
}
#endif
} else {
o = PyObject_GetItem(v, ip);
if (o == NULL)
o = Py_None;
if (o == NULL)
o = Py_None;
Py_INCREF(o);
return o;
}
@ -947,14 +944,14 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
if (fun == FUNCTOR_dollar1) {
char *s = NULL;
term_t targ = PL_new_term_ref();
AOK ( PL_get_arg(1, t, targ), NULL );
AOK ( PL_get_atom_chars(targ, &s), NULL );
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_get_atom_chars(targ, &s), NULL);
/* return __main__,s */
PyObject *o = PyObject_GetAttrString(py_Main, s);
return o;
}
if (fun == FUNCTOR_brackets1) {
AOK ( PL_get_arg(1, t, t), NULL );
AOK(PL_get_arg(1, t, t), NULL);
return term_to_python(t, true, NULL);
}
if (fun == FUNCTOR_complex2) {
@ -962,9 +959,9 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
PyObject *lhs, *rhs;
double d1, d2;
AOK ( PL_get_arg(1, t, targ), NULL );
AOK(PL_get_arg(1, t, targ), NULL);
lhs = term_to_python(targ, true, NULL);
AOK ( PyNumber_Check(lhs), NULL );
AOK(PyNumber_Check(lhs), NULL);
if (PyFloat_Check(lhs)) {
d1 = PyFloat_AsDouble(lhs);
} else if (PyLong_Check(lhs)) {
@ -976,9 +973,9 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
} else {
return NULL;
}
AOK (PL_get_arg(2, t, targ), NULL );
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
AOK (PyNumber_Check(rhs), NULL);
AOK(PyNumber_Check(rhs), NULL);
if (PyFloat_Check(rhs)) {
d2 = PyFloat_AsDouble(rhs);
} else if (PyLong_Check(rhs)) {
@ -997,21 +994,21 @@ PyObject *compound_to_data(term_t t, PyObject *o, functor_t fun, bool exec) {
term_t targ = PL_new_term_ref(), taux = PL_new_term_ref();
PyObject *dict;
AOK ( PL_get_arg(1, t, t), NULL );
AOK(PL_get_arg(1, t, t), NULL);
if (!(dict = PyDict_New()))
return NULL;
DebugPrintf("Dict %p\n", dict);
while (PL_is_functor(t, FUNCTOR_comma2)) {
AOK ( PL_get_arg(1, t, targ), NULL );
AOK ( PL_is_functor(targ, FUNCTOR_colon2), NULL);
AOK(PL_get_arg(1, t, targ), NULL);
AOK(PL_is_functor(targ, FUNCTOR_colon2), NULL);
AOK( copy_to_dictionary(dict, targ, taux, true), NULL);
AOK( PL_get_arg(2, t, t) , NULL );
}
AOK(copy_to_dictionary(dict, targ, taux, true), NULL);
AOK(PL_get_arg(2, t, t), NULL);
}
if (PL_is_functor(t, FUNCTOR_colon2)) {
AOK ( copy_to_dictionary(dict, t, taux, true), NULL);
AOK(copy_to_dictionary(dict, t, taux, true), NULL);
}
return dict;
}
@ -1025,17 +1022,17 @@ PyObject *compound_to_pytree(term_t t, PyObject *context) {
int arity;
o = find_obj(context, t, false);
AOK( PL_get_name_arity(t, &name, &arity), NULL );
AOK(PL_get_name_arity(t, &name, &arity), NULL);
if (arity == 0)
return term_to_python(t, false, o);
AOK( PL_get_functor(t, &fun), NULL);
AOK(PL_get_functor(t, &fun), NULL);
if ((no = compound_to_data(t, o, fun, false)) != o && no) {
return no;
}
if (!arity) {
char *s = NULL;
AOK (!PL_get_atom_chars(t, &s), NULL );
AOK(!PL_get_atom_chars(t, &s), NULL);
// this should never happen
return term_to_python(t, false, o);
} else {
@ -1050,12 +1047,12 @@ PyObject *compound_to_pytree(term_t t, PyObject *context) {
tleft = PL_new_term_ref();
for (i = 0; i < arity; i++) {
PyObject *pArg;
AOK (PL_get_arg(i + 1, t, tleft), NULL );
AOK(PL_get_arg(i + 1, t, tleft), NULL);
pArg = term_to_python(tleft, false, NULL);
if (pArg) {
/* pArg reference stolen here: */
PyTuple_SET_ITEM(out, i, pArg);
Py_INCREF(pArg);
/* pArg reference stolen here: */
PyTuple_SET_ITEM(out, i, pArg);
Py_INCREF(pArg);
}
}
if (CHECKNULL(t, out) == NULL) {
@ -1064,11 +1061,11 @@ PyObject *compound_to_pytree(term_t t, PyObject *context) {
}
PyObject *c = lookupPySymbol(s, o, NULL);
if ( c && PyCallable_Check(c)) {
PyObject *n = PyTuple_New(arity);
PyTuple_SET_ITEM(n, 0, c);
PyTuple_SET_ITEM(n, 1, out);
return n;
if (c && PyCallable_Check(c)) {
PyObject *n = PyTuple_New(arity);
PyTuple_SET_ITEM(n, 0, c);
PyTuple_SET_ITEM(n, 1, out);
return n;
}
return term_to_nametuple(s, arity, out);
}
@ -1081,7 +1078,7 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
functor_t fun;
o = find_obj(context, t, true);
AOK (PL_get_name_arity(t, &name, &arity), NULL );
AOK(PL_get_name_arity(t, &name, &arity), NULL);
if (arity == 0)
return term_to_python(t, true, o);
if (!PL_get_functor(t, &fun))
@ -1117,7 +1114,7 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
term_t targ = PL_new_term_ref();
PyObject *ptr;
AOK (PL_get_arg(1, t, targ), NULL );
AOK(PL_get_arg(1, t, targ), NULL);
ptr = term_to_python(targ, true, NULL);
return PyLong_FromLong(PyObject_Length(ptr));
}
@ -1125,7 +1122,7 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
term_t targ = PL_new_term_ref();
PyObject *ptr;
AOK ( PL_get_arg(1, t, targ), NULL );
AOK(PL_get_arg(1, t, targ), NULL);
ptr = term_to_python(targ, true, NULL);
return PyObject_Dir(ptr);
@ -1138,7 +1135,7 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
if (!PL_get_arg(1, t, targ))
return NULL;
lhs = term_to_python(targ, true, NULL);
AOK( PL_get_arg(2, t, targ), NULL );
AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL);
if (PySequence_Check(lhs) && PySequence_Check(rhs)) {
return PySequence_Concat(lhs, rhs);
@ -1167,12 +1164,12 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
term_t targ = PL_new_term_ref();
PyObject *lhs, *rhs;
AOK (PL_get_arg(1, t, targ), NULL );
AOK(PL_get_arg(1, t, targ), NULL);
(lhs = term_to_python(targ, true, NULL));
CHECKNULL( targ, lhs);
AOK (PL_get_arg(2, t, targ), NULL );
CHECKNULL(targ, lhs);
AOK(PL_get_arg(2, t, targ), NULL);
(rhs = term_to_python(targ, true, NULL));
CHECKNULL( targ, rhs);
CHECKNULL(targ, rhs);
if (PySequence_Check(lhs) && (
#if PY_MAJOR_VERSION < 3
PyInt_Check(rhs) ||
@ -1188,9 +1185,9 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
char *s = NULL;
PyObject *pValue;
AOK (PL_get_atom_chars(t, &s), NULL );
AOK(PL_get_atom_chars(t, &s), NULL);
pValue = PyObject_GetAttrString(o, s);
if (CHECKNULL(t,pValue) == NULL) {
if (CHECKNULL(t, pValue) == NULL) {
PyErr_Print();
return NULL;
}
@ -1198,7 +1195,7 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
} else {
char *s = PL_atom_chars(name);
o = lookupPySymbol(s, o, NULL);
if (CHECKNULL(t,o) == NULL) {
if (CHECKNULL(t, o) == NULL) {
PyErr_Print();
return NULL;
}
@ -1208,30 +1205,30 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context) {
term_t tleft = PL_new_term_ref();
for (i = 0; i < arity; i++) {
PyObject *pArg;
AOK (PL_get_arg(i + 1, t, tleft), NULL );
AOK(PL_get_arg(i + 1, t, tleft), NULL);
/* ignore (_) */
if (i == 0 && PL_is_variable(tleft)) {
pArg = Py_None;
} else {
pArg = term_to_python(tleft, true, NULL);
PyObject_Print(pArg,fdopen(2,"w"),0);
if (pArg == NULL) {
pArg = Py_None;
}
/* pArg reference stolen here: */
Py_INCREF(pArg);
pArg = term_to_python(tleft, true, NULL);
// PyObject_Print(pArg,fdopen(2,"w"),0);
if (pArg == NULL) {
pArg = Py_None;
}
/* pArg reference stolen here: */
Py_INCREF(pArg);
}
PyTuple_SetItem(pArgs, i, pArg);
}
if ( !PyCallable_Check(o)) {
return term_to_nametuple(s, arity, pArgs);
if (!PyCallable_Check(o)) {
return term_to_nametuple(s, arity, pArgs);
}
PyObject *rc;
PyObject *rc;
//PyObject_Print(pArgs, stderr, 0);
//PyObject_Print(o, stderr, 0);
CHECK_CALL(rc ,t, PyObject_CallObject(o, pArgs));
// PyObject_Print(pArgs, stderr, 0);
// PyObject_Print(o, stderr, 0);
CHECK_CALL(rc, t, PyObject_CallObject(o, pArgs));
Py_DECREF(pArgs);
Py_DECREF(o);
DebugPrintf("CallObject %p\n", rc);

View File

@ -638,7 +638,7 @@ static YAP_Int p_python_threaded(void) {
static PyGILState_STATE gstate;
term_t python_acquire_GIL(void) {
term_t curSlot = 1; //PL_new_term_ref();
term_t curSlot = PL_new_term_ref();
if (!_threaded)
pyErrorAndReturn(curSlot, false);
// extern int Yap_do_low_level_trace;
@ -652,7 +652,7 @@ term_t python_acquire_GIL(void) {
bool python_release_GIL(term_t curBlock) {
PyErr_Clear();
// PL_reset_term_refs(curBlock);
PL_reset_term_refs(curBlock);
if (_threaded) {
PyGILState_Release(gstate);
}