Mercurial > hg > octave-max
annotate src/dynamic-ld.cc @ 11323:d7fbb08e28cf
strmatch.m: avoid passing length of 0 to strncmp
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Dec 2010 03:25:04 -0500 |
parents | 57a59eae83cc |
children | fd0a3ac60b0e |
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, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
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) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
109 { |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
110 // Erase first to avoid potentially invalidating the pointer by the |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
111 // following hooks. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
112 lib_list.erase (p); |
1664 | 113 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
114 shl.close (cl_hook); |
3033 | 115 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
116 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
117 } |
1664 | 118 } |
119 } | |
120 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
121 octave_shlib |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
122 octave_shlib_list::do_find_file (const std::string& file_name) const |
3325 | 123 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
124 octave_shlib retval; |
1664 | 125 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
126 for (const_iterator p = lib_list.begin (); p != lib_list.end (); p++) |
3325 | 127 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
128 if (p->file_name () == file_name) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
129 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
130 retval = *p; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
131 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
132 } |
3325 | 133 } |
134 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
135 return retval; |
3325 | 136 } |
2926 | 137 |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
138 void |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
139 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
|
140 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
141 std::cerr << "current shared libraries:" << std::endl; |
7748 | 142 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
|
143 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
|
144 } |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
145 |
2926 | 146 bool |
3325 | 147 octave_shlib_list::instance_ok (void) |
2926 | 148 { |
149 bool retval = true; | |
150 | |
151 if (! instance) | |
3325 | 152 instance = new octave_shlib_list (); |
2926 | 153 |
154 if (! instance) | |
155 { | |
3325 | 156 ::error ("unable to create shared library list object!"); |
2926 | 157 |
158 retval = false; | |
159 } | |
160 | |
161 return retval; | |
162 } | |
163 | |
164 void | |
3325 | 165 octave_shlib_list::append (const octave_shlib& shl) |
166 { | |
167 if (instance_ok ()) | |
168 instance->do_append (shl); | |
169 } | |
170 | |
171 void | |
6063 | 172 octave_shlib_list::remove (octave_shlib& shl, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
173 octave_shlib::close_hook cl_hook) |
2894 | 174 { |
3325 | 175 if (instance_ok ()) |
6063 | 176 instance->do_remove (shl, cl_hook); |
2894 | 177 } |
178 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
179 octave_shlib |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
180 octave_shlib_list::find_file (const std::string& file_name) |
3325 | 181 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
182 return (instance_ok ()) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
183 ? instance->do_find_file (file_name) : octave_shlib (); |
3325 | 184 } |
185 | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
186 void |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
187 octave_shlib_list::display (void) |
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 if (instance_ok ()) |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
190 instance->do_display (); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
191 } |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
192 |
5864 | 193 class |
194 octave_mex_file_list | |
195 { | |
196 public: | |
197 | |
7748 | 198 typedef std::list<octave_shlib>::iterator iterator; |
199 typedef std::list<octave_shlib>::const_iterator const_iterator; | |
200 | |
5864 | 201 static void append (const octave_shlib& shl); |
202 | |
6063 | 203 static void remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0); |
5864 | 204 |
205 private: | |
206 | |
207 octave_mex_file_list (void) { } | |
208 | |
209 ~octave_mex_file_list (void) { } | |
210 | |
211 void do_append (const octave_shlib& shl); | |
212 | |
6063 | 213 void do_remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0); |
5864 | 214 |
215 static octave_mex_file_list *instance; | |
216 | |
217 static bool instance_ok (void); | |
218 | |
219 // List of libraries we have loaded. | |
220 std::list<octave_shlib> file_list; | |
221 | |
222 // No copying! | |
223 | |
224 octave_mex_file_list (const octave_mex_file_list&); | |
225 | |
226 octave_mex_file_list& operator = (const octave_mex_file_list&); | |
227 }; | |
228 | |
229 octave_mex_file_list *octave_mex_file_list::instance = 0; | |
230 | |
231 void | |
232 octave_mex_file_list::do_append (const octave_shlib& shl) | |
233 { | |
234 file_list.push_back (shl); | |
235 } | |
236 | |
237 void | |
6063 | 238 octave_mex_file_list::do_remove (octave_shlib& shl, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
239 octave_shlib::close_hook cl_hook) |
5864 | 240 { |
7748 | 241 for (iterator p = file_list.begin (); p != file_list.end (); p++) |
5864 | 242 { |
243 if (*p == shl) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
244 { |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
245 // Erase first to avoid potentially invalidating the pointer by the |
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
246 // following hooks. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
247 file_list.erase (p); |
5864 | 248 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
249 shl.close (cl_hook); |
5864 | 250 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
251 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
252 } |
5864 | 253 } |
254 } | |
255 | |
256 bool | |
257 octave_mex_file_list::instance_ok (void) | |
258 { | |
259 bool retval = true; | |
260 | |
261 if (! instance) | |
262 instance = new octave_mex_file_list (); | |
263 | |
264 if (! instance) | |
265 { | |
266 ::error ("unable to create shared library list object!"); | |
267 | |
268 retval = false; | |
269 } | |
270 | |
271 return retval; | |
272 } | |
273 | |
274 void | |
275 octave_mex_file_list::append (const octave_shlib& shl) | |
276 { | |
277 if (instance_ok ()) | |
278 instance->do_append (shl); | |
279 } | |
280 | |
281 void | |
6063 | 282 octave_mex_file_list::remove (octave_shlib& shl, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
283 octave_shlib::close_hook cl_hook) |
5864 | 284 { |
285 if (instance_ok ()) | |
6063 | 286 instance->do_remove (shl, cl_hook); |
5864 | 287 } |
288 | |
3325 | 289 octave_dynamic_loader *octave_dynamic_loader::instance = 0; |
290 | |
291 bool octave_dynamic_loader::doing_load = false; | |
292 | |
2969 | 293 bool |
3325 | 294 octave_dynamic_loader::instance_ok (void) |
707 | 295 { |
3325 | 296 bool retval = true; |
1664 | 297 |
3325 | 298 if (! instance) |
299 instance = new octave_dynamic_loader (); | |
707 | 300 |
3325 | 301 if (! instance) |
707 | 302 { |
3655 | 303 ::error ("unable to create dynamic loader object!"); |
707 | 304 |
3325 | 305 retval = false; |
707 | 306 } |
307 | |
2893 | 308 return retval; |
309 } | |
310 | |
10287
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 static void |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 do_clear_function (const std::string& fcn_name) |
3325 | 313 { |
5781 | 314 warning_with_id ("Octave:reload-forces-clear", " %s", fcn_name.c_str ()); |
3325 | 315 |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
316 symbol_table::clear_dld_function (fcn_name); |
3325 | 317 } |
318 | |
6323 | 319 static void |
320 clear (octave_shlib& oct_file) | |
321 { | |
322 if (oct_file.number_of_functions_loaded () > 1) | |
10287
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
323 { |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
324 warning_with_id ("Octave:reload-forces-clear", |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
325 "reloading %s clears the following functions:", |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
326 oct_file.file_name().c_str ()); |
6323 | 327 |
10287
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
328 octave_shlib_list::remove (oct_file, do_clear_function); |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
329 } |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
330 else |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
331 octave_shlib_list::remove (oct_file, symbol_table::clear_dld_function); |
6323 | 332 } |
333 | |
7336 | 334 octave_function * |
5864 | 335 octave_dynamic_loader::do_load_oct (const std::string& fcn_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
336 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
337 bool relative) |
2893 | 338 { |
7336 | 339 octave_function *retval = 0; |
3325 | 340 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
341 unwind_protect frame; |
3325 | 342 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
343 frame.protect_var (octave_dynamic_loader::doing_load); |
3325 | 344 |
345 doing_load = true; | |
346 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
347 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
|
348 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
349 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
|
350 clear (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 (! oct_file) |
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 oct_file.open (file_name); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
355 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
356 if (! error_state && oct_file) |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
357 octave_shlib_list::append (oct_file); |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
358 } |
3325 | 359 |
360 if (! error_state) | |
361 { | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
362 if (oct_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
363 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
364 void *function = oct_file.search (fcn_name, name_mangler); |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
365 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
366 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
367 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
368 // FIXME -- can we determine this C mangling scheme |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
369 // automatically at run time or configure time? |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
370 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
371 function = oct_file.search (fcn_name, name_uscore_mangler); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
372 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
373 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
374 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
375 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
376 octave_dld_fcn_getter f |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
377 = FCN_PTR_CAST (octave_dld_fcn_getter, function); |
7748 | 378 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
379 retval = f (oct_file, relative); |
7748 | 380 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
381 if (! retval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
382 ::error ("failed to install .oct file function `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
383 fcn_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
384 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
385 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
386 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
387 ::error ("%s is not a valid shared library", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
388 file_name.c_str ()); |
3325 | 389 } |
3655 | 390 |
3325 | 391 return retval; |
392 } | |
393 | |
7336 | 394 octave_function * |
5864 | 395 octave_dynamic_loader::do_load_mex (const std::string& fcn_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
396 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
397 bool /*relative*/) |
5864 | 398 { |
7336 | 399 octave_function *retval = 0; |
5864 | 400 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
401 unwind_protect frame; |
5864 | 402 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
403 frame.protect_var (octave_dynamic_loader::doing_load); |
5864 | 404 |
405 doing_load = true; | |
406 | |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
407 octave_shlib mex_file = octave_shlib_list::find_file (file_name); |
6323 | 408 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
409 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
|
410 clear (mex_file); |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
411 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
412 if (! mex_file) |
6323 | 413 { |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
414 mex_file.open (file_name); |
6323 | 415 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
416 if (! error_state && mex_file) |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
417 octave_shlib_list::append (mex_file); |
6323 | 418 } |
5864 | 419 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
420 if (! error_state) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
421 { |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
422 if (mex_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
423 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
424 void *function = 0; |
5864 | 425 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
426 bool have_fmex = false; |
5864 | 427 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
428 octave_mex_file_list::append (mex_file); |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
429 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
430 function = mex_file.search (fcn_name, mex_mangler); |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
431 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
432 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
433 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
434 // FIXME -- can we determine this C mangling scheme |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
435 // automatically at run time or configure time? |
5864 | 436 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
437 function = mex_file.search (fcn_name, mex_uscore_mangler); |
5864 | 438 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
439 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
440 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
441 function = mex_file.search (fcn_name, mex_f77_mangler); |
6221 | 442 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
443 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
444 have_fmex = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
445 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
446 } |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
447 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
448 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
449 retval = new octave_mex_function (function, have_fmex, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
450 mex_file, fcn_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
451 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
452 ::error ("failed to install .mex file function `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
453 fcn_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
454 } |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
455 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
456 ::error ("%s is not a valid shared library", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
457 file_name.c_str ()); |
5864 | 458 } |
459 | |
460 return retval; | |
461 } | |
462 | |
463 bool | |
7872 | 464 octave_dynamic_loader::do_remove_oct (const std::string& fcn_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
465 octave_shlib& shl) |
3325 | 466 { |
467 bool retval = false; | |
468 | |
469 // We don't need to do anything if this is called because we are in | |
470 // the process of reloading a .oct file that has changed. | |
471 | |
472 if (! doing_load) | |
473 { | |
474 retval = shl.remove (fcn_name); | |
475 | |
476 if (shl.number_of_functions_loaded () == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
477 octave_shlib_list::remove (shl); |
3325 | 478 } |
479 | |
480 return retval; | |
481 } | |
482 | |
7872 | 483 bool |
484 octave_dynamic_loader::do_remove_mex (const std::string& fcn_name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
485 octave_shlib& shl) |
7872 | 486 { |
487 bool retval = false; | |
488 | |
489 // We don't need to do anything if this is called because we are in | |
490 // the process of reloading a .oct file that has changed. | |
491 | |
492 if (! doing_load) | |
493 { | |
494 retval = shl.remove (fcn_name); | |
495 | |
496 if (shl.number_of_functions_loaded () == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
497 octave_mex_file_list::remove (shl); |
7872 | 498 } |
499 | |
500 return retval; | |
501 } | |
502 | |
7336 | 503 octave_function * |
5864 | 504 octave_dynamic_loader::load_oct (const std::string& fcn_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
505 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
506 bool relative) |
3325 | 507 { |
6323 | 508 return (instance_ok ()) |
7336 | 509 ? instance->do_load_oct (fcn_name, file_name, relative) : 0; |
5864 | 510 } |
511 | |
7336 | 512 octave_function * |
5864 | 513 octave_dynamic_loader::load_mex (const std::string& fcn_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
514 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
515 bool relative) |
5864 | 516 { |
6323 | 517 return (instance_ok ()) |
7336 | 518 ? instance->do_load_mex (fcn_name, file_name, relative) : 0; |
3325 | 519 } |
520 | |
521 bool | |
7872 | 522 octave_dynamic_loader::remove_oct (const std::string& fcn_name, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
523 octave_shlib& shl) |
3325 | 524 { |
7872 | 525 return (instance_ok ()) ? instance->do_remove_oct (fcn_name, shl) : false; |
526 } | |
527 | |
528 bool | |
529 octave_dynamic_loader::remove_mex (const std::string& fcn_name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
530 octave_shlib& shl) |
7872 | 531 { |
532 return (instance_ok ()) ? instance->do_remove_mex (fcn_name, shl) : false; | |
2893 | 533 } |
707 | 534 |
3536 | 535 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
536 octave_dynamic_loader::name_mangler (const std::string& name) |
2894 | 537 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
538 return "G" + name; |
2894 | 539 } |
707 | 540 |
7336 | 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_uscore_mangler (const std::string& name) |
7336 | 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; |
7336 | 545 } |
546 | |
7872 | 547 std::string |
548 octave_dynamic_loader::mex_mangler (const std::string&) | |
549 { | |
550 return "mexFunction"; | |
551 } | |
552 | |
553 std::string | |
554 octave_dynamic_loader::mex_uscore_mangler (const std::string&) | |
555 { | |
556 return "_mexFunction"; | |
557 } | |
558 | |
559 std::string | |
560 octave_dynamic_loader::mex_f77_mangler (const std::string&) | |
561 { | |
562 return STRINGIFY (F77_FUNC (mexfunction, MEXFUNCTION)); | |
563 } |