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