Mercurial > octave
annotate liboctave/util/oct-shlib.cc @ 23457:21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
* FigureWindow.h, Logger.cc, Menu.cc, MouseModeActionGroup.h, Object.h,
ObjectFactory.cc, ObjectProxy.h, color-picker.h, documentation-dock-widget.h,
files-dock-widget.h, find-files-dialog.h, history-dock-widget.h,
file-editor-tab.cc, file-editor.cc, file-editor.h, find-dialog.h,
main-window.cc, main-window.h, octave-dock-widget.h, parser.cc, parser.h,
webinfo.h, resource-manager.cc, shortcut-manager.cc, shortcut-manager.h,
terminal-dock-widget.h, welcome-wizard.cc, welcome-wizard.h, workspace-model.h,
workspace-view.h, __magick_read__.cc, call-stack.cc, call-stack.h, cdisplay.c,
display.cc, dlmread.cc, dynamic-ld.cc, ft-text-renderer.cc, gl2ps-print.cc,
graphics.cc, graphics.in.h, input.h, interpreter.cc, interpreter.h, ls-hdf5.cc,
mex.cc, mxarray.in.h, oct-errno.in.cc, oct-fstrm.cc, oct-iostrm.h,
oct-procbuf.cc, oct-stdstrm.h, oct-stream.cc, oct-stream.h, octave-link.cc,
pager.cc, pr-output.cc, profiler.h, qz.cc, sighandlers.cc, strfns.cc,
symtab.cc, symtab.h, typecast.cc, urlwrite.cc, variables.cc, __eigs__.cc,
__init_fltk__.cc, __ode15__.cc, colamd.cc, ov-base-int.cc, ov-base.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-builtin.cc, ov-class.cc, ov-classdef.cc,
ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc,
ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-java.cc, ov-java.h, ov-lazy-idx.cc,
ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc,
ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.h, octave.cc, octave.h, bp-table.cc,
jit-ir.cc, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, lex.h, pt-arg-list.cc,
pt-arg-list.h, pt-array-list.h, pt-cell.h, pt-classdef.h, pt-colon.cc,
pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.h, pt-idx.h, pt-jit.cc, pt-jit.h,
pt-loop.h, pt-mat.h, pt-select.h, pt.h, CSparse.cc, dSparse.cc, DASPK.cc,
DASRT.cc, DASSL.cc, oct-fftw.cc, oct-rand.cc, oct-spparms.cc, child-list.cc,
file-ops.cc, mach-info.cc, oct-env.cc, oct-time.cc, cmd-edit.cc, cmd-hist.cc,
oct-locbuf.cc, oct-shlib.cc, pathsearch.cc, singleton-cleanup.cc,
unwind-prot.h, url-transfer.cc:
Use C++11 nullptr rather than 0 or NULL when possible.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 28 Apr 2017 13:19:12 -0700 |
parents | cd4e1ee28716 |
children | b075b1629c26 |
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 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
80 octave::sys::file_stat fs (file); |
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. |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
88 octave::sys::file_stat fs (file); |
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 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
117 void |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
118 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
|
119 { |
21862
5c67b16acc4a
maint: Use C++ 'auto' keyword in some instances in liboctave.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
120 auto p = fcn_names.find (name); |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
121 |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
122 if (p == fcn_names.end ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
123 fcn_names[name] = 1; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
124 else |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
125 ++(p->second); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
126 } |
3326 | 127 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
128 bool |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
129 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
|
130 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
131 bool retval = false; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
132 |
21862
5c67b16acc4a
maint: Use C++ 'auto' keyword in some instances in liboctave.
Rik <rik@octave.org>
parents:
21751
diff
changeset
|
133 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
|
134 |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
135 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
|
136 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
137 fcn_names.erase (fcn_name); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
138 retval = true; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
139 } |
3326 | 140 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
141 return retval; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
142 } |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
143 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
144 void |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
145 dynamic_library::dynlib_rep::do_close_hook (dynamic_library::close_hook cl_hook) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
146 { |
22873
2830a770405b
maint: Fix up more for loops with range operators in liboctave.
Rik <rik@octave.org>
parents:
22869
diff
changeset
|
147 for (auto& fcn_sz : fcn_names) |
2830a770405b
maint: Fix up more for loops with range operators in liboctave.
Rik <rik@octave.org>
parents:
22869
diff
changeset
|
148 cl_hook (fcn_sz.first); |
3326 | 149 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
150 fcn_names.clear (); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
151 } |
3326 | 152 |
22402
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
153 std::map<std::string, dynamic_library::dynlib_rep *> |
4caa7b28d183
maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
154 dynamic_library::dynlib_rep::instances; |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
155 |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
156 dynamic_library::dynlib_rep dynamic_library::nil_rep; |
3326 | 157 |
4110 | 158 #if defined (HAVE_DLOPEN_API) |
3326 | 159 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
160 class |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
161 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
|
162 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
163 public: |
3326 | 164 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
165 octave_dlopen_shlib (const std::string& f); |
3326 | 166 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
167 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
168 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
169 octave_dlopen_shlib (const octave_dlopen_shlib&) = delete; |
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& operator = (const octave_dlopen_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
172 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
173 ~octave_dlopen_shlib (void); |
3326 | 174 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
175 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
|
176 dynamic_library::name_mangler mangler = 0); |
3326 | 177 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
178 // 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
|
179 // 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
|
180 // library. Leave it here for possible future use. |
3326 | 181 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
182 bool is_open (void) const { return (library != 0); } |
3326 | 183 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
184 private: |
3326 | 185 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
186 void *library; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
187 }; |
3326 | 188 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
189 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
|
190 : dynamic_library::dynlib_rep (f), library (0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
191 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
192 int flags = 0; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
193 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
194 // 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
|
195 // 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
|
196 // 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
|
197 // 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
|
198 # if defined (RTLD_NOW) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
199 flags |= RTLD_NOW; |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
200 # endif |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
201 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
202 // 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
|
203 // 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
|
204 # if defined (RTLD_GLOBAL) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
205 flags |= RTLD_GLOBAL; |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
206 # endif |
20493
3f01c585f54e
oct-shlib.cc: Use RTLD_GLOBAL option for dlopen
Mike Miller <mtmiller@octave.org>
parents:
19697
diff
changeset
|
207 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
208 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
|
209 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
210 if (! library) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
211 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
212 const char *msg = dlerror (); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
213 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
214 if (msg) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
215 (*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
|
216 file.c_str (), msg); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
217 else |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
218 (*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
|
219 file.c_str ()); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
220 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
221 } |
3326 | 222 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
223 octave_dlopen_shlib::~octave_dlopen_shlib (void) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
224 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
225 if (library) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
226 dlclose (library); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
227 } |
3326 | 228 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
229 void * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
230 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
|
231 dynamic_library::name_mangler mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
232 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
233 void *function = nullptr; |
3326 | 234 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
235 if (! is_open ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
236 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
237 ("shared library %s is not open", file.c_str ()); |
3326 | 238 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
239 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
|
240 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
241 if (mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
242 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
|
243 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
244 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
|
245 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
246 return function; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
247 } |
3326 | 248 |
4110 | 249 #elif defined (HAVE_SHL_LOAD_API) |
3326 | 250 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
251 class |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
252 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
|
253 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
254 public: |
3326 | 255 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
256 octave_shl_load_shlib (const std::string& f); |
3326 | 257 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
258 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
259 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
260 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
|
261 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
262 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
|
263 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
264 ~octave_shl_load_shlib (void); |
3326 | 265 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
266 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
|
267 dynamic_library::name_mangler mangler = 0); |
3326 | 268 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
269 bool is_open (void) const { return (library != 0); } |
3326 | 270 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
271 private: |
3326 | 272 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
273 shl_t library; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
274 }; |
3326 | 275 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
276 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
|
277 : dynamic_library::dynlib_rep (f), library (0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
278 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
279 file = f; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
280 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
281 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
|
282 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
283 if (! library) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
284 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
285 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
|
286 (*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
|
287 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
288 } |
3326 | 289 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
290 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
|
291 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
292 if (library) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
293 shl_unload (library); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
294 } |
3326 | 295 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
296 void * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
297 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
|
298 dynamic_library::name_mangler mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
299 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
300 void *function = nullptr; |
3326 | 301 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
302 if (! is_open ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
303 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
304 ("shared library %s is not open", file.c_str ()); |
3326 | 305 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
306 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
|
307 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
308 if (mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
309 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
|
310 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
311 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
|
312 TYPE_UNDEFINED, &function); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
313 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
314 return function; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
315 } |
3326 | 316 |
4110 | 317 #elif defined (HAVE_LOADLIBRARY_API) |
318 | |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
319 class |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
320 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
|
321 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
322 public: |
4110 | 323 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
324 octave_w32_shlib (const std::string& f); |
4110 | 325 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
326 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
327 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
328 octave_w32_shlib (const octave_w32_shlib&) = delete; |
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& operator = (const octave_w32_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
331 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
332 ~octave_w32_shlib (void); |
4110 | 333 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
334 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
|
335 dynamic_library::name_mangler mangler = 0); |
4110 | 336 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
337 bool is_open (void) const { return (handle != 0); } |
4110 | 338 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
339 private: |
4110 | 340 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
341 HINSTANCE handle; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
342 }; |
4110 | 343 |
22146
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
344 static void |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
345 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
|
346 { |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
347 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
|
348 } |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
349 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
350 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
|
351 : dynamic_library::dynlib_rep (f), handle (0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
352 { |
22146
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
353 std::string dir = octave::sys::file_ops::dirname (f); |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
354 |
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
355 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
|
356 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
357 handle = LoadLibrary (file.c_str ()); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
358 |
22146
ef91e43f162a
set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
359 set_dll_directory (); |
22157
c5842206aaea
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
22146
diff
changeset
|
360 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
361 if (! handle) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
362 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
363 DWORD lastError = GetLastError (); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
364 const char *msg; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
365 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
366 switch (lastError) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
367 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
368 case ERROR_MOD_NOT_FOUND: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
369 case ERROR_DLL_NOT_FOUND: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
370 msg = "could not find library or dependencies"; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
371 break; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
372 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
373 case ERROR_INVALID_DLL: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
374 msg = "library or its dependencies are damaged"; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
375 break; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
376 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
377 case ERROR_DLL_INIT_FAILED: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
378 msg = "library initialization routine failed"; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
379 break; |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
380 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
381 default: |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
382 msg = "library open failed"; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
383 } |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
384 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
385 (*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
|
386 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
387 } |
4110 | 388 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
389 octave_w32_shlib::~octave_w32_shlib (void) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
390 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
391 if (handle) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
392 FreeLibrary (handle); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
393 } |
4110 | 394 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
395 void * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
396 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
|
397 dynamic_library::name_mangler mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
398 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
399 void *function = nullptr; |
4110 | 400 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
401 if (! is_open ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
402 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
403 ("shared library %s is not open", file.c_str ()); |
4110 | 404 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
405 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
|
406 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
407 if (mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
408 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
|
409 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
410 function = reinterpret_cast<void *> (GetProcAddress (handle, |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
411 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
|
412 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
413 return function; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
414 } |
4110 | 415 |
4162 | 416 #elif defined (HAVE_DYLD_API) |
417 | |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
418 class |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
419 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
|
420 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
421 public: |
4162 | 422 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
423 octave_dyld_shlib (void); |
4162 | 424 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
425 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
426 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
427 octave_dyld_shlib (const octave_dyld_shlib&) = delete; |
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& operator = (const octave_dyld_shlib&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
430 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
431 ~octave_dyld_shlib (void); |
4162 | 432 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
433 void open (const std::string& f); |
4162 | 434 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
435 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
|
436 dynamic_library::name_mangler mangler = 0); |
4162 | 437 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
438 void close (dynamic_library::close_hook cl_hook = 0); |
4162 | 439 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
440 bool is_open (void) const {return (handle != 0); } |
4162 | 441 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
442 private: |
4162 | 443 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
444 NSObjectFileImage img; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
445 NSModule handle; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
446 }; |
4162 | 447 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
448 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
|
449 : dynamic_library::dynlib_rep (f), handle (0) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
450 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
451 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
|
452 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
453 if (NSObjectFileImageSuccess != returnCode) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
454 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
455 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
456 ("got NSObjectFileImageReturnCode %d", returnCode); |
9958
80432f0ee895
improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents:
9493
diff
changeset
|
457 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
458 // FIXME: should use NSLinkEditError () to get |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
459 // more info on what went wrong. |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
460 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
461 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
462 handle = NSLinkModule (img, file.c_str (), |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
463 (NSLINKMODULE_OPTION_RETURN_ON_ERROR |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
464 | NSLINKMODULE_OPTION_PRIVATE)); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
465 if (! handle) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
466 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
467 NSLinkEditErrors ler; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
468 int lerno; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
469 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
|
470 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
|
471 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
472 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
|
473 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
474 if (! errstr) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
475 errstr = "unspecified error"; |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
476 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
477 (*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
|
478 } |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
479 } |
4162 | 480 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
481 octave_dyld_shlib::~octave_dyld_shlib (void) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
482 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
483 if (handle) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
484 NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); |
4162 | 485 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
486 NSDestroyObjectFileImage (img); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
487 } |
4162 | 488 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
489 void * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
490 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
|
491 dynamic_library::name_mangler mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
492 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
493 void *function = nullptr; |
4162 | 494 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
495 if (! is_open ()) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
496 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
497 ("bundle %s is not open", file.c_str ()); |
4162 | 498 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
499 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
|
500 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
501 if (mangler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
502 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
|
503 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
504 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
|
505 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
506 if (symbol) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
507 { |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
508 function = NSAddressOfSymbol (symbol); |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
509 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
510 |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
511 return function; |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
512 } |
4162 | 513 |
3326 | 514 #endif |
515 | |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
516 dynamic_library::dynlib_rep * |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
517 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
|
518 { |
4110 | 519 #if defined (HAVE_DLOPEN_API) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
520 return new octave_dlopen_shlib (f); |
4110 | 521 #elif defined (HAVE_SHL_LOAD_API) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
522 return new octave_shl_load_shlib (f); |
4110 | 523 #elif defined (HAVE_LOADLIBRARY_API) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
524 return new octave_w32_shlib (f); |
4162 | 525 #elif defined (HAVE_DYLD_API) |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
526 return new octave_dyld_shlib (f); |
3326 | 527 #else |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
528 (*current_liboctave_error_handler) |
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
529 ("support for dynamically loaded libraries was unavailable or disabled when liboctave was built"); |
3326 | 530 #endif |
21750
6720e5a220ba
use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
531 } |
3326 | 532 } |