From 6619bd44b0c91dad596481eaa3e09798d8306d2b Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 30 Jun 2010 13:18:15 +0200 Subject: [PATCH 1/6] fix interfacey --- library/yap2swi/yap2swi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/yap2swi/yap2swi.c b/library/yap2swi/yap2swi.c index 614aaafad..e1760c2a4 100755 --- a/library/yap2swi/yap2swi.c +++ b/library/yap2swi/yap2swi.c @@ -167,8 +167,8 @@ SWIFunctorToFunctor(functor_t at) { if (IsAtomTerm(at)) return (Functor)at; - if ((CELL)(at) & 1) - return SWI_Functors[((CELL)at)/2]; + if ((CELL)(at) & 2) + return SWI_Functors[((CELL)at)/4]; return (Functor)at; } @@ -181,7 +181,7 @@ Yap_InitSWIHash(void) add_to_hash(i*2+1, (ADDR)SWI_Atoms[i]); } for (j=0; j < N_SWI_FUNCTORS; j++) { - add_to_hash((((CELL)(j))*2+1), (ADDR)SWI_Functors[j]); + add_to_hash((((CELL)(j))*4+2), (ADDR)SWI_Functors[j]); } } From 8cab19c6b1fdefc9f8728fef5db78c6f144eeb6f Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 30 Jun 2010 17:50:28 +0200 Subject: [PATCH 2/6] fix bad recovery of thread locals (report from Jiefie Ma). --- C/threads.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/C/threads.c b/C/threads.c index 551c7fe79..917f9beaa 100755 --- a/C/threads.c +++ b/C/threads.c @@ -111,6 +111,8 @@ kill_thread_engine (int wid, int always_die) Prop p0 = AbsPredProp(FOREIGN_ThreadHandle(wid).local_preds); GlobalEntry *gl = GlobalVariables; + FOREIGN_ThreadHandle(wid).local_preds = NIL; + GlobalVariables = NULL; /* kill all thread local preds */ while(p0) { PredEntry *ap = RepPredProp(p0); From 72a224de6f64e43b307712360693a818d8eff526 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 30 Jun 2010 17:51:28 +0200 Subject: [PATCH 3/6] fix compilation on OSX. --- configure | 7 ++++++- configure.in | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/configure b/configure index f6e23df54..6585c602e 100755 --- a/configure +++ b/configure @@ -6971,7 +6971,12 @@ fi EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -Wl,-install_name,\$(DESTDIR)\$(YAPLIBDIR)/\$@" INSTALL_ENV="YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)" fi - INSTALL_DLLS="" + if test "$ac_cv_c_compiler_gnu" = "yes" + then + SHLIB_CFLAGS="-shared -fPIC $CFLAGS" + SHLIB_CXXFLAGS="-shared -fPIC $CXXFLAGS" + INSTALL_DLLS="" + fi CC="$CC -fstrict-aliasing -freorder-blocks -fsched-interblock -Wall -Wstrict-aliasing=2" DYNYAPLIB=libYap."$SO" YAPLIB_LD="$CC -dynamiclib -Wl,-install_name,$prefix/lib/libYap.dylib" diff --git a/configure.in b/configure.in index b31752c08..4167a8db0 100755 --- a/configure.in +++ b/configure.in @@ -1021,7 +1021,12 @@ dnl Linux has both elf and a.out, in this case we found elf EXTRA_LIBS_FOR_DLLS="$EXTRA_LIBS_FOR_DLLS -Wl,-install_name,\$(DESTDIR)\$(YAPLIBDIR)/\$@" INSTALL_ENV="YAPSHAREDIR=\$(DESTDIR)\$(SHAREDIR) YAPLIBDIR=\$(DESTDIR)\$(YAPLIBDIR)" fi - INSTALL_DLLS="" + if test "$ac_cv_prog_gcc" = "yes" + then + SHLIB_CFLAGS="-shared -fPIC $CFLAGS" + SHLIB_CXXFLAGS="-shared -fPIC $CXXFLAGS" + INSTALL_DLLS="" + fi CC="$CC -fstrict-aliasing -freorder-blocks -fsched-interblock -Wall -Wstrict-aliasing=2" DYNYAPLIB=libYap."$SO" YAPLIB_LD="$CC -dynamiclib -Wl,-install_name,$prefix/lib/libYap.dylib" From 0f241ae87cf7001b6646fdba1900b3b16c182bf8 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 30 Jun 2010 17:53:26 +0200 Subject: [PATCH 4/6] pyswip was using old SWI function. --- packages/pyswip/pyswip/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pyswip/pyswip/core.py b/packages/pyswip/pyswip/core.py index 488c32969..e7e00f98b 100755 --- a/packages/pyswip/pyswip/core.py +++ b/packages/pyswip/pyswip/core.py @@ -244,7 +244,7 @@ PL_get_atom_chars.argtypes = [term_t, POINTER(c_char_p)] ##define PL_get_string_chars(t, s, l) PL_get_string(t,s,l) # /* PL_get_string() is depricated */ #PL_EXPORT(int) PL_get_string(term_t t, char **s, size_t *len); -PL_get_string = _lib.PL_get_string +PL_get_string = _lib.PL_get_string_chars PL_get_string.argtypes = [term_t, POINTER(c_char_p), c_int_p] PL_get_string_chars = PL_get_string PL_get_string_chars.argtypes = [term_t, POINTER(c_char_p), c_int_p] From 8f8ba6221e6602b11831e8f76da01b31ce214f95 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 30 Jun 2010 17:54:02 +0200 Subject: [PATCH 5/6] add SWI's PL_get_string --- include/SWI-Prolog.h | 1 + library/yap2swi/yap2swi.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/SWI-Prolog.h b/include/SWI-Prolog.h index 54e2b7bd0..3abdea25a 100755 --- a/include/SWI-Prolog.h +++ b/include/SWI-Prolog.h @@ -502,6 +502,7 @@ extern X_API int PL_thread_at_exit(void (*)(void *), void *, int); extern X_API PL_engine_t PL_create_engine(const PL_thread_attr_t *); extern X_API int PL_destroy_engine(PL_engine_t); extern X_API int PL_set_engine(PL_engine_t,PL_engine_t *); +extern X_API int PL_get_string(term_t, char **, size_t *); extern X_API int PL_get_string_chars(term_t, char **, size_t *); extern X_API record_t PL_record(term_t); extern X_API int PL_recorded(record_t, term_t); diff --git a/library/yap2swi/yap2swi.c b/library/yap2swi/yap2swi.c index e1760c2a4..1b17fe457 100755 --- a/library/yap2swi/yap2swi.c +++ b/library/yap2swi/yap2swi.c @@ -684,6 +684,11 @@ X_API int PL_get_head(term_t ts, term_t h) return 1; } +X_API int PL_get_string(term_t t, char **s, size_t *len) +{ + return PL_get_string_chars(t, s, len); +} + X_API int PL_get_string_chars(term_t t, char **s, size_t *len) { Term tt = Yap_GetFromSlot(t); From 8690fb8ca088f748c9e57dcba3395da1f78b0c2c Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 30 Jun 2010 17:54:58 +0200 Subject: [PATCH 6/6] make clp(bn) work again. --- C/attvar.c | 20 ++++++++++++-------- packages/CLPBN/clpbn.yap | 2 +- packages/CLPBN/clpbn/display.yap | 2 +- pl/attributes.yap | 30 ++++++++++++++++++++++-------- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/C/attvar.c b/C/attvar.c index 644eb62aa..fb0249ce3 100644 --- a/C/attvar.c +++ b/C/attvar.c @@ -859,15 +859,19 @@ p_swi_all_atts(void) { return Yap_unify(ARG2,TermNil); while (!IsVarTerm(tatt)) { Functor f = FunctorOfTerm(tatt); + UInt ar = ArityOfFunctor(f); - if (ArityOfFunctor(f) == 2) { - if (H != h0) - H[-1] = AbsAppl(H); - H[0] = (CELL) attf; - H[1] = MkAtomTerm(NameOfFunctor(f)); - H[2] = ArgOfTerm(2,tatt); - H+=4; - } + if (H != h0) + H[-1] = AbsAppl(H); + H[0] = (CELL) attf; + H[1] = MkAtomTerm(NameOfFunctor(f)); + /* SWI */ + if (ar == 2) + H[2] = ArgOfTerm(2,tatt); + else + H[2] = tatt; + H += 4; + H[-1] = AbsAppl(H); tatt = ArgOfTerm(1,tatt); } if (h0 != H) { diff --git a/packages/CLPBN/clpbn.yap b/packages/CLPBN/clpbn.yap index c5090bdcb..c28814f92 100644 --- a/packages/CLPBN/clpbn.yap +++ b/packages/CLPBN/clpbn.yap @@ -169,7 +169,7 @@ add_evidence(V,K,_,V) :- clpbn_marginalise(V, Dist) :- attributes:all_attvars(AVars), project_attributes([V], AVars), - vel:get_atts(V, posterior(_,_,Dist,_)). + clpbn_display:get_atts(V, posterior(_,_,Dist,_)). % % called by top-level diff --git a/packages/CLPBN/clpbn/display.yap b/packages/CLPBN/clpbn/display.yap index cce28aeee..840060947 100644 --- a/packages/CLPBN/clpbn/display.yap +++ b/packages/CLPBN/clpbn/display.yap @@ -33,7 +33,7 @@ gen_eqs([V], D, (V=D)) :- !. gen_eqs([V|Vs], [D|Ds], ((V=D),Eqs)) :- gen_eqs(Vs,Ds,Eqs). -add_alldiffs([],Eqs,Eqs). +add_alldiffs([],Eqs,Eqs) :- !. add_alldiffs(AllDiffs,Eqs,(Eqs/alldiff(AllDiffs))). diff --git a/pl/attributes.yap b/pl/attributes.yap index 7e0db2529..17664c284 100644 --- a/pl/attributes.yap +++ b/pl/attributes.yap @@ -19,6 +19,8 @@ delayed_goals/4 ]). +:- dynamic attributes:attributed_module/3, attributes:modules_with_attributes/1. + prolog:get_attr(Var, Mod, Att) :- functor(AttTerm, Mod, 2), arg(2, AttTerm, Att), @@ -201,6 +203,20 @@ attvar_residuals(att(Module,Value,As), V) --> -> % a previous projection predicate could have instantiated % this variable, for example, to avoid redundant goals [] + ; { attributes:attributed_module(Module, _, _) } -> + % SICStus like run, put attributes back first + { Value =.. [Name,_|Vs], + NValue =.. [Name,_|Vs], + attributes:put_module_atts(V,NValue) + }, + attvar_residuals(As, V), + ( { '$undefined'(attribute_goal(V, Goal), Module) } + -> + [] + ; + { '$notrace'(Module:attribute_goal(V, Goal)) }, + dot_list(Goal) + ) ; ( { current_predicate(Module:attribute_goals/3) } -> { '$notrace'(Module:attribute_goals(V, Goals, [])) }, list(Goals) @@ -208,9 +224,9 @@ attvar_residuals(att(Module,Value,As), V) --> -> { '$notrace'(Module:attribute_goal(V, Goal)) }, dot_list(Goal) ; [put_attr(V, Module, Value)] - ) - ), - attvar_residuals(As, V). + ), + attvar_residuals(As, V) + ). list([]) --> []. list([L|Ls]) --> [L], list(Ls). @@ -242,7 +258,7 @@ prolog:call_residue(Goal,Residue) :- call_residue(Goal,Module,Residue) :- prolog:call_residue_vars(Module:Goal,NewAttVars), ( - '$undefined'(modules_with_attributes(_),attributes) + attributes:modules_with_attributes([_|_]) -> project_attributes(NewAttVars, Module:Goal) ; @@ -254,13 +270,12 @@ delayed_goals(G, Vs, NVs, Gs) :- project_delayed_goals(G), copy_term(G.Vs, _.NVs, Gs). -project_delayed_goals(G) :- - '$undefined'(modules_with_attributes(_),attributes), !. project_delayed_goals(G) :- % SICStus compatible step, % just try to simplify store by projecting constraints % over query variables. % called by top_level to find out about delayed goals + attributes:modules_with_attributes([_|_]), !, attributes:all_attvars(LAV), LAV = [_|_], project_attributes(LAV, G), !. @@ -279,10 +294,9 @@ att_vars([_|LGs], AttVars) :- % make sure we set the suspended goal list to its previous state! % make sure we have installed a SICStus like constraint solver. -project_attributes(_, _) :- - '$undefined'(modules_with_attributes(_),attributes), !. project_attributes(AllVs, G) :- attributes:modules_with_attributes(LMods), + LMods = [_|_], term_variables(G, InputVs), pick_att_vars(InputVs, AttIVs), project_module(LMods, AttIVs, AllVs).