summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteffen Mueller <smueller@cpan.org>2012-01-16 21:10:05 +0100
committerSteffen Mueller <smueller@cpan.org>2012-02-01 08:07:48 +0100
commit604db64537a70495a3bd46d134dbbe1637f87eb2 (patch)
treee107ceec88512437bd390687a0017c8e8935b8af
parentdcea22eb4cec3666c5b5af4699af5f6ae0ab2f6a (diff)
downloadperl-604db64537a70495a3bd46d134dbbe1637f87eb2.tar.gz
Typemap tests: T_SHORT, T_U_INT, T_INT, T_LONG
-rw-r--r--ext/XS-Typemap/Typemap.xs43
-rw-r--r--ext/XS-Typemap/t/Typemap.t40
-rw-r--r--ext/XS-Typemap/typemap5
3 files changed, 74 insertions, 14 deletions
diff --git a/ext/XS-Typemap/Typemap.xs b/ext/XS-Typemap/Typemap.xs
index 2fcad56488..2aa4451e33 100644
--- a/ext/XS-Typemap/Typemap.xs
+++ b/ext/XS-Typemap/Typemap.xs
@@ -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
diff --git a/ext/XS-Typemap/t/Typemap.t b/ext/XS-Typemap/t/Typemap.t
index f40b9075cf..ed3aea671b 100644
--- a/ext/XS-Typemap/t/Typemap.t
+++ b/ext/XS-Typemap/t/Typemap.t
@@ -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);
diff --git a/ext/XS-Typemap/typemap b/ext/XS-Typemap/typemap
index 52c130f8a2..56ed48eb6b 100644
--- a/ext/XS-Typemap/typemap
+++ b/ext/XS-Typemap/typemap
@@ -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