YAP 7.1.0
load_dld.c
1/*************************************************************************
2* *
3* YAP Prolog *
4* *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: load_dld.c *
12* comments: dld based dynamic loaderr of external routines *
13* tested on i486-linuxaout *
14*************************************************************************/
15
16#if defined(linux) && !defined(__ELF__) && !defined(__LCC__)
17
18#include "Foreign.h"
19#include <dld.h>
20#include <malloc.h>
21#include <stdio.h>
22
23this code is no being maintained anymore
24
25/*
26 * YAP_FindExecutable(argv[0]) should be called on yap initialization to
27 * locate the executable of Yap
28*/
29char *
30Yap_FindExecutable(void)
31{
32 /* use dld_find_executable */
33 char *res;
34 if(name != NULL && (res=dld_find_executable(name))) {
35 return GLOBAL_Executable;
36 } else {
37 return "yap";
38 }
39}
40
41
42static void *
43Yap_LoadForeignFile(char *file, int flags)
44{
45 /* not implemented */
46 return NULL;
47}
48
49int
50Yap_CallForeignFile(void *handle, char *f)
51{
52 return FALSE;
53}
54
55int
56Yap_CloseForeignFile(void *handle)
57{
58 return -1;
59}
60
61/*
62 * LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign
63 * code files and libraries and locates an initialization routine
64*/
65static int
66LoadForeign(StringList ofiles, StringList libs,
67 char *proc_name, YapInitProc *init_proc)
68{
69 static int firstTime = 1;
70 int error;
71
72 if(firstTime) {
73 error = dld_init(GLOBAL_Executable);
74 if(error) {
75 strcpy(LOCAL_ErrorSay,dld_strerror(error));
76 return LOAD_FAILLED;
77 }
78 firstTime=0;
79 }
80
81 while (ofiles) {
82 if((error=dld_link(AtomName(ofiles->name))) !=0) {
83 strcpy(LOCAL_ErrorSay,dld_strerror(error));
84 return LOAD_FAILLED;
85 }
86 ofiles = ofiles->next;
87 }
88
89
90 /* TODO: handle libs */
91 *init_proc = (YapInitProc) dld_get_func(proc_name);
92 if(! *init_proc) {
93 strcpy(LOCAL_ErrorSay,"Could not locate initialization routine");
94 return LOAD_FAILLED;
95 }
96 if(!dld_function_executable_p(proc_name)) {
97 char **undefs = dld_list_undefined_sym();
98 char **p = undefs;
99 int k = dld_undefined_sym_count;
100 strcpy(LOCAL_ErrorSay,"Could not resolve all symbols");
101 while(k) {
102 YP_printf("[undefined symbol %s]\n",*p++);
103 --k;
104 }
105 free(undefs);
106 return LOAD_FAILLED;
107 }
108
109 return LOAD_SUCCEEDED;
110}
111
112Int
113Yap_LoadForeign(StringList ofiles, StringList libs,
114 char *proc_name, YapInitProc *init_proc)
115{
116 return LoadForeign(ofiles, libs, proc_name, init_proc);
117}
118
119void
120Yap_ShutdownLoadForeign(void)
121{
122}
123
124Int
125Yap_ReLoadForeign(StringList ofiles, StringList libs,
126 char *proc_name, YapInitProc *init_proc)
127{
128 return(LoadForeign(ofiles,libs, proc_name, init_proc));
129}
130
131#endif
load_foreign_files/3 has works for the following configurations: