access list elements from C code

dmaugis <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
Well...I m trying to access list element from C code, and obviously there is
something I miss-understood, because I crash. any help/explanation would be
welcome.

On the gprolog side I have:

:-foreign(sdl_init(+term)).

initialise :- 
		sdl_init([timer,audio,video]).

On the C side:

int		sdl_init(PlTerm list)
{
	unsigned long flags=0;
	if(Pl_Builtin_List(list)) {
		PlTerm *terms=NULL;
		int len=Pl_List_Length(list);
		terms=malloc(sizeof(PlTerm)*len);
		if(terms) {
			unsigned i=Pl_Rd_Proper_List_Check(list, terms);
			for(i=0; i<len; i++) {
				char* s;
				switch(Pl_Type_Of_Term(terms[i])) {
				case PL_INT:
					printf("integer.\n");
					flags|=Pl_Rd_Integer(terms[i]);
					break;
				case PL_ATM:
					s=Pl_Atom_Name(terms[i]);
					printf("atom '%s'\n",Pl_Is_Valid_Atom(terms[i]) ? "valid":"invalid");
					break;
				}
			}
			
And I get:

| ?- go.
atom 'invalid'
Fatal Error: Segmentation Violation

it seems when doing :

s=Pl_Atom_Name(terms[i]);



-- 
View this message in context: http://old.nabble.com/access-list-elements-from-C-code-tp34058672p34058672.html
Sent from the Gnu - Prolog - Users mailing list archive at Nabble.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.