File: mxSWIG.i

package info (click to toggle)
egenix-mx-base 2.0.6-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,028 kB
  • ctags: 4,762
  • sloc: ansic: 14,965; python: 11,739; sh: 313; makefile: 117
file content (82 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef MXSWIG_I
#define MXSWIG_I
/*---------------------------------------------------------------------------
   mxSWIG.i - Some nice stuff to make SWIG really spin... 

   (c) 1998, Marc-Andre Lemburg; All Rights Reserved; mailto:mal@lemburg.com
   See the documentation for further copyright information or contact
   the author.

  ---------------------------------------------------------------------------*/

/* We catch all C++ exceptions, expecting correct settings in Python's
   thread state. */
%except(python) {
    try {
	$function
    }
    catch (...) {
	$cleanup
	if (!PyErr_Occurred())
	    PyErr_SetString(PyExc_SystemError,
			    "unhandled C++ exception occurred");
	return NULL;
    }
}

/* To pass Python strings we use the direct interface -- that way the
   string length is not lost due to embedded \0s. */
%typemap(python,arginit) PyStringObject * {
    $target = 0;
}
%typemap(python,in) PyStringObject * {
    if (!PyString_Check($source)) {
	PyObject *v;
	
	/* Try to auto-convert */
	v = PyObject_Str($source);
	if (!v) {
	    $cleanup
	    return NULL;
	}
	if (!PyString_Check(v)) {
	    PyErr_SetString(PyExc_TypeError,
			    "__str__ failed to return a string");
	    Py_DECREF(v);
	    $cleanup
	    return NULL;
	}
	$target = (PyStringObject *)v;
    }
    else {
	$target = (PyStringObject *)$source;
	Py_INCREF($target);
    }
}
%typemap(python,freearg) PyStringObject * {
    Py_XDECREF($source);
}

/* Pass PyObjects as-is, only assure that they are non-NULL */
%typemap(python,in) PyObject * {
    if (!$source) {
	PyErr_BadInternalCall();
	return NULL;
    }
    $target = (PyObject *)$source;
}
%typemap(python,out) PyObject * {
    $target = $source;
}

/* Call the module init function initModule() at import time. */
%init %{
	extern int initModule(PyObject *module, PyObject *moddict);

	if (initModule(m,d) != 0)
	     return;
%}

/* EOF */
#endif