1 # Copyright (C) 2001-2003, The Perl Foundation.
6 config/auto/sizes.pm - Various Sizes
10 Determines the sizes of various types.
19 use base
qw(Parrot::Configure::Step);
21 use Parrot
::Configure
::Utils
':auto';
27 $data{description
} = q{Determining some sizes};
33 my ( $self, $conf ) = @_;
35 if ( defined $conf->options->get('miniparrot') ) {
49 hugefloatval
=> 'double',
50 hugefloatvalsize
=> 8,
56 $self->set_result('using miniparrot defaults');
60 $conf->cc_gen('config/auto/sizes/test_c.in');
62 my %results = eval $conf->cc_run();
65 for ( keys %results ) {
66 $conf->data->set( $_ => $results{$_} );
69 _handle_intval_ptrsize_discrepancy
(\
%results);
71 # set fixed sized types
72 _set_int2
($conf, \
%results);
74 _set_int4
($conf, \
%results);
76 _set_float4
($conf, \
%results);
78 _set_float8
($conf, \
%results);
81 my $intval = $conf->data->get('iv');
82 my $intvalsize = $conf->data->get('intvalsize');
84 # Get HUGEINTVAL, note that we prefer standard types
85 foreach my $type ( 'long', 'int', 'long long', '__int64' ) {
87 $conf->data->set( int8_t
=> $type );
89 $conf->cc_gen('config/auto/sizes/test2_c.in');
91 %hugeintval = eval $conf->cc_run();
95 # clear int8_t on error
96 if ( $@
|| !exists $hugeintval{hugeintval
} ) {
97 $conf->data->set( int8_t
=> undef );
101 if ( $hugeintval{hugeintvalsize
} > $intvalsize ) {
103 # We found something bigger than intval.
104 $conf->data->set(%hugeintval);
108 _handle_hugeintvalsize
(
111 hugeintval
=> \
%hugeintval,
113 intvalsize
=> $intvalsize,
120 my $size = _probe_for_hugefloatval
( $conf );
121 _set_hugefloatval
( $conf, $size );
128 #################### INTERNAL SUBROUTINES ####################
130 sub _handle_intval_ptrsize_discrepancy
{
131 my $resultsref = shift;
132 if ( $resultsref->{ptrsize
} != $resultsref->{intvalsize
} ) {
135 Hmm, I see your chosen INTVAL isn't the same size as your pointers. Parrot
136 should still compile and run, but you may see a ton of warnings.
142 my ($conf, $resultsref) = @_;
143 if ( $resultsref->{shortsize
} == 2 ) {
144 $conf->data->set( int2_t
=> 'short' );
147 $conf->data->set( int2_t
=> 'int' );
150 Can't find a int type with size 2, conversion ops might fail!
157 my ($conf, $resultsref) = @_;
158 if ( $resultsref->{shortsize
} == 4 ) {
159 $conf->data->set( int4_t
=> 'short' );
161 elsif ( $resultsref->{intsize
} == 4 ) {
162 $conf->data->set( int4_t
=> 'int' );
164 elsif ( $resultsref->{longsize
} == 4 ) {
165 $conf->data->set( int4_t
=> 'long' );
168 $conf->data->set( int4_t
=> 'int' );
171 Can't find a int type with size 4, conversion ops might fail!
178 my ($conf, $resultsref) = @_;
179 if ( $resultsref->{floatsize
} == 4 ) {
180 $conf->data->set( float4_t
=> 'float' );
183 $conf->data->set( float4_t
=> 'double' );
186 Can't find a float type with size 4, conversion ops might fail!
193 my ($conf, $resultsref) = @_;
194 if ( $resultsref->{doublesize
} == 8 ) {
195 $conf->data->set( float8_t
=> 'double' );
198 $conf->data->set( float8_t
=> 'double' );
201 Can't find a float type with size 8, conversion ops might fail!
207 sub _handle_hugeintvalsize
{
210 if ( ! defined( $arg->{hugeintval
}{hugeintvalsize
} )
211 || $arg->{hugeintval
}{hugeintvalsize
} == $arg->{intvalsize
} )
214 # Could not find anything bigger than intval.
216 hugeintval
=> $arg->{intval
},
217 hugeintvalsize
=> $arg->{intvalsize
},
222 sub _probe_for_hugefloatval
{
226 open( my $TEST, ">", "test.c" ) or die "Can't open test.c: $!";
227 print {$TEST} <<'END';
232 printf("%u", sizeof(foo));
243 sub _set_hugefloatval
{
244 my ( $conf, $size ) = @_;
247 hugefloatval
=> 'long double',
248 hugefloatvalsize
=> $size
253 hugefloatval
=> 'double',
254 hugefloatvalsize
=> $conf->data->get('doublesize')
263 # cperl-indent-level: 4
266 # vim: expandtab shiftwidth=4: