2 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
30 %typemap(in) guint64 {
31 $1 = amglue_SvU64($input);
35 $1 = amglue_SvI64($input);
38 %typemap(in) guint32 {
39 $1 = amglue_SvU32($input);
43 $1 = amglue_SvI32($input);
46 %typemap(in) guint16 {
47 $1 = amglue_SvU16($input);
51 $1 = amglue_SvI16($input);
55 $1 = amglue_SvU8($input);
59 $1 = amglue_SvI8($input);
62 /* remaining types depend on the complier to optimize out constant sizeof()
63 * expressions. The SWIG preprocessor can't perform calculations based on
66 %define typemap_in_unsigned(type)
68 if (sizeof(type) == 1) {
69 $1 = amglue_SvU8($input);
70 } else if (sizeof(type) == 2) {
71 $1 = amglue_SvU16($input);
72 } else if (sizeof(type) == 4) {
73 $1 = amglue_SvU32($input);
74 } else if (sizeof(type) == 8) {
75 $1 = amglue_SvU64($input);
77 croak("Unexpected type >64 bits?"); /* should be optimized out unless sizeof(type) > 8 */
82 typemap_in_unsigned(unsigned int)
83 typemap_in_unsigned(guint)
84 typemap_in_unsigned(unsigned short)
85 typemap_in_unsigned(gushort)
86 typemap_in_unsigned(size_t)
87 typemap_in_unsigned(gsize)
88 typemap_in_unsigned(unsigned long long)
89 typemap_in_unsigned(unsigned long)
90 typemap_in_unsigned(gulong)
91 typemap_in_unsigned(off_t)
92 typemap_in_unsigned(ptrdiff_t)
93 typemap_in_unsigned(uintmax_t)
95 %define typemap_in_signed(type)
97 if (sizeof(type) == 1) {
98 $1 = amglue_SvI8($input);
99 } else if (sizeof(type) == 2) {
100 $1 = amglue_SvI16($input);
101 } else if (sizeof(type) == 4) {
102 $1 = amglue_SvI32($input);
103 } else if (sizeof(type) == 8) {
104 $1 = amglue_SvI64($input);
106 g_critical("Unexpected type >64 bits?"); /* should be optimized out unless sizeof(type) > 8 */
111 typemap_in_signed(int)
112 typemap_in_signed(gint)
113 typemap_in_signed(signed int)
114 typemap_in_signed(short)
115 typemap_in_signed(gshort)
116 typemap_in_signed(signed short)
117 typemap_in_signed(ssize_t)
118 typemap_in_signed(gssize)
119 typemap_in_signed(long long)
120 typemap_in_signed(signed long long)
121 typemap_in_signed(long)
122 typemap_in_signed(signed long)
123 typemap_in_signed(glong)
124 typemap_in_signed(intmax_t)
130 /* All conversions from C to Perl create Math::BigInt objects, even when the
131 * C datatype is 32 bits or smaller. This is to ensure that Perl's automatic
132 * promotion to double does not silently corrupt arithmetic on large numbers.
134 * The complex typemaps here are to ensure that the argument stack is protected
135 * against stomping by amglue_newSV*64, which may invoke a significant amount
136 * of perl code. "SP += argvi; PUTBACK;" increments the global stack pointer
137 * to cover the arguments processed so far, while "SPAGAIN; SP -= argvi;"
138 * restores the local stack pointer. The latter must be done before the newest
139 * argument is added to the stack. This whole process is a hack around SWIG's
140 * habit of invoking (out) typemaps while building the stack, instead of doing
144 /* (these all use newSV*64, relying on C to upcast to a 64-bit integer) */
146 %define typemap_out_unsigned(type)
149 SP += argvi; PUTBACK;
150 for_stack = sv_2mortal(amglue_newSVu64($1));
151 SPAGAIN; SP -= argvi;
157 typemap_out_unsigned(guint64)
158 typemap_out_unsigned(guint32)
159 typemap_out_unsigned(guint16)
160 typemap_out_unsigned(guint8)
161 typemap_out_unsigned(unsigned int)
162 typemap_out_unsigned(guint)
163 typemap_out_unsigned(unsigned short)
164 typemap_out_unsigned(gushort)
165 typemap_out_unsigned(size_t)
166 typemap_out_unsigned(gsize)
167 typemap_out_unsigned(unsigned long long)
168 typemap_out_unsigned(unsigned long)
169 typemap_out_unsigned(gulong)
170 typemap_out_unsigned(off_t)
171 typemap_out_unsigned(ptrdiff_t)
172 typemap_out_unsigned(uintmax_t)
174 %define typemap_out_signed(type)
177 SP += argvi; PUTBACK;
178 for_stack = sv_2mortal(amglue_newSVi64($1));
179 SPAGAIN; SP -= argvi;
185 typemap_out_signed(gint64)
186 typemap_out_signed(gint32)
187 typemap_out_signed(gint16)
188 typemap_out_signed(gint8)
189 typemap_out_signed(int)
190 typemap_out_signed(gint)
191 typemap_out_signed(signed int)
192 typemap_out_signed(short)
193 typemap_out_signed(gshort)
194 typemap_out_signed(signed short)
195 typemap_out_signed(ssize_t)
196 typemap_out_signed(gssize)
197 typemap_out_signed(long long)
198 typemap_out_signed(signed long long)
199 typemap_out_signed(long)
200 typemap_out_signed(signed long)
201 typemap_out_signed(glong)
202 typemap_out_signed(intmax_t)