source: swig/python/language.i @ 756011e

abac0-leak
Last change on this file since 756011e was 98aafce, checked in by Ted Faber <faber@…>, 11 years ago

More python interface errors

  • Property mode set to 100644
File size: 1.0 KB
Line 
1%include "chunk.i"
2
3%typemap(argout) bool &success {
4    PyObject *o, *o2, *o3;
5    o = PyBool_FromLong(*$1);
6    if ((!$result) || ($result == Py_None)) {
7        $result = o;
8    } else {
9        if (!PyTuple_Check($result)) {
10            PyObject *o2 = $result;
11            $result = PyTuple_New(1);
12            PyTuple_SetItem($result,0,o2);
13        }
14        o3 = PyTuple_New(2);
15        PyTuple_SetItem(o3,0,o);
16        PyTuple_SetItem(o3,1,$result);
17        $result = o3;
18    }
19}
20
21%typemap(in,numinputs=0) bool &success(bool temp) {
22    $1 = &temp;
23}
24
25// treat Python files as FILE *
26%typemap(in) FILE * %{
27    if (!PyFile_Check($input))
28        SWIG_exception(SWIG_TypeError, "Expected file object");
29
30    $1 = PyFile_AsFile($input);
31%}
32
33%exception {
34    try {
35        $action
36    }
37    catch (std::invalid_argument& e) {
38        PyErr_SetString(PyExc_ValueError, e.what());
39        return NULL;
40    }
41    catch (std::logic_error& e) {
42        PyErr_SetString(PyExc_RuntimeError, e.what());
43        return NULL;
44    }
45}
Note: See TracBrowser for help on using the repository browser.