Mercurial > hg > octave-nkf
annotate libinterp/octave-value/ov-mex-fcn.cc @ 19840:c5270263d466 gui-release
close gui-release branch
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Jan 2015 17:41:50 -0500 |
parents | 91cd85a75705 |
children | 76478d2da117 |
rev | line source |
---|---|
5864 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
3 Copyright (C) 1996-2013 John W. Eaton |
5864 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
5864 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
5864 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "oct-shlib.h" | |
28 | |
29 #include <defaults.h> | |
30 #include "dynamic-ld.h" | |
31 #include "error.h" | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7872
diff
changeset
|
32 #include "gripes.h" |
5864 | 33 #include "oct-obj.h" |
34 #include "ov-mex-fcn.h" | |
35 #include "ov.h" | |
12783
ad9263d965dc
First experimental profiler implementation with flat profile.
Daniel Kraft <d@domob.eu>
parents:
11523
diff
changeset
|
36 #include "profiler.h" |
5864 | 37 #include "toplev.h" |
38 #include "unwind-prot.h" | |
39 | |
40 DEFINE_OCTAVE_ALLOCATOR (octave_mex_function); | |
41 | |
42 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_mex_function, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
43 "mex function", "mex function"); |
5864 | 44 |
45 octave_mex_function::octave_mex_function | |
46 (void *fptr, bool fmex, const octave_shlib& shl, | |
47 const std::string& nm) | |
6068 | 48 : octave_function (nm), mex_fcn_ptr (fptr), exit_fcn_ptr (0), |
49 have_fmex (fmex), sh_lib (shl) | |
5864 | 50 { |
51 mark_fcn_file_up_to_date (time_parsed ()); | |
52 | |
53 std::string file_name = fcn_file_name (); | |
54 | |
55 system_fcn_file | |
56 = (! file_name.empty () | |
57 && Voct_file_dir == file_name.substr (0, Voct_file_dir.length ())); | |
58 } | |
59 | |
60 octave_mex_function::~octave_mex_function (void) | |
61 { | |
6068 | 62 if (exit_fcn_ptr) |
63 (*exit_fcn_ptr) (); | |
64 | |
7872 | 65 octave_dynamic_loader::remove_mex (my_name, sh_lib); |
5864 | 66 } |
67 | |
68 std::string | |
69 octave_mex_function::fcn_file_name (void) const | |
70 { | |
71 return sh_lib.file_name (); | |
72 } | |
73 | |
74 octave_time | |
75 octave_mex_function::time_parsed (void) const | |
76 { | |
77 return sh_lib.time_loaded (); | |
78 } | |
79 | |
80 octave_value_list | |
81 octave_mex_function::subsref (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
82 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
83 int nargout) |
5864 | 84 { |
85 octave_value_list retval; | |
86 | |
87 switch (type[0]) | |
88 { | |
89 case '(': | |
90 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
91 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5864 | 92 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
93 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
5864 | 94 } |
95 break; | |
96 | |
97 case '{': | |
98 case '.': | |
99 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
100 std::string nm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
101 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
5864 | 102 } |
103 break; | |
104 | |
105 default: | |
106 panic_impossible (); | |
107 } | |
108 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 // FIXME: perhaps there should be an |
5864 | 110 // octave_value_list::next_subsref member function? See also |
111 // octave_user_function::subsref. | |
112 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 // FIXME: Note that if a function call returns multiple |
5864 | 114 // values, and there is further indexing to perform, then we are |
115 // ignoring all but the first value. Is this really what we want to | |
116 // do? If it is not, then what should happen for stat("file").size, | |
117 // for exmaple? | |
118 | |
119 if (idx.size () > 1) | |
120 retval = retval(0).next_subsref (nargout, type, idx); | |
121 | |
122 return retval; | |
123 } | |
124 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
125 // FIXME: shouldn't this declaration be a header file somewhere? |
5864 | 126 extern octave_value_list |
6068 | 127 call_mex (bool have_fmex, void *f, const octave_value_list& args, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
128 int nargout, octave_mex_function *curr_mex_fcn); |
5864 | 129 |
130 octave_value_list | |
131 octave_mex_function::do_multi_index_op (int nargout, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
132 const octave_value_list& args) |
5864 | 133 { |
134 octave_value_list retval; | |
135 | |
136 if (error_state) | |
137 return retval; | |
138 | |
139 if (args.has_magic_colon ()) | |
140 ::error ("invalid use of colon in function argument list"); | |
141 else | |
142 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
143 unwind_protect frame; |
5864 | 144 |
145 octave_call_stack::push (this); | |
146 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9396
diff
changeset
|
147 frame.add_fcn (octave_call_stack::pop); |
5864 | 148 |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
149 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
150 { |
19520
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
17787
diff
changeset
|
151 BEGIN_PROFILER_BLOCK (octave_mex_function) |
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
17787
diff
changeset
|
152 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
153 retval = call_mex (have_fmex, mex_fcn_ptr, args, nargout, this); |
19520
91cd85a75705
Reduce profiling overhead using inlining and templates.
Julien Bect <julien.bect@supelec.fr>
parents:
17787
diff
changeset
|
154 |
12960
43d78e103984
Use macro to start profiler blocks.
Daniel Kraft <d@domob.eu>
parents:
12920
diff
changeset
|
155 END_PROFILER_BLOCK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
156 } |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
157 catch (octave_execution_exception) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
158 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
159 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
160 } |
5864 | 161 } |
162 | |
163 return retval; | |
164 } |