annotate src/dynamic-ld.cc @ 13983:7dd7cccf0757

clean up memory allocated for singletons before exit * singleton-cleanup.h, singleton-cleanup.cc: New files. * liboctave/Makefile.am (INCS, LIBOCTAVE_CXX_SOURCES): Add them to the lists. * toplev.cc (clean_up_and_exit): Call singleton_cleanup_list::cleanup. * debug.h, debug.cc (bp_table::instance_ok): Move definition to debug.cc. * coment-list.h (octave_comment_buffer::~octave_comment_buffer): Define destructor for class. * ov-typeinfo.h (octave_value_typeinfo::~octave_value_typeinfo): Likewise. * cmd-edit.h (command_editor::cleanup_instance): New function. * cmd-hist.h (command_history::cleanup_instance): New function. * file-ops.h (file_ops::cleanup_instance): New function. * mach-info.h (oct_mach_info::cleanup_instance): New function. * oct-env.h (octave_env::cleanup_instance): New function. * oct-fftw.h (octave_fftw_planner::cleanup_instance): New function. * oct-rand.h (octave_rand::cleanup_instance): New function. * oct-spparms.h (octave_sparse_params::cleanup_instance): New function. * pathsearch.h (static_members::cleanup_instance): New function. * comment-list.h (octave_comment_buffer::cleanup_instance): New function. * debug.h (bp_table::cleanup_instance): New function. * display.h (display_info::cleanup_instance): New function. * dynamic-ld.cc (octave_shlib_list::cleanup_instance, octave_mex_file_list::cleanup_instance): New functions. * dynamic-ld.h (octave_dynamic_loader::cleanup_instance): New function. * load-path.h (load_path::cleanup_instance): New function. * oct-stream.h (octave_stream_list::cleanup_instance): New function. * ov-typeinfo.h (octave_value_typeinfo::cleanup_instance): New function. * pager.h, pager.cc (octave_pager_stream::instance_ok, octave_pager_stream::cleanup_instance): New functions. (octave_diary_stream::instance_ok, octave_diary_stream::cleanup_instance): New functions. * sighandlers.h (octave_child_list::cleanup_instance): New function. * toplev.h (octave_call_stack * pager.cc (octave_pager_stream::stream, octave_diary_stream::stream): Use instance_ok to create instance. * toplev.h (octave_call_stack::cleanup_instance): New function. * cmd-edit.cc (command_editor::instance_ok): Register cleanup function. * cmd-hist.cc (command_history::instance_ok): Likewise. * file-ops.cc (file_ops::instance_ok): Likewise. * mach-info.cc (oct_mach_info::instance_ok): Likewise. * oct-env.cc (octave_env::instance_ok): Likewise. * oct-fftw.cc (octave_fftw_planner::instance_ok): Likewise. * oct-rand.cc (octave_rand::instance_ok): Likewise. * oct-spparms.cc (octave_sparse_params::instance_ok): Likewise. * pathsearch.cc (dir_path::static_members::instance_ok): Likewise. * comment-list.cc (comment_list::instance_ok): Likewise. * debug.cc (bp_table::instance_ok): Likewise. * display.cc (display_info::instance_ok): Likewise. * dynamic-ld.cc (octave_shlib_list::instance_ok, octave_mex_file_list::instance_ok, octave_dynamic_loader): Likewise. * load-path.cc (load_path::instance_ok): Likewise. * oct-stream.cc (octave_stream_list::instance_ok): Likewise. * ov-typeinfo.cc (octave_value_typeinfo::instance_ok): Likewise. * sighandlers.cc (octave_child_list::instance_ok): Likewise. * symtab.h, symtab.cc (symbol_table::scope_id::create_instance): New function. * symtab.h (symbol_table::scope_id::instance_ok): Call create_instance. * toplev.h, toplev.cc (octave_call_stack::create_instance): New function. * toplev.cc (octave_call_stack::instance_ok): Call create_instance. * pager.h, pager.cc (octave_pager_stream::set_diary_skip, octave_pager_stream::flush_current_contents_to_diary): Now static. octave_pager_stream::do_set_diary_skip, octave_pager_stream::do_flush_current_contents_to_diary): New functions. (octave_pager_stream::stream): Return std::ostream&, not octave_pager_stream&. If instance creation fails, return std::cout. (octave_diary_stream::stream): Return std::ostream&, not octave_diary_stream&. If instance creation fails, return std::cout. (octave_pager_stream::do_reset, octave_diary_stream::do_reset): Use instance_ok to create instance.
author John W. Eaton <jwe@octave.org>
date Sat, 03 Dec 2011 04:34:17 -0500
parents 12df7854fa7c
children 72c96de7a403
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10315
diff changeset
3 Copyright (C) 1993-2011 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6323
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6323
diff changeset
10 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6323
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6323
diff changeset
19 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 184
diff changeset
23 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1155
diff changeset
24 #include <config.h>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
8950
d865363208d6 include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
27 #include <iostream>
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4009
diff changeset
28 #include <list>
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4009
diff changeset
29
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
30 #include "file-stat.h"
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
31 #include "oct-env.h"
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
32 #include "oct-time.h"
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
33 #include "singleton-cleanup.h"
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
34
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2370
diff changeset
35 #include <defaults.h>
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
36
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
37 #include "defun.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
38 #include "dynamic-ld.h"
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
39 #include "ov-fcn.h"
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
40 #include "ov-dld-fcn.h"
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
41 #include "ov-mex-fcn.h"
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
42 #include "parse.h"
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
43 #include "unwind-prot.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
44 #include "utils.h"
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
45 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
46
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
47 #define STRINGIFY(s) STRINGIFY1(s)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
48 #define STRINGIFY1(s) #s
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
49
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
50 class
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
51 octave_shlib_list
1664
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
52 {
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
53 public:
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
54
7748
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
55 typedef std::list<octave_shlib>::iterator iterator;
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
56 typedef std::list<octave_shlib>::const_iterator const_iterator;
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
57
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
58 static void append (const octave_shlib& shl);
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
59
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
60 static void remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0);
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
61
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
62 static octave_shlib find_file (const std::string& file_name);
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
63
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
64 static void display (void);
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
65
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
66 private:
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
67
11584
cda4aa780d58 Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11523
diff changeset
68 octave_shlib_list (void) : lib_list () { }
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
69
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
70 ~octave_shlib_list (void) { }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
71
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
72 void do_append (const octave_shlib& shl);
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
73
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
74 void do_remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0);
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
75
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
76 octave_shlib do_find_file (const std::string& file_name) const;
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
77
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
78 void do_display (void) const;
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
79
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
80 static octave_shlib_list *instance;
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
81
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
82 static void cleanup_instance (void) { delete instance; instance = 0; }
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
83
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
84 static bool instance_ok (void);
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
85
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
86 // List of libraries we have loaded.
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4009
diff changeset
87 std::list<octave_shlib> lib_list;
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
88
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
89 // No copying!
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
90
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
91 octave_shlib_list (const octave_shlib_list&);
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
92
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
93 octave_shlib_list& operator = (const octave_shlib_list&);
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
94 };
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
95
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
96 octave_shlib_list *octave_shlib_list::instance = 0;
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3222
diff changeset
97
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
98 void
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
99 octave_shlib_list::do_append (const octave_shlib& shl)
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
100 {
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4009
diff changeset
101 lib_list.push_back (shl);
1664
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
102 }
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
103
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
104 void
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
105 octave_shlib_list::do_remove (octave_shlib& shl,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
106 octave_shlib::close_hook cl_hook)
1664
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
107 {
7748
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
108 for (iterator p = lib_list.begin (); p != lib_list.end (); p++)
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
109 {
4219
23d06c9e1edd [project @ 2002-12-06 21:29:17 by jwe]
jwe
parents: 4009
diff changeset
110 if (*p == shl)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
111 {
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
112 // Erase first to avoid potentially invalidating the pointer by the
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
113 // following hooks.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
114 lib_list.erase (p);
1664
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
115
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
116 shl.close (cl_hook);
3033
968e85a82e25 [project @ 1997-06-05 16:50:05 by jwe]
jwe
parents: 2994
diff changeset
117
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
118 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
119 }
1664
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
120 }
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
121 }
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
122
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
123 octave_shlib
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
124 octave_shlib_list::do_find_file (const std::string& file_name) const
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
125 {
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
126 octave_shlib retval;
1664
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
127
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
128 for (const_iterator p = lib_list.begin (); p != lib_list.end (); p++)
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
129 {
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
130 if (p->file_name () == file_name)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
131 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
132 retval = *p;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
133 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
134 }
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
135 }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
136
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
137 return retval;
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
138 }
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
139
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
140 void
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
141 octave_shlib_list::do_display (void) const
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
142 {
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
143 std::cerr << "current shared libraries:" << std::endl;
7748
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
144 for (const_iterator p = lib_list.begin (); p != lib_list.end (); p++)
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
145 std::cerr << " " << p->file_name () << std::endl;
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
146 }
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
147
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
148 bool
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
149 octave_shlib_list::instance_ok (void)
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
150 {
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
151 bool retval = true;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
152
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
153 if (! instance)
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
154 {
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
155 instance = new octave_shlib_list ();
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
156
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
157 if (instance)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
158 singleton_cleanup_list::add (cleanup_instance);
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
159 }
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
160
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
161 if (! instance)
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
162 {
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
163 ::error ("unable to create shared library list object!");
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
164
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
165 retval = false;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
166 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
167
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
168 return retval;
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
169 }
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
170
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2895
diff changeset
171 void
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
172 octave_shlib_list::append (const octave_shlib& shl)
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
173 {
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
174 if (instance_ok ())
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
175 instance->do_append (shl);
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
176 }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
177
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
178 void
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
179 octave_shlib_list::remove (octave_shlib& shl,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
180 octave_shlib::close_hook cl_hook)
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
181 {
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
182 if (instance_ok ())
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
183 instance->do_remove (shl, cl_hook);
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
184 }
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
185
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
186 octave_shlib
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
187 octave_shlib_list::find_file (const std::string& file_name)
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
188 {
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
189 return (instance_ok ())
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
190 ? instance->do_find_file (file_name) : octave_shlib ();
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
191 }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
192
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
193 void
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
194 octave_shlib_list::display (void)
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
195 {
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
196 if (instance_ok ())
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
197 instance->do_display ();
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
198 }
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
199
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
200 class
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
201 octave_mex_file_list
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
202 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
203 public:
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
204
7748
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
205 typedef std::list<octave_shlib>::iterator iterator;
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
206 typedef std::list<octave_shlib>::const_iterator const_iterator;
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
207
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
208 static void append (const octave_shlib& shl);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
209
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
210 static void remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
211
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
212 private:
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
213
11584
cda4aa780d58 Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11523
diff changeset
214 octave_mex_file_list (void) : file_list () { }
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
215
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
216 ~octave_mex_file_list (void) { }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
217
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
218 void do_append (const octave_shlib& shl);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
219
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
220 void do_remove (octave_shlib& shl, octave_shlib::close_hook cl_hook = 0);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
221
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
222 static octave_mex_file_list *instance;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
223
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
224 static void cleanup_instance (void) { delete instance; instance = 0; }
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
225
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
226 static bool instance_ok (void);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
227
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
228 // List of libraries we have loaded.
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
229 std::list<octave_shlib> file_list;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
230
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
231 // No copying!
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
232
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
233 octave_mex_file_list (const octave_mex_file_list&);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
234
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
235 octave_mex_file_list& operator = (const octave_mex_file_list&);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
236 };
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
237
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
238 octave_mex_file_list *octave_mex_file_list::instance = 0;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
239
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
240 void
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
241 octave_mex_file_list::do_append (const octave_shlib& shl)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
242 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
243 file_list.push_back (shl);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
244 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
245
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
246 void
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
247 octave_mex_file_list::do_remove (octave_shlib& shl,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
248 octave_shlib::close_hook cl_hook)
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
249 {
7748
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
250 for (iterator p = file_list.begin (); p != file_list.end (); p++)
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
251 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
252 if (*p == shl)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
253 {
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
254 // Erase first to avoid potentially invalidating the pointer by the
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
255 // following hooks.
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
256 file_list.erase (p);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
257
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
258 shl.close (cl_hook);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
259
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
260 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
261 }
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
262 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
263 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
264
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
265 bool
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
266 octave_mex_file_list::instance_ok (void)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
267 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
268 bool retval = true;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
269
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
270 if (! instance)
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
271 {
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
272 instance = new octave_mex_file_list ();
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
273
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
274 if (instance)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
275 singleton_cleanup_list::add (cleanup_instance);
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
276 }
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
277
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
278 if (! instance)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
279 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
280 ::error ("unable to create shared library list object!");
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
281
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
282 retval = false;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
283 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
284
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
285 return retval;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
286 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
287
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
288 void
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
289 octave_mex_file_list::append (const octave_shlib& shl)
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
290 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
291 if (instance_ok ())
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
292 instance->do_append (shl);
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
293 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
294
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
295 void
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
296 octave_mex_file_list::remove (octave_shlib& shl,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
297 octave_shlib::close_hook cl_hook)
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
298 {
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
299 if (instance_ok ())
6063
8010902404b9 [project @ 2006-10-19 01:27:35 by jwe]
jwe
parents: 5864
diff changeset
300 instance->do_remove (shl, cl_hook);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
301 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
302
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
303 octave_dynamic_loader *octave_dynamic_loader::instance = 0;
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
304
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
305 bool octave_dynamic_loader::doing_load = false;
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
306
2969
1b47dd00a831 [project @ 1997-05-15 17:57:48 by jwe]
jwe
parents: 2926
diff changeset
307 bool
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
308 octave_dynamic_loader::instance_ok (void)
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
309 {
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
310 bool retval = true;
1664
913a157f1e02 [project @ 1995-12-24 07:00:22 by jwe]
jwe
parents: 1488
diff changeset
311
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
312 if (! instance)
13983
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
313 {
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
314 instance = new octave_dynamic_loader ();
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
315
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
316 if (instance)
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
317 singleton_cleanup_list::add (cleanup_instance);
7dd7cccf0757 clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
318 }
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
319
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
320 if (! instance)
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
321 {
3655
6324a4994278 [project @ 2000-04-03 21:06:26 by jwe]
jwe
parents: 3536
diff changeset
322 ::error ("unable to create dynamic loader object!");
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
323
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
324 retval = false;
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
325 }
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
326
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2862
diff changeset
327 return retval;
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2862
diff changeset
328 }
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2862
diff changeset
329
10287
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
330 static void
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
331 do_clear_function (const std::string& fcn_name)
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
332 {
5781
faafc2d98b8d [project @ 2006-05-02 19:40:19 by jwe]
jwe
parents: 5760
diff changeset
333 warning_with_id ("Octave:reload-forces-clear", " %s", fcn_name.c_str ());
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
334
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
335 symbol_table::clear_dld_function (fcn_name);
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
336 }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
337
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
338 static void
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
339 clear (octave_shlib& oct_file)
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
340 {
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
341 if (oct_file.number_of_functions_loaded () > 1)
10287
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
342 {
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
343 warning_with_id ("Octave:reload-forces-clear",
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
344 "reloading %s clears the following functions:",
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
345 oct_file.file_name().c_str ());
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
346
10287
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
347 octave_shlib_list::remove (oct_file, do_clear_function);
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
348 }
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
349 else
7c7685cc0676 fix reload warning for dynamically linked functions
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
350 octave_shlib_list::remove (oct_file, symbol_table::clear_dld_function);
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
351 }
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
352
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
353 octave_function *
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
354 octave_dynamic_loader::do_load_oct (const std::string& fcn_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
355 const std::string& file_name,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
356 bool relative)
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2862
diff changeset
357 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
358 octave_function *retval = 0;
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
359
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9958
diff changeset
360 unwind_protect frame;
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
361
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9958
diff changeset
362 frame.protect_var (octave_dynamic_loader::doing_load);
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
363
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
364 doing_load = true;
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
365
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
366 octave_shlib oct_file = octave_shlib_list::find_file (file_name);
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
367
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
368 if (oct_file && oct_file.is_out_of_date ())
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
369 clear (oct_file);
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
370
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
371 if (! oct_file)
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
372 {
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
373 oct_file.open (file_name);
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
374
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
375 if (! error_state && oct_file)
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
376 octave_shlib_list::append (oct_file);
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
377 }
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
378
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
379 if (! error_state)
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
380 {
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
381 if (oct_file)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
382 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
383 void *function = oct_file.search (fcn_name, name_mangler);
7996
6a7db240b3a3 configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents: 7872
diff changeset
384
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
385 if (! function)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
386 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
387 // FIXME -- can we determine this C mangling scheme
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
388 // automatically at run time or configure time?
7996
6a7db240b3a3 configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents: 7872
diff changeset
389
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
390 function = oct_file.search (fcn_name, name_uscore_mangler);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
391 }
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
392
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
393 if (function)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
394 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
395 octave_dld_fcn_getter f
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
396 = FCN_PTR_CAST (octave_dld_fcn_getter, function);
7748
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
397
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
398 retval = f (oct_file, relative);
7748
3dc91baee089 dynamic-ld.cc: cleanups
John W. Eaton <jwe@octave.org>
parents: 7745
diff changeset
399
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
400 if (! retval)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
401 ::error ("failed to install .oct file function `%s'",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
402 fcn_name.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
403 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
404 }
7749
14e05160b99f reference counting for functions loaded from shared libraries
John W. Eaton <jwe@octave.org>
parents: 7748
diff changeset
405 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
406 ::error ("%s is not a valid shared library",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
407 file_name.c_str ());
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
408 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11584
diff changeset
409
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
410 return retval;
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
411 }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
412
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
413 octave_function *
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
414 octave_dynamic_loader::do_load_mex (const std::string& fcn_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
415 const std::string& file_name,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
416 bool /*relative*/)
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
417 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
418 octave_function *retval = 0;
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
419
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9958
diff changeset
420 unwind_protect frame;
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
421
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9958
diff changeset
422 frame.protect_var (octave_dynamic_loader::doing_load);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
423
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
424 doing_load = true;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
425
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
426 octave_shlib mex_file = octave_shlib_list::find_file (file_name);
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
427
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
428 if (mex_file && mex_file.is_out_of_date ())
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
429 clear (mex_file);
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
430
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
431 if (! mex_file)
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
432 {
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
433 mex_file.open (file_name);
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
434
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
435 if (! error_state && mex_file)
9958
80432f0ee895 improve octave_shlib for safer shared libs treatment
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
436 octave_shlib_list::append (mex_file);
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
437 }
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
438
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
439 if (! error_state)
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
440 {
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
441 if (mex_file)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
442 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
443 void *function = 0;
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
444
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
445 bool have_fmex = false;
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
446
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
447 octave_mex_file_list::append (mex_file);
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
448
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
449 function = mex_file.search (fcn_name, mex_mangler);
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
450
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
451 if (! function)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
452 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
453 // FIXME -- can we determine this C mangling scheme
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
454 // automatically at run time or configure time?
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
455
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
456 function = mex_file.search (fcn_name, mex_uscore_mangler);
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
457
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
458 if (! function)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
459 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
460 function = mex_file.search (fcn_name, mex_f77_mangler);
6221
8e0f1eda266b [project @ 2007-01-03 17:23:33 by jwe]
jwe
parents: 6063
diff changeset
461
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
462 if (function)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
463 have_fmex = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
464 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
465 }
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
466
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
467 if (function)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
468 retval = new octave_mex_function (function, have_fmex,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
469 mex_file, fcn_name);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
470 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
471 ::error ("failed to install .mex file function `%s'",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
472 fcn_name.c_str ());
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
473 }
8832
9dddbad47122 automatically reload out of date mex files
John W. Eaton <jwe@octave.org>
parents: 7996
diff changeset
474 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
475 ::error ("%s is not a valid shared library",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
476 file_name.c_str ());
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
477 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
478
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
479 return retval;
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
480 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
481
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
482 bool
7872
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
483 octave_dynamic_loader::do_remove_oct (const std::string& fcn_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
484 octave_shlib& shl)
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
485 {
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
486 bool retval = false;
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
487
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
488 // We don't need to do anything if this is called because we are in
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
489 // the process of reloading a .oct file that has changed.
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
490
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
491 if (! doing_load)
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
492 {
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
493 retval = shl.remove (fcn_name);
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
494
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
495 if (shl.number_of_functions_loaded () == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
496 octave_shlib_list::remove (shl);
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
497 }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
498
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
499 return retval;
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
500 }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
501
7872
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
502 bool
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
503 octave_dynamic_loader::do_remove_mex (const std::string& fcn_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
504 octave_shlib& shl)
7872
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
505 {
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
506 bool retval = false;
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
507
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
508 // We don't need to do anything if this is called because we are in
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
509 // the process of reloading a .oct file that has changed.
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
510
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
511 if (! doing_load)
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
512 {
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
513 retval = shl.remove (fcn_name);
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
514
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
515 if (shl.number_of_functions_loaded () == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
516 octave_mex_file_list::remove (shl);
7872
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
517 }
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
518
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
519 return retval;
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
520 }
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
521
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
522 octave_function *
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
523 octave_dynamic_loader::load_oct (const std::string& fcn_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
524 const std::string& file_name,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
525 bool relative)
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
526 {
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
527 return (instance_ok ())
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
528 ? instance->do_load_oct (fcn_name, file_name, relative) : 0;
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
529 }
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
530
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
531 octave_function *
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
532 octave_dynamic_loader::load_mex (const std::string& fcn_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
533 const std::string& file_name,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
534 bool relative)
5864
e884ab4f29ee [project @ 2006-06-22 00:57:27 by jwe]
jwe
parents: 5854
diff changeset
535 {
6323
ea65de49e18e [project @ 2007-02-17 02:51:02 by jwe]
jwe
parents: 6221
diff changeset
536 return (instance_ok ())
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
537 ? instance->do_load_mex (fcn_name, file_name, relative) : 0;
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
538 }
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
539
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
540 bool
7872
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
541 octave_dynamic_loader::remove_oct (const std::string& fcn_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
542 octave_shlib& shl)
3325
2efa28a91e7a [project @ 1999-10-29 21:39:20 by jwe]
jwe
parents: 3321
diff changeset
543 {
7872
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
544 return (instance_ok ()) ? instance->do_remove_oct (fcn_name, shl) : false;
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
545 }
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
546
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
547 bool
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
548 octave_dynamic_loader::remove_mex (const std::string& fcn_name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10287
diff changeset
549 octave_shlib& shl)
7872
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
550 {
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
551 return (instance_ok ()) ? instance->do_remove_mex (fcn_name, shl) : false;
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2862
diff changeset
552 }
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
553
3536
e8fbc8c3d6d9 [project @ 2000-02-02 12:01:00 by jwe]
jwe
parents: 3534
diff changeset
554 std::string
7996
6a7db240b3a3 configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents: 7872
diff changeset
555 octave_dynamic_loader::name_mangler (const std::string& name)
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
556 {
7996
6a7db240b3a3 configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents: 7872
diff changeset
557 return "G" + name;
2894
f1c5f8151397 [project @ 1997-04-28 05:39:26 by jwe]
jwe
parents: 2893
diff changeset
558 }
707
d7c4962ec7a0 [project @ 1994-09-16 13:50:20 by jwe]
jwe
parents: 527
diff changeset
559
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
560 std::string
7996
6a7db240b3a3 configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents: 7872
diff changeset
561 octave_dynamic_loader::name_uscore_mangler (const std::string& name)
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
562 {
7996
6a7db240b3a3 configure.in: eliminate CXX_ABI and OCTAVE_CXX_PREPEND_UNDERSCORE
John W. Eaton <jwe@octave.org>
parents: 7872
diff changeset
563 return "_G" + name;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
564 }
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7017
diff changeset
565
7872
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
566 std::string
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
567 octave_dynamic_loader::mex_mangler (const std::string&)
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
568 {
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
569 return "mexFunction";
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
570 }
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
571
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
572 std::string
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
573 octave_dynamic_loader::mex_uscore_mangler (const std::string&)
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
574 {
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
575 return "_mexFunction";
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
576 }
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
577
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
578 std::string
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
579 octave_dynamic_loader::mex_f77_mangler (const std::string&)
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
580 {
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
581 return STRINGIFY (F77_FUNC (mexfunction, MEXFUNCTION));
1b63f8da772d fix unloading of mex files
John W. Eaton <jwe@octave.org>
parents: 7749
diff changeset
582 }