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