Mercurial > octave
annotate liboctave/util/oct-shlib.cc @ 23696:08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
* octave-gui.cc, dynamic-ld.h, ft-text-renderer.cc, gl-render.cc,
gl-render.h, gl2ps-print.cc, input.cc, input.h, interpreter.cc,
load-path.cc, load-path.h, oct-stream.cc, sighandlers.cc, symtab.cc,
symtab.h, __ode15__.cc, gzip.cc, octave.cc, lex.ll, oct-parse.in.yy,
parse.h, pt-arg-list.cc, pt-arg-list.h, pt-array-list.h,
pt-classdef.h, pt-decl.h, pt-eval.cc, pt-eval.h, pt-exp.h,
pt-fcn-handle.cc, pt-idx.cc, pt-misc.h, pt-select.h, pt-stmt.h,
pt-tm-const.cc, pt-tm-const.h, pt.cc, aepbalance.cc, chol.cc,
gepbalance.cc, gsvd.cc, hess.cc, lo-mappers.h, lo-specfun.cc, lu.cc,
qr.cc, qrp.cc, schur.cc, sparse-chol.cc, sparse-lu.cc, sparse-qr.cc,
svd.cc, child-list.cc, dir-ops.cc, file-ops.cc, file-stat.cc,
file-stat.h, lo-sysdep.cc, oct-env.cc, oct-syscalls.cc, cmd-edit.cc,
cmd-hist.cc, oct-glob.cc, oct-locbuf.cc, oct-mutex.cc, oct-mutex.h,
oct-shlib.cc, oct-shlib.h, pathsearch.cc, url-transfer.cc,
url-transfer.h: Remove octave:: namespace tag from symbols used
inside octave namespace.
* oct-conf-post.in.h (OCTAVE_USE_DEPRECATED_FUNCTIONS): Don't define.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 26 Jun 2017 09:05:37 -0400 |
parents | b075b1629c26 |
children | 980f39c3ab90 |
rev | line source |
---|---|
3326 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1999-2017 John W. Eaton |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague |
3326 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
11 (at your option) any later version. |
3326 | 12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
16 GNU General Public License for more details. |
3326 | 17 |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
3326 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21661
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21236
diff
changeset
|
25 # include "config.h" |
3326 | 26 #endif |
27 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
28 #include <map> |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
29 |
4110 | 30 #if defined (HAVE_SHL_LOAD_API) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
31 # include <cerrno> |
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
32 # include <cstring> |
3326 | 33 #endif |
34 | |
4162 | 35 #if defined (HAVE_DYLD_API) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
36 # include <mach-o/dyld.h> |
4162 | 37 #endif |
38 | |
3326 | 39 extern "C" |
40 { | |
4110 | 41 #if defined (HAVE_DLOPEN_API) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
42 # if defined (HAVE_DLFCN_H) |
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
43 # include <dlfcn.h> |
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
44 # else |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
45 extern void * dlopen (const char *, int); |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
46 extern const char * dlerror (void); |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
47 extern void * dlsym (void *, const char *); |
3326 | 48 extern int dlclose (void *); |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
49 # endif |
4110 | 50 #elif defined (HAVE_SHL_LOAD_API) |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
51 # include <dl.h> |
5451 | 52 #elif defined (HAVE_LOADLIBRARY_API) |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
53 # define WIN32_LEAN_AND_MEAN 1 |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
54 # include <windows.h> |
3326 | 55 #endif |
56 } | |
57 | |
22146
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
58 #include "file-ops.h" |
3326 | 59 #include "file-stat.h" |
60 #include "lo-error.h" | |
61 #include "oct-shlib.h" | |
62 #include "str-vec.h" | |
63 | |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
64 namespace octave |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
65 { |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
66 dynamic_library::dynlib_rep::dynlib_rep (const std::string& f) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
67 : count (1), file (f), tm_loaded (), fcn_names () |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
68 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
69 instances[f] = this; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
70 |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
71 if (is_out_of_date ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
72 (*current_liboctave_warning_with_id_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
73 ("Octave:warn-future-time-stamp", |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
74 "timestamp on file %s is in the future", file.c_str ()); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
75 } |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
76 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
77 bool |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
78 dynamic_library::dynlib_rep::is_out_of_date (void) const |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
79 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23554
diff
changeset
|
80 sys::file_stat fs (file); |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
81 return (fs && fs.is_newer (tm_loaded)); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
82 } |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
83 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
84 void |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
85 dynamic_library::dynlib_rep::fake_reload (void) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
86 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
87 // We can't actually reload the library, but we'll pretend we did. |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23554
diff
changeset
|
88 sys::file_stat fs (file); |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
89 if (fs && fs.is_newer (tm_loaded)) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
90 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
91 tm_loaded = fs.mtime (); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
92 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
93 (*current_liboctave_warning_with_id_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
94 ("Octave:library-reload", |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
95 "library %s not reloaded due to existing references", file.c_str ()); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
96 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
97 } |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
98 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
99 dynamic_library::dynlib_rep * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
100 dynamic_library::dynlib_rep::get_instance (const std::string& f, bool fake) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
101 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
102 dynlib_rep *retval = nullptr; |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
103 std::map<std::string, dynlib_rep *>::iterator p = instances.find (f); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
104 if (p != instances.end ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
105 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
106 retval = p->second; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
107 retval->count++; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
108 if (fake) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
109 retval->fake_reload (); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
110 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
111 else |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
112 retval = new_instance (f); |
3326 | 113 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
114 return retval; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
115 } |
3326 | 116 |
23554
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
117 std::list<std::string> |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
118 dynamic_library::dynlib_rep::function_names (void) const |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
119 { |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
120 std::list<std::string> retval; |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
121 |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
122 for (const auto& p : fcn_names) |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
123 retval.push_back (p.first); |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
124 |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
125 return retval; |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
126 } |
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
127 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
128 void |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
129 dynamic_library::dynlib_rep::add_fcn_name (const std::string& name) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
130 { |
21862
5c67b16acc4a
maint: Use C++ 'auto' keyword in some instances in liboctave.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
131 auto p = fcn_names.find (name); |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
132 |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
133 if (p == fcn_names.end ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
134 fcn_names[name] = 1; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
135 else |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
136 ++(p->second); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
137 } |
3326 | 138 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
139 bool |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
140 dynamic_library::dynlib_rep::remove_fcn_name (const std::string& fcn_name) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
141 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
142 bool retval = false; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
143 |
21862
5c67b16acc4a
maint: Use C++ 'auto' keyword in some instances in liboctave.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
144 auto p = fcn_names.find (fcn_name); |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
145 |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
146 if (p != fcn_names.end () && --(p->second) == 0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
147 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
148 fcn_names.erase (fcn_name); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
149 retval = true; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
150 } |
3326 | 151 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
152 return retval; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
153 } |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
154 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
155 std::map<std::string, dynamic_library::dynlib_rep *> |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
156 dynamic_library::dynlib_rep::instances; |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
157 |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
158 dynamic_library::dynlib_rep dynamic_library::nil_rep; |
3326 | 159 |
4110 | 160 #if defined (HAVE_DLOPEN_API) |
3326 | 161 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
162 class |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
163 octave_dlopen_shlib : public dynamic_library::dynlib_rep |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
164 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
165 public: |
3326 | 166 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
167 octave_dlopen_shlib (const std::string& f); |
3326 | 168 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
169 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
170 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
171 octave_dlopen_shlib (const octave_dlopen_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
172 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
173 octave_dlopen_shlib& operator = (const octave_dlopen_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
174 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
175 ~octave_dlopen_shlib (void); |
3326 | 176 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
177 void * search (const std::string& name, |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
178 dynamic_library::name_mangler mangler = 0); |
3326 | 179 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
180 // FIXME: this is possibly redundant because failure to open a library will |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
181 // normally throw an exception, avoiding the construction of an invalid |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
182 // library. Leave it here for possible future use. |
3326 | 183 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
184 bool is_open (void) const { return (library != 0); } |
3326 | 185 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
186 private: |
3326 | 187 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
188 void *library; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
189 }; |
3326 | 190 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
191 octave_dlopen_shlib::octave_dlopen_shlib (const std::string& f) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
192 : dynamic_library::dynlib_rep (f), library (0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
193 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
194 int flags = 0; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
195 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
196 // Use RTLD_NOW to resolve all symbols before dlopen returns. |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
197 // By using this option, dlopen will detect errors and Octave |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
198 // won't exit if there are unresolved symbols in the file we are |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
199 // loading, and we may even get a useful diagnostic. |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
200 # if defined (RTLD_NOW) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
201 flags |= RTLD_NOW; |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
202 # endif |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
203 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
204 // Use RTLD_GLOBAL to export symbols from loaded objects so they are |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
205 // available to other subsequently loaded libraries. |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
206 # if defined (RTLD_GLOBAL) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
207 flags |= RTLD_GLOBAL; |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
208 # endif |
20493
3f01c585f54e
oct-shlib.cc: Use RTLD_GLOBAL option for dlopen
Mike Miller <mtmiller@octave.org>
parents:
19697
diff
changeset
|
209 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
210 library = dlopen (file.c_str (), flags); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
211 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
212 if (! library) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
213 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
214 const char *msg = dlerror (); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
215 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
216 if (msg) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
217 (*current_liboctave_error_handler) ("%s: failed to load: %s", |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
218 file.c_str (), msg); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
219 else |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
220 (*current_liboctave_error_handler) ("%s: failed to load", |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
221 file.c_str ()); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
222 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
223 } |
3326 | 224 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
225 octave_dlopen_shlib::~octave_dlopen_shlib (void) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
226 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
227 if (library) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
228 dlclose (library); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
229 } |
3326 | 230 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
231 void * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
232 octave_dlopen_shlib::search (const std::string& name, |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
233 dynamic_library::name_mangler mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
234 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
235 void *function = nullptr; |
3326 | 236 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
237 if (! is_open ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
238 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
239 ("shared library %s is not open", file.c_str ()); |
3326 | 240 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
241 std::string sym_name = name; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
242 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
243 if (mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
244 sym_name = mangler (name); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
245 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
246 function = dlsym (library, sym_name.c_str ()); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
247 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
248 return function; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
249 } |
3326 | 250 |
4110 | 251 #elif defined (HAVE_SHL_LOAD_API) |
3326 | 252 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
253 class |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
254 octave_shl_load_shlib : public dynamic_library::dynlib_rep |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
255 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
256 public: |
3326 | 257 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
258 octave_shl_load_shlib (const std::string& f); |
3326 | 259 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
260 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
261 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
262 octave_shl_load_shlib (const octave_shl_load_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
263 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
264 octave_shl_load_shlib& operator = (const octave_shl_load_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
265 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
266 ~octave_shl_load_shlib (void); |
3326 | 267 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
268 void * search (const std::string& name, |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
269 dynamic_library::name_mangler mangler = 0); |
3326 | 270 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
271 bool is_open (void) const { return (library != 0); } |
3326 | 272 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
273 private: |
3326 | 274 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
275 shl_t library; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
276 }; |
3326 | 277 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
278 octave_shl_load_shlib::octave_shl_load_shlib (const std::string& f) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
279 : dynamic_library::dynlib_rep (f), library (0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
280 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
281 file = f; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
282 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
283 library = shl_load (file.c_str (), BIND_IMMEDIATE, 0L); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
284 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
285 if (! library) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
286 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
287 using namespace std; // FIXME: Why have this line? |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21876
diff
changeset
|
288 (*current_liboctave_error_handler) ("%s", std::strerror (errno)); |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
289 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
290 } |
3326 | 291 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
292 octave_shl_load_shlib::~octave_shl_load_shlib (void) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
293 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
294 if (library) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
295 shl_unload (library); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
296 } |
3326 | 297 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
298 void * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
299 octave_shl_load_shlib::search (const std::string& name, |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
300 dynamic_library::name_mangler mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
301 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
302 void *function = nullptr; |
3326 | 303 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
304 if (! is_open ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
305 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
306 ("shared library %s is not open", file.c_str ()); |
3326 | 307 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
308 std::string sym_name = name; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
309 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
310 if (mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
311 sym_name = mangler (name); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
312 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
313 int status = shl_findsym (&library, sym_name.c_str (), |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
314 TYPE_UNDEFINED, &function); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
315 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
316 return function; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
317 } |
3326 | 318 |
4110 | 319 #elif defined (HAVE_LOADLIBRARY_API) |
320 | |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
321 class |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
322 octave_w32_shlib: public dynamic_library::dynlib_rep |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
323 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
324 public: |
4110 | 325 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
326 octave_w32_shlib (const std::string& f); |
4110 | 327 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
328 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
329 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
330 octave_w32_shlib (const octave_w32_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
331 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
332 octave_w32_shlib& operator = (const octave_w32_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
333 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
334 ~octave_w32_shlib (void); |
4110 | 335 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
336 void * search (const std::string& name, |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
337 dynamic_library::name_mangler mangler = 0); |
4110 | 338 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
339 bool is_open (void) const { return (handle != 0); } |
4110 | 340 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
341 private: |
4110 | 342 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
343 HINSTANCE handle; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
344 }; |
4110 | 345 |
22146
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
346 static void |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
347 set_dll_directory (const std::string& dir = "") |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
348 { |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
349 SetDllDirectory (dir.empty () ? 0 : dir.c_str ()); |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
350 } |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
351 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
352 octave_w32_shlib::octave_w32_shlib (const std::string& f) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
353 : dynamic_library::dynlib_rep (f), handle (0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
354 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23554
diff
changeset
|
355 std::string dir = sys::file_ops::dirname (f); |
22146
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
356 |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
357 set_dll_directory (dir); |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
358 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
359 handle = LoadLibrary (file.c_str ()); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
360 |
22146
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
361 set_dll_directory (); |
22157
c5842206aaea
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22146
diff
changeset
|
362 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
363 if (! handle) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
364 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
365 DWORD lastError = GetLastError (); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
366 const char *msg; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
367 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
368 switch (lastError) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
369 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
370 case ERROR_MOD_NOT_FOUND: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
371 case ERROR_DLL_NOT_FOUND: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
372 msg = "could not find library or dependencies"; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
373 break; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
374 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
375 case ERROR_INVALID_DLL: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
376 msg = "library or its dependencies are damaged"; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
377 break; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
378 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
379 case ERROR_DLL_INIT_FAILED: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
380 msg = "library initialization routine failed"; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
381 break; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
382 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
383 default: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
384 msg = "library open failed"; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
385 } |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
386 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
387 (*current_liboctave_error_handler) ("%s: %s", msg, file.c_str ()); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
388 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
389 } |
4110 | 390 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
391 octave_w32_shlib::~octave_w32_shlib (void) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
392 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
393 if (handle) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
394 FreeLibrary (handle); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
395 } |
4110 | 396 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
397 void * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
398 octave_w32_shlib::search (const std::string& name, |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
399 dynamic_library::name_mangler mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
400 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
401 void *function = nullptr; |
4110 | 402 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
403 if (! is_open ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
404 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
405 ("shared library %s is not open", file.c_str ()); |
4110 | 406 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
407 std::string sym_name = name; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
408 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
409 if (mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
410 sym_name = mangler (name); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
411 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
412 function = reinterpret_cast<void *> (GetProcAddress (handle, |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
413 sym_name.c_str ())); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
414 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
415 return function; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
416 } |
4110 | 417 |
4162 | 418 #elif defined (HAVE_DYLD_API) |
419 | |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
420 class |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
421 octave_dyld_shlib : public dynamic_library::dynlib_rep |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
422 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
423 public: |
4162 | 424 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
425 octave_dyld_shlib (void); |
4162 | 426 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
427 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
428 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
429 octave_dyld_shlib (const octave_dyld_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
430 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
431 octave_dyld_shlib& operator = (const octave_dyld_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
432 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
433 ~octave_dyld_shlib (void); |
4162 | 434 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
435 void open (const std::string& f); |
4162 | 436 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
437 void * search (const std::string& name, |
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
438 dynamic_library::name_mangler mangler = 0); |
4162 | 439 |
23554
b075b1629c26
don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
440 void close (void); |
4162 | 441 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
442 bool is_open (void) const {return (handle != 0); } |
4162 | 443 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
444 private: |
4162 | 445 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
446 NSObjectFileImage img; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
447 NSModule handle; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
448 }; |
4162 | 449 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
450 octave_dyld_shlib::octave_dyld_shlib (const std::string& f) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
451 : dynamic_library::dynlib_rep (f), handle (0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
452 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
453 int returnCode = NSCreateObjectFileImageFromFile (file.c_str (), &img); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
454 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
455 if (NSObjectFileImageSuccess != returnCode) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
456 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
457 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
458 ("got NSObjectFileImageReturnCode %d", returnCode); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
459 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
460 // FIXME: should use NSLinkEditError () to get |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
461 // more info on what went wrong. |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
462 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
463 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
464 handle = NSLinkModule (img, file.c_str (), |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
465 (NSLINKMODULE_OPTION_RETURN_ON_ERROR |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
466 | NSLINKMODULE_OPTION_PRIVATE)); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
467 if (! handle) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
468 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
469 NSLinkEditErrors ler; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
470 int lerno; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
471 const char *file2; |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
472 const char *errstr = nullptr; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
473 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
474 NSLinkEditError (&ler, &lerno, &file2, &errstr); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
475 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
476 if (! errstr) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
477 errstr = "unspecified error"; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
478 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
479 (*current_liboctave_error_handler) ("%s: %s", file.c_str (), errstr); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
480 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
481 } |
4162 | 482 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
483 octave_dyld_shlib::~octave_dyld_shlib (void) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
484 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
485 if (handle) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
486 NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); |
4162 | 487 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
488 NSDestroyObjectFileImage (img); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
489 } |
4162 | 490 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
491 void * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
492 octave_dyld_shlib::search (const std::string& name, |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
493 dynamic_library::name_mangler mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
494 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
495 void *function = nullptr; |
4162 | 496 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
497 if (! is_open ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
498 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
499 ("bundle %s is not open", file.c_str ()); |
4162 | 500 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
501 std::string sym_name = name; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
502 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
503 if (mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
504 sym_name = mangler (name); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
505 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
506 NSSymbol symbol = NSLookupSymbolInModule (handle, sym_name.c_str ()); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
507 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
508 if (symbol) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
509 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
510 function = NSAddressOfSymbol (symbol); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
511 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
512 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
513 return function; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
514 } |
4162 | 515 |
3326 | 516 #endif |
517 | |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
518 dynamic_library::dynlib_rep * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
519 dynamic_library::dynlib_rep::new_instance (const std::string& f) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
520 { |
4110 | 521 #if defined (HAVE_DLOPEN_API) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
522 return new octave_dlopen_shlib (f); |
4110 | 523 #elif defined (HAVE_SHL_LOAD_API) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
524 return new octave_shl_load_shlib (f); |
4110 | 525 #elif defined (HAVE_LOADLIBRARY_API) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
526 return new octave_w32_shlib (f); |
4162 | 527 #elif defined (HAVE_DYLD_API) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
528 return new octave_dyld_shlib (f); |
3326 | 529 #else |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
530 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
531 ("support for dynamically loaded libraries was unavailable or disabled when liboctave was built"); |
3326 | 532 #endif |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
533 } |
3326 | 534 } |