x still a variable after a successful call to c2p_list(x) (2nd attempt)

Dear all,
following the advice of Kostis, here is something anyone can easily run to try reproducing what seems a rather serious bug in XSB. The files foo.c and foo.H follow:
------------------------------ foo.c ------------------------------ #include <cinterf.h> #include <stdio.h>
xsbBool foo() { prolog_term x = p2p_new(); if (is_var(x) == TRUE) printf("`x' is a variable: fine!\n"); if (c2p_list(x) == TRUE) printf("`c2p_list(x)' succeeded: fine!!\n"); // Hey, how can `x' still be a variable? if (is_var(x) == TRUE) printf("`x' is still a variable!!!\n"); return TRUE; } --------------------------- end of foo.c --------------------------
------------------------------ foo.H ------------------------------ :- export foo/0. --------------------------- end of foo.H --------------------------
Then assume your XSB emulator directory is
/usr/local/lib/xsb/2.5/emu
and run
echo "consult(foo, [cc('gcc'), cc_opts('-I/usr/local/lib/xsb/2.5/emu')]), foo." | xsb
What I see is
[xsb_configuration loaded] [sysinitrc loaded] [packaging loaded]
XSB Version 2.5 (Okocim) of March 11, 2002 [i686-pc-linux-gnu; mode: optimal; engine: slg-wam; gc: indirection; scheduling: local]
| ?- [Compiling Foreign Module ./foo (Prolog compiler options are ignored)] [foo compiled, cpu time used: 0.0000 seconds] [Compiling C file ./foo.c using gcc] In file included from /usr/local/lib/xsb/2.5/emu/export.h:28, from /usr/local/lib/xsb/2.5/emu/cinterf.h:155, from foo.c:1: /usr/local/lib/xsb/2.5/config/i686-pc-linux-gnu/xsb_config.h:275:28: warning: no newline at end of file [foo loaded] `x' is a variable: fine! `c2p_list(x)' succeeded: fine!! `x' is still a variable!!!
yes | ?- End XSB (cputime 0.04 secs, elapsetime 0.16 secs)
The warning given by gcc constitutes a problem in xsb_config.h that is totally unrelated, of course. Please let me know if you need further information. All the best
Roberto

should be easy to fix: seems like is_var does not deref
Bart

Bart Demoen wrote:
should be easy to fix: seems like is_var does not deref
I have checked: none of the is_*() functions seems to dereference. However, other interface functions do dereference.
Notice also that, while cinterf.h contains the declaration of p2p_deref() along with the rather obscure comment
** p2p_deref: prolog_term -> prolog_term !! uncommon
p2p_deref() is never mentioned in the XSB manuals.
So the questions are: how is one supposed to use the foreign language interface? Calling p2p_deref() before any invocation of is_*()? Are there other interface functions that require the client code to call p2p_deref() for proper operation?
All the best
Roberto

Roberto Bagnara writes:
Bart Demoen wrote:
should be easy to fix: seems like is_var does not deref
I have checked: none of the is_*() functions seems to dereference. However, other interface functions do dereference.
Notice also that, while cinterf.h contains the declaration of p2p_deref() along with the rather obscure comment
** p2p_deref: prolog_term -> prolog_term !! uncommon
p2p_deref() is never mentioned in the XSB manuals.
So the questions are: how is one supposed to use the foreign language interface? Calling p2p_deref() before any invocation of is_*()? Are there other interface functions that require the client code to call p2p_deref() for proper operation?
This certainly looks to me like a bug. I think we should put deref's into all those interface functions. I can only imagine that Jiyang, when he wrote these routines, expected to use the p2p_deref, but somehow that "convention" got lost down through the ages (in the later documentation in particular). Does anyone have any reason we shouldn't add the derefs?
-David

Hi Roberto,
First of all, I'd like to say that we really appreciate your bug reports. Thanks!
I've just commited to CVS the changes to is_*() functions so that they dereference their arguments. It took a little while since these functions were being used inside the emulator, instead of the lower-level macros.
-Luis
Roberto Bagnara bagnara@cs.unipr.it writes:
Bart Demoen wrote:
should be easy to fix: seems like is_var does not deref
I have checked: none of the is_*() functions seems to dereference. However, other interface functions do dereference.
Notice also that, while cinterf.h contains the declaration of p2p_deref() along with the rather obscure comment
** p2p_deref: prolog_term -> prolog_term !! uncommon
p2p_deref() is never mentioned in the XSB manuals.
So the questions are: how is one supposed to use the foreign language interface? Calling p2p_deref() before any invocation of is_*()? Are there other interface functions that require the client code to call p2p_deref() for proper operation?
All the best
Roberto
-- Prof. Roberto Bagnara Computer Science Group Department of Mathematics, University of Parma, Italy http://www.cs.unipr.it/~bagnara/ mailto:bagnara@cs.unipr.it
This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Xsb-development mailing list Xsb-development@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/xsb-development
participants (4)
-
Bart Demoen
-
David Warren
-
Luis Fernando Pias de Castro
-
Roberto Bagnara