Mercurial > octave-libgccjit
annotate libinterp/corefcn/dynamic-ld.cc @ 18905:82773ee8119a
Fix ambiguous Matrix initialization from csetdf972b9d080a
* graphics.cc (default_patch_x/ydata): explicitly use decimal numbers to initialize Matrices to double values
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Thu, 10 Jul 2014 09:52:49 +0200 |
parents | 175b392e91fe |
children |
rev | line source |
---|---|
1 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
3 Copyright (C) 1993-2013 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 ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
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 |
3325 | 200 octave_dynamic_loader *octave_dynamic_loader::instance = 0; |
201 | |
202 bool octave_dynamic_loader::doing_load = false; | |
203 | |
2969 | 204 bool |
3325 | 205 octave_dynamic_loader::instance_ok (void) |
707 | 206 { |
3325 | 207 bool retval = true; |
1664 | 208 |
3325 | 209 if (! instance) |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
210 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
211 instance = new octave_dynamic_loader (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
212 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
213 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
214 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
|
215 } |
707 | 216 |
3325 | 217 if (! instance) |
707 | 218 { |
3655 | 219 ::error ("unable to create dynamic loader object!"); |
707 | 220 |
3325 | 221 retval = false; |
707 | 222 } |
223 | |
2893 | 224 return retval; |
225 } | |
226 | |
10287
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
227 static void |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
228 do_clear_function (const std::string& fcn_name) |
3325 | 229 { |
5781 | 230 warning_with_id ("Octave:reload-forces-clear", " %s", fcn_name.c_str ()); |
3325 | 231 |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
232 symbol_table::clear_dld_function (fcn_name); |
3325 | 233 } |
234 | |
6323 | 235 static void |
236 clear (octave_shlib& oct_file) | |
237 { | |
238 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
|
239 { |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
240 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
|
241 "reloading %s clears the following functions:", |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
242 oct_file.file_name ().c_str ()); |
6323 | 243 |
10287
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
244 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
|
245 } |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
246 else |
7c7685cc0676
fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
247 octave_shlib_list::remove (oct_file, symbol_table::clear_dld_function); |
6323 | 248 } |
249 | |
7336 | 250 octave_function * |
5864 | 251 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
|
252 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
253 bool relative) |
2893 | 254 { |
7336 | 255 octave_function *retval = 0; |
3325 | 256 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
257 unwind_protect frame; |
3325 | 258 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
259 frame.protect_var (octave_dynamic_loader::doing_load); |
3325 | 260 |
261 doing_load = true; | |
262 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
263 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
|
264 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
265 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
|
266 clear (oct_file); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
267 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
268 if (! oct_file) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
269 { |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
270 oct_file.open (file_name); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
271 |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
272 if (! error_state && oct_file) |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
273 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
|
274 } |
3325 | 275 |
276 if (! error_state) | |
277 { | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
278 if (oct_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
279 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
280 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
|
281 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
282 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
283 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
284 // FIXME: can we determine this C mangling scheme |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
285 // 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
|
286 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
287 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
|
288 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
289 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
290 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
291 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
292 octave_dld_fcn_getter f |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
293 = FCN_PTR_CAST (octave_dld_fcn_getter, function); |
7748 | 294 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
295 retval = f (oct_file, relative); |
7748 | 296 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
297 if (! retval) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
298 ::error ("failed to install .oct file function '%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
299 fcn_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
300 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
301 } |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7748
diff
changeset
|
302 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
303 ::error ("%s is not a valid shared library", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
304 file_name.c_str ()); |
3325 | 305 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
306 |
3325 | 307 return retval; |
308 } | |
309 | |
7336 | 310 octave_function * |
5864 | 311 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
|
312 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
313 bool /*relative*/) |
5864 | 314 { |
7336 | 315 octave_function *retval = 0; |
5864 | 316 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
317 unwind_protect frame; |
5864 | 318 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
319 frame.protect_var (octave_dynamic_loader::doing_load); |
5864 | 320 |
321 doing_load = true; | |
322 | |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
323 octave_shlib mex_file = octave_shlib_list::find_file (file_name); |
6323 | 324 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
325 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
|
326 clear (mex_file); |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
327 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
328 if (! mex_file) |
6323 | 329 { |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
330 mex_file.open (file_name); |
6323 | 331 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
332 if (! error_state && mex_file) |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
333 octave_shlib_list::append (mex_file); |
6323 | 334 } |
5864 | 335 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
336 if (! error_state) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
337 { |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
338 if (mex_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
339 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
340 void *function = 0; |
5864 | 341 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
342 bool have_fmex = false; |
5864 | 343 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
344 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
|
345 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
346 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
347 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
348 // FIXME: can we determine this C mangling scheme |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
349 // automatically at run time or configure time? |
5864 | 350 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
351 function = mex_file.search (fcn_name, mex_uscore_mangler); |
5864 | 352 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
353 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
355 function = mex_file.search (fcn_name, mex_f77_mangler); |
6221 | 356 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
357 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
358 have_fmex = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
359 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
360 } |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
361 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
362 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
363 retval = new octave_mex_function (function, have_fmex, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
364 mex_file, fcn_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
365 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
366 ::error ("failed to install .mex file function '%s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
367 fcn_name.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
368 } |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
369 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
370 ::error ("%s is not a valid shared library", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
371 file_name.c_str ()); |
5864 | 372 } |
373 | |
374 return retval; | |
375 } | |
376 | |
377 bool | |
7872 | 378 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
|
379 octave_shlib& shl) |
3325 | 380 { |
381 bool retval = false; | |
382 | |
383 // We don't need to do anything if this is called because we are in | |
384 // the process of reloading a .oct file that has changed. | |
385 | |
386 if (! doing_load) | |
387 { | |
388 retval = shl.remove (fcn_name); | |
389 | |
390 if (shl.number_of_functions_loaded () == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
391 octave_shlib_list::remove (shl); |
3325 | 392 } |
393 | |
394 return retval; | |
395 } | |
396 | |
7872 | 397 bool |
398 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
|
399 octave_shlib& shl) |
7872 | 400 { |
401 bool retval = false; | |
402 | |
403 // We don't need to do anything if this is called because we are in | |
404 // the process of reloading a .oct file that has changed. | |
405 | |
406 if (! doing_load) | |
407 { | |
408 retval = shl.remove (fcn_name); | |
409 | |
410 if (shl.number_of_functions_loaded () == 0) | |
16143
752a5de459c2
Fix mex function reloading (bug 34861).
Janne Olavi Paanajärvi <janne.paanajarvi@aalto.fi>
parents:
15467
diff
changeset
|
411 octave_shlib_list::remove (shl); |
7872 | 412 } |
413 | |
414 return retval; | |
415 } | |
416 | |
7336 | 417 octave_function * |
5864 | 418 octave_dynamic_loader::load_oct (const std::string& fcn_name, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
419 const std::string& file_name, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
420 bool relative) |
3325 | 421 { |
6323 | 422 return (instance_ok ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
423 ? instance->do_load_oct (fcn_name, file_name, relative) : 0; |
5864 | 424 } |
425 | |
7336 | 426 octave_function * |
5864 | 427 octave_dynamic_loader::load_mex (const std::string& fcn_name, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
428 const std::string& file_name, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
429 bool relative) |
5864 | 430 { |
6323 | 431 return (instance_ok ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
432 ? instance->do_load_mex (fcn_name, file_name, relative) : 0; |
3325 | 433 } |
434 | |
435 bool | |
7872 | 436 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
|
437 octave_shlib& shl) |
3325 | 438 { |
7872 | 439 return (instance_ok ()) ? instance->do_remove_oct (fcn_name, shl) : false; |
440 } | |
441 | |
442 bool | |
443 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
|
444 octave_shlib& shl) |
7872 | 445 { |
446 return (instance_ok ()) ? instance->do_remove_mex (fcn_name, shl) : false; | |
2893 | 447 } |
707 | 448 |
3536 | 449 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
450 octave_dynamic_loader::name_mangler (const std::string& name) |
2894 | 451 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
452 return "G" + name; |
2894 | 453 } |
707 | 454 |
7336 | 455 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
456 octave_dynamic_loader::name_uscore_mangler (const std::string& name) |
7336 | 457 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
458 return "_G" + name; |
7336 | 459 } |
460 | |
7872 | 461 std::string |
462 octave_dynamic_loader::mex_mangler (const std::string&) | |
463 { | |
464 return "mexFunction"; | |
465 } | |
466 | |
467 std::string | |
468 octave_dynamic_loader::mex_uscore_mangler (const std::string&) | |
469 { | |
470 return "_mexFunction"; | |
471 } | |
472 | |
473 std::string | |
474 octave_dynamic_loader::mex_f77_mangler (const std::string&) | |
475 { | |
476 return STRINGIFY (F77_FUNC (mexfunction, MEXFUNCTION)); | |
477 } |