Mercurial > hg > octave-nkf
annotate liboctave/oct-shlib.cc @ 7893:eb9ccb44ea41
make regexp(...,'once') matlab compatible
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 18 Jun 2008 21:00:06 +0200 |
parents | 1b63f8da772d |
children | 095b3e4d64e9 |
rev | line source |
---|---|
3326 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1999, 2000, 2002, 2003, 2005, 2006, 2007 John W. Eaton |
3326 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3326 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3326 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
27 #include <map> |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
28 |
4110 | 29 #if defined (HAVE_SHL_LOAD_API) |
3326 | 30 #include <cerrno> |
31 #include <cstring> | |
32 #endif | |
33 | |
4162 | 34 #if defined (HAVE_DYLD_API) |
4429 | 35 #include <mach-o/dyld.h> |
4162 | 36 #endif |
37 | |
3326 | 38 extern "C" |
39 { | |
4110 | 40 #if defined (HAVE_DLOPEN_API) |
3326 | 41 #if defined (HAVE_DLFCN_H) |
42 #include <dlfcn.h> | |
43 #else | |
44 extern void *dlopen (const char *, int); | |
45 extern const char *dlerror (void); | |
46 extern void *dlsym (void *, const char *); | |
47 extern int dlclose (void *); | |
48 #endif | |
4110 | 49 #elif defined (HAVE_SHL_LOAD_API) |
3326 | 50 #include <dl.h> |
5451 | 51 #elif defined (HAVE_LOADLIBRARY_API) |
52 #include <windows.h> | |
6123 | 53 #undef min |
54 #undef max | |
3326 | 55 #endif |
56 } | |
57 | |
58 #include "file-stat.h" | |
59 #include "lo-error.h" | |
60 #include "oct-shlib.h" | |
61 #include "str-vec.h" | |
62 | |
63 class | |
64 octave_base_shlib : public octave_shlib | |
65 { | |
66 public: | |
67 | |
68 octave_base_shlib (void) | |
69 : octave_shlib (octave_xshlib ()), file (), fcn_names (), | |
70 tm_loaded (static_cast<time_t> (0)) | |
71 { count = 1; } | |
72 | |
3504 | 73 octave_base_shlib (const std::string& f) |
3326 | 74 : octave_shlib (octave_xshlib ()), file (f), fcn_names (), |
75 tm_loaded (static_cast<time_t> (0)) | |
76 { count = 1; } | |
77 | |
78 ~octave_base_shlib (void) { } | |
79 | |
5781 | 80 void open (const std::string&) { } |
3326 | 81 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
82 // FIXME -- instead of returning a direct pointer to a function, |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
83 // perhaps this should return an object containing the pointer. |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
84 // Then we could do the reference counting without relying on users |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
85 // of this class to call remove at the appropriate time. However, |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
86 // when users accessed the internal pointer, they would still need |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
87 // to know that the pointer is only valid while the container is |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
88 // valid (similar to the std::string::c_str method). |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
89 |
3504 | 90 void *search (const std::string&, name_mangler = 0) { return 0; } |
3326 | 91 |
92 void close (octave_shlib::close_hook = 0) { } | |
93 | |
3504 | 94 bool remove (const std::string& fcn_name); |
3326 | 95 |
96 bool is_open (void) const { return false; } | |
97 | |
98 bool is_out_of_date (void) const; | |
99 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
100 size_t number_of_functions_loaded (void) const { return fcn_names.size (); } |
3326 | 101 |
3504 | 102 std::string file_name (void) const { return file; } |
3326 | 103 |
104 octave_time time_loaded (void) const { return tm_loaded; } | |
105 | |
106 protected: | |
107 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
108 typedef std::map<std::string, size_t>::iterator fcn_names_iterator; |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
109 typedef std::map<std::string, size_t>::const_iterator fcn_names_const_iterator; |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
110 |
3504 | 111 std::string file; |
3326 | 112 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
113 std::map<std::string, size_t> fcn_names; |
3326 | 114 |
115 octave_time tm_loaded; | |
116 | |
5781 | 117 void stamp_time (void); |
3326 | 118 |
3504 | 119 void add_to_fcn_names (const std::string& name); |
3326 | 120 |
121 void do_close_hook (octave_shlib::close_hook = 0); | |
122 | |
123 void tabula_rasa (void); | |
124 | |
125 // No copying! | |
126 | |
127 octave_base_shlib (const octave_base_shlib&); | |
128 | |
129 octave_base_shlib& operator = (const octave_base_shlib&); | |
130 }; | |
131 | |
132 bool | |
3504 | 133 octave_base_shlib::remove (const std::string& fcn_name) |
3326 | 134 { |
135 bool retval = false; | |
136 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
137 fcn_names_iterator p = fcn_names.find (fcn_name); |
3326 | 138 |
7872 | 139 if (p != fcn_names.end () && --(p->second) == 0) |
3326 | 140 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
141 fcn_names.erase (fcn_name); |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
142 retval = true; |
3326 | 143 } |
144 | |
145 return retval; | |
146 } | |
147 | |
148 bool | |
149 octave_base_shlib::is_out_of_date (void) const | |
150 { | |
151 file_stat fs (file); | |
152 | |
153 return fs.is_newer (tm_loaded); | |
154 } | |
155 | |
156 void | |
5781 | 157 octave_base_shlib::stamp_time (void) |
3326 | 158 { |
159 tm_loaded.stamp (); | |
160 | |
5781 | 161 file_stat fs (file); |
3326 | 162 |
5781 | 163 if (fs.is_newer (tm_loaded)) |
164 (*current_liboctave_warning_with_id_handler) | |
165 ("Octave:warn-future-time-stamp", | |
166 "timestamp on file %s is in the future", file.c_str ()); | |
3326 | 167 } |
168 | |
169 void | |
3504 | 170 octave_base_shlib::add_to_fcn_names (const std::string& name) |
3326 | 171 { |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
172 fcn_names_iterator p = fcn_names.find (name); |
3326 | 173 |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
174 if (p == fcn_names.end ()) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
175 fcn_names[name] = 1; |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
176 else |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
177 ++(p->second); |
3326 | 178 } |
179 | |
180 void | |
181 octave_base_shlib::do_close_hook (octave_shlib::close_hook cl_hook) | |
182 { | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
183 for (fcn_names_iterator p = fcn_names.begin (); p != fcn_names.end (); p++) |
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
184 cl_hook (p->first); |
3326 | 185 } |
186 | |
187 void | |
188 octave_base_shlib::tabula_rasa (void) | |
189 { | |
190 file = ""; | |
191 | |
7749
14e05160b99f
reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
192 fcn_names.clear (); |
3326 | 193 |
194 tm_loaded = static_cast<time_t> (0); | |
195 } | |
196 | |
4110 | 197 #if defined (HAVE_DLOPEN_API) |
3326 | 198 |
199 class | |
200 octave_dlopen_shlib : public octave_base_shlib | |
201 { | |
202 public: | |
203 | |
204 octave_dlopen_shlib (void); | |
205 | |
206 ~octave_dlopen_shlib (void); | |
207 | |
5781 | 208 void open (const std::string& f); |
3326 | 209 |
3504 | 210 void *search (const std::string& name, name_mangler mangler = 0); |
3326 | 211 |
212 void close (octave_shlib::close_hook cl_hook = 0); | |
213 | |
214 bool is_open (void) const { return (library != 0); } | |
215 | |
216 private: | |
217 | |
218 // No copying! | |
219 | |
220 octave_dlopen_shlib (const octave_dlopen_shlib&); | |
221 | |
222 octave_dlopen_shlib& operator = (const octave_dlopen_shlib&); | |
223 | |
224 void *library; | |
225 }; | |
226 | |
227 octave_dlopen_shlib::octave_dlopen_shlib (void) | |
228 : octave_base_shlib (), library (0) | |
229 { | |
230 } | |
231 | |
232 octave_dlopen_shlib::~octave_dlopen_shlib (void) | |
233 { | |
234 close (); | |
235 } | |
236 | |
237 void | |
5781 | 238 octave_dlopen_shlib::open (const std::string& f) |
3326 | 239 { |
240 if (! is_open ()) | |
241 { | |
242 file = f; | |
243 | |
4184 | 244 int flags = 0; |
245 | |
246 #if defined (RTLD_LAZY) | |
4193 | 247 flags |= RTLD_LAZY; |
4184 | 248 #endif |
249 | |
250 #if defined (RTLD_GLOBAL) | |
4193 | 251 flags |= RTLD_GLOBAL; |
4184 | 252 #endif |
253 | |
254 library = dlopen (file.c_str (), flags); | |
3326 | 255 |
256 if (library) | |
5781 | 257 stamp_time (); |
3326 | 258 else |
259 { | |
260 const char *msg = dlerror (); | |
261 | |
262 if (msg) | |
263 (*current_liboctave_error_handler) ("%s", msg); | |
264 } | |
265 } | |
266 else | |
267 (*current_liboctave_error_handler) | |
268 ("shared library %s is already open", file.c_str ()); | |
269 } | |
270 | |
271 void * | |
3504 | 272 octave_dlopen_shlib::search (const std::string& name, |
3326 | 273 octave_shlib::name_mangler mangler) |
274 { | |
275 void *function = 0; | |
276 | |
277 if (is_open ()) | |
278 { | |
3504 | 279 std::string sym_name = name; |
3326 | 280 |
281 if (mangler) | |
282 sym_name = mangler (name); | |
283 | |
284 function = dlsym (library, sym_name.c_str ()); | |
285 | |
286 if (function) | |
287 add_to_fcn_names (name); | |
288 } | |
289 else | |
290 (*current_liboctave_error_handler) | |
291 ("shared library %s is not open", file.c_str ()); | |
292 | |
293 return function; | |
294 } | |
295 | |
296 void | |
297 octave_dlopen_shlib::close (octave_shlib::close_hook cl_hook) | |
298 { | |
299 if (is_open ()) | |
300 { | |
5864 | 301 if (cl_hook) |
302 do_close_hook (cl_hook); | |
3326 | 303 |
304 dlclose (library); | |
305 | |
306 library = 0; | |
307 | |
308 tabula_rasa (); | |
309 } | |
310 } | |
311 | |
4110 | 312 #elif defined (HAVE_SHL_LOAD_API) |
3326 | 313 |
314 class | |
315 octave_shl_load_shlib : public octave_base_shlib | |
316 { | |
317 public: | |
318 | |
319 octave_shl_load_shlib (void); | |
320 | |
321 ~octave_shl_load_shlib (void); | |
322 | |
5781 | 323 void open (const std::string& f); |
3326 | 324 |
3504 | 325 void *search (const std::string& name, name_mangler mangler = 0); |
3326 | 326 |
327 void close (octave_shlib::close_hook cl_hook = 0); | |
328 | |
3609 | 329 bool is_open (void) const { return (library != 0); } |
3326 | 330 |
331 private: | |
332 | |
333 // No copying! | |
334 | |
335 octave_shl_load_shlib (const octave_shl_load_shlib&); | |
336 | |
337 octave_shl_load_shlib& operator = (const octave_shl_load_shlib&); | |
338 | |
339 shl_t library; | |
340 }; | |
341 | |
342 octave_shl_load_shlib::octave_shl_load_shlib (void) | |
343 : octave_base_shlib (), library (0) | |
344 { | |
345 } | |
346 | |
347 octave_shl_load_shlib::~octave_shl_load_shlib (void) | |
348 { | |
349 close (); | |
350 } | |
351 | |
352 void | |
5781 | 353 octave_shl_load_shlib::open (const std::string& f) |
3326 | 354 { |
355 if (! is_open ()) | |
356 { | |
357 file = f; | |
358 | |
359 library = shl_load (file.c_str (), BIND_DEFERRED, 0L); | |
360 | |
361 if (library) | |
5781 | 362 stamp_time (); |
3326 | 363 else |
3504 | 364 { |
365 using namespace std; | |
366 (*current_liboctave_error_handler) ("%s", strerror (errno)); | |
367 } | |
3326 | 368 } |
369 else | |
370 (*current_liboctave_error_handler) | |
371 ("shared library %s is already open", file.c_str ()); | |
372 } | |
373 | |
374 void * | |
3504 | 375 octave_shl_load_shlib::search (const std::string& name, |
3326 | 376 octave_shlib::name_mangler mangler) |
377 { | |
378 void *function = 0; | |
379 | |
380 if (is_open ()) | |
381 { | |
3609 | 382 std::string sym_name = name; |
3326 | 383 |
384 if (mangler) | |
385 sym_name = mangler (name); | |
386 | |
387 int status = shl_findsym (&library, sym_name.c_str (), | |
388 TYPE_UNDEFINED, &function); | |
389 | |
390 if (status == 0) | |
391 add_to_fcn_names (name); | |
392 } | |
393 else | |
394 (*current_liboctave_error_handler) | |
395 ("shared library %s is not open", file.c_str ()); | |
396 | |
397 return function; | |
398 } | |
399 | |
400 void | |
401 octave_shl_load_shlib::close (octave_shlib::close_hook cl_hook) | |
402 { | |
403 if (is_open ()) | |
404 { | |
5864 | 405 if (cl_hook) |
406 do_close_hook (cl_hook); | |
3326 | 407 |
408 shl_unload (library); | |
409 | |
410 library = 0; | |
411 | |
412 tabula_rasa (); | |
413 } | |
414 } | |
415 | |
4110 | 416 #elif defined (HAVE_LOADLIBRARY_API) |
417 | |
418 class | |
419 octave_w32_shlib: public octave_base_shlib | |
420 { | |
421 public: | |
422 | |
423 octave_w32_shlib (void); | |
424 | |
425 ~octave_w32_shlib (void); | |
426 | |
5781 | 427 void open (const std::string& f); |
4110 | 428 |
429 void *search (const std::string& name, name_mangler mangler = 0); | |
430 | |
431 void close (octave_shlib::close_hook cl_hook = 0); | |
432 | |
433 bool is_open (void) const { return (handle != 0); } | |
434 | |
435 private: | |
436 | |
437 // No copying! | |
438 | |
439 octave_w32_shlib (const octave_w32_shlib&); | |
440 | |
441 octave_w32_shlib& operator = (const octave_w32_shlib&); | |
442 | |
443 HINSTANCE handle; | |
444 }; | |
445 | |
446 octave_w32_shlib::octave_w32_shlib (void) | |
447 : octave_base_shlib (), handle (0) | |
448 { | |
449 } | |
450 | |
451 octave_w32_shlib::~octave_w32_shlib (void) | |
452 { | |
453 close (); | |
454 } | |
455 | |
456 void | |
5781 | 457 octave_w32_shlib::open (const std::string& f) |
4110 | 458 { |
459 if (! is_open ()) | |
460 { | |
461 file = f; | |
462 | |
463 handle = LoadLibrary (file.c_str ()); | |
464 | |
7520 | 465 if (handle) |
5781 | 466 stamp_time (); |
4110 | 467 else |
468 { | |
469 DWORD lastError = GetLastError (); | |
470 char *msg; | |
471 | |
472 switch (lastError) | |
473 { | |
474 case ERROR_MOD_NOT_FOUND: | |
475 case ERROR_DLL_NOT_FOUND: | |
476 msg = "could not find library or dependents"; | |
477 break; | |
478 | |
479 case ERROR_INVALID_DLL: | |
480 msg = "library or its dependents are damaged"; | |
481 break; | |
482 | |
483 case ERROR_DLL_INIT_FAILED: | |
484 msg = "library initialization routine failed"; | |
485 break; | |
486 | |
487 default: | |
488 msg = "library open failed"; | |
489 } | |
490 | |
491 (*current_liboctave_error_handler) ("%s: %s", msg, file.c_str ()); | |
492 } | |
493 } | |
494 else | |
495 (*current_liboctave_error_handler) | |
496 ("shared library %s is already open", file.c_str ()); | |
497 } | |
498 | |
5451 | 499 extern "C" |
500 { | |
501 void * octave_w32_search (HINSTANCE handle, const char * name); | |
502 } | |
503 | |
4110 | 504 void * |
505 octave_w32_shlib::search (const std::string& name, | |
506 octave_shlib::name_mangler mangler) | |
507 { | |
508 void *function = 0; | |
509 | |
510 if (is_open ()) | |
511 { | |
512 std::string sym_name = name; | |
513 | |
514 if (mangler) | |
515 sym_name = mangler (name); | |
516 | |
5451 | 517 function = octave_w32_library_search (handle, sym_name.c_str ()); |
4110 | 518 |
519 if (function) | |
520 add_to_fcn_names (name); | |
521 } | |
522 else | |
523 (*current_liboctave_error_handler) | |
524 ("shared library %s is not open", file.c_str ()); | |
525 | |
526 return function; | |
527 } | |
528 | |
529 void | |
530 octave_w32_shlib::close (octave_shlib::close_hook cl_hook) | |
531 { | |
532 if (is_open ()) | |
533 { | |
5864 | 534 if (cl_hook) |
535 do_close_hook (cl_hook); | |
4110 | 536 |
537 FreeLibrary (handle); | |
538 | |
539 handle = 0; | |
540 | |
541 tabula_rasa (); | |
542 } | |
543 } | |
544 | |
4162 | 545 #elif defined (HAVE_DYLD_API) |
546 | |
547 class | |
548 octave_dyld_shlib : public octave_base_shlib | |
549 { | |
550 public: | |
551 | |
552 octave_dyld_shlib (void); | |
553 | |
554 ~octave_dyld_shlib (void); | |
555 | |
5781 | 556 void open (const std::string& f); |
4162 | 557 |
558 void *search (const std::string& name, name_mangler mangler = 0); | |
559 | |
560 void close (octave_shlib::close_hook cl_hook = 0); | |
561 | |
562 bool is_open (void) const {return (isOpen); } | |
563 | |
564 private: | |
565 | |
566 // No copying! | |
567 | |
568 octave_dyld_shlib (const octave_dyld_shlib&); | |
569 | |
570 octave_dyld_shlib& operator = (const octave_dyld_shlib&); | |
571 | |
572 bool isOpen; | |
573 NSObjectFileImage img; | |
574 NSModule handle; | |
575 }; | |
576 | |
577 octave_dyld_shlib::octave_dyld_shlib (void) | |
578 : octave_base_shlib (), isOpen (false), handle (0) | |
579 { | |
580 } | |
581 | |
582 octave_dyld_shlib::~octave_dyld_shlib (void) | |
583 { | |
584 close (); | |
585 } | |
586 | |
587 void | |
5781 | 588 octave_dyld_shlib::open (const std::string& f) |
4162 | 589 { |
590 int returnCode; | |
591 | |
592 if (! is_open ()) | |
593 { | |
594 file = f; | |
595 | |
596 returnCode = NSCreateObjectFileImageFromFile (file.c_str (), &img); | |
597 | |
598 if (NSObjectFileImageSuccess == returnCode) | |
599 { | |
600 handle = NSLinkModule (img, file.c_str (), | |
601 (NSLINKMODULE_OPTION_RETURN_ON_ERROR | |
602 | NSLINKMODULE_OPTION_PRIVATE)); | |
603 if (handle) | |
604 { | |
5781 | 605 stamp_time (); |
4162 | 606 isOpen = true; |
607 } | |
608 else | |
609 { | |
610 (*current_liboctave_error_handler) | |
611 ("couldn't link module %s", file.c_str ()); | |
612 } | |
613 } | |
614 else | |
615 { | |
616 (*current_liboctave_error_handler) | |
617 ("got NSObjectFileImageReturnCode %d", returnCode); | |
618 | |
5775 | 619 // FIXME -- should use NSLinkEditError () to get |
4162 | 620 // more info on what went wrong. |
621 } | |
622 } | |
623 else | |
624 { | |
625 (*current_liboctave_error_handler) | |
626 ("bundle %s is already open", file.c_str ()); | |
627 } | |
628 } | |
629 | |
630 void * | |
631 octave_dyld_shlib::search (const std::string& name, | |
632 octave_shlib::name_mangler mangler) | |
633 { | |
634 void *function = 0; | |
635 | |
636 if (is_open ()) | |
637 { | |
638 std::string sym_name = name; | |
639 | |
640 if (mangler) | |
641 sym_name = mangler (name); | |
642 | |
643 NSSymbol symbol = NSLookupSymbolInModule (handle, sym_name.c_str ()); | |
644 | |
645 if (symbol) | |
646 { | |
647 function = NSAddressOfSymbol (symbol); | |
648 add_to_fcn_names (name); | |
649 } | |
650 } | |
651 else | |
652 (*current_liboctave_error_handler) | |
653 ("bundle %s is not open", file.c_str ()); | |
654 | |
655 return function; | |
656 } | |
657 | |
658 void | |
659 octave_dyld_shlib::close (octave_shlib::close_hook cl_hook) | |
660 { | |
661 if (is_open ()) | |
662 { | |
663 do_close_hook (cl_hook); | |
664 | |
665 NSUnLinkModule (handle, NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES); | |
666 | |
667 handle = 0; | |
668 | |
669 if (NSDestroyObjectFileImage (img)) | |
670 isOpen = false; | |
671 | |
672 tabula_rasa (); | |
673 } | |
674 } | |
675 | |
3326 | 676 #endif |
677 | |
678 octave_shlib * | |
679 octave_shlib::make_shlib (void) | |
680 { | |
4110 | 681 #if defined (HAVE_DLOPEN_API) |
3326 | 682 return new octave_dlopen_shlib (); |
4110 | 683 #elif defined (HAVE_SHL_LOAD_API) |
3326 | 684 return new octave_shl_load_shlib (); |
4110 | 685 #elif defined (HAVE_LOADLIBRARY_API) |
686 return new octave_w32_shlib (); | |
4162 | 687 #elif defined (HAVE_DYLD_API) |
688 return new octave_dyld_shlib (); | |
3326 | 689 #else |
690 return new octave_base_shlib (); | |
691 #endif | |
692 } | |
693 | |
694 /* | |
695 ;;; Local Variables: *** | |
696 ;;; mode: C++ *** | |
697 ;;; End: *** | |
698 */ |