Difficulty compiling a Prolog file from C in Yap.

View: New views
2 Messages — Rating Filter:   Alert me  

Difficulty compiling a Prolog file from C in Yap.

by jean mehat-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

When I instruct Yap to compile a file through the C library, I get an
error (segmentation violation).

If tried to reduce the problem to a simple form in the attached C
program. Its trace under gdb is :
----
$ uname -a
Linux tenuki 2.6.24-19-generic #1 SMP Wed Aug 20 17:53:40 UTC 2008
x86_64 GNU/Linux
$ gdb -q tc
(gdb) run
Starting program: tc
% Restoring file /usr/local/lib/Yap/startup

Program received signal SIGSEGV, Segmentation fault.
0x00000000004cee7a in CopyTermToArena ()
Current language:  auto; currently asm
(gdb) where
#0  0x00000000004cee7a in CopyTermToArena ()
#1  0x00000000004cf9f6 in p_nb_setarg ()
#2  0x000000000040be70 in Yap_absmi ()
#3  0x000000000045421a in exec_absmi ()
#4  0x0000000000455c23 in do_goal ()
#5  0x00000000004044fd in YAP_RunGoalOnce ()
#6  0x00000000004038dd in main (ac=1, av=0x7fff2be99448) at tc.c:53
----

Does the problem occur on your system?
Any suggestion for solving it?

----
Jean Méhat

[tc.c]

/*
 Test yap compilation from C
*/
# include "/usr/local/include/Yap/YapInterface.h"
# include <stdio.h>
# include <assert.h>

static void
sendp(char * s){
  static char * prologstr;
  static int iprologstr;
  int
    mygetc(void){
    if (prologstr[iprologstr] == 0)
      return -1;
    return prologstr[iprologstr++];
  }
  YAP_Term term;
  int n;

  prologstr = s;
  iprologstr = 0;
  term = YAP_Read(mygetc);
  n = YAP_RunGoalOnce(term);
  printf("Ran %s, got %d\n", s, n);
}

int
main(int ac, char * av[]){
  char buffer[1024];

  { FILE * fd = fopen("plgame", "w");
    assert(fd != 0);
    fprintf(fd, "foo(1).\n");
    fprintf(fd, "foo(2).\n");
    fprintf(fd, "foo(3).\n");
    fprintf(fd, "foo(4).\n");
    fprintf(fd, "bar(X) :- foo(X).\n");
    fclose(fd);
  }

  YAP_FastInit(0);

# if 1
  YAP_Term inp, arg[1];
  YAP_Functor compilop;
  YAP_Atom plfile;

  plfile = YAP_LookupAtom("plgame");
  arg[0] = YAP_MkAtomTerm(plfile);
  compilop = YAP_MkFunctor(YAP_LookupAtom("compile"), 1);
  inp = YAP_MkApplTerm(compilop, 1, arg);
  YAP_RunGoalOnce(inp);
# else
  sendp("compile('plgame').");
# endif
  printf("Done\n");

  while((printf("? "), fgets(buffer, sizeof buffer, stdin)) != 0)
    sendp(buffer);

  return 0;
}


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Yap-users mailing list
Yap-users@...
https://lists.sourceforge.net/lists/listinfo/yap-users

Re: Difficulty compiling a Prolog file from C in Yap.

by Vitor Santos Costa-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jean

Before I look into this more closely, have you tried to get the most
recent version from the git repository?

http://gitorious.org/projects/yap-git/

It sounds like something I thought I had fixed a while ago (but maybe
I didn't :(

Cheers

Vitor

2009/2/2 jean mehat <jm@...>:

> When I instruct Yap to compile a file through the C library, I get an
> error (segmentation violation).
>
> If tried to reduce the problem to a simple form in the attached C
> program. Its trace under gdb is :
> ----
> $ uname -a
> Linux tenuki 2.6.24-19-generic #1 SMP Wed Aug 20 17:53:40 UTC 2008
> x86_64 GNU/Linux
> $ gdb -q tc
> (gdb) run
> Starting program: tc
> % Restoring file /usr/local/lib/Yap/startup
>
> Program received signal SIGSEGV, Segmentation fault.
> 0x00000000004cee7a in CopyTermToArena ()
> Current language:  auto; currently asm
> (gdb) where
> #0  0x00000000004cee7a in CopyTermToArena ()
> #1  0x00000000004cf9f6 in p_nb_setarg ()
> #2  0x000000000040be70 in Yap_absmi ()
> #3  0x000000000045421a in exec_absmi ()
> #4  0x0000000000455c23 in do_goal ()
> #5  0x00000000004044fd in YAP_RunGoalOnce ()
> #6  0x00000000004038dd in main (ac=1, av=0x7fff2be99448) at tc.c:53
> ----
>
> Does the problem occur on your system?
> Any suggestion for solving it?
>
> ----
> Jean Méhat
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Yap-users mailing list
> Yap-users@...
> https://lists.sourceforge.net/lists/listinfo/yap-users
>
>

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Yap-users mailing list
Yap-users@...
https://lists.sourceforge.net/lists/listinfo/yap-users