Mercurial > octave
annotate libinterp/corefcn/dynamic-ld.cc @ 20428:7ac907da9fba
Use error() rather than ::error() unless explicitly required.
* resource-manager.cc (instance_ok), shortcut-manager.cc (instance_ok),
daspk.cc (DASPK_ABORT, DASPK_ABORT2), dasrt.cc (DASRT_ABORT, DASRT_ABORT2),
dassl.cc (DASSL_ABORT, DASSL_ABORT2), debug.cc (instance_ok),
display.cc (instance_ok), dynamic-ld.cc (octave_shlib_list::instance_ok,
octave_dynamic_loader::instance_ok, do_load_oct, do_load_mex), file-io.cc
(fopen_mode_to_ios_mode, do_stream_open, Ffprintf, Fsprintf, Fscanf, Ffscanf,
get_sscanf_data, Fsscanf, do_fread, do_fwrite, Fpopen, Ftempname, convert,
Fumask), graphics.in.h (graphics_toolkit::instance_ok,
gh_manager::instance_ok), load-path.cc (instance_ok),
ls-oct-ascii.cc (save_three_d), lsode.cc (LSODE_ABORT, LSODE_ABORT2),
oct-errno.in.cc (instance_ok), octave-link.cc (connect_link),
pager.cc (octave_pager_stream::instance_ok, octave_diary_stream::instance_ok),
quad.cc (QUAD_ABORT, QUAD_ABORT2),
sighandlers.cc (w32_interrupt_manager::instance_ok,
octave_child_list::instance_ok), symtab.cc (do_update_nest),
symtab.h (instance_ok), syscalls.cc (convert), toplev.h (instance_ok),
txt-eng-ft.cc (instance_ok, set_mode), urlwrite.cc (instance_ok),
__init_fltk__.cc (instance_ok), ov-builtin.cc (do_multi_index_op),
ov-classdef.cc (class_fevalStatic, make_class, octave_classdef::subsasgn,
do_multi_index_op, cdef_object_array::subsref, cdef_object_array::subsasgn,
install_meth, meta_subsref, run_constructor, make_meta_class, get_value,
set_value, check_method), ov-classdef.h (meta_subsref, instance_ok),
ov-fcn-handle.cc (octave_fcn_handle), ov-mex-fcn.cc (do_multi_index_op),
ov-range.h (octave_range), ov-typeinfo.cc (instance_ok),
ov-usr-fcn.cc (subsref, do_multi_index_op), pt-arg-list.cc (Fend,
convert_to_const_vector), pt-cell.cc (rvalue1), pt-colon.cc (append, rvalue1),
pt-eval.cc (visit_simple_for_command, visit_switch_command),
pt-exp.cc (is_logically_true, rvalue), pt-id.cc (eval_undefined_error),
pt-id.h (workspace_error), pt-mat.cc (get_concat_class):
Use error() rather than ::error().
author | Rik <rik@octave.org> |
---|---|
date | Thu, 06 Aug 2015 08:09:01 -0700 |
parents | 4197fc428c7d |
children | f90c8372b7ba |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 1993-2015 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 { | |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
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 { |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
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) |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
298 error ("failed to install .oct file function '%s'", |
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
299 fcn_name.c_str ()); |
10315
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 |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
303 error ("%s is not a valid shared library", file_name.c_str ()); |
3325 | 304 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
305 |
3325 | 306 return retval; |
307 } | |
308 | |
7336 | 309 octave_function * |
5864 | 310 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
|
311 const std::string& file_name, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
312 bool /*relative*/) |
5864 | 313 { |
7336 | 314 octave_function *retval = 0; |
5864 | 315 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
316 unwind_protect frame; |
5864 | 317 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9958
diff
changeset
|
318 frame.protect_var (octave_dynamic_loader::doing_load); |
5864 | 319 |
320 doing_load = true; | |
321 | |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
322 octave_shlib mex_file = octave_shlib_list::find_file (file_name); |
6323 | 323 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
324 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
|
325 clear (mex_file); |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
326 |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
327 if (! mex_file) |
6323 | 328 { |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
329 mex_file.open (file_name); |
6323 | 330 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
331 if (! error_state && mex_file) |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
332 octave_shlib_list::append (mex_file); |
6323 | 333 } |
5864 | 334 |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
335 if (! error_state) |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
336 { |
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
337 if (mex_file) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
338 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
339 void *function = 0; |
5864 | 340 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
341 bool have_fmex = false; |
5864 | 342 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
343 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
|
344 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
345 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
346 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
347 // 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
|
348 // automatically at run time or configure time? |
5864 | 349 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
350 function = mex_file.search (fcn_name, mex_uscore_mangler); |
5864 | 351 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
352 if (! function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
353 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
354 function = mex_file.search (fcn_name, mex_f77_mangler); |
6221 | 355 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
356 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
357 have_fmex = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
358 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
359 } |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
360 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
361 if (function) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
362 retval = new octave_mex_function (function, have_fmex, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
363 mex_file, fcn_name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
364 else |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
365 error ("failed to install .mex file function '%s'", |
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
366 fcn_name.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
367 } |
8832
9dddbad47122
automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents:
7996
diff
changeset
|
368 else |
20428
7ac907da9fba
Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
369 error ("%s is not a valid shared library", file_name.c_str ()); |
5864 | 370 } |
371 | |
372 return retval; | |
373 } | |
374 | |
375 bool | |
7872 | 376 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
|
377 octave_shlib& shl) |
3325 | 378 { |
379 bool retval = false; | |
380 | |
381 // We don't need to do anything if this is called because we are in | |
382 // the process of reloading a .oct file that has changed. | |
383 | |
384 if (! doing_load) | |
385 { | |
386 retval = shl.remove (fcn_name); | |
387 | |
388 if (shl.number_of_functions_loaded () == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10287
diff
changeset
|
389 octave_shlib_list::remove (shl); |
3325 | 390 } |
391 | |
392 return retval; | |
393 } | |
394 | |
7872 | 395 bool |
396 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
|
397 octave_shlib& shl) |
7872 | 398 { |
399 bool retval = false; | |
400 | |
401 // We don't need to do anything if this is called because we are in | |
402 // the process of reloading a .oct file that has changed. | |
403 | |
404 if (! doing_load) | |
405 { | |
406 retval = shl.remove (fcn_name); | |
407 | |
408 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
|
409 octave_shlib_list::remove (shl); |
7872 | 410 } |
411 | |
412 return retval; | |
413 } | |
414 | |
7336 | 415 octave_function * |
5864 | 416 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
|
417 const std::string& file_name, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
418 bool relative) |
3325 | 419 { |
6323 | 420 return (instance_ok ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
421 ? instance->do_load_oct (fcn_name, file_name, relative) : 0; |
5864 | 422 } |
423 | |
7336 | 424 octave_function * |
5864 | 425 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
|
426 const std::string& file_name, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
427 bool relative) |
5864 | 428 { |
6323 | 429 return (instance_ok ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
430 ? instance->do_load_mex (fcn_name, file_name, relative) : 0; |
3325 | 431 } |
432 | |
433 bool | |
7872 | 434 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
|
435 octave_shlib& shl) |
3325 | 436 { |
7872 | 437 return (instance_ok ()) ? instance->do_remove_oct (fcn_name, shl) : false; |
438 } | |
439 | |
440 bool | |
441 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
|
442 octave_shlib& shl) |
7872 | 443 { |
444 return (instance_ok ()) ? instance->do_remove_mex (fcn_name, shl) : false; | |
2893 | 445 } |
707 | 446 |
3536 | 447 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
448 octave_dynamic_loader::name_mangler (const std::string& name) |
2894 | 449 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
450 return "G" + name; |
2894 | 451 } |
707 | 452 |
7336 | 453 std::string |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
454 octave_dynamic_loader::name_uscore_mangler (const std::string& name) |
7336 | 455 { |
7996
6a7db240b3a3
configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
456 return "_G" + name; |
7336 | 457 } |
458 | |
7872 | 459 std::string |
460 octave_dynamic_loader::mex_mangler (const std::string&) | |
461 { | |
462 return "mexFunction"; | |
463 } | |
464 | |
465 std::string | |
466 octave_dynamic_loader::mex_uscore_mangler (const std::string&) | |
467 { | |
468 return "_mexFunction"; | |
469 } | |
470 | |
471 std::string | |
472 octave_dynamic_loader::mex_f77_mangler (const std::string&) | |
473 { | |
474 return STRINGIFY (F77_FUNC (mexfunction, MEXFUNCTION)); | |
475 } |