Mercurial > hg > octave-lyh
annotate src/dynamic-ld.cc @ 8832:9dddbad47122
automatically reload out of date mex files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 20 Feb 2009 14:59:29 -0500 |
parents | 6a7db240b3a3 |
children | eb63fbe60fab |
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 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
360 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
|
361 |
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
362 if (! function) |
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
363 { |
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
364 // 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
|
365 // 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
|
366 |
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
367 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
|
368 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
369 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
370 if (function) |
6323 | 371 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
372 octave_dld_fcn_getter f |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
373 = FCN_PTR_CAST (octave_dld_fcn_getter, function); |
7748 | 374 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
375 retval = f (oct_file, relative); |
7748 | 376 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
377 if (! retval) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
378 ::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
|
379 fcn_name.c_str ()); |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
380 } |
3325 | 381 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
382 else |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
383 ::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
|
384 file_name.c_str ()); |
3325 | 385 } |
3655 | 386 |
3325 | 387 unwind_protect::run_frame ("octave_dynamic_loader::do_load"); |
388 | |
389 return retval; | |
390 } | |
391 | |
7336 | 392 octave_function * |
5864 | 393 octave_dynamic_loader::do_load_mex (const std::string& fcn_name, |
6323 | 394 const std::string& file_name, |
395 bool relative) | |
5864 | 396 { |
7336 | 397 octave_function *retval = 0; |
5864 | 398 |
399 unwind_protect::begin_frame ("octave_dynamic_loader::do_load"); | |
400 | |
401 unwind_protect_bool (octave_dynamic_loader::doing_load); | |
402 | |
403 doing_load = true; | |
404 | |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
405 octave_shlib mex_file = octave_shlib_list::find_file (file_name); |
6323 | 406 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
407 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
|
408 clear (mex_file); |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
409 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
410 if (! mex_file) |
6323 | 411 { |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
412 mex_file.open (file_name); |
6323 | 413 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
414 if (! error_state && mex_file) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
415 { |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
416 octave_shlib_list::append (mex_file); |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
417 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
418 if (relative) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
419 mex_file.mark_relative (); |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
420 } |
6323 | 421 } |
5864 | 422 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
423 if (! error_state) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
424 { |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
425 if (mex_file) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
426 { |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
427 void *function = 0; |
5864 | 428 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
429 bool have_fmex = false; |
5864 | 430 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
431 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
|
432 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
433 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
|
434 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
435 if (! function) |
5864 | 436 { |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
437 // 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
|
438 // automatically at run time or configure time? |
5864 | 439 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
440 function = mex_file.search (fcn_name, mex_uscore_mangler); |
5864 | 441 |
442 if (! function) | |
443 { | |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
444 function = mex_file.search (fcn_name, mex_f77_mangler); |
6221 | 445 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
446 if (function) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
447 have_fmex = true; |
5864 | 448 } |
449 } | |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
450 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
451 if (function) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
452 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
|
453 mex_file, fcn_name); |
5864 | 454 else |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
455 ::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
|
456 fcn_name.c_str ()); |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
457 } |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
458 else |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
459 ::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
|
460 file_name.c_str ()); |
5864 | 461 } |
462 | |
463 unwind_protect::run_frame ("octave_dynamic_loader::do_load"); | |
464 | |
465 return retval; | |
466 } | |
467 | |
468 bool | |
7872 | 469 octave_dynamic_loader::do_remove_oct (const std::string& fcn_name, |
470 octave_shlib& shl) | |
3325 | 471 { |
472 bool retval = false; | |
473 | |
474 // We don't need to do anything if this is called because we are in | |
475 // the process of reloading a .oct file that has changed. | |
476 | |
477 if (! doing_load) | |
478 { | |
479 retval = shl.remove (fcn_name); | |
480 | |
481 if (shl.number_of_functions_loaded () == 0) | |
482 octave_shlib_list::remove (shl); | |
483 } | |
484 | |
485 return retval; | |
486 } | |
487 | |
7872 | 488 bool |
489 octave_dynamic_loader::do_remove_mex (const std::string& fcn_name, | |
490 octave_shlib& shl) | |
491 { | |
492 bool retval = false; | |
493 | |
494 // We don't need to do anything if this is called because we are in | |
495 // the process of reloading a .oct file that has changed. | |
496 | |
497 if (! doing_load) | |
498 { | |
499 retval = shl.remove (fcn_name); | |
500 | |
501 if (shl.number_of_functions_loaded () == 0) | |
502 octave_mex_file_list::remove (shl); | |
503 } | |
504 | |
505 return retval; | |
506 } | |
507 | |
7336 | 508 octave_function * |
5864 | 509 octave_dynamic_loader::load_oct (const std::string& fcn_name, |
7336 | 510 const std::string& file_name, |
511 bool relative) | |
3325 | 512 { |
6323 | 513 return (instance_ok ()) |
7336 | 514 ? instance->do_load_oct (fcn_name, file_name, relative) : 0; |
5864 | 515 } |
516 | |
7336 | 517 octave_function * |
5864 | 518 octave_dynamic_loader::load_mex (const std::string& fcn_name, |
7336 | 519 const std::string& file_name, |
520 bool relative) | |
5864 | 521 { |
6323 | 522 return (instance_ok ()) |
7336 | 523 ? instance->do_load_mex (fcn_name, file_name, relative) : 0; |
3325 | 524 } |
525 | |
526 bool | |
7872 | 527 octave_dynamic_loader::remove_oct (const std::string& fcn_name, |
528 octave_shlib& shl) | |
3325 | 529 { |
7872 | 530 return (instance_ok ()) ? instance->do_remove_oct (fcn_name, shl) : false; |
531 } | |
532 | |
533 bool | |
534 octave_dynamic_loader::remove_mex (const std::string& fcn_name, | |
535 octave_shlib& shl) | |
536 { | |
537 return (instance_ok ()) ? instance->do_remove_mex (fcn_name, shl) : false; | |
2893 | 538 } |
707 | 539 |
3536 | 540 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
541 octave_dynamic_loader::name_mangler (const std::string& name) |
2894 | 542 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
543 return "G" + name; |
2894 | 544 } |
707 | 545 |
7336 | 546 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
547 octave_dynamic_loader::name_uscore_mangler (const std::string& name) |
7336 | 548 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
549 return "_G" + name; |
7336 | 550 } |
551 | |
7872 | 552 std::string |
553 octave_dynamic_loader::mex_mangler (const std::string&) | |
554 { | |
555 return "mexFunction"; | |
556 } | |
557 | |
558 std::string | |
559 octave_dynamic_loader::mex_uscore_mangler (const std::string&) | |
560 { | |
561 return "_mexFunction"; | |
562 } | |
563 | |
564 std::string | |
565 octave_dynamic_loader::mex_f77_mangler (const std::string&) | |
566 { | |
567 return STRINGIFY (F77_FUNC (mexfunction, MEXFUNCTION)); | |
568 } | |
569 | |
1 | 570 /* |
571 ;;; Local Variables: *** | |
572 ;;; mode: C++ *** | |
573 ;;; End: *** | |
574 */ |