Mercurial > hg > octave-lyh
annotate src/dynamic-ld.cc @ 14899:f25d2224fa02
Initial JIT support
build-aux/common.mk: Add llvm flags.
configure.ac: Link with llvm.
src/Makefile: Add pt-jit.
src/link-deps.mk: Link with llvm.
src/oct-conf.in.h: Add llvm flags.
src/toplev.cc: Add llvm flags.
src/pt-eval.cc: Try to jit statements.
src/pt-jit.cc: New file.
src/pt-jit.h: New file
author | Max Brister <max@2bass.com> |
---|---|
date | Sun, 06 May 2012 20:17:30 -0600 |
parents | 72c96de7a403 |
children | 460a3c6d8bf1 d174210ce1ec |
rev | line source |
---|---|
1 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
3 Copyright (C) 1993-2012 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 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
30 #include "file-stat.h" |
6323 | 31 #include "oct-env.h" |
3325 | 32 #include "oct-time.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
33 #include "singleton-cleanup.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 | |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
68 octave_shlib_list (void) : lib_list () { } |
3325 | 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 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
82 static void cleanup_instance (void) { delete instance; instance = 0; } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
83 |
3325 | 84 static bool instance_ok (void); |
85 | |
86 // List of libraries we have loaded. | |
4219 | 87 std::list<octave_shlib> lib_list; |
2894 | 88 |
89 // No copying! | |
90 | |
3325 | 91 octave_shlib_list (const octave_shlib_list&); |
2894 | 92 |
3325 | 93 octave_shlib_list& operator = (const octave_shlib_list&); |
2894 | 94 }; |
95 | |
3325 | 96 octave_shlib_list *octave_shlib_list::instance = 0; |
3321 | 97 |
3325 | 98 void |
99 octave_shlib_list::do_append (const octave_shlib& shl) | |
100 { | |
4219 | 101 lib_list.push_back (shl); |
1664 | 102 } |
103 | |
3325 | 104 void |
6063 | 105 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
|
106 octave_shlib::close_hook cl_hook) |
1664 | 107 { |
7748 | 108 for (iterator p = lib_list.begin (); p != lib_list.end (); p++) |
3325 | 109 { |
4219 | 110 if (*p == shl) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
111 { |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
112 // 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
|
113 // following hooks. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
114 lib_list.erase (p); |
1664 | 115 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
116 shl.close (cl_hook); |
3033 | 117 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
118 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
119 } |
1664 | 120 } |
121 } | |
122 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
123 octave_shlib |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
124 octave_shlib_list::do_find_file (const std::string& file_name) const |
3325 | 125 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
126 octave_shlib retval; |
1664 | 127 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
128 for (const_iterator p = lib_list.begin (); p != lib_list.end (); p++) |
3325 | 129 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
130 if (p->file_name () == file_name) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
131 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
132 retval = *p; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
133 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
134 } |
3325 | 135 } |
136 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
137 return retval; |
3325 | 138 } |
2926 | 139 |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
140 void |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
141 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
|
142 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
143 std::cerr << "current shared libraries:" << std::endl; |
7748 | 144 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
|
145 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
|
146 } |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
147 |
2926 | 148 bool |
3325 | 149 octave_shlib_list::instance_ok (void) |
2926 | 150 { |
151 bool retval = true; | |
152 | |
153 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
154 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
155 instance = new octave_shlib_list (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
156 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
157 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
158 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
159 } |
2926 | 160 |
161 if (! instance) | |
162 { | |
3325 | 163 ::error ("unable to create shared library list object!"); |
2926 | 164 |
165 retval = false; | |
166 } | |
167 | |
168 return retval; | |
169 } | |
170 | |
171 void | |
3325 | 172 octave_shlib_list::append (const octave_shlib& shl) |
173 { | |
174 if (instance_ok ()) | |
175 instance->do_append (shl); | |
176 } | |
177 | |
178 void | |
6063 | 179 octave_shlib_list::remove (octave_shlib& shl, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
180 octave_shlib::close_hook cl_hook) |
2894 | 181 { |
3325 | 182 if (instance_ok ()) |
6063 | 183 instance->do_remove (shl, cl_hook); |
2894 | 184 } |
185 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
186 octave_shlib |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
187 octave_shlib_list::find_file (const std::string& file_name) |
3325 | 188 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
189 return (instance_ok ()) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
190 ? instance->do_find_file (file_name) : octave_shlib (); |
3325 | 191 } |
192 | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
193 void |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
194 octave_shlib_list::display (void) |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
195 { |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
196 if (instance_ok ()) |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
197 instance->do_display (); |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
198 } |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
199 |
5864 | 200 class |
201 octave_mex_file_list | |
202 { | |
203 public: | |
204 | |
7748 | 205 typedef std::list<octave_shlib>::iterator iterator; |
206 typedef std::list<octave_shlib>::const_iterator const_iterator; | |
207 | |
5864 | 208 static void append (const octave_shlib& shl); |
209 | |
6063 | 210 static void remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0); |
5864 | 211 |
212 private: | |
213 | |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
214 octave_mex_file_list (void) : file_list () { } |
5864 | 215 |
216 ~octave_mex_file_list (void) { } | |
217 | |
218 void do_append (const octave_shlib& shl); | |
219 | |
6063 | 220 void do_remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0); |
5864 | 221 |
222 static octave_mex_file_list *instance; | |
223 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
224 static void cleanup_instance (void) { delete instance; instance = 0; } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
225 |
5864 | 226 static bool instance_ok (void); |
227 | |
228 // List of libraries we have loaded. | |
229 std::list<octave_shlib> file_list; | |
230 | |
231 // No copying! | |
232 | |
233 octave_mex_file_list (const octave_mex_file_list&); | |
234 | |
235 octave_mex_file_list& operator = (const octave_mex_file_list&); | |
236 }; | |
237 | |
238 octave_mex_file_list *octave_mex_file_list::instance = 0; | |
239 | |
240 void | |
241 octave_mex_file_list::do_append (const octave_shlib& shl) | |
242 { | |
243 file_list.push_back (shl); | |
244 } | |
245 | |
246 void | |
6063 | 247 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
|
248 octave_shlib::close_hook cl_hook) |
5864 | 249 { |
7748 | 250 for (iterator p = file_list.begin (); p != file_list.end (); p++) |
5864 | 251 { |
252 if (*p == shl) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
253 { |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
254 // 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
|
255 // following hooks. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
256 file_list.erase (p); |
5864 | 257 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
258 shl.close (cl_hook); |
5864 | 259 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
260 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
261 } |
5864 | 262 } |
263 } | |
264 | |
265 bool | |
266 octave_mex_file_list::instance_ok (void) | |
267 { | |
268 bool retval = true; | |
269 | |
270 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
271 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
272 instance = new octave_mex_file_list (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
273 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
274 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
275 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
276 } |
5864 | 277 |
278 if (! instance) | |
279 { | |
280 ::error ("unable to create shared library list object!"); | |
281 | |
282 retval = false; | |
283 } | |
284 | |
285 return retval; | |
286 } | |
287 | |
288 void | |
289 octave_mex_file_list::append (const octave_shlib& shl) | |
290 { | |
291 if (instance_ok ()) | |
292 instance->do_append (shl); | |
293 } | |
294 | |
295 void | |
6063 | 296 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
|
297 octave_shlib::close_hook cl_hook) |
5864 | 298 { |
299 if (instance_ok ()) | |
6063 | 300 instance->do_remove (shl, cl_hook); |
5864 | 301 } |
302 | |
3325 | 303 octave_dynamic_loader *octave_dynamic_loader::instance = 0; |
304 | |
305 bool octave_dynamic_loader::doing_load = false; | |
306 | |
2969 | 307 bool |
3325 | 308 octave_dynamic_loader::instance_ok (void) |
707 | 309 { |
3325 | 310 bool retval = true; |
1664 | 311 |
3325 | 312 if (! instance) |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
313 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
314 instance = new octave_dynamic_loader (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
315 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
316 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
317 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
318 } |
707 | 319 |
3325 | 320 if (! instance) |
707 | 321 { |
3655 | 322 ::error ("unable to create dynamic loader object!"); |
707 | 323 |
3325 | 324 retval = false; |
707 | 325 } |
326 | |
2893 | 327 return retval; |
328 } | |
329 | |
10287
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
330 static void |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
331 do_clear_function (const std::string& fcn_name) |
3325 | 332 { |
5781 | 333 warning_with_id ("Octave:reload-forces-clear", " %s", fcn_name.c_str ()); |
3325 | 334 |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
335 symbol_table::clear_dld_function (fcn_name); |
3325 | 336 } |
337 | |
6323 | 338 static void |
339 clear (octave_shlib& oct_file) | |
340 { | |
341 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
|
342 { |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
343 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
|
344 "reloading %s clears the following functions:", |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
345 oct_file.file_name().c_str ()); |
6323 | 346 |
10287
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
347 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
|
348 } |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
349 else |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
350 octave_shlib_list::remove (oct_file, symbol_table::clear_dld_function); |
6323 | 351 } |
352 | |
7336 | 353 octave_function * |
5864 | 354 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
|
355 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
356 bool relative) |
2893 | 357 { |
7336 | 358 octave_function *retval = 0; |
3325 | 359 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
360 unwind_protect frame; |
3325 | 361 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
362 frame.protect_var (octave_dynamic_loader::doing_load); |
3325 | 363 |
364 doing_load = true; | |
365 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
366 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
|
367 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
368 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
|
369 clear (oct_file); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
370 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
371 if (! oct_file) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
372 { |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
373 oct_file.open (file_name); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
374 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
375 if (! error_state && oct_file) |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
376 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
|
377 } |
3325 | 378 |
379 if (! error_state) | |
380 { | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
381 if (oct_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
382 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
383 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
|
384 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
385 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
386 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
387 // FIXME -- can we determine this C mangling scheme |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
388 // 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
|
389 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
390 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
|
391 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
392 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
393 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
394 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
395 octave_dld_fcn_getter f |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
396 = FCN_PTR_CAST (octave_dld_fcn_getter, function); |
7748 | 397 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
398 retval = f (oct_file, relative); |
7748 | 399 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
400 if (! retval) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
401 ::error ("failed to install .oct file function `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
402 fcn_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
404 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
405 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
406 ::error ("%s is not a valid shared library", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
407 file_name.c_str ()); |
3325 | 408 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
409 |
3325 | 410 return retval; |
411 } | |
412 | |
7336 | 413 octave_function * |
5864 | 414 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
|
415 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
416 bool /*relative*/) |
5864 | 417 { |
7336 | 418 octave_function *retval = 0; |
5864 | 419 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
420 unwind_protect frame; |
5864 | 421 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
422 frame.protect_var (octave_dynamic_loader::doing_load); |
5864 | 423 |
424 doing_load = true; | |
425 | |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
426 octave_shlib mex_file = octave_shlib_list::find_file (file_name); |
6323 | 427 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
428 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
|
429 clear (mex_file); |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
430 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
431 if (! mex_file) |
6323 | 432 { |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
433 mex_file.open (file_name); |
6323 | 434 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
435 if (! error_state && mex_file) |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
436 octave_shlib_list::append (mex_file); |
6323 | 437 } |
5864 | 438 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
439 if (! error_state) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
440 { |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
441 if (mex_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
442 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
443 void *function = 0; |
5864 | 444 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
445 bool have_fmex = false; |
5864 | 446 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
447 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
|
448 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
449 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
|
450 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
451 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
452 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
453 // FIXME -- can we determine this C mangling scheme |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
454 // automatically at run time or configure time? |
5864 | 455 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
456 function = mex_file.search (fcn_name, mex_uscore_mangler); |
5864 | 457 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
458 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
459 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
460 function = mex_file.search (fcn_name, mex_f77_mangler); |
6221 | 461 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
462 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
463 have_fmex = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
464 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
465 } |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
466 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
467 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
468 retval = new octave_mex_function (function, have_fmex, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
469 mex_file, fcn_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
470 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
471 ::error ("failed to install .mex file function `%s'", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
472 fcn_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
473 } |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
474 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
475 ::error ("%s is not a valid shared library", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
476 file_name.c_str ()); |
5864 | 477 } |
478 | |
479 return retval; | |
480 } | |
481 | |
482 bool | |
7872 | 483 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
|
484 octave_shlib& shl) |
3325 | 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_shlib_list::remove (shl); |
3325 | 497 } |
498 | |
499 return retval; | |
500 } | |
501 | |
7872 | 502 bool |
503 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
|
504 octave_shlib& shl) |
7872 | 505 { |
506 bool retval = false; | |
507 | |
508 // We don't need to do anything if this is called because we are in | |
509 // the process of reloading a .oct file that has changed. | |
510 | |
511 if (! doing_load) | |
512 { | |
513 retval = shl.remove (fcn_name); | |
514 | |
515 if (shl.number_of_functions_loaded () == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
516 octave_mex_file_list::remove (shl); |
7872 | 517 } |
518 | |
519 return retval; | |
520 } | |
521 | |
7336 | 522 octave_function * |
5864 | 523 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
|
524 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
525 bool relative) |
3325 | 526 { |
6323 | 527 return (instance_ok ()) |
7336 | 528 ? instance->do_load_oct (fcn_name, file_name, relative) : 0; |
5864 | 529 } |
530 | |
7336 | 531 octave_function * |
5864 | 532 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
|
533 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
534 bool relative) |
5864 | 535 { |
6323 | 536 return (instance_ok ()) |
7336 | 537 ? instance->do_load_mex (fcn_name, file_name, relative) : 0; |
3325 | 538 } |
539 | |
540 bool | |
7872 | 541 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
|
542 octave_shlib& shl) |
3325 | 543 { |
7872 | 544 return (instance_ok ()) ? instance->do_remove_oct (fcn_name, shl) : false; |
545 } | |
546 | |
547 bool | |
548 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
|
549 octave_shlib& shl) |
7872 | 550 { |
551 return (instance_ok ()) ? instance->do_remove_mex (fcn_name, shl) : false; | |
2893 | 552 } |
707 | 553 |
3536 | 554 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
555 octave_dynamic_loader::name_mangler (const std::string& name) |
2894 | 556 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
557 return "G" + name; |
2894 | 558 } |
707 | 559 |
7336 | 560 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
561 octave_dynamic_loader::name_uscore_mangler (const std::string& name) |
7336 | 562 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
563 return "_G" + name; |
7336 | 564 } |
565 | |
7872 | 566 std::string |
567 octave_dynamic_loader::mex_mangler (const std::string&) | |
568 { | |
569 return "mexFunction"; | |
570 } | |
571 | |
572 std::string | |
573 octave_dynamic_loader::mex_uscore_mangler (const std::string&) | |
574 { | |
575 return "_mexFunction"; | |
576 } | |
577 | |
578 std::string | |
579 octave_dynamic_loader::mex_f77_mangler (const std::string&) | |
580 { | |
581 return STRINGIFY (F77_FUNC (mexfunction, MEXFUNCTION)); | |
582 } |