Typemap tests: T_SHORT, T_U_INT, T_INT, T_LONG
authorSteffen Mueller <smueller@cpan.org>
Mon, 16 Jan 2012 20:10:05 +0000 (21:10 +0100)
committerSteffen Mueller <smueller@cpan.org>
Wed, 1 Feb 2012 07:07:48 +0000 (08:07 +0100)
ext/XS-Typemap/Typemap.xs
ext/XS-Typemap/t/Typemap.t
ext/XS-Typemap/typemap

index 2fcad56..2aa4451 100644 (file)
@@ -25,8 +25,11 @@ typedef int intRef; /* T_PTRREF */
 typedef int intObj; /* T_PTROBJ */
 typedef int intRefIv; /* T_REF_IV_PTR */
 typedef int intArray; /* T_ARRAY */
+typedef int intTINT; /* T_INT */
+typedef int intTLONG; /* T_LONG */
 typedef short shortOPQ;   /* T_OPAQUE */
 typedef int intOpq;   /* T_OPAQUEPTR */
+typedef unsigned intUnsigned; /* T_U_INT */
 
 /* A structure to test T_OPAQUEPTR */
 struct t_opaqueptr {
@@ -317,6 +320,16 @@ the value to perl it is processed in the same way as for T_IV.
 
 Its behaviour is identical to using an C<int> type in XS with T_IV.
 
+=cut
+
+intTINT
+T_INT( i )
+  intTINT i
+ CODE:
+  RETVAL = i;
+ OUTPUT:
+  RETVAL
+
 =item T_ENUM
 
 An enum value. Used to transfer an enum component
@@ -357,12 +370,32 @@ This is for unsigned integers. It is equivalent to using T_UV
 but explicitly casts the variable to type C<unsigned int>.
 The default type for C<unsigned int> is T_UV.
 
+=cut
+
+intUnsigned
+T_U_INT( uint )
+  intUnsigned uint
+ CODE:
+  RETVAL = uint;
+ OUTPUT:
+  RETVAL
+
 =item T_SHORT
 
 Short integers. This is equivalent to T_IV but explicitly casts
 the return to type C<short>. The default typemap for C<short>
 is T_IV.
 
+=cut
+
+short
+T_SHORT( s )
+  short s
+ CODE:
+  RETVAL = s;
+ OUTPUT:
+  RETVAL
+
 =item T_U_SHORT
 
 Unsigned short integers. This is equivalent to T_UV but explicitly
@@ -388,6 +421,16 @@ Long integers. This is equivalent to T_IV but explicitly casts
 the return to type C<long>. The default typemap for C<long>
 is T_IV.
 
+=cut
+
+intTLONG
+T_LONG( in )
+  intTLONG in
+ CODE:
+  RETVAL = in;
+ OUTPUT:
+  RETVAL
+
 =item T_U_LONG
 
 Unsigned long integers. This is equivalent to T_UV but explicitly
index f40b907..ed3aea6 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     }
 }
 
-use Test::More tests => 84;
+use Test::More tests => 102;
 
 use strict;
 use warnings;
@@ -110,16 +110,34 @@ note("T_UV");
 is( T_UV(5), 5 );    # pass
 isnt( T_UV(-4), -4); # fail
 
-# T_IV - signed integer
-note("T_IV");
-is( T_IV(5), 5);
-is( T_IV(-4), -4);
-is( T_IV(4.1), int(4.1));
-is( T_IV("52"), "52");
-isnt( T_IV(4.5), 4.5); # failure
+# T_U_INT - unsigned integer with (unsigned int) cast
+note("T_U_INT");
+is( T_U_INT(5), 5 );    # pass
+isnt( T_U_INT(-4), -4); # fail
 
+# T_IV - signed integer
+# T_INT - signed integer with cast
+# T_LONG - signed integer with cast to IV
+# T_SHORT - signed short
+for my $t (['T_IV', \&T_IV],
+           ['T_INT', \&T_INT],
+           ['T_LONG', \&T_LONG],
+           ['T_SHORT', \&T_SHORT])
+{
+  note($t->[0]);
+  is( $t->[1]->(5), 5);
+  is( $t->[1]->(-4), -4);
+  is( $t->[1]->(4.1), int(4.1));
+  is( $t->[1]->("52"), "52");
+  isnt( $t->[1]->(4.5), 4.5); # failure
+}
 
-# Skip T_INT
+if ($Config{shortsize} == 2) {
+  isnt( T_SHORT(32801), 32801 );
+}
+else {
+  pass(); # e.g. Crays have shortsize 4 (T3X) or 8 (CXX and SVX)
+}
 
 # T_ENUM - enum list
 ok( T_ENUM(), 'T_ENUM' ); # just hope for a true value
@@ -132,10 +150,6 @@ ok( ! T_BOOL(0) );
 ok( ! T_BOOL('') );
 ok( ! T_BOOL(undef) );
 
-# Skip T_U_INT
-
-# Skip T_SHORT
-
 # T_U_SHORT aka U16
 note("T_U_SHORT");
 is( T_U_SHORT(32000), 32000);
index 52c130f..56ed48e 100644 (file)
@@ -14,7 +14,10 @@ intRefIv        T_IV
 intArray *      T_ARRAY
 intOpq          T_IV
 intOpq   *      T_OPAQUEPTR
-shortOPQ          T_OPAQUE
+intUnsigned     T_U_INT
+intTINT         T_INT
+intTLONG        T_LONG
+shortOPQ        T_OPAQUE
 shortOPQ *      T_OPAQUEPTR
 astruct *       T_OPAQUEPTR
 AV_FIXED *     T_AVREF_REFCOUNT_FIXED