annotate liboctave/util/oct-shlib.cc @ 21750:6720e5a220ba

use namespace for octave_shlib class * oct-shlib.h, oct-shlib.cc: Put octave_shlib in octave namespace and rename to dyamic_library. Change all uses.
author John W. Eaton <jwe@octave.org>
date Thu, 19 May 2016 19:42:57 -0400
parents 0504351a45e6
children b571fc85953f
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
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
58 #include "file-stat.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
59 #include "lo-error.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
60 #include "oct-shlib.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
61 #include "str-vec.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
62
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
63 namespace octave
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
64 {
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
65 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
66 : 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
67 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
68 instances[f] = this;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
69
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
70 if (is_out_of_date ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
71 (*current_liboctave_warning_with_id_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
72 ("Octave:warn-future-time-stamp",
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
73 "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
74 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
75
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
76 bool
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
77 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
78 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
79 octave::sys::file_stat fs (file);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
80 return (fs && fs.is_newer (tm_loaded));
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
81 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
82
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
83 void
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
84 dynamic_library::dynlib_rep::fake_reload (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
85 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
86 // 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
87 octave::sys::file_stat fs (file);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
88 if (fs && fs.is_newer (tm_loaded))
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
89 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
90 tm_loaded = fs.mtime ();
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
91
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
92 (*current_liboctave_warning_with_id_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
93 ("Octave:library-reload",
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
94 "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
95 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
96 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
97
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
98 dynamic_library::dynlib_rep *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
99 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
100 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
101 dynlib_rep *retval = 0;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
102 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
103 if (p != instances.end ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
104 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
105 retval = p->second;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
106 retval->count++;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
107 if (fake)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
108 retval->fake_reload ();
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
109 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
110 else
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
111 retval = new_instance (f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
112
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
113 return retval;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
114 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
115
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
116 void
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
117 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
118 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
119 fcn_names_iterator p = fcn_names.find (name);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
120
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
121 if (p == fcn_names.end ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
122 fcn_names[name] = 1;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
123 else
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
124 ++(p->second);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
125 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
126
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
127 bool
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
128 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
129 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
130 bool retval = false;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
131
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
132 fcn_names_iterator p = fcn_names.find (fcn_name);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
133
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
134 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
135 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
136 fcn_names.erase (fcn_name);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
137 retval = true;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
138 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
139
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
140 return retval;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
141 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
142
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
143 void
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
144 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
145 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
146 for (fcn_names_iterator p = fcn_names.begin (); p != fcn_names.end (); p++)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
147 cl_hook (p->first);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
148
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
149 fcn_names.clear ();
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
150 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
151
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
152 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
153
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
154 dynamic_library::dynlib_rep dynamic_library::nil_rep;
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
155
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
156 #if defined (HAVE_DLOPEN_API)
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
157
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
158 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
159 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
160 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
161 public:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
162
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
163 octave_dlopen_shlib (const std::string& f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
164
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
165 ~octave_dlopen_shlib (void);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
166
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
167 void *search (const std::string& name,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
168 dynamic_library::name_mangler mangler = 0);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
169
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
170 // 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
171 // normally throw an exception, avoiding the construction of an invalid
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
172 // library. Leave it here for possible future use.
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
173
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
174 bool is_open (void) const { return (library != 0); }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
175
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
176 private:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
177
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
178 // No copying!
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
179
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
180 octave_dlopen_shlib (const octave_dlopen_shlib&);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
181
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
182 octave_dlopen_shlib& operator = (const octave_dlopen_shlib&);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
183
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
184 void *library;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
185 };
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
186
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
187 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
188 : dynamic_library::dynlib_rep (f), library (0)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
189 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
190 int flags = 0;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
191
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
192 // 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
193 // 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
194 // 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
195 // 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
196 # if defined (RTLD_NOW)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
197 flags |= RTLD_NOW;
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
198 # endif
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
199
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
200 // 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
201 // 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
202 # if defined (RTLD_GLOBAL)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
203 flags |= RTLD_GLOBAL;
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
204 # endif
20493
3f01c585f54e oct-shlib.cc: Use RTLD_GLOBAL option for dlopen
Mike Miller <mtmiller@octave.org>
parents: 19697
diff changeset
205
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
206 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
207
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
208 if (! library)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
209 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
210 const char *msg = dlerror ();
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
211
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
212 if (msg)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
213 (*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
214 file.c_str (), msg);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
215 else
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
216 (*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
217 file.c_str ());
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
218 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
219 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
220
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
221 octave_dlopen_shlib::~octave_dlopen_shlib (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
222 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
223 if (library)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
224 dlclose (library);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
225 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
226
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
227 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
228 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
229 dynamic_library::name_mangler mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
230 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
231 void *function = 0;
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
232
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
233 if (! is_open ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
234 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
235 ("shared library %s is not open", file.c_str ());
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
236
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
237 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
238
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
239 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
240 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
241
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
242 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
243
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
244 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
245 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
246
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
247 #elif defined (HAVE_SHL_LOAD_API)
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
248
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
249 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
250 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
251 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
252 public:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
253
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
254 octave_shl_load_shlib (const std::string& f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
255
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
256 ~octave_shl_load_shlib (void);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
257
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
258 void *search (const std::string& name,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
259 dynamic_library::name_mangler mangler = 0);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
260
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
261 bool is_open (void) const { return (library != 0); }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
262
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
263 private:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
264
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
265 // No copying!
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
266
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
267 octave_shl_load_shlib (const octave_shl_load_shlib&);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
268
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
269 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
270
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
271 shl_t library;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
272 };
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
273
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
274 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
275 : dynamic_library::dynlib_rep (f), library (0)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
276 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
277 file = f;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
278
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
279 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
280
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
281 if (! library)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
282 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
283 using namespace std; // FIXME: Why have this line?
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
284 (*current_liboctave_error_handler) ("%s", gnulib::strerror (errno));
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
285 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
286 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
287
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
288 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
289 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
290 if (library)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
291 shl_unload (library);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
292 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
293
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
294 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
295 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
296 dynamic_library::name_mangler mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
297 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
298 void *function = 0;
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
299
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
300 if (! is_open ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
301 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
302 ("shared library %s is not open", file.c_str ());
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
303
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
304 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
305
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
306 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
307 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
308
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
309 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
310 TYPE_UNDEFINED, &function);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21109
diff changeset
311
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
312 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
313 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
314
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
315 #elif defined (HAVE_LOADLIBRARY_API)
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
316
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
317 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
318 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
319 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
320 public:
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
321
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
322 octave_w32_shlib (const std::string& f);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
323
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
324 ~octave_w32_shlib (void);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
325
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
326 void *search (const std::string& name,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
327 dynamic_library::name_mangler mangler = 0);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
328
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
329 bool is_open (void) const { return (handle != 0); }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
330
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
331 private:
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
332
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
333 // No copying!
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
334
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
335 octave_w32_shlib (const octave_w32_shlib&);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
336
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
337 octave_w32_shlib& operator = (const octave_w32_shlib&);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
338
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
339 HINSTANCE handle;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
340 };
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
341
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
342 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
343 : dynamic_library::dynlib_rep (f), handle (0)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
344 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
345 handle = LoadLibrary (file.c_str ());
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
346
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
347 if (! handle)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
348 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
349 DWORD lastError = GetLastError ();
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
350 const char *msg;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
351
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
352 switch (lastError)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
353 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
354 case ERROR_MOD_NOT_FOUND:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
355 case ERROR_DLL_NOT_FOUND:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
356 msg = "could not find library or dependencies";
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
357 break;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
358
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
359 case ERROR_INVALID_DLL:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
360 msg = "library or its dependencies are damaged";
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
361 break;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
362
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
363 case ERROR_DLL_INIT_FAILED:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
364 msg = "library initialization routine failed";
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
365 break;
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
366
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
367 default:
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
368 msg = "library open failed";
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
369 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
370
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
371 (*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
372 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
373 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
374
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
375 octave_w32_shlib::~octave_w32_shlib (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
376 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
377 if (handle)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
378 FreeLibrary (handle);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
379 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
380
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
381 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
382 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
383 dynamic_library::name_mangler mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
384 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
385 void *function = 0;
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
386
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
387 if (! is_open ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
388 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
389 ("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
390
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
391 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
392
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
393 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
394 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
395
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
396 function = reinterpret_cast<void *> (GetProcAddress (handle,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
397 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
398
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
399 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
400 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
401
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
402 #elif defined (HAVE_DYLD_API)
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
403
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
404 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
405 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
406 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
407 public:
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
408
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
409 octave_dyld_shlib (void);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
410
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
411 ~octave_dyld_shlib (void);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
412
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
413 void open (const std::string& f);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
414
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
415 void *search (const std::string& name,
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
416 dynamic_library::name_mangler mangler = 0);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
417
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
418 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
419
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
420 bool is_open (void) const {return (handle != 0); }
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 private:
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 // No copying!
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 octave_dyld_shlib (const octave_dyld_shlib&);
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 octave_dyld_shlib& operator = (const octave_dyld_shlib&);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
429
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
430 NSObjectFileImage img;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
431 NSModule handle;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
432 };
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
433
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
434 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
435 : dynamic_library::dynlib_rep (f), handle (0)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
436 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
437 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
438
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
439 if (NSObjectFileImageSuccess != returnCode)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
440 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
441 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
442 ("got NSObjectFileImageReturnCode %d", returnCode);
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
443
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
444 // FIXME: should use NSLinkEditError () to get
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
445 // more info on what went wrong.
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
446 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21109
diff changeset
447
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
448 handle = NSLinkModule (img, file.c_str (),
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
449 (NSLINKMODULE_OPTION_RETURN_ON_ERROR
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
450 | NSLINKMODULE_OPTION_PRIVATE));
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
451 if (! handle)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
452 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
453 NSLinkEditErrors ler;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
454 int lerno;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
455 const char *file2;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
456 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
457
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
458 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
459
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
460 if (! errstr)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
461 errstr = "unspecified error";
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21109
diff changeset
462
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
463 (*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
464 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
465 }
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
466
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
467 octave_dyld_shlib::~octave_dyld_shlib (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
468 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
469 if (handle)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
470 NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
471
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
472 NSDestroyObjectFileImage (img);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
473 }
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
474
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
475 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
476 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
477 dynamic_library::name_mangler mangler)
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 void *function = 0;
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
480
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
481 if (! is_open ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
482 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
483 ("bundle %s is not open", file.c_str ());
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 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
486
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
487 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
488 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
489
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
490 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
491
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
492 if (symbol)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
493 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
494 function = NSAddressOfSymbol (symbol);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
495 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21109
diff changeset
496
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
497 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
498 }
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
499
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
500 #endif
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
501
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
502 dynamic_library::dynlib_rep *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
503 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
504 {
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
505 #if defined (HAVE_DLOPEN_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
506 return new octave_dlopen_shlib (f);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
507 #elif defined (HAVE_SHL_LOAD_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
508 return new octave_shl_load_shlib (f);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
509 #elif defined (HAVE_LOADLIBRARY_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
510 return new octave_w32_shlib (f);
4162
bcdf1c264e08 [project @ 2002-11-10 00:34:37 by jwe]
jwe
parents: 4110
diff changeset
511 #elif defined (HAVE_DYLD_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
512 return new octave_dyld_shlib (f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
513 #else
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
514 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
515 ("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
516 #endif
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
517 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
518 }