1
|
1 // dynamic-ld.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1993 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef __GNUG__ |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
|
28 extern "C" |
|
29 { |
|
30 #include "dld.h" |
|
31 } |
|
32 |
|
33 #include "dynamic-ld.h" |
|
34 #include "tree-const.h" |
|
35 #include "user-prefs.h" |
|
36 #include "octave.h" |
|
37 #include "utils.h" |
|
38 #include "error.h" |
|
39 |
|
40 void |
164
|
41 octave_dld_tc2_unlink_by_symbol (const char *name, int hard = 1) |
1
|
42 { |
|
43 char *mangled_fcn_name = strconcat (name, "__FP13tree_constantii"); |
|
44 int status = dld_unlink_by_symbol (mangled_fcn_name, hard); |
|
45 if (status != 0) |
|
46 dld_perror ("octave_dld_tc2_unlink_by_symbol"); |
|
47 delete [] mangled_fcn_name; |
|
48 } |
|
49 |
|
50 void |
164
|
51 octave_dld_tc2_unlink_by_file (const char *name, int hard = 1) |
1
|
52 { |
|
53 int status = dld_unlink_by_file (name, hard); |
|
54 if (status != 0) |
|
55 dld_perror ("octave_dld_tc2_unlink_by_file"); |
|
56 } |
|
57 |
|
58 static void |
|
59 octave_dld_init (void) |
|
60 { |
|
61 static int initialized = 0; |
|
62 |
|
63 if (! initialized) |
|
64 { |
|
65 char *full_path = dld_find_executable (raw_prog_name); |
|
66 if (full_path != (char *) NULL) |
|
67 { |
|
68 int status = dld_init (full_path); |
|
69 if (status != 0) |
|
70 { |
|
71 dld_perror ("octave_dld_tc2_and_go"); |
|
72 error ("failed to load symbols from `%s'", full_path); |
|
73 } |
|
74 else |
|
75 initialized = 1; |
|
76 } |
|
77 else |
|
78 error ("octave_dld_tc2_and_go: can't find full path to `%s'", |
|
79 prog_name); |
|
80 } |
|
81 } |
|
82 |
|
83 /* |
|
84 * Look for object in path. It should provide a definition for the |
|
85 * function we just marked as undefined. If we find it, we\'ll also |
|
86 * try to load the remaining undefined symbols. |
|
87 */ |
|
88 static int |
164
|
89 octave_dld_link (const char *object) |
1
|
90 { |
|
91 char *file = file_in_path (object, (char *) NULL); |
|
92 int status = dld_link (file); |
|
93 if (status != 0) |
|
94 dld_perror ("octave_dld_link"); |
|
95 |
|
96 delete [] file; |
|
97 return status; |
|
98 } |
|
99 |
|
100 int |
164
|
101 octave_dld_tc2_link (const char *object) |
1
|
102 { |
|
103 int status = octave_dld_link (object); |
|
104 if (status == 0) |
|
105 { |
|
106 status = octave_dld_link ("liboctave.a"); |
|
107 if (status == 0) |
|
108 octave_dld_link ("libcruft.a"); |
|
109 } |
|
110 return status; |
|
111 } |
|
112 |
|
113 builtin_fcn_ptr |
164
|
114 octave_dld_tc2 (const char *name, const char *fcn, const char *object) |
1
|
115 { |
|
116 builtin_fcn_ptr retval = (builtin_fcn_ptr) NULL; |
|
117 |
|
118 octave_dld_init (); |
|
119 |
|
120 char *mangled_fcn_name = strconcat (fcn, "__FP13tree_constantii"); |
|
121 |
|
122 // See if the function has already been loaded. If not, mark it as |
|
123 // undefined. |
|
124 |
|
125 if (dld_get_func (mangled_fcn_name) == 0) |
|
126 dld_create_reference (mangled_fcn_name); |
|
127 |
|
128 int status = octave_dld_link (object); |
|
129 if (status == 0) |
|
130 { |
|
131 // Return a pointer to the function we just loaded. If we can\'t find |
|
132 // it, this will return NULL. |
|
133 |
|
134 retval = (builtin_fcn_ptr) dld_get_func (mangled_fcn_name); |
|
135 } |
|
136 |
|
137 delete [] mangled_fcn_name; |
|
138 |
|
139 return retval; |
|
140 |
|
141 } |
|
142 |
|
143 tree_constant * |
|
144 octave_dld_tc2_and_go (tree_constant *args, int nargin, int nargout, |
164
|
145 const char *name, const char *fcn, const char *object) |
1
|
146 { |
|
147 tree_constant *retval = NULL_TREE_CONST; |
|
148 |
|
149 builtin_fcn_ptr fcn_to_call = octave_dld_tc2 (name, fcn, object); |
|
150 |
|
151 if (fcn_to_call != (builtin_fcn_ptr) NULL) |
|
152 retval = (*fcn_to_call) (args, nargin, nargout); |
|
153 else |
|
154 error ("octave_dld_tc2_and_go: failed to load `%s'", name); |
|
155 |
|
156 return retval; |
|
157 } |
|
158 |
|
159 /* |
|
160 ;;; Local Variables: *** |
|
161 ;;; mode: C++ *** |
|
162 ;;; page-delimiter: "^/\\*" *** |
|
163 ;;; End: *** |
|
164 */ |