Mercurial > octave
annotate src/dynamic-ld.cc @ 7749:14e05160b99f
reference counting for functions loaded from shared libraries
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 01 May 2008 17:25:56 -0400 |
parents | 3dc91baee089 |
children | 1b63f8da772d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
4 2002, 2004, 2005, 2006, 2007 John W. Eaton | |
1 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
240 | 24 #ifdef HAVE_CONFIG_H |
1192 | 25 #include <config.h> |
1 | 26 #endif |
27 | |
4219 | 28 #include <list> |
29 | |
6323 | 30 #include "oct-env.h" |
3325 | 31 #include "oct-time.h" |
32 #include "file-stat.h" | |
707 | 33 |
2492 | 34 #include <defaults.h> |
3325 | 35 |
36 #include "defun.h" | |
1352 | 37 #include "dynamic-ld.h" |
7336 | 38 #include "ov-fcn.h" |
39 #include "ov-dld-fcn.h" | |
40 #include "ov-mex-fcn.h" | |
3325 | 41 #include "parse.h" |
42 #include "unwind-prot.h" | |
1352 | 43 #include "utils.h" |
707 | 44 #include "variables.h" |
1 | 45 |
5864 | 46 #define STRINGIFY(s) STRINGIFY1(s) |
47 #define STRINGIFY1(s) #s | |
48 | |
2894 | 49 class |
3325 | 50 octave_shlib_list |
1664 | 51 { |
2894 | 52 public: |
53 | |
7748 | 54 typedef std::list<octave_shlib>::iterator iterator; |
55 typedef std::list<octave_shlib>::const_iterator const_iterator; | |
56 | |
3325 | 57 static void append (const octave_shlib& shl); |
2894 | 58 |
6063 | 59 static void remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0); |
3325 | 60 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
61 static octave_shlib find_file (const std::string& file_name); |
2894 | 62 |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
63 static void display (void); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
64 |
2894 | 65 private: |
66 | |
3325 | 67 octave_shlib_list (void) { } |
68 | |
69 ~octave_shlib_list (void) { } | |
70 | |
71 void do_append (const octave_shlib& shl); | |
72 | |
6063 | 73 void do_remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0); |
3325 | 74 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
75 octave_shlib do_find_file (const std::string& file_name) const; |
3325 | 76 |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
77 void do_display (void) const; |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
78 |
3325 | 79 static octave_shlib_list *instance; |
80 | |
81 static bool instance_ok (void); | |
82 | |
83 // List of libraries we have loaded. | |
4219 | 84 std::list<octave_shlib> lib_list; |
2894 | 85 |
86 // No copying! | |
87 | |
3325 | 88 octave_shlib_list (const octave_shlib_list&); |
2894 | 89 |
3325 | 90 octave_shlib_list& operator = (const octave_shlib_list&); |
2894 | 91 }; |
92 | |
3325 | 93 octave_shlib_list *octave_shlib_list::instance = 0; |
3321 | 94 |
3325 | 95 void |
96 octave_shlib_list::do_append (const octave_shlib& shl) | |
97 { | |
4219 | 98 lib_list.push_back (shl); |
1664 | 99 } |
100 | |
3325 | 101 void |
6063 | 102 octave_shlib_list::do_remove (octave_shlib& shl, |
103 octave_shlib::close_hook cl_hook) | |
1664 | 104 { |
7748 | 105 for (iterator p = lib_list.begin (); p != lib_list.end (); p++) |
3325 | 106 { |
4219 | 107 if (*p == shl) |
3325 | 108 { |
6063 | 109 shl.close (cl_hook); |
1664 | 110 |
4219 | 111 lib_list.erase (p); |
3033 | 112 |
3325 | 113 break; |
1664 | 114 } |
115 } | |
116 } | |
117 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
118 octave_shlib |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
119 octave_shlib_list::do_find_file (const std::string& file_name) const |
3325 | 120 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
121 octave_shlib retval; |
1664 | 122 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
123 for (const_iterator p = lib_list.begin (); p != lib_list.end (); p++) |
3325 | 124 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
125 if (p->file_name () == file_name) |
3325 | 126 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
127 retval = *p; |
3325 | 128 break; |
129 } | |
130 } | |
131 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
132 return retval; |
3325 | 133 } |
2926 | 134 |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
135 void |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
136 octave_shlib_list::do_display (void) const |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
137 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
138 std::cerr << "current shared libraries:" << std::endl; |
7748 | 139 for (const_iterator p = lib_list.begin (); p != lib_list.end (); p++) |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
140 std::cerr << " " << p->file_name () << std::endl; |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
141 } |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
142 |
2926 | 143 bool |
3325 | 144 octave_shlib_list::instance_ok (void) |
2926 | 145 { |
146 bool retval = true; | |
147 | |
148 if (! instance) | |
3325 | 149 instance = new octave_shlib_list (); |
2926 | 150 |
151 if (! instance) | |
152 { | |
3325 | 153 ::error ("unable to create shared library list object!"); |
2926 | 154 |
155 retval = false; | |
156 } | |
157 | |
158 return retval; | |
159 } | |
160 | |
161 void | |
3325 | 162 octave_shlib_list::append (const octave_shlib& shl) |
163 { | |
164 if (instance_ok ()) | |
165 instance->do_append (shl); | |
166 } | |
167 | |
168 void | |
6063 | 169 octave_shlib_list::remove (octave_shlib& shl, |
170 octave_shlib::close_hook cl_hook) | |
2894 | 171 { |
3325 | 172 if (instance_ok ()) |
6063 | 173 instance->do_remove (shl, cl_hook); |
2894 | 174 } |
175 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
176 octave_shlib |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
177 octave_shlib_list::find_file (const std::string& file_name) |
3325 | 178 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
179 return (instance_ok ()) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
180 ? instance->do_find_file (file_name) : octave_shlib (); |
3325 | 181 } |
182 | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
183 void |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
184 octave_shlib_list::display (void) |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
185 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
186 if (instance_ok ()) |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
187 instance->do_display (); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
188 } |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
189 |
5864 | 190 class |
191 octave_mex_file_list | |
192 { | |
193 public: | |
194 | |
7748 | 195 typedef std::list<octave_shlib>::iterator iterator; |
196 typedef std::list<octave_shlib>::const_iterator const_iterator; | |
197 | |
5864 | 198 static void append (const octave_shlib& shl); |
199 | |
6063 | 200 static void remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0); |
5864 | 201 |
202 private: | |
203 | |
204 octave_mex_file_list (void) { } | |
205 | |
206 ~octave_mex_file_list (void) { } | |
207 | |
208 void do_append (const octave_shlib& shl); | |
209 | |
6063 | 210 void do_remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0); |
5864 | 211 |
212 static octave_mex_file_list *instance; | |
213 | |
214 static bool instance_ok (void); | |
215 | |
216 // List of libraries we have loaded. | |
217 std::list<octave_shlib> file_list; | |
218 | |
219 // No copying! | |
220 | |
221 octave_mex_file_list (const octave_mex_file_list&); | |
222 | |
223 octave_mex_file_list& operator = (const octave_mex_file_list&); | |
224 }; | |
225 | |
226 octave_mex_file_list *octave_mex_file_list::instance = 0; | |
227 | |
228 void | |
229 octave_mex_file_list::do_append (const octave_shlib& shl) | |
230 { | |
231 file_list.push_back (shl); | |
232 } | |
233 | |
234 void | |
6063 | 235 octave_mex_file_list::do_remove (octave_shlib& shl, |
236 octave_shlib::close_hook cl_hook) | |
5864 | 237 { |
7748 | 238 for (iterator p = file_list.begin (); p != file_list.end (); p++) |
5864 | 239 { |
240 if (*p == shl) | |
241 { | |
6063 | 242 shl.close (cl_hook); |
5864 | 243 |
244 file_list.erase (p); | |
245 | |
246 break; | |
247 } | |
248 } | |
249 } | |
250 | |
251 bool | |
252 octave_mex_file_list::instance_ok (void) | |
253 { | |
254 bool retval = true; | |
255 | |
256 if (! instance) | |
257 instance = new octave_mex_file_list (); | |
258 | |
259 if (! instance) | |
260 { | |
261 ::error ("unable to create shared library list object!"); | |
262 | |
263 retval = false; | |
264 } | |
265 | |
266 return retval; | |
267 } | |
268 | |
269 void | |
270 octave_mex_file_list::append (const octave_shlib& shl) | |
271 { | |
272 if (instance_ok ()) | |
273 instance->do_append (shl); | |
274 } | |
275 | |
276 void | |
6063 | 277 octave_mex_file_list::remove (octave_shlib& shl, |
278 octave_shlib::close_hook cl_hook) | |
5864 | 279 { |
280 if (instance_ok ()) | |
6063 | 281 instance->do_remove (shl, cl_hook); |
5864 | 282 } |
283 | |
3325 | 284 octave_dynamic_loader *octave_dynamic_loader::instance = 0; |
285 | |
286 bool octave_dynamic_loader::doing_load = false; | |
287 | |
2969 | 288 bool |
3325 | 289 octave_dynamic_loader::instance_ok (void) |
707 | 290 { |
3325 | 291 bool retval = true; |
1664 | 292 |
3325 | 293 if (! instance) |
294 instance = new octave_dynamic_loader (); | |
707 | 295 |
3325 | 296 if (! instance) |
707 | 297 { |
3655 | 298 ::error ("unable to create dynamic loader object!"); |
707 | 299 |
3325 | 300 retval = false; |
707 | 301 } |
302 | |
2893 | 303 return retval; |
304 } | |
305 | |
3325 | 306 static |
4954 | 307 void do_clear_function (const std::string& fcn_name) |
3325 | 308 { |
5781 | 309 warning_with_id ("Octave:reload-forces-clear", " %s", fcn_name.c_str ()); |
3325 | 310 |
7336 | 311 symbol_table::clear_user_function (fcn_name); |
3325 | 312 } |
313 | |
6323 | 314 static void |
315 clear (octave_shlib& oct_file) | |
316 { | |
317 if (oct_file.number_of_functions_loaded () > 1) | |
318 warning_with_id ("Octave:reload-forces-clear", | |
319 "reloading %s clears the following functions:", | |
320 oct_file.file_name().c_str ()); | |
321 | |
322 octave_shlib_list::remove (oct_file, do_clear_function); | |
323 } | |
324 | |
7336 | 325 octave_function * |
5864 | 326 octave_dynamic_loader::do_load_oct (const std::string& fcn_name, |
6323 | 327 const std::string& file_name, |
328 bool relative) | |
2893 | 329 { |
7336 | 330 octave_function *retval = 0; |
3325 | 331 |
332 unwind_protect::begin_frame ("octave_dynamic_loader::do_load"); | |
333 | |
334 unwind_protect_bool (octave_dynamic_loader::doing_load); | |
335 | |
336 doing_load = true; | |
337 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
338 octave_shlib oct_file = octave_shlib_list::find_file (file_name); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
339 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
340 if (oct_file && oct_file.is_out_of_date ()) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
341 clear (oct_file); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
342 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
343 if (! oct_file) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
344 { |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
345 oct_file.open (file_name); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
346 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
347 if (! error_state && oct_file) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
348 { |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
349 octave_shlib_list::append (oct_file); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
350 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
351 if (relative) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
352 oct_file.mark_relative (); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
353 } |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
354 } |
3325 | 355 |
356 if (! error_state) | |
357 { | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
358 if (oct_file) |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
359 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
360 void *function = oct_file.search (fcn_name, xmangle_name); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
361 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
362 if (function) |
6323 | 363 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
364 octave_dld_fcn_getter f |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
365 = FCN_PTR_CAST (octave_dld_fcn_getter, function); |
7748 | 366 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
367 retval = f (oct_file, relative); |
7748 | 368 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
369 if (! retval) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
370 ::error ("failed to install .oct file function `%s'", |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
371 fcn_name.c_str ()); |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
372 } |
3325 | 373 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
374 else |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
375 ::error ("%s is not a valid shared library", |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
376 file_name.c_str ()); |
3325 | 377 } |
3655 | 378 |
3325 | 379 unwind_protect::run_frame ("octave_dynamic_loader::do_load"); |
380 | |
381 return retval; | |
382 } | |
383 | |
7336 | 384 octave_function * |
5864 | 385 octave_dynamic_loader::do_load_mex (const std::string& fcn_name, |
6323 | 386 const std::string& file_name, |
387 bool relative) | |
5864 | 388 { |
7336 | 389 octave_function *retval = 0; |
5864 | 390 |
391 octave_shlib mex_file; | |
392 | |
393 unwind_protect::begin_frame ("octave_dynamic_loader::do_load"); | |
394 | |
395 unwind_protect_bool (octave_dynamic_loader::doing_load); | |
396 | |
397 doing_load = true; | |
398 | |
6323 | 399 std::string mex_file_name = file_name; |
400 | |
401 if (mex_file_name.empty ()) | |
402 { | |
403 mex_file_name = mex_file_in_path (fcn_name); | |
404 | |
405 if (! mex_file_name.empty ()) | |
406 relative = ! octave_env::absolute_pathname (mex_file_name); | |
407 } | |
5864 | 408 |
409 void *function = 0; | |
410 | |
411 bool have_fmex = false; | |
412 | |
413 if (! mex_file_name.empty ()) | |
414 { | |
415 mex_file.open (mex_file_name); | |
416 | |
417 if (! error_state) | |
418 { | |
419 if (mex_file) | |
420 { | |
421 octave_mex_file_list::append (mex_file); | |
422 | |
423 function = mex_file.search ("mexFunction"); | |
424 | |
425 if (! function) | |
426 { | |
6221 | 427 // FIXME -- can we determine this C mangling scheme |
428 // automatically at run time or configure time? | |
429 | |
430 function = mex_file.search ("_mexFunction"); | |
431 | |
432 if (! function) | |
433 { | |
434 function = mex_file.search (STRINGIFY (F77_FUNC (mexfunction, MEXFUNCTION))); | |
435 if (function) | |
436 have_fmex = true; | |
437 } | |
5864 | 438 } |
439 } | |
440 else | |
441 ::error ("%s is not a valid shared library", | |
442 mex_file_name.c_str ()); | |
443 } | |
444 } | |
445 | |
446 if (function) | |
7336 | 447 retval = new octave_mex_function (function, have_fmex, mex_file, fcn_name); |
5864 | 448 else |
449 ::error ("failed to install .mex file function `%s'", fcn_name.c_str ()); | |
450 | |
451 unwind_protect::run_frame ("octave_dynamic_loader::do_load"); | |
452 | |
453 return retval; | |
454 } | |
455 | |
456 bool | |
3523 | 457 octave_dynamic_loader::do_remove (const std::string& fcn_name, octave_shlib& shl) |
3325 | 458 { |
459 bool retval = false; | |
460 | |
461 // We don't need to do anything if this is called because we are in | |
462 // the process of reloading a .oct file that has changed. | |
463 | |
464 if (! doing_load) | |
465 { | |
466 retval = shl.remove (fcn_name); | |
467 | |
468 if (shl.number_of_functions_loaded () == 0) | |
469 octave_shlib_list::remove (shl); | |
470 } | |
471 | |
472 return retval; | |
473 } | |
474 | |
7336 | 475 octave_function * |
5864 | 476 octave_dynamic_loader::load_oct (const std::string& fcn_name, |
7336 | 477 const std::string& file_name, |
478 bool relative) | |
3325 | 479 { |
6323 | 480 return (instance_ok ()) |
7336 | 481 ? instance->do_load_oct (fcn_name, file_name, relative) : 0; |
5864 | 482 } |
483 | |
7336 | 484 octave_function * |
5864 | 485 octave_dynamic_loader::load_mex (const std::string& fcn_name, |
7336 | 486 const std::string& file_name, |
487 bool relative) | |
5864 | 488 { |
6323 | 489 return (instance_ok ()) |
7336 | 490 ? instance->do_load_mex (fcn_name, file_name, relative) : 0; |
3325 | 491 } |
492 | |
493 bool | |
3523 | 494 octave_dynamic_loader::remove (const std::string& fcn_name, octave_shlib& shl) |
3325 | 495 { |
496 return (instance_ok ()) ? instance->do_remove (fcn_name, shl) : false; | |
2893 | 497 } |
707 | 498 |
3536 | 499 std::string |
3523 | 500 octave_dynamic_loader::mangle_name (const std::string& name) |
2894 | 501 { |
3222 | 502 #if defined (CXX_PREPENDS_UNDERSCORE) |
3523 | 503 std::string retval ("_FS"); |
3222 | 504 #else |
3523 | 505 std::string retval ("FS"); |
3222 | 506 #endif |
2894 | 507 retval.append (name); |
3842 | 508 retval.append ("_"); |
509 retval.append (STRINGIFY (CXX_ABI)); | |
2894 | 510 return retval; |
511 } | |
707 | 512 |
7336 | 513 std::string |
514 octave_dynamic_loader::xmangle_name (const std::string& name) | |
515 { | |
516 #if defined (CXX_PREPENDS_UNDERSCORE) | |
517 std::string retval ("_G"); | |
518 #else | |
519 std::string retval ("G"); | |
520 #endif | |
521 retval.append (name); | |
522 retval.append ("_"); | |
523 retval.append (STRINGIFY (CXX_ABI)); | |
524 return retval; | |
525 } | |
526 | |
1 | 527 /* |
528 ;;; Local Variables: *** | |
529 ;;; mode: C++ *** | |
530 ;;; End: *** | |
531 */ |