2 * Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program 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 General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
29 %typemap(in) guint64 {
30 $1 = amglue_SvU64($input);
34 $1 = amglue_SvI64($input);
37 %typemap(in) guint32 {
38 $1 = amglue_SvU32($input);
42 $1 = amglue_SvI32($input);
45 %typemap(in) guint16 {
46 $1 = amglue_SvU16($input);
50 $1 = amglue_SvI16($input);
54 $1 = amglue_SvU8($input);
58 $1 = amglue_SvI8($input);
61 /* remaining types depend on the complier to optimize out constant sizeof()
62 * expressions. The SWIG preprocessor can't perform calculations based on
65 %define typemap_in_unsigned(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);
76 croak("Unexpected type >64 bits?"); /* should be optimized out unless sizeof(type) > 8 */
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)
94 %define typemap_in_signed(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);
105 g_critical("Unexpected type >64 bits?"); /* should be optimized out unless sizeof(type) > 8 */
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)
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.
133 * The complex typemaps here are to ensure that the argument stack is protected
134 * against stomping by amglue_newSV*64, which may invoke a significant amount
135 * of perl code. "SP += argvi; PUTBACK;" increments the global stack pointer
136 * to cover the arguments processed so far, while "SPAGAIN; SP -= argvi;"
137 * restores the local stack pointer. The latter must be done before the newest
138 * argument is added to the stack. This whole process is a hack around SWIG's
139 * habit of invoking (out) typemaps while building the stack, instead of doing
143 /* (these all use newSV*64, relying on C to upcast to a 64-bit integer) */
145 %define typemap_out_unsigned(type)
148 SP += argvi; PUTBACK;
149 for_stack = sv_2mortal(amglue_newSVu64($1));
150 SPAGAIN; SP -= argvi;
156 typemap_out_unsigned(guint64)
157 typemap_out_unsigned(guint32)
158 typemap_out_unsigned(guint16)
159 typemap_out_unsigned(guint8)
160 typemap_out_unsigned(unsigned int)
161 typemap_out_unsigned(guint)
162 typemap_out_unsigned(unsigned short)
163 typemap_out_unsigned(gushort)
164 typemap_out_unsigned(size_t)
165 typemap_out_unsigned(gsize)
166 typemap_out_unsigned(unsigned long long)
167 typemap_out_unsigned(unsigned long)
168 typemap_out_unsigned(gulong)
169 typemap_out_unsigned(off_t)
170 typemap_out_unsigned(ptrdiff_t)
171 typemap_out_unsigned(uintmax_t)
173 %define typemap_out_signed(type)
176 SP += argvi; PUTBACK;
177 for_stack = sv_2mortal(amglue_newSVi64($1));
178 SPAGAIN; SP -= argvi;
184 typemap_out_signed(gint64)
185 typemap_out_signed(gint32)
186 typemap_out_signed(gint16)
187 typemap_out_signed(gint8)
188 typemap_out_signed(int)
189 typemap_out_signed(gint)
190 typemap_out_signed(signed int)
191 typemap_out_signed(short)
192 typemap_out_signed(gshort)
193 typemap_out_signed(signed short)
194 typemap_out_signed(ssize_t)
195 typemap_out_signed(gssize)
196 typemap_out_signed(long long)
197 typemap_out_signed(signed long long)
198 typemap_out_signed(long)
199 typemap_out_signed(signed long)
200 typemap_out_signed(glong)
201 typemap_out_signed(intmax_t)