annotate exceptions.cc @ 392:09a1acb81d8b

Delete legacy code no longer used in project * configure.ac: Drop checks for headers and functions no longer needed. * exceptions.cc, exceptions.h: Delete pytave::init_exceptions and related methods and properties for registering exceptions with Boost.Python runtime. * octave_to_python.cc, octave_to_python.h (pytave::octlist_to_pytuple): Delete. * python_to_octave.cc, python_to_octave.h (pytave::pytuple_to_octlist): Delete.
author Mike Miller <mtmiller@octave.org>
date Mon, 03 Apr 2017 13:31:00 -0700
parents d36f06f07082
children aef165ff92b0
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: 40
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: 40
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: 40
diff changeset
5
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
6 This file is part of Pytave.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
7
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
8 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: 40
diff changeset
9 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: 40
diff changeset
10 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: 40
diff changeset
11 option) any later version.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
12
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
13 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: 40
diff changeset
14 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: 40
diff changeset
15 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: 40
diff changeset
16 for more details.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
17
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
18 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: 40
diff changeset
19 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: 40
diff changeset
20 <http://www.gnu.org/licenses/>.
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
21
b12908ffa6df maint: Use Octave style for file copyright block, delete editor footer
Mike Miller <mtmiller@octave.org>
parents: 40
diff changeset
22 */
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
23
140
d9fa0b60e889 * exceptions.cc: Include config.h before all other header files.
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
24 #if defined (HAVE_CONFIG_H)
d9fa0b60e889 * exceptions.cc: Include config.h before all other header files.
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
25 # include <config.h>
d9fa0b60e889 * exceptions.cc: Include config.h before all other header files.
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
26 #endif
d9fa0b60e889 * exceptions.cc: Include config.h before all other header files.
Mike Miller <mtmiller@octave.org>
parents: 139
diff changeset
27
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
28 #include "exceptions.h"
381
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
29 #include "oct-py-eval.h"
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
30 #include "oct-py-types.h"
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
31
146
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 140
diff changeset
32 namespace pytave
8e3d06f2f5cf Use Octave coding style for C++ sources, PEP8 style for Python sources
Mike Miller <mtmiller@octave.org>
parents: 140
diff changeset
33 {
231
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
34 std::string fetch_exception_message (void)
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
35 {
381
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
36 PyObject *ptype, *pvalue, *ptraceback;
231
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
37 PyErr_Fetch (&ptype, &pvalue, &ptraceback);
253
ef057c4e6aa2 Normalize exception info before extracting text (fixes issue #32)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 233
diff changeset
38 PyErr_NormalizeException (&ptype, &pvalue, &ptraceback);
231
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
39
382
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
40 PyObject *args = PyTuple_New (2);
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
41 PyTuple_SetItem (args, 0, ptype);
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
42 PyTuple_SetItem (args, 1, pvalue);
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
43 PyObject *formatted_list = py_call_function
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
44 ("traceback.format_exception_only", args);
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
45 Py_DECREF (args);
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
46
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
47 std::string message;
233
0deddd1b0526 Eliminate extra newlines in Python error formatting
Mike Miller <mtmiller@octave.org>
parents: 231
diff changeset
48
381
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
49 if (formatted_list && PyList_Check (formatted_list))
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
50 {
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
51 int len = PyList_Size (formatted_list);
233
0deddd1b0526 Eliminate extra newlines in Python error formatting
Mike Miller <mtmiller@octave.org>
parents: 231
diff changeset
52
381
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
53 for (int i = 0; i < len; i++)
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
54 message.append (extract_py_str (PyList_GetItem (formatted_list, i)));
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
55 Py_DECREF (formatted_list);
231
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
56 }
381
f777dca58361 Rewrite exception handling using Python/C API
NVS Abhilash <nvs232@gmail.com>
parents: 253
diff changeset
57 else
231
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
58 {
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
59 PyErr_Restore (ptype, pvalue, ptraceback);
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
60 PyErr_Print ();
382
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
61 message = "exceptions.cc (pytave::fetch_exception_message): cannot call 'format_exceptions_only' for the traceback";
231
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
62 }
382
d36f06f07082 Minor code reorganization to previous commit
Mike Miller <mtmiller@octave.org>
parents: 381
diff changeset
63
231
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
64 return message;
6fffa6219b2c Properly extract exception text from Python (fixes issue #24)
Abhinav Tripathi <genuinelucifer@gmail.com>
parents: 171
diff changeset
65 }
0
4da14cce0890 First launchpad.net check in.
David Grundberg <c04dgg@cs.umu.se>
parents:
diff changeset
66 }