GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-dld-fcn.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include "file-ops.h"
31#include "oct-shlib.h"
32
33#include "defaults.h"
34#include "dynamic-ld.h"
35#include "error.h"
36#include "interpreter-private.h"
37#include "ovl.h"
38#include "ov-dld-fcn.h"
39#include "ov.h"
40
41
43 "dynamically-linked function",
44 "dynamically-linked function");
45
48 const std::string& nm, const std::string& ds)
49 : octave_builtin (ff, nm, ds), m_sh_lib (shl)
50{
52
53 std::string file_name = fcn_file_name ();
54
55 static const std::string canonical_oct_file_dir
57 static const std::string oct_file_dir
58 = canonical_oct_file_dir.empty () ? octave::config::oct_file_dir ()
59 : canonical_oct_file_dir;
60
62 = (! file_name.empty ()
63 && oct_file_dir == file_name.substr (0, oct_file_dir.length ()));
64}
65
68 const std::string& nm, const std::string& ds)
69 : octave_builtin (mm, nm, ds), m_sh_lib (shl)
70{
72
73 std::string file_name = fcn_file_name ();
74
75 static const std::string canonical_oct_file_dir
77 static const std::string oct_file_dir
78 = canonical_oct_file_dir.empty () ? octave::config::oct_file_dir ()
79 : canonical_oct_file_dir;
80
82 = (! file_name.empty ()
83 && oct_file_dir == file_name.substr (0, oct_file_dir.length ()));
84}
85
87{
88 octave::dynamic_loader& dyn_loader
89 = octave::__get_dynamic_loader__ ("~octave_dld_function");
90
91 dyn_loader.remove_oct (m_name, m_sh_lib);
92}
93
94std::string
96{
97 return m_sh_lib.file_name ();
98}
99
102{
103 return m_sh_lib.time_loaded ();
104}
105
106// Note: this wrapper around the octave_dld_function constructor is
107// necessary to work around a MSVC limitation handling in
108// virtual destructors that prevents unloading a dynamic module
109// before *all* objects (of class using a virtual dtor) have
110// been fully deleted; indeed, MSVC attaches auto-generated code
111// (scalar deleting destructor) to objects created in a dynamic
112// module, and this code will be executed in the dynamic module
113// context at object deletion; unloading the dynamic module
114// before objects have been deleted will make the "delete" code
115// of objects to point to an invalid code segment.
116
119 const octave::dynamic_library& shl,
120 const std::string& nm, const std::string& ds)
121{
122 return new octave_dld_function (ff, shl, nm, ds);
123}
124
127 const octave::dynamic_library& shl,
128 const std::string& nm, const std::string& ds)
129{
130 return new octave_dld_function (mm, shl, nm, ds);
131}
sys::time time_loaded(void) const
Definition: oct-shlib.h:202
std::string file_name(void) const
Definition: oct-shlib.h:199
bool remove_oct(const std::string &fcn_name, dynamic_library &shl)
Definition: dynamic-ld.cc:267
octave_value_list(* fcn)(const octave_value_list &, int)
Definition: ov-builtin.h:62
octave_value_list(* meth)(octave::interpreter &, const octave_value_list &, int)
Definition: ov-builtin.h:59
octave::sys::time time_parsed(void) const
Definition: ov-dld-fcn.cc:101
octave_dld_function(void)
Definition: ov-dld-fcn.h:50
std::string fcn_file_name(void) const
Definition: ov-dld-fcn.cc:95
~octave_dld_function(void)
Definition: ov-dld-fcn.cc:86
void mark_fcn_file_up_to_date(const octave::sys::time &t)
Definition: ov-dld-fcn.h:72
octave::dynamic_library m_sh_lib
Definition: ov-dld-fcn.h:101
static octave_dld_function * create(octave_builtin::fcn ff, const octave::dynamic_library &shl, const std::string &nm="", const std::string &ds="")
Definition: ov-dld-fcn.cc:118
std::string m_name
Definition: ov-fcn.h:266
std::string oct_file_dir(void)
Definition: defaults.cc:283
std::string canonicalize_file_name(const std::string &name)
Definition: file-ops.cc:688
dynamic_loader & __get_dynamic_loader__(const std::string &who)
#define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c)
Definition: ov-base.h:222