pointer-in-out.i 3.2 KB

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