diff --git a/C/tracer.c b/C/tracer.c index c4de2fb23..38bd6e2a1 100644 --- a/C/tracer.c +++ b/C/tracer.c @@ -91,15 +91,19 @@ static char *send_tracer_message(char *start, char *name, arity_t arity, Quote_illegal_f | Handle_vars_f); size_t sz; if (sn == NULL) { - sn = "<* error *>"; + sn = malloc(strlen("<* error *>")+1); + strcpy((char*)sn, "<* error *>"); } sz = strlen(sn); if (max <= sz) { min = sz + 1024; expand = true; + free((void*)sn); continue; } strcpy(s, sn); + free((void*)sn); + sn = NULL; s += sz; max -= sz; } diff --git a/os/fmem.c b/os/fmem.c index e2e586f67..faebfb81e 100644 --- a/os/fmem.c +++ b/os/fmem.c @@ -204,8 +204,6 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) { st = GLOBAL_Stream + sno; st->status = Output_Stream_f | InMemory_Stream_f; - if (src) - st->status |= FreeOnClose_Stream_f; st->linepos = 0; st->charcount = 0; st->linecount = 1; @@ -269,7 +267,7 @@ FILE *f = GLOBAL_Stream[sno].file; memcpy(buf, s, len); // s[fseek(GLOBAL_Stream[sno].file, 0, SEEK_END)] = '\0'; #else - fread(buf, sz, 1, GLOBAL_Stream[sno].file); + fread(buf, len, 1, GLOBAL_Stream[sno].file); #endif buf[len] = '\0'; return buf; diff --git a/packages/python/py2pl.c b/packages/python/py2pl.c index 4e85b6ab5..7193c28a0 100644 --- a/packages/python/py2pl.c +++ b/packages/python/py2pl.c @@ -90,7 +90,10 @@ else if (PyUnicode_Check(pVal)) { rc = rc && PL_unify_atom_chars(t, s); else #endif + if (pyStringToString) return MkStringTerm(s); + else + return MkAtomTerm(Yap_LookupAtom(s)); } else if (PyByteArray_Check(pVal)) { return MkStringTerm(PyByteArray_AsString(pVal)); diff --git a/packages/python/py4yap.h b/packages/python/py4yap.h index 280b9e1e8..79c29543a 100644 --- a/packages/python/py4yap.h +++ b/packages/python/py4yap.h @@ -93,6 +93,7 @@ extern PyObject *py_Sys; #define py_Builtin PyEval_GetBuiltins() extern X_API bool python_in_python; +extern bool pyStringToString; extern bool python_release_GIL(term_t gstate); extern term_t python_acquire_GIL(void); diff --git a/packages/python/pypreds.c b/packages/python/pypreds.c index b6121dde2..292e223e3 100644 --- a/packages/python/pypreds.c +++ b/packages/python/pypreds.c @@ -231,6 +231,24 @@ static foreign_t assign_python(term_t exp, term_t name) { pyErrorAndReturn(b); } + +static foreign_t python_string_to(term_t f) { + if (PL_is_atom(f)) { + char *s = NULL; + if (!PL_get_chars(f, &s, CVT_ALL | CVT_EXCEPTION | REP_UTF8)) { + pyErrorAndReturn(false); + } + if (!strcmp(s,"atom")) + pyStringToString = false; + if (!strcmp(s,"string")) + pyStringToString = true; + else + return false; + return true; + } + return true; +} + static foreign_t python_builtin_eval(term_t caller, term_t dict, term_t out) { PyErr_Clear(); PyObject *pI, *pArgs, *pOut; @@ -759,6 +777,7 @@ install_t install_pypreds(void) { PL_register_foreign("python_access", 3, python_access, 0); PL_register_foreign("python_threaded", 0, p_python_threaded, 0); PL_register_foreign("python_clear_errors", 0, python_clear_errors, 0); + PL_register_foreign("python_string_to", 0, python_string_to, 1); init_python_vfs(); } diff --git a/packages/python/python.c b/packages/python/python.c index 5c287a36e..ca176ebb5 100644 --- a/packages/python/python.c +++ b/packages/python/python.c @@ -28,6 +28,8 @@ PyObject *py_Context; X_API PyObject *Py_f2p; +bool pyStringToString; + extern X_API bool python_in_python; static void add_modules(void) { diff --git a/packages/python/python.pl b/packages/python/python.pl index db4082ee7..7cf3cc275 100644 --- a/packages/python/python.pl +++ b/packages/python/python.pl @@ -28,6 +28,7 @@ array_to_python_tuple/4, array_to_python_view/5, python/2, + python_string_to/1, acquire_GIL/0, release_GIL/0, python_threaded/0, diff --git a/packages/yap-lbfgs/CMakeLists.txt b/packages/yap-lbfgs/CMakeLists.txt index d36147063..de3695233 100644 --- a/packages/yap-lbfgs/CMakeLists.txt +++ b/packages/yap-lbfgs/CMakeLists.txt @@ -20,9 +20,11 @@ ENDIF (NOT YAP_FOUND) ) + SET ( LBFGS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_ansi.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_sse_double.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_sse_float.h ) + SET ( LBFGS_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_ansi.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_sse_double.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/arithmetic_sse_float.h ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/lbfgs.c ${CMAKE_CURRENT_SOURCE_DIR}/yap_lbfgs.c) + ${CMAKE_CURRENT_SOURCE_DIR}/${LBFGS_SRC}/lib/lbfgs.c ${CMAKE_CURRENT_SOURCE_DIR}/yap_lbfgs.c) add_library(LBFGS ${LBFGS_SOURCES}) diff --git a/packages/yap-lbfgs/ex1.pl b/packages/yap-lbfgs/ex1.pl index 45731c13b..77258b20d 100644 --- a/packages/yap-lbfgs/ex1.pl +++ b/packages/yap-lbfgs/ex1.pl @@ -40,7 +40,8 @@ progress(FX,X,G,X_Norm,G_Norm,Step,_N,Iteration,Ls, 0) :- demo :- - format('Optimizing the function f(x0) = sin(x0)~n',[]), +start_low_level_trace, + format('Optimizing the function f(x0) = sin(x0)~n',[]), optimizer_initialize(1,X,Status), diff --git a/packages/yap-lbfgs/yap_lbfgs.c b/packages/yap-lbfgs/yap_lbfgs.c index 800cf3791..0a3c21f48 100644 --- a/packages/yap-lbfgs/yap_lbfgs.c +++ b/packages/yap-lbfgs/yap_lbfgs.c @@ -239,17 +239,15 @@ meaning. static YAP_Bool optimizer_run(void) { int ret = 0; int n = YAP_IntOfTerm(YAP_ARG1); - YAP_Term t2 = YAP_ARG2; YAP_Int s1, s2; lbfgsfloatval_t fx; - lbfgsfloatval_t *temp_x = ( lbfgsfloatval_t *) YAP_IntOfTerm(YAP_ARG2), - *temp_ox = ( lbfgsfloatval_t *) YAP_IntOfTerm(YAP_ARG4); + lbfgsfloatval_t *temp_x = ( lbfgsfloatval_t *)YAP_IntOfTerm( YAP_ArgOfTerm(1, YAP_ARG2)), + *temp_ox = ( lbfgsfloatval_t *) YAP_IntOfTerm(YAP_ArgOfTerm(1,YAP_ARG4)); lbfgs_parameter_t *temp_p = (lbfgs_parameter_t * ) YAP_IntOfTerm(YAP_ARG6); - - //optimizer_status = OPTIMIZER_STATUS_RUNNING; ret = lbfgs(n, temp_x, &fx, evaluate, progress, temp_ox, temp_p); - return YAP_Unify(YAP_MkIntTerm(ret), YAP_ARG5); + return YAP_Unify(YAP_MkIntTerm(ret), YAP_ARG5) && + YAP_Unify(YAP_MkFloatTerm(fx), YAP_ARG3); } diff --git a/pl/consult.yap b/pl/consult.yap index f4afdb88e..490f14224 100644 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -311,7 +311,7 @@ load_files(Files0,Opts) :- ( LC > 0 -> '__NB_getval__'('$lf_status', OldTOpts, fail), - nonvar(OldTOpts), + nonvar(OldTOpts), functor( OldTOpts, opt, LastOpt ), '$lf_opt'(autoload, OldTOpts, OldAutoload), '$lf_opt'('$context_module', OldTOpts, OldContextModule) ; diff --git a/pl/messages.yap b/pl/messages.yap index 705eedcf1..703fa0bfe 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -257,15 +257,14 @@ location(style_check(A,LN,FileName,B ), Level , LC) --> display_consulting( FileName, Level,style_check(A,LN,FileName,B ), LC ), [ '~a:~d:0 ~a ' - [FileName,LN,Level] ] . location( error(_,Info), Level, LC ) --> - { '$error_descriptor'(Info, Desc) }, - { - query_exception(prologPredFile, Desc, File), + { + query_exception(prologPredFile, Desc, File), query_exception(prologPredLine, Desc, FilePos), query_exception(prologPredModule, Desc, M), query_exception(prologPredName, Desc, Na), query_exception(prologPredArity, Desc, Ar) - }, + }, !, display_consulting( File, Level, Info, LC ), {simplify_pred(M:Na/Ar,FF)}, @@ -358,7 +357,7 @@ display_consulting( F, Level, Info, LC) --> { LC > 0, '$error_descriptor'(Info, Desc), query_exception(prologParserFile, Desc, F0), - query_exception(prologarserLine, Desc, L), + query_exception(prologParserLine, Desc, L), F \= F0 }, !, [ '~a:~d:0: ~a raised at:'-[F0,L,Level], nl ].