annotate liboctave/util/oct-shlib.cc @ 22146:ef91e43f162a

set DLL directory when loading DLLs on Windows systems (bug #48511) * file-ops.h (file_ops::dirname): New function. * oct-shlib.cc (set_dll_directory): New function. (octave_w32_shlib::octave_w32_shlib): Call file_ops::dirname to get directory part of shared library file, then use set_dll_directory to temporarily alter DLL search path. * ov-java.cc (set_dll_directory): Delete. (initialize_jvm): Don't set DLL search path for Windows systems here. That job is now handled by octave::dynamic_library.
author John W. Eaton <jwe@octave.org>
date Tue, 19 Jul 2016 12:07:34 -0400
parents aab79a1885cc
children c5842206aaea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
1 /*
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19410
diff changeset
3 Copyright (C) 1999-2015 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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
5
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
7
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6123
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6123
diff changeset
11 option) any later version.
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
12
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
16 for more details.
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
17
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6123
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6123
diff changeset
20 <http://www.gnu.org/licenses/>.
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
21
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
22 */
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
26 #endif
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
33 #endif
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
34
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
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
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
37 #endif
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
38
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
39 extern "C"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
40 {
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
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
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
45 extern void *dlopen (const char *, int);
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
46 extern const char *dlerror (void);
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
47 extern void *dlsym (void *, const char *);
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
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
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
55 #endif
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
56 }
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
59 #include "file-stat.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
60 #include "lo-error.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
61 #include "oct-shlib.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
62 #include "str-vec.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
102 dynlib_rep *retval = 0;
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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 {
21876
ef25c202bacc maint: Clean up for-range usage in liboctave in cset 5c67b16acc4a.
Rik <rik@octave.org>
parents: 21862
diff changeset
147 for (auto& fcn_sz_p : fcn_names)
ef25c202bacc maint: Clean up for-range usage in liboctave in cset 5c67b16acc4a.
Rik <rik@octave.org>
parents: 21862
diff changeset
148 cl_hook (fcn_sz_p.first);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
152
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
153 std::map<std::string, dynamic_library::dynlib_rep *> dynamic_library::dynlib_rep::instances;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
154
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
155 dynamic_library::dynlib_rep dynamic_library::nil_rep;
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
156
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
157 #if defined (HAVE_DLOPEN_API)
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
158
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
159 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
160 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
161 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
162 public:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
163
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
164 octave_dlopen_shlib (const std::string& f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
165
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
166 ~octave_dlopen_shlib (void);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
167
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
168 void *search (const std::string& name,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
169 dynamic_library::name_mangler mangler = 0);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
170
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
171 // 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
172 // normally throw an exception, avoiding the construction of an invalid
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21750
diff changeset
173 // library. Leave it here for possible future use.
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
174
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
175 bool is_open (void) const { return (library != 0); }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
176
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
177 private:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
178
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
179 // No copying!
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
180
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
181 octave_dlopen_shlib (const octave_dlopen_shlib&);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
182
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
183 octave_dlopen_shlib& operator = (const octave_dlopen_shlib&);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
184
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
185 void *library;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
186 };
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
187
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
188 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
189 : dynamic_library::dynlib_rep (f), library (0)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
190 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
191 int flags = 0;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
192
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
193 // 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
194 // 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
195 // 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
196 // 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
197 # if defined (RTLD_NOW)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
198 flags |= RTLD_NOW;
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
199 # endif
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
200
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
201 // 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
202 // 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
203 # if defined (RTLD_GLOBAL)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
204 flags |= RTLD_GLOBAL;
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
205 # endif
20493
3f01c585f54e oct-shlib.cc: Use RTLD_GLOBAL option for dlopen
Mike Miller <mtmiller@octave.org>
parents: 19697
diff changeset
206
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
207 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
208
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
209 if (! library)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
210 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
211 const char *msg = dlerror ();
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
212
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
213 if (msg)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
214 (*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
215 file.c_str (), msg);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
216 else
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",
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
218 file.c_str ());
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
219 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
220 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
221
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
222 octave_dlopen_shlib::~octave_dlopen_shlib (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
223 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
224 if (library)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
225 dlclose (library);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
226 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
227
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
228 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
229 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
230 dynamic_library::name_mangler mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
231 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
232 void *function = 0;
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
233
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
234 if (! is_open ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
235 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
236 ("shared library %s is not open", file.c_str ());
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
237
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
238 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
239
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
240 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
241 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
242
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
243 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
244
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
245 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
246 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
247
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
248 #elif defined (HAVE_SHL_LOAD_API)
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
249
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
250 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
251 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
252 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
253 public:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
254
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
255 octave_shl_load_shlib (const std::string& f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
256
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
257 ~octave_shl_load_shlib (void);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
258
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
259 void *search (const std::string& name,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
260 dynamic_library::name_mangler mangler = 0);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
261
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
262 bool is_open (void) const { return (library != 0); }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
263
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
264 private:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
265
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
266 // No copying!
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
267
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
268 octave_shl_load_shlib (const octave_shl_load_shlib&);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
269
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
270 octave_shl_load_shlib& operator = (const octave_shl_load_shlib&);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
271
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
272 shl_t library;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
273 };
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
274
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
275 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
276 : dynamic_library::dynlib_rep (f), library (0)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
277 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
278 file = f;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
279
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
280 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
281
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
282 if (! library)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
283 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
284 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
285 (*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
286 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
287 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
288
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
289 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
290 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
291 if (library)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
292 shl_unload (library);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
293 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
294
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
295 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
296 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
297 dynamic_library::name_mangler mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
298 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
299 void *function = 0;
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
300
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
301 if (! is_open ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
302 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
303 ("shared library %s is not open", file.c_str ());
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
304
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
305 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
306
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
307 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
308 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
309
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
310 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
311 TYPE_UNDEFINED, &function);
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 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
314 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
315
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
316 #elif defined (HAVE_LOADLIBRARY_API)
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
317
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
318 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
319 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
320 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
321 public:
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
322
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
323 octave_w32_shlib (const std::string& f);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
324
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
325 ~octave_w32_shlib (void);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
326
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
327 void *search (const std::string& name,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
328 dynamic_library::name_mangler mangler = 0);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
329
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
330 bool is_open (void) const { return (handle != 0); }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
331
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
332 private:
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
333
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
334 // No copying!
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
335
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
336 octave_w32_shlib (const octave_w32_shlib&);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
337
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
338 octave_w32_shlib& operator = (const octave_w32_shlib&);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
339
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
340 HINSTANCE handle;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
341 };
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
342
22146
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
343 static void
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
344 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
345 {
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
346 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
347 }
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
348
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
349 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
350 : dynamic_library::dynlib_rep (f), handle (0)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
351 {
22146
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
352 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
353
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
354 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
355
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
356 handle = LoadLibrary (file.c_str ());
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
357
22146
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
358 set_dll_directory ();
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
359
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
360 if (! handle)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
361 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
362 DWORD lastError = GetLastError ();
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
363 const char *msg;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
364
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
365 switch (lastError)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
366 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
367 case ERROR_MOD_NOT_FOUND:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
368 case ERROR_DLL_NOT_FOUND:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
369 msg = "could not find library or dependencies";
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
370 break;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
371
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
372 case ERROR_INVALID_DLL:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
373 msg = "library or its dependencies are damaged";
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
374 break;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
375
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
376 case ERROR_DLL_INIT_FAILED:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
377 msg = "library initialization routine failed";
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
378 break;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
379
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
380 default:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
381 msg = "library open failed";
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
382 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
383
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
384 (*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
385 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
386 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
387
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
388 octave_w32_shlib::~octave_w32_shlib (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
389 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
390 if (handle)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
391 FreeLibrary (handle);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
392 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
393
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
394 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
395 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
396 dynamic_library::name_mangler mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
397 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
398 void *function = 0;
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
399
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
400 if (! is_open ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
401 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
402 ("shared library %s is not open", file.c_str ());
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
403
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
404 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
405
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
406 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
407 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
408
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
409 function = reinterpret_cast<void *> (GetProcAddress (handle,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
410 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
411
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
412 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
413 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
414
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
415 #elif defined (HAVE_DYLD_API)
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
416
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
417 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
418 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
419 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
420 public:
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
421
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
422 octave_dyld_shlib (void);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
423
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
424 ~octave_dyld_shlib (void);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
425
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
426 void open (const std::string& f);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
427
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
428 void *search (const std::string& name,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
429 dynamic_library::name_mangler mangler = 0);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
430
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
431 void close (dynamic_library::close_hook cl_hook = 0);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
432
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
433 bool is_open (void) const {return (handle != 0); }
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
434
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
435 private:
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
436
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
437 // No copying!
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
438
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
439 octave_dyld_shlib (const octave_dyld_shlib&);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
440
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
441 octave_dyld_shlib& operator = (const octave_dyld_shlib&);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
442
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
443 NSObjectFileImage img;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
444 NSModule handle;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
445 };
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
446
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
447 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
448 : dynamic_library::dynlib_rep (f), handle (0)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
449 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
450 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
451
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
452 if (NSObjectFileImageSuccess != returnCode)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
453 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
454 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
455 ("got NSObjectFileImageReturnCode %d", returnCode);
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
456
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
457 // FIXME: should use NSLinkEditError () to get
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
458 // more info on what went wrong.
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
459 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21109
diff changeset
460
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
461 handle = NSLinkModule (img, file.c_str (),
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
462 (NSLINKMODULE_OPTION_RETURN_ON_ERROR
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
463 | NSLINKMODULE_OPTION_PRIVATE));
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
464 if (! handle)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
465 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
466 NSLinkEditErrors ler;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
467 int lerno;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
468 const char *file2;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
469 const char *errstr = 0;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21109
diff changeset
470
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
471 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
472
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
473 if (! errstr)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
474 errstr = "unspecified error";
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 (*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
477 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
478 }
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
479
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
480 octave_dyld_shlib::~octave_dyld_shlib (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
481 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
482 if (handle)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
483 NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
484
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
485 NSDestroyObjectFileImage (img);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
486 }
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
487
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
488 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
489 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
490 dynamic_library::name_mangler mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
491 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
492 void *function = 0;
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
493
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
494 if (! is_open ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
495 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
496 ("bundle %s is not open", file.c_str ());
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
497
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
498 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
499
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
500 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
501 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
502
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
503 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
504
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
505 if (symbol)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
506 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
507 function = NSAddressOfSymbol (symbol);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
508 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21109
diff changeset
509
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
510 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
511 }
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
512
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
513 #endif
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
514
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
515 dynamic_library::dynlib_rep *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
516 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
517 {
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
518 #if defined (HAVE_DLOPEN_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
519 return new octave_dlopen_shlib (f);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
520 #elif defined (HAVE_SHL_LOAD_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
521 return new octave_shl_load_shlib (f);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
522 #elif defined (HAVE_LOADLIBRARY_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
523 return new octave_w32_shlib (f);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
524 #elif defined (HAVE_DYLD_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
525 return new octave_dyld_shlib (f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
526 #else
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
527 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
528 ("support for dynamically loaded libraries was unavailable or disabled when liboctave was built");
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
529 #endif
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
530 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
531 }