PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Lib/guile/pointer-in-out.i

#
Swig | 105 lines | 43 code | 13 blank | 49 comment | 0 complexity | 87d574d447f69a5c0a554eaf1283f9de MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * pointer-in-out.i
  6. *
  7. * Guile typemaps for passing pointers indirectly
  8. * ----------------------------------------------------------------------------- */
  9. /* Here is a macro that will define typemaps for passing C pointers indirectly.
  10. TYPEMAP_POINTER_INPUT_OUTPUT(PTRTYPE, SCM_TYPE)
  11. Supported calling conventions (in this example, PTRTYPE is int *):
  12. func(int **INPUT)
  13. Scheme wrapper will take one argument, a wrapped C pointer.
  14. The address of a variable containing this pointer will be
  15. passed to the function.
  16. func(int **INPUT_CONSUMED)
  17. Likewise, but mark the pointer object as not garbage
  18. collectable.
  19. func(int **INPUT_DESTROYED)
  20. Likewise, but mark the pointer object as destroyed.
  21. func(int **OUTPUT)
  22. Scheme wrapper will take no arguments. The address of an int *
  23. variable will be passed to the function. The function is
  24. expected to modify the variable; its value is wrapped and
  25. becomes an extra return value. (See the documentation on how
  26. to deal with multiple values.)
  27. func(int **OUTPUT_NONCOLLECTABLE)
  28. Likewise, but make the pointer object not garbage collectable.
  29. func(int **BOTH)
  30. func(int **INOUT)
  31. This annotation combines INPUT and OUTPUT.
  32. */
  33. %define TYPEMAP_POINTER_INPUT_OUTPUT(PTRTYPE, SCM_TYPE)
  34. %typemap(in, doc="$NAME is of type <" #SCM_TYPE ">") PTRTYPE *INPUT(PTRTYPE temp)
  35. {
  36. if (SWIG_ConvertPtr($input, (void **) &temp, $*descriptor, 0)) {
  37. scm_wrong_type_arg(FUNC_NAME, $argnum, $input);
  38. }
  39. $1 = &temp;
  40. }
  41. %typemap(in, doc="$NAME is of type <" #SCM_TYPE "> and is consumed by the function") PTRTYPE *INPUT_CONSUMED(PTRTYPE temp)
  42. {
  43. if (SWIG_ConvertPtr($input, (void **) &temp, $*descriptor, 0)) {
  44. scm_wrong_type_arg(FUNC_NAME, $argnum, $input);
  45. }
  46. SWIG_Guile_MarkPointerNoncollectable($input);
  47. $1 = &temp;
  48. }
  49. %typemap(in, doc="$NAME is of type <" #SCM_TYPE "> and is consumed by the function") PTRTYPE *INPUT_DESTROYED(PTRTYPE temp)
  50. {
  51. if (SWIG_ConvertPtr($input, (void **) &temp, $*descriptor, 0)) {
  52. scm_wrong_type_arg(FUNC_NAME, $argnum, $input);
  53. }
  54. SWIG_Guile_MarkPointerDestroyed($input);
  55. $1 = &temp;
  56. }
  57. %typemap(in, numinputs=0) PTRTYPE *OUTPUT(PTRTYPE temp),
  58. PTRTYPE *OUTPUT_NONCOLLECTABLE(PTRTYPE temp)
  59. "$1 = &temp;";
  60. %typemap(argout, doc="<" #SCM_TYPE ">") PTRTYPE *OUTPUT
  61. "SWIG_APPEND_VALUE(SWIG_NewPointerObj(*$1, $*descriptor, 1));";
  62. %typemap(argout, doc="<" #SCM_TYPE ">") PTRTYPE *OUTPUT_NONCOLLECTABLE
  63. "SWIG_APPEND_VALUE(SWIG_NewPointerObj(*$1, $*descriptor, 0));";
  64. %typemap(in) PTRTYPE *BOTH = PTRTYPE *INPUT;
  65. %typemap(argout) PTRTYPE *BOTH = PTRTYPE *OUTPUT;
  66. %typemap(in) PTRTYPE *INOUT = PTRTYPE *INPUT;
  67. %typemap(argout) PTRTYPE *INOUT = PTRTYPE *OUTPUT;
  68. /* As a special convenience measure, also attach docs involving
  69. SCM_TYPE to the standard pointer typemaps */
  70. %typemap(in, doc="$NAME is of type <" #SCM_TYPE ">") PTRTYPE {
  71. if (SWIG_ConvertPtr($input, (void **) &$1, $descriptor, 0))
  72. scm_wrong_type_arg(FUNC_NAME, $argnum, $input);
  73. }
  74. %typemap(out, doc="<" #SCM_TYPE ">") PTRTYPE {
  75. $result = SWIG_NewPointerObj ($1, $descriptor, $owner);
  76. }
  77. %enddef