annotate liboctave/util/oct-shlib.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents 076e19eac74a
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29572
diff changeset
3 // Copyright (C) 1999-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21236
diff changeset
27 # include "config.h"
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
28 #endif
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
29
30749
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
30 #include <list>
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
31 #include <map>
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7520
diff changeset
32
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
33 extern "C"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
34 {
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
35 #if defined (HAVE_DLOPEN_API)
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
36 # if defined (HAVE_DLFCN_H)
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
37 # include <dlfcn.h>
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
38 # else
23446
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
39 extern void * dlopen (const char *, int);
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
40 extern const char * dlerror (void);
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
41 extern void * dlsym (void *, const char *);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
42 extern int dlclose (void *);
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
43 # endif
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
44 #elif defined (HAVE_LOADLIBRARY_API)
21213
f7d1050b9b53 maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents: 21202
diff changeset
45 # 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
46 # include <windows.h>
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
47 # include <psapi.h>
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
48 #endif
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
49 }
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
50
22146
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
51 #include "file-ops.h"
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
52 #include "file-stat.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
53 #include "lo-error.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
54 #include "oct-shlib.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
55 #include "str-vec.h"
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
56
25524
366d4b8f6668 Fix loading of shared libraries from paths with non-ASCII chars on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
57 #if defined (HAVE_LOADLIBRARY_API)
366d4b8f6668 Fix loading of shared libraries from paths with non-ASCII chars on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
58 # include "lo-sysdep.h"
366d4b8f6668 Fix loading of shared libraries from paths with non-ASCII chars on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
59 #endif
366d4b8f6668 Fix loading of shared libraries from paths with non-ASCII chars on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25103
diff changeset
60
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30749
diff changeset
61 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30749
diff changeset
62
30749
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
63 std::list<dynamic_library> possibly_unreferenced_dynamic_libraries;
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
64
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
65 void dynamic_library::delete_later (void)
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
66 {
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
67 possibly_unreferenced_dynamic_libraries.push_back (*this);
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
68 }
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
69
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
70 int release_unreferenced_dynamic_libraries (void)
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
71 {
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
72 possibly_unreferenced_dynamic_libraries.clear ();
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
73
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
74 return 0;
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
75 }
076e19eac74a allow deletion of dynamic_library objects to be delayed
John W. Eaton <jwe@octave.org>
parents: 30727
diff changeset
76
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
77 dynamic_library::dynlib_rep::dynlib_rep (const std::string& f)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
78 : m_count (1), m_fcn_names (), m_file (f), m_time_loaded (),
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
79 m_search_all_loaded (false)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
80 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
81 s_instances[f] = this;
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
82
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
83 if (is_out_of_date ())
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
84 (*current_liboctave_warning_with_id_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
85 ("Octave:warn-future-time-stamp",
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
86 "timestamp on file %s is in the future", m_file.c_str ());
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
87 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
88
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
89 bool
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
90 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
91 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
92 sys::file_stat fs (m_file);
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
93 return (fs && fs.is_newer (m_time_loaded));
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
94 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
95
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
96 void
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
97 dynamic_library::dynlib_rep::fake_reload (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
98 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
99 // We can't actually reload the library, but we'll pretend we did.
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
100 sys::file_stat fs (m_file);
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
101 if (fs && fs.is_newer (m_time_loaded))
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
102 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
103 m_time_loaded = fs.mtime ();
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
104
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
105 (*current_liboctave_warning_with_id_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
106 ("Octave:library-reload",
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
107 "library %s not reloaded due to existing references", m_file.c_str ());
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
108 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
109 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
110
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
111 dynamic_library::dynlib_rep *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
112 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
113 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23446
diff changeset
114 dynlib_rep *retval = nullptr;
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
115 std::map<std::string, dynlib_rep *>::iterator p = s_instances.find (f);
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
116 if (p != s_instances.end ())
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
117 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
118 retval = p->second;
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
119 retval->m_count++;
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
120 if (fake)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
121 retval->fake_reload ();
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
122 }
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 retval = new_instance (f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
125
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
126 return retval;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
127 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
128
23554
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
129 std::list<std::string>
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
130 dynamic_library::dynlib_rep::function_names (void) const
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
131 {
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
132 std::list<std::string> retval;
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
133
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
134 for (const auto& p : m_fcn_names)
23554
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
135 retval.push_back (p.first);
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
136
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
137 return retval;
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
138 }
b075b1629c26 don't use hook function in dynamic_library::dynlib_rep::close function
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
139
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
140 void
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
141 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
142 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
143 auto p = m_fcn_names.find (name);
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
144
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
145 if (p == m_fcn_names.end ())
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
146 m_fcn_names[name] = 1;
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
147 else
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
148 ++(p->second);
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
149 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
150
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
151 bool
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
152 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
153 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
154 bool retval = false;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
155
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
156 auto p = m_fcn_names.find (fcn_name);
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
157
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
158 if (p != m_fcn_names.end () && --(p->second) == 0)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
159 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
160 m_fcn_names.erase (fcn_name);
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
161 retval = true;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
162 }
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 return retval;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
165 }
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
166
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
167 std::map<std::string, dynamic_library::dynlib_rep *>
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
168 dynamic_library::dynlib_rep::s_instances;
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
169
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
170 dynamic_library::dynlib_rep dynamic_library::s_nil_rep;
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
171
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
172 #if defined (HAVE_DLOPEN_API)
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 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
175 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
176 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
177 public:
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 octave_dlopen_shlib (const std::string& f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
180
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
181 // No copying!
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
182
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
183 octave_dlopen_shlib (const octave_dlopen_shlib&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
184
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
185 octave_dlopen_shlib& operator = (const octave_dlopen_shlib&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
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 (void);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
188
23446
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
189 void * search (const std::string& name,
28057
b3701ea5a48d use std::function object for passing name mangler to search function
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
190 const dynamic_library::name_mangler& mangler
b3701ea5a48d use std::function object for passing name mangler to search function
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
191 = dynamic_library::name_mangler ());
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
192
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
193 // 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
194 // normally throw an exception, avoiding the construction of an invalid
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22323
diff changeset
195 // library. Leave it here for possible future use.
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
196
24656
cd79f32fba85 Fix errors in changeset f0de21a6a426 (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24653
diff changeset
197 bool is_open (void) const
cd79f32fba85 Fix errors in changeset f0de21a6a426 (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24653
diff changeset
198 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
199 return (m_search_all_loaded || m_library != nullptr);
24656
cd79f32fba85 Fix errors in changeset f0de21a6a426 (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24653
diff changeset
200 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
201
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
202 private:
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
203
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
204 void *m_library;
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
205 };
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
206
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
207 octave_dlopen_shlib::octave_dlopen_shlib (const std::string& f)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
208 : dynamic_library::dynlib_rep (f), m_library (nullptr)
21750
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 int flags = 0;
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 // 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
213 // 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
214 // 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
215 // 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
216 # if defined (RTLD_NOW)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
217 flags |= RTLD_NOW;
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
218 # endif
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
219
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
220 // 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
221 // 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
222 # if defined (RTLD_GLOBAL)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
223 flags |= RTLD_GLOBAL;
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 21136
diff changeset
224 # endif
20493
3f01c585f54e oct-shlib.cc: Use RTLD_GLOBAL option for dlopen
Mike Miller <mtmiller@octave.org>
parents: 19697
diff changeset
225
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
226 if (m_file.empty ())
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
227 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
228 m_search_all_loaded = true;
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
229 return;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
230 }
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
231
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
232 m_library = dlopen (m_file.c_str (), flags);
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
233
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
234 if (! m_library)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
235 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
236 const char *msg = dlerror ();
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
237
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
238 if (msg)
30727
bfff3d523690 oct-shlib.cc: Clarify error message if loading library failed.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
239 (*current_liboctave_error_handler)
bfff3d523690 oct-shlib.cc: Clarify error message if loading library failed.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
240 ("%s: failed to load\nIncompatible version or missing dependency?"
bfff3d523690 oct-shlib.cc: Clarify error message if loading library failed.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
241 "\n%s", m_file.c_str (), msg);
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
242 else
30727
bfff3d523690 oct-shlib.cc: Clarify error message if loading library failed.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
243 (*current_liboctave_error_handler)
bfff3d523690 oct-shlib.cc: Clarify error message if loading library failed.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
244 ("%s: failed to load\nIncompatible version or missing dependency?",
bfff3d523690 oct-shlib.cc: Clarify error message if loading library failed.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30564
diff changeset
245 m_file.c_str ());
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
246 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
247 }
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 octave_dlopen_shlib::~octave_dlopen_shlib (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
250 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
251 if (m_library)
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
252 dlclose (m_library);
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
253 }
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 void *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
256 octave_dlopen_shlib::search (const std::string& name,
28057
b3701ea5a48d use std::function object for passing name mangler to search function
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
257 const dynamic_library::name_mangler& mangler)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
258 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23446
diff changeset
259 void *function = nullptr;
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
260
24656
cd79f32fba85 Fix errors in changeset f0de21a6a426 (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24653
diff changeset
261 if (! is_open ())
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
262 (*current_liboctave_error_handler)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
263 ("shared library %s is not open", m_file.c_str ());
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 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
266
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
267 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
268 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
269
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
270 if (m_search_all_loaded)
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
271 function = dlsym (RTLD_DEFAULT, sym_name.c_str ());
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
272 else
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
273 function = dlsym (m_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
274
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
275 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
276 }
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
277
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
278 #elif defined (HAVE_LOADLIBRARY_API)
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
279
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
280 class
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
281 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
282 {
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
283 public:
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
284
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
285 octave_w32_shlib (const std::string& f);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
286
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
287 // No copying!
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
288
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
289 octave_w32_shlib (const octave_w32_shlib&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
290
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
291 octave_w32_shlib& operator = (const octave_w32_shlib&) = delete;
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
292
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
293 ~octave_w32_shlib (void);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
294
23446
cd4e1ee28716 maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
295 void * search (const std::string& name,
28057
b3701ea5a48d use std::function object for passing name mangler to search function
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
296 const dynamic_library::name_mangler& mangler
b3701ea5a48d use std::function object for passing name mangler to search function
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
297 = dynamic_library::name_mangler ());
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
298
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
299 void * global_search (const std::string& sym_name);
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
300
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
301 bool is_open (void) const
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
302 {
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
303 return (m_search_all_loaded || m_handle != nullptr);
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
304 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
305
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
306 private:
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
307
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
308 HINSTANCE m_handle;
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
309 };
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
310
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
311 octave_w32_shlib::octave_w32_shlib (const std::string& f)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
312 : dynamic_library::dynlib_rep (f), m_handle (nullptr)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
313 {
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
314 if (f.empty())
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
315 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
316 m_search_all_loaded = true;
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
317 return;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
318 }
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
319
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23554
diff changeset
320 std::string dir = sys::file_ops::dirname (f);
28175
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28057
diff changeset
321 std::wstring wdir = sys::u8_to_wstring (dir);
27700
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
322 SetDllDirectoryW (dir.empty ()
28175
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28057
diff changeset
323 ? nullptr : wdir.c_str ());
22146
ef91e43f162a set DLL directory when loading DLLs on Windows systems (bug #48511)
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
324
28175
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28057
diff changeset
325 std::wstring wfile = sys::u8_to_wstring (m_file);
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28057
diff changeset
326 m_handle = LoadLibraryW (wfile.c_str ());
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
327
27700
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
328 SetDllDirectoryW (nullptr);
22157
c5842206aaea maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22146
diff changeset
329
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
330 if (! m_handle)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
331 {
27700
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
332 DWORD last_error = GetLastError ();
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
333
27700
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
334 wchar_t *error_text = nullptr;
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
335 FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
336 FORMAT_MESSAGE_ALLOCATE_BUFFER |
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
337 FORMAT_MESSAGE_IGNORE_INSERTS,
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
338 nullptr, last_error,
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
339 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
340 reinterpret_cast <wchar_t *> (&error_text), 0, nullptr);
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
341
27706
847dece1ae10 Include error number in message if library loading fails (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27700
diff changeset
342 std::ostringstream err_str;
847dece1ae10 Include error number in message if library loading fails (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27700
diff changeset
343 err_str << "opening the library '" << m_file << "' failed (error "
847dece1ae10 Include error number in message if library loading fails (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27700
diff changeset
344 << last_error << "): ";
27700
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
345 if (error_text != nullptr)
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
346 {
27706
847dece1ae10 Include error number in message if library loading fails (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27700
diff changeset
347 err_str << sys::u8_from_wstring (error_text);
27700
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
348 LocalFree (error_text);
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
349 }
6455c82d5180 When loading a library display error message from OS on Windows (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27379
diff changeset
350 else
27706
847dece1ae10 Include error number in message if library loading fails (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27700
diff changeset
351 err_str << "Unknown error.";
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9493
diff changeset
352
27706
847dece1ae10 Include error number in message if library loading fails (bug #57202).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27700
diff changeset
353 (*current_liboctave_error_handler) ("%s", err_str.str ().c_str ());
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
354 }
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
355 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
356
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
357 octave_w32_shlib::~octave_w32_shlib (void)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
358 {
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
359 if (m_handle)
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
360 FreeLibrary (m_handle);
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
361 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
362
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
363 void *
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
364 octave_w32_shlib::global_search (const std::string& sym_name)
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
365 {
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
366 void *function = nullptr;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
367
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
368 HANDLE proc = GetCurrentProcess ();
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
369
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
370 if (! proc)
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
371 (*current_liboctave_error_handler)
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
372 ("Unable to get handle to own process.");
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
373
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
374 std::size_t lib_num = 64;
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
375 std::size_t size_lib = sizeof (HMODULE);
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
376 HMODULE *h_libs;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
377 DWORD bytes_all_libs;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
378 bool got_libs;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
379
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
380 // Get a list of all the libraries in own process.
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
381 h_libs = static_cast<HMODULE *> (malloc (size_lib*lib_num));
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
382 got_libs = EnumProcessModules (proc, h_libs, size_lib*lib_num,
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
383 &bytes_all_libs);
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
384 int ii = 0;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
385 while (((size_lib*lib_num) < bytes_all_libs) && ii++ < 3)
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
386 {
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
387 lib_num = bytes_all_libs / size_lib;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
388 h_libs = static_cast<HMODULE *> (realloc (h_libs, bytes_all_libs));
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
389 got_libs = EnumProcessModules (proc, h_libs, bytes_all_libs,
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
390 &bytes_all_libs);
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
391 }
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
392
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
393 if (got_libs)
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
394 {
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
395 for (std::size_t i = 0; i < (bytes_all_libs / size_lib); i++)
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
396 {
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
397 // Check for function in library.
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
398 function = reinterpret_cast<void *>
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
399 (GetProcAddress (h_libs[i], sym_name.c_str ()));
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
400
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
401 if (function)
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
402 break;
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
403 }
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
404 }
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
405
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
406 // Release the handle to the process.
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
407 CloseHandle (proc);
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
408
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
409 return function;
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
410 }
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
411
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
412 void *
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
413 octave_w32_shlib::search (const std::string& name,
28057
b3701ea5a48d use std::function object for passing name mangler to search function
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
414 const dynamic_library::name_mangler& mangler)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
415 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23446
diff changeset
416 void *function = nullptr;
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
417
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
418 if (! m_search_all_loaded && ! is_open ())
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
419 (*current_liboctave_error_handler)
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
420 ("shared library %s is not open", m_file.c_str ());
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
421
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
422 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
423
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
424 if (mangler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
425 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
426
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
427 if (m_search_all_loaded)
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
428 function = global_search (sym_name);
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
429 else
27379
3db033e86376 use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents: 26604
diff changeset
430 function = reinterpret_cast<void *> (GetProcAddress (m_handle,
24653
f0de21a6a426 Use new LAPACK functions in gsvd if available (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
431 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
432
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
433 return function;
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
434 }
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
435
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
436 #endif
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
437
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
438 dynamic_library::dynlib_rep *
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
439 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
440 {
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
441 #if defined (HAVE_DLOPEN_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
442 return new octave_dlopen_shlib (f);
4110
b9238356dd07 [project @ 2002-10-17 16:14:44 by jwe]
jwe
parents: 4051
diff changeset
443 #elif defined (HAVE_LOADLIBRARY_API)
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
444 return new octave_w32_shlib (f);
3326
c19f4b9484af [project @ 1999-10-29 21:52:12 by jwe]
jwe
parents:
diff changeset
445 #else
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
446 (*current_liboctave_error_handler)
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
447 ("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
448 #endif
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
449 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30749
diff changeset
450
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30749
diff changeset
451 OCTAVE_END_NAMESPACE(octave)