I am sure I am missing something, but I don't know what.
Below the signature I report everything that is necessary
to reproduce my observations. In short, PL_unify_pointer()
does not seem to work as expected: in the C code I unify
a term with a pointer pointing at X, and in Prolog I get
a different pointer. Notice that X has been obtained, in
the original code, by C++'s operator new(). But it doesn't
even look like a truncation problem, since in different runs
of SWI-Prolog I get different values.
What am I missing?
All the best,
Roberto
P.S. I am sort of rushing this report because I know the
release of version 5.6.0 is imminent: sorry if I have
overlooked something simple.
--
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara@xxxxxxxxxxx
$ cat swibug.c
#include <SWI-Prolog.h>
foreign_t
foo(term_t t) {
void* p = (void*) 162669896;
PL_unify_pointer(t, p);
return TRUE;
}
#define PL_EXTENSION_ENTRY(name, arity) { #name, arity, (void*) name, 0 },
PL_extension predicates[] = {
PL_EXTENSION_ENTRY(foo, 1)
{ NULL, 0, NULL, 0 }
};
install_t
install() {
PL_register_extensions(predicates);
}
install_t
uninstall() {
}
$ gcc -I/usr/local/lib/pl-5.5.40/include/ -g -c -o swibug.o swibug.c
$ g++ -shared -o swibug.so swibug.o
$ pl
Welcome to SWI-Prolog (Multi-threaded, Version 5.5.40)
Copyright (c) 1990-2005 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- load_foreign_library(swibug).
Yes
?- foo(X).
X = 7113042
Yes
?-
% halt
$ pl
Welcome to SWI-Prolog (Multi-threaded, Version 5.5.40)
Copyright (c) 1990-2005 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- load_foreign_library(swibug).
Yes
?- foo(X).
X = 5015890
Yes
?-
% halt
$ pl
Welcome to SWI-Prolog (Multi-threaded, Version 5.5.40)
Copyright (c) 1990-2005 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
?- load_foreign_library(swibug).
Yes
?- foo(X).
X = 821586
Yes
?-
% halt
|