calling C from Yap problem

Help
2010-11-03
2013-05-20
  • Laura Antanas
    Laura Antanas
    2010-11-03

    Hello,

    I am trying to call a C function from from some Yap code. I am using Yap 6.2.0 and i get the following output:

    %
    % YAP OOOPS in USER C-CODE: tried to access illegal address 0x101a2f9!!!!.
    %
    %
    4411KB of Code Space (0x10000000-0x1044ee10)
    %
    % PC: meta-call
    %   Continuation: user:selectCE0/3 at clause 1
    %    993KB of Global Stack (0x1045b000-0x10553648)
    %    3KB of Local Stack (0x10686260-0x10687000)
    %    1KB of Trail (0x10687004-0x106875cc)
    %    Performed 6 garbage collections
    % All Active Calls and
    %         Goals With Alternatives Open  (Global In Use-Local In Use)
    %
    %  user:selectCE0/3 at clause 1
    %         lists:member/2 (993KB-3KB)
    ….
    %         lists:member/2 (992KB-0KB)
    %  user:selectCE0/3 at clause 1
    %  user:selectCE/3 at clause 2
    %  user:runo0/1 at clause 2
    %  prolog:$do_yes_no/2 at clause 2
    %  prolog:$yes_no/2 at clause 1
    %  prolog:$command/4 at clause 2
    %  prolog:$enter_top_level/0 at clause 6
    %         prolog:$catch/3 (512KB-0KB)
    %  prolog:$system_catch/4 at clause 1
    %  meta-call
    % Existing ….

    My prolog code looks like this:

    "…………..
    load_foreign_files(,,init_my_predicates),
    getclique(DimacsFile,Err), ………" . It gets stuck in the "get clique" predicate.

    and my C 'optimize.c'  file is:

    #include "YapInterface.h"
    #include <unistd.h>
    #include <stdio.h>
    #include "cliquer.h"

    int getclique(char *argv) {
        graph_t *g;
        set_t s;
        int *order;
        FILE *f;

    f = fopen ("solutions.pl", "wt");
    g=graph_read_dimacs_file(argv);
    if (g==NULL) return 1;

    ASSERT(graph_test(g,stderr));
    fprintf(stderr,"%d \n\n",g->n);
    graph_print(g);
    //order=reorder_by_degree(g,TRUE);
    //reorder_graph(g,order);
    s=clique_find_single(g,0,0,TRUE,NULL);

    fprintf(f,"solution(5,[");
    set_printfile(f,s);
    fprintf(f,"]).\n");

    fclose(f);
    return 0;
    }

    static int pl_getclique(void)
    {
      YAP_Term in = YAP_ARG1;
      char* invGraphFileNames = (char*)YAP_IntOfTerm(YAP_ARG1);
      int rnd= getclique(invGraphFileNames);
      YAP_Term out = YAP_ARG2;

      YAP_Term val= YAP_MkFloatTerm(rnd);
      return(YAP_Unify(out,val));
    }

    void init_my_predicates()
    {
        YAP_UserCPredicate("getclique",pl_getclique,2);
    }

    Thank you very much in advance,
    Laura

     
  • Laura Antanas
    Laura Antanas
    2010-11-04

    The problem is this line

    *char* invGraphFileNames = (char*)YAP_IntOfTerm(YAP_ARG1); * I need to replace *YAP_IntOfTerm* with something else since this is a YAP_Int and my declaration is a char*

    Laura