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