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