64db72a5f4e4fb857ca4826113aef6b70d375b66
[debian/amanda] / perl / amglue / integers.swg
1 /*
2  * Copyright (c) Zmanda, Inc.  All Rights Reserved.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2.1
6  * as published by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
11  * License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
16  *
17  * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18  * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19  */
20
21 %{
22 #include "amglue.h"
23 %}
24
25 /*
26  * perl -> C (input)
27  */
28
29 %typemap(in) guint64 {
30     $1 = amglue_SvU64($input);
31 }
32
33 %typemap(in) gint64 {
34     $1 = amglue_SvI64($input);
35 }
36
37 %typemap(in) guint32 {
38     $1 = amglue_SvU32($input);
39 }
40
41 %typemap(in) gint32 {
42     $1 = amglue_SvI32($input);
43 }
44
45 %typemap(in) guint16 {
46     $1 = amglue_SvU16($input);
47 }
48
49 %typemap(in) gint16 {
50     $1 = amglue_SvI16($input);
51 }
52
53 %typemap(in) guint8 {
54     $1 = amglue_SvU8($input);
55 }
56
57 %typemap(in) gint8 {
58     $1 = amglue_SvI8($input);
59 }
60
61 /* remaining types depend on the complier to optimize out constant sizeof() 
62  * expressions.  The SWIG preprocessor can't perform calculations based on 
63  * sizeof(). */
64
65 %define typemap_in_unsigned(type)
66 %typemap(in) type {
67     if (sizeof(type) == 1) {
68         $1 = amglue_SvU8($input);
69     } else if (sizeof(type) == 2) {
70         $1 = amglue_SvU16($input);
71     } else if (sizeof(type) == 4) {
72         $1 = amglue_SvU32($input);
73     } else if (sizeof(type) == 8) {
74         $1 = amglue_SvU64($input);
75     } else {
76         croak("Unexpected type >64 bits?"); /* should be optimized out unless sizeof(type) > 8 */
77     }
78 }
79 %enddef
80
81 typemap_in_unsigned(unsigned int)
82 typemap_in_unsigned(guint)
83 typemap_in_unsigned(unsigned short)
84 typemap_in_unsigned(gushort)
85 typemap_in_unsigned(size_t)
86 typemap_in_unsigned(gsize)
87 typemap_in_unsigned(unsigned long long)
88 typemap_in_unsigned(unsigned long)
89 typemap_in_unsigned(gulong)
90 typemap_in_unsigned(off_t)
91 typemap_in_unsigned(ptrdiff_t)
92 typemap_in_unsigned(uintmax_t)
93
94 %define typemap_in_signed(type)
95 %typemap(in) type {
96     if (sizeof(type) == 1) {
97         $1 = amglue_SvI8($input);
98     } else if (sizeof(type) == 2) {
99         $1 = amglue_SvI16($input);
100     } else if (sizeof(type) == 4) {
101         $1 = amglue_SvI32($input);
102     } else if (sizeof(type) == 8) {
103         $1 = amglue_SvI64($input);
104     } else {
105         g_critical("Unexpected type >64 bits?"); /* should be optimized out unless sizeof(type) > 8 */
106     }
107 }
108 %enddef
109
110 typemap_in_signed(int)
111 typemap_in_signed(gint)
112 typemap_in_signed(signed int)
113 typemap_in_signed(short)
114 typemap_in_signed(gshort)
115 typemap_in_signed(signed short)
116 typemap_in_signed(ssize_t)
117 typemap_in_signed(gssize)
118 typemap_in_signed(long long)
119 typemap_in_signed(signed long long)
120 typemap_in_signed(long)
121 typemap_in_signed(signed long)
122 typemap_in_signed(glong)
123 typemap_in_signed(intmax_t)
124
125 /*
126  * C -> perl (output)
127  */
128
129 /* All conversions from C to Perl create Math::BigInt objects, even when the
130  * C datatype is 32 bits or smaller.  This is to ensure that Perl's automatic
131  * promotion to double does not silently corrupt arithmetic on large numbers.
132  */
133
134 /* (these all use newSV*64, relying on C to upcast to a 64-bit integer) */
135
136 %define typemap_out_unsigned(type)
137 %typemap(out) type {
138     $result = sv_2mortal(amglue_newSVu64($1));
139     argvi++;
140 }
141 %enddef
142
143 typemap_out_unsigned(guint64)
144 typemap_out_unsigned(guint32)
145 typemap_out_unsigned(guint16)
146 typemap_out_unsigned(guint8)
147 typemap_out_unsigned(unsigned int)
148 typemap_out_unsigned(guint)
149 typemap_out_unsigned(unsigned short)
150 typemap_out_unsigned(gushort)
151 typemap_out_unsigned(size_t)
152 typemap_out_unsigned(gsize)
153 typemap_out_unsigned(unsigned long long)
154 typemap_out_unsigned(unsigned long)
155 typemap_out_unsigned(gulong)
156 typemap_out_unsigned(off_t)
157 typemap_out_unsigned(ptrdiff_t)
158 typemap_out_unsigned(uintmax_t)
159
160 %define typemap_out_signed(type)
161 %typemap(out) type {
162     $result = sv_2mortal(amglue_newSVi64($1));
163     argvi++;
164 }
165 %enddef
166
167 typemap_out_signed(gint64)
168 typemap_out_signed(gint32)
169 typemap_out_signed(gint16)
170 typemap_out_signed(gint8)
171 typemap_out_signed(int)
172 typemap_out_signed(gint)
173 typemap_out_signed(signed int)
174 typemap_out_signed(short)
175 typemap_out_signed(gshort)
176 typemap_out_signed(signed short)
177 typemap_out_signed(ssize_t)
178 typemap_out_signed(gssize)
179 typemap_out_signed(long long)
180 typemap_out_signed(signed long long)
181 typemap_out_signed(long)
182 typemap_out_signed(signed long)
183 typemap_out_signed(glong)
184 typemap_out_signed(intmax_t)