annotate pytave.cc @ 375:d0a7f66393fc

Fix __py_class_name__ tests to work with Python 2 * __py_struct_from_dict__.cc: Fix __py_class_name__ tests to work with Python 2.
author Mike Miller <mtmiller@octave.org>
date Fri, 26 Aug 2016 18:51:29 -0700
parents 43e92dd60dd0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
1 /*
139
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
2
150
a3dc9d24ae38 maint: Add myself to copyright notices
Mike Miller <mtmiller@octave.org>
parents: 146
diff changeset
3 Copyright (C) 2015-2016 Mike Miller
139
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
4 Copyright (C) 2008 David Grundberg, HÃ¥kan Fors Nilsson
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
5 Copyright (C) 2009 Jaroslav Hajek, VZLU Prague
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
6
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
7 This file is part of Pytave.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
8
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
9 Pytave is free software: you can redistribute it and/or modify it
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
10 under the terms of the GNU General Public License as published by the
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
11 Free Software Foundation, either version 3 of the License, or (at your
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
12 option) any later version.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
13
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
14 Pytave is distributed in the hope that it will be useful, but WITHOUT
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
17 for more details.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
18
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
19 You should have received a copy of the GNU General Public License
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
20 along with Pytave; see the file COPYING. If not, see
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
21 <http://www.gnu.org/licenses/>.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
22
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 132
diff changeset
23 */
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
24
132
386772f4e12d Clean up includes thanks to Octave header changes
Mike Miller <mtmiller@octave.org>
parents: 113
diff changeset
25 #if defined (HAVE_CONFIG_H)
386772f4e12d Clean up includes thanks to Octave header changes
Mike Miller <mtmiller@octave.org>
parents: 113
diff changeset
26 # include <config.h>
386772f4e12d Clean up includes thanks to Octave header changes
Mike Miller <mtmiller@octave.org>
parents: 113
diff changeset
27 #endif
386772f4e12d Clean up includes thanks to Octave header changes
Mike Miller <mtmiller@octave.org>
parents: 113
diff changeset
28
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
29 #include <boost/python.hpp>
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
30 #include <boost/python/numeric.hpp>
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
31
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
32 #include <octave/oct.h>
18
7a5fbc15fc6e Improved error messages from Octave.
David Grundberg <c04dgg@cs.umu.se>
parents: 14
diff changeset
33 #include <octave/oct-map.h>
13
dc8f6015f3e1 Use octave_main() to initiate Octave
David Grundberg <individ@acc.umu.se>
parents: 6
diff changeset
34 #include <octave/octave.h>
dc8f6015f3e1 Use octave_main() to initiate Octave
David Grundberg <individ@acc.umu.se>
parents: 6
diff changeset
35 #include <octave/ov.h>
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
36 #include <octave/parse.h>
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
37 #include <octave/symtab.h>
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
38 #include <octave/toplev.h>
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
39 #include <octave/utils.h>
196
43e92dd60dd0 build: include new <octave/call-stack.h> header if available
Mike Miller <mtmiller@octave.org>
parents: 171
diff changeset
40 #if defined (HAVE_OCTAVE_CALL_STACK_H)
43e92dd60dd0 build: include new <octave/call-stack.h> header if available
Mike Miller <mtmiller@octave.org>
parents: 171
diff changeset
41 # include <octave/call-stack.h>
43e92dd60dd0 build: include new <octave/call-stack.h> header if available
Mike Miller <mtmiller@octave.org>
parents: 171
diff changeset
42 #endif
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
43
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
44 #include <iostream>
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
45 #ifdef HAVE_USELOCALE
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
46 #include <locale.h>
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
47 #endif
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
48 #include <sstream>
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
49 #include <sys/types.h>
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
50
77
fb227ceacc65 ensure proper NumPy API init
Jaroslav Hajek <highegg@gmail.com>
parents: 74
diff changeset
51 #define PYTAVE_DO_DECLARE_SYMBOL
fb227ceacc65 ensure proper NumPy API init
Jaroslav Hajek <highegg@gmail.com>
parents: 74
diff changeset
52 #include "arrayobjectdefs.h"
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
53 #include "exceptions.h"
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
54 #include "octave_to_python.h"
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
55 #include "python_to_octave.h"
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
56
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
57 using namespace boost::python;
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
58
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
59 namespace pytave
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
60 {
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
61
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
62 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
63 locale_t c_locale;
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
64 #endif
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
65
113
6552040d6d4c pytave.cc: Second attempt to make return type Python 2 or 3 compatible
Mike Miller <mtmiller@octave.org>
parents: 111
diff changeset
66 #if defined (PYTHON_ABI_VERSION)
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
67 PyObject *
113
6552040d6d4c pytave.cc: Second attempt to make return type Python 2 or 3 compatible
Mike Miller <mtmiller@octave.org>
parents: 111
diff changeset
68 #else
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
69 void
113
6552040d6d4c pytave.cc: Second attempt to make return type Python 2 or 3 compatible
Mike Miller <mtmiller@octave.org>
parents: 111
diff changeset
70 #endif
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
71 init (bool silent = true)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
72 {
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
73 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
74 c_locale = newlocale (LC_ALL, "C", 0);
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
75 #endif
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
76
171
b8560f97e9bf Wrap custom exception initialization in a function
Mike Miller <mtmiller@octave.org>
parents: 167
diff changeset
77 if (! init_exceptions ())
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
78 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
79 PyErr_SetString (PyExc_ImportError, "_pytave: init failed");
113
6552040d6d4c pytave.cc: Second attempt to make return type Python 2 or 3 compatible
Mike Miller <mtmiller@octave.org>
parents: 111
diff changeset
80 #if defined (PYTHON_ABI_VERSION)
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
81 return 0;
113
6552040d6d4c pytave.cc: Second attempt to make return type Python 2 or 3 compatible
Mike Miller <mtmiller@octave.org>
parents: 111
diff changeset
82 #else
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
83 return;
113
6552040d6d4c pytave.cc: Second attempt to make return type Python 2 or 3 compatible
Mike Miller <mtmiller@octave.org>
parents: 111
diff changeset
84 #endif
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
85 }
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
86
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
87 // Initialize Octave.
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
88 // Also print Octave startup message.
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
89 int argc = 5;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
90 const char *argv[] =
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
91 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
92 "octave",
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
93 "--no-line-editing",
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
94 "--no-history",
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
95 "--no-init-file",
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
96 "--silent",
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
97 0
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
98 };
42
c0851ec35936 don't display Octave banner if not interactive run
Jaroslav Hajek <highegg@gmail.com>
parents: 40
diff changeset
99
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
100 if (silent)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
101 {
96
66bd40c8d36e Make Pytave compile against Octave 3.3+. Fix configuration bugs.
David Grundberg <individ@acc.umu.se>
parents: 93
diff changeset
102 argc--;
66bd40c8d36e Make Pytave compile against Octave 3.3+. Fix configuration bugs.
David Grundberg <individ@acc.umu.se>
parents: 93
diff changeset
103 argv[argc] = 0;
42
c0851ec35936 don't display Octave banner if not interactive run
Jaroslav Hajek <highegg@gmail.com>
parents: 40
diff changeset
104 }
c0851ec35936 don't display Octave banner if not interactive run
Jaroslav Hajek <highegg@gmail.com>
parents: 40
diff changeset
105
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
106 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
107 // Set C locale
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
108 locale_t old_locale = uselocale (c_locale);
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
109 #endif
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
110
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
111 octave_main (argc, const_cast<char **> (argv), 1);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
112
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
113 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
114 // Reset locale
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
115 uselocale (old_locale);
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
116 #endif
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
117
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
118 // Initialize NumPy Array
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
119
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
120 // Let boost use numpy
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
121 numeric::array::set_module_and_type ("numpy", "ndarray");
111
f89a4eb2e864 pytave::init: Make compatible with Python 3 module initialization
Mike Miller <mtmiller@octave.org>
parents: 108
diff changeset
122
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
123 // This is actually a macro that becomes a block expression. If an error
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
124 // occurs, e.g. NumPy not installed, an exception is set.
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
125 import_array ()
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
126 }
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
127
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
128 boost::python::tuple
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
129 get_exceptions ()
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
130 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
131 return make_tuple (object (handle<PyObject> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
132 octave_error_exception::excclass)),
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
133 object (handle<PyObject> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
134 value_convert_exception::excclass)),
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
135 object (handle<PyObject> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
136 object_convert_exception::excclass)),
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
137 object (handle<PyObject> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
138 octave_parse_exception::excclass)),
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
139 object (handle<PyObject> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
140 variable_name_exception::excclass)));
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
141 }
144
ad964e46cd48 Handle errors properly with latest Octave interpreter changes
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
142
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
143 std::string
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
144 make_error_message ()
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
145 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
146 std::ostringstream exceptionmsg;
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
147
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
148 std::string message = last_error_message ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
149 std::string identifier = last_error_id ();
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
150
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
151 // Trim trailing new lines
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
152 message = message.substr (0, message.find_last_not_of ("\r\n") + 1);
144
ad964e46cd48 Handle errors properly with latest Octave interpreter changes
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
153
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
154 octave_map stack = last_error_stack ();
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
155
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
156 if (! stack.is_empty ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
157 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
158 std::string file = stack(0).getfield ("file").string_value ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
159 std::string name = stack(0).getfield ("name").string_value ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
160 int line = stack(0).getfield ("line").int_value ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
161 int column = stack(0).getfield ("column").int_value ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
162
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
163 exceptionmsg << file << ":" << line << ":" << column << ": ";
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
164 if (! name.empty ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
165 exceptionmsg << "in '" << name << "': ";
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
166 }
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
167
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
168 if (! identifier.empty ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
169 exceptionmsg << "(identifier: " << identifier << ") ";
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
170
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
171 exceptionmsg << message;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
172
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
173 return exceptionmsg.str ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
174 }
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
175
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
176 boost::python::tuple
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
177 func_eval (int nargout, const std::string& funcname, const boost::python::tuple& arguments)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
178 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
179 octave_value_list octave_args, retval;
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
180
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
181 pytuple_to_octlist (octave_args, arguments);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
182
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
183 reset_error_handler ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
184 buffer_error_messages++;
65
11cff59bc932 Let Octave reread changed files
David Grundberg <individ@acc.umu.se>
parents: 59
diff changeset
185
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
186 // Updating the timestamp makes Octave reread changed files
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
187 Vlast_prompt_time.stamp ();
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
188
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
189 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
190 // Set C locale
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
191 locale_t old_locale = uselocale (c_locale);
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
192 #endif
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
193
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
194 bool bad_alloc_state = false;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
195 bool octave_error = false;
144
ad964e46cd48 Handle errors properly with latest Octave interpreter changes
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
196
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
197 Py_BEGIN_ALLOW_THREADS
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
198 try
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
199 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
200 retval = feval (funcname, octave_args, (nargout >= 0) ? nargout : 0);
93
737d78f8495c don't crash on out-of-memory exceptions
Jaroslav Hajek <highegg@gmail.com>
parents: 84
diff changeset
201 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
202 catch (std::bad_alloc)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
203 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
204 bad_alloc_state = true;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
205 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
206 catch (const octave_execution_exception&)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
207 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
208 octave_error = true;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
209 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
210 Py_END_ALLOW_THREADS
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
211
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
212 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
213 // Reset locale
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
214 uselocale (old_locale);
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
215 #endif
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
216
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
217 if (bad_alloc_state)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
218 throw std::bad_alloc (); // Translated to MemoryError by boost::python
93
737d78f8495c don't crash on out-of-memory exceptions
Jaroslav Hajek <highegg@gmail.com>
parents: 84
diff changeset
219
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
220 if (octave_error)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
221 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
222 std::string exceptionmsg = make_error_message ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
223 if (! exceptionmsg.empty ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
224 throw octave_error_exception (exceptionmsg);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
225 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
226 throw octave_error_exception ("No Octave error available");
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
227 }
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
228
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
229 if (nargout >= 0)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
230 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
231 boost::python::tuple pytuple;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
232 octlist_to_pytuple (pytuple, retval);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
233 return pytuple;
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
234 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
235 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
236 return make_tuple ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
237 }
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
238
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
239 boost::python::tuple
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
240 str_eval (int nargout, const std::string& code, bool silent)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
241 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
242 octave_value_list retval;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
243 int parse_status;
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
244
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
245 reset_error_handler ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
246 buffer_error_messages++;
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
247
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
248 // Updating the timestamp makes Octave reread changed files
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
249 Vlast_prompt_time.stamp ();
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
250
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
251 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
252 // Set C locale
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
253 locale_t old_locale = uselocale (c_locale);
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
254 #endif
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
255
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
256 bool bad_alloc_state = false;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
257 bool octave_error = false;
144
ad964e46cd48 Handle errors properly with latest Octave interpreter changes
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
258
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
259 Py_BEGIN_ALLOW_THREADS
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
260 try
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
261 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
262 retval = eval_string (code, silent, parse_status, (nargout >= 0) ? nargout : 0);
93
737d78f8495c don't crash on out-of-memory exceptions
Jaroslav Hajek <highegg@gmail.com>
parents: 84
diff changeset
263 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
264 catch (std::bad_alloc)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
265 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
266 bad_alloc_state = true;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
267 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
268 catch (const octave_execution_exception&)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
269 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
270 octave_error = true;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
271 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
272 Py_END_ALLOW_THREADS
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
273
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
274 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
275 // Reset locale
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
276 uselocale (old_locale);
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
277 #endif
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
278
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
279 if (bad_alloc_state)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
280 throw std::bad_alloc (); // Translated to MemoryError by boost::python
93
737d78f8495c don't crash on out-of-memory exceptions
Jaroslav Hajek <highegg@gmail.com>
parents: 84
diff changeset
281
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
282 if (octave_error || parse_status)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
283 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
284 std::string exceptionmsg = make_error_message ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
285 if (! exceptionmsg.empty ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
286 {
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
287 if (parse_status != 0)
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
288 throw octave_parse_exception (exceptionmsg);
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
289 else
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
290 throw octave_error_exception (exceptionmsg);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
291 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
292 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
293 throw octave_error_exception ("No Octave error available");
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
294 }
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
295
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
296 if (nargout >= 0)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
297 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
298 boost::python::tuple pytuple;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
299 octlist_to_pytuple (pytuple, retval);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
300 return pytuple;
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
301 }
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
302 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
303 return make_tuple ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
304 }
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
305
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
306 boost::python::object
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
307 getvar (const std::string& name, bool global)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
308 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
309 octave_value val;
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
310
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
311 if (global)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
312 val = symbol_table::global_varval (name);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
313 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
314 val = symbol_table::varval (name);
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
315
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
316 if (val.is_undefined ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
317 throw variable_name_exception (name + " not defined in current scope");
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
318
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
319 boost::python::object pyobject;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
320 octvalue_to_pyobj (pyobject, val);
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
321
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
322 return pyobject;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
323 }
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
324
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
325 void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
326 setvar (const std::string& name, const boost::python::object& pyobject, bool global)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
327 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
328 octave_value val;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
329
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
330 if (! valid_identifier (name))
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
331 throw variable_name_exception (name + " is not a valid identifier");
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
332
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
333 pyobj_to_octvalue (val, pyobject);
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
334
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
335 if (global)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
336 symbol_table::global_assign (name, val);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
337 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
338 symbol_table::assign (name, val);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
339 }
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
340
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
341 bool
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
342 isvar (const std::string& name, bool global)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
343 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
344 bool retval;
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
345
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
346 if (global)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
347 retval = symbol_table::global_varval (name).is_defined ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
348 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
349 retval = symbol_table::is_variable (name);
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
350
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
351 return retval;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
352 }
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
353
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
354 void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
355 delvar (const std::string& name, bool global)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
356 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
357 if (global)
167
f31a5f5b5269 maint: remove workarounds and comments on old Octave versions
Mike Miller <mtmiller@octave.org>
parents: 150
diff changeset
358 symbol_table::clear_global (name);
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
359 else
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
360 symbol_table::clear_variable (name);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
361 }
59
f379cb14c4d4 implement deleting variables
Jaroslav Hajek <highegg@gmail.com>
parents: 58
diff changeset
362
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
363 int
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
364 push_scope ()
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
365 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
366 symbol_table::scope_id local_scope = symbol_table::alloc_scope ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
367 symbol_table::set_scope (local_scope);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
368 octave_call_stack::push (local_scope);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
369 return local_scope;
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
370 }
40
824354efaa1a implement direct variable manipulation and local scoping
Jaroslav Hajek <highegg@gmail.com>
parents: 36
diff changeset
371
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
372 void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
373 pop_scope ()
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
374 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
375 symbol_table::scope_id curr_scope = symbol_table::current_scope ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
376 if (curr_scope != symbol_table::top_scope ())
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
377 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
378 symbol_table::erase_scope (curr_scope);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
379 octave_call_stack::pop ();
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
380 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
381 }
72
e9834fd34416 Fix lp:368487.
David Grundberg <individ@acc.umu.se>
parents: 70
diff changeset
382
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
383 // Make sure Octave is correctly unloaded. We cannot depend on Octave running
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
384 // at the (true) process atexit point, because at that time the Octave library
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
385 // might have been unloaded.
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
386 //
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
387 // At least that is the hypothesis, since Octave (in certain circumstances)
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
388 // cause a segmentation fault in do_octave_atexit called from the exit
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
389 // function. (One Octave call that causes this is "sleep(0)".)
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
390 void
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
391 atexit ()
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
392 {
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
393 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
394 // Set C locale
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
395 locale_t old_locale = uselocale (c_locale);
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
396 #endif
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
397
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
398 Py_BEGIN_ALLOW_THREADS
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
399 clean_up_and_exit (0);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
400 Py_END_ALLOW_THREADS
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
401
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
402 #ifdef HAVE_USELOCALE
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
403 // Reset locale
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
404 uselocale (old_locale);
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
405 #endif
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
406 }
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
407 }
74
6517417e75b2 Fix crashes on exit().
David Grundberg <individ@acc.umu.se>
parents: 72
diff changeset
408
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
409 BOOST_PYTHON_MODULE (_pytave)
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
410 {
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
411 using namespace boost::python;
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
412
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
413 def ("init", pytave::init);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
414 def ("feval", pytave::func_eval);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
415 def ("eval", pytave::str_eval);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
416 def ("getvar", pytave::getvar);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
417 def ("setvar", pytave::setvar);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
418 def ("isvar", pytave::isvar);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
419 def ("delvar", pytave::delvar);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
420 def ("push_scope", pytave::push_scope);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
421 def ("pop_scope", pytave::pop_scope);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
422 def ("atexit", pytave::atexit);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
423 def ("get_exceptions", pytave::get_exceptions);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
424
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
425 register_exception_translator<pytave::pytave_exception> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
426 pytave::pytave_exception::translate_exception);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
427
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
428 register_exception_translator<pytave::octave_error_exception> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
429 pytave::octave_error_exception::translate_exception);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
430
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
431 register_exception_translator<pytave::octave_parse_exception> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
432 pytave::octave_parse_exception::translate_exception);
36
ae4554656fa1 Added an eval function.
David Grundberg <individ@acc.umu.se>
parents: 26
diff changeset
433
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
434 register_exception_translator<pytave::object_convert_exception> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
435 pytave::object_convert_exception::translate_exception);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
436
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
437 register_exception_translator<pytave::value_convert_exception> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
438 pytave::value_convert_exception::translate_exception);
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
439
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
440 register_exception_translator<pytave::variable_name_exception> (
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
441 pytave::variable_name_exception::translate_exception);
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 144
diff changeset
442 }