/trunk/Lib/python/pytypemaps.swg

# · Unknown · 101 lines · 71 code · 30 blank · 0 comment · 0 complexity · ef3319295c527b02fa45e462f8e7e048 MD5 · raw file

  1. /* ------------------------------------------------------------
  2. * Typemap specializations for Python
  3. * ------------------------------------------------------------ */
  4. /* ------------------------------------------------------------
  5. * Fragment section
  6. * ------------------------------------------------------------ */
  7. /* bool is dangerous in Python, change precedence */
  8. #undef SWIG_TYPECHECK_BOOL
  9. %define SWIG_TYPECHECK_BOOL 10000 %enddef
  10. /* Include fundamental fragemt definitions */
  11. %include <typemaps/fragments.swg>
  12. /* Look for user fragments file. */
  13. %include <pyfragments.swg>
  14. /* Python fragments for fundamental types */
  15. %include <pyprimtypes.swg>
  16. /* Python fragments for char* strings */
  17. %include <pystrings.swg>
  18. /* Backward compatibility output helper */
  19. %fragment("t_output_helper","header") %{
  20. #define t_output_helper SWIG_Python_AppendOutput
  21. %}
  22. /* ------------------------------------------------------------
  23. * Unified typemap section
  24. * ------------------------------------------------------------ */
  25. /* directors are supported in Python */
  26. #ifndef SWIG_DIRECTOR_TYPEMAPS
  27. #define SWIG_DIRECTOR_TYPEMAPS
  28. #endif
  29. /* Python types */
  30. #define SWIG_Object PyObject *
  31. #define VOID_Object SWIG_Py_Void()
  32. /* Python allows implicit conversion */
  33. #define %implicitconv_flag $implicitconv
  34. /* Overload of the output/constant/exception/dirout handling */
  35. /* append output */
  36. #define SWIG_AppendOutput(result, obj) SWIG_Python_AppendOutput(result, obj)
  37. /* set constant */
  38. #if defined(SWIGPYTHON_BUILTIN)
  39. #define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, d == md ? public_interface : NULL, name,obj)
  40. #else
  41. #define SWIG_SetConstant(name, obj) SWIG_Python_SetConstant(d, name,obj)
  42. #endif
  43. /* raise */
  44. #define SWIG_Raise(obj, type, desc) SWIG_Python_Raise(obj, type, desc)
  45. /* Include the unified typemap library */
  46. %include <typemaps/swigtypemaps.swg>
  47. /* ------------------------------------------------------------
  48. * Python extra typemaps / typemap overrides
  49. * ------------------------------------------------------------ */
  50. /* Get the address of the 'python self' object */
  51. %typemap(in,numinputs=0,noblock=1) PyObject **PYTHON_SELF {
  52. $1 = &$self;
  53. }
  54. /* Consttab, needed for callbacks, it should be removed later */
  55. %typemap(consttab) SWIGTYPE ((*)(ANY))
  56. { SWIG_PY_POINTER, (char*)"$symname", 0, 0, (void *)($value), &$descriptor }
  57. %typemap(constcode) SWIGTYPE ((*)(ANY)) "";
  58. /* Smart Pointers */
  59. %typemap(out,noblock=1) const SWIGTYPE & SMARTPOINTER {
  60. $result = SWIG_NewPointerObj(%new_copy(*$1, $*ltype), $descriptor, SWIG_POINTER_OWN | %newpointer_flags);
  61. }
  62. %typemap(ret,noblock=1) const SWIGTYPE & SMARTPOINTER, SWIGTYPE SMARTPOINTER {
  63. if ($result) {
  64. PyObject *robj = PyObject_CallMethod($result, (char *)"__deref__", NULL);
  65. if (robj && !PyErr_Occurred()) {
  66. SwigPyObject_append((PyObject *) SWIG_Python_GetSwigThis($result),
  67. (PyObject *) SWIG_Python_GetSwigThis(robj));
  68. Py_DECREF(robj);
  69. }
  70. }
  71. }