Skip to content

Commit

Permalink
use _minimal_ type with size greater than sizeof (void *) for ptrcast
Browse files Browse the repository at this point in the history
no change on non-exotic platforms, but in priciple the right thing to do
  • Loading branch information
gerdr committed Jan 31, 2012
1 parent fb186dd commit d4760a5
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion config/auto/sizes.pm
Expand Up @@ -132,6 +132,27 @@ sub _find_type_max {
return $type;
}

sub _find_type_min {
my ($sizesref, $checklist) = @_;
my $size = 1024; # magic number greater than size of any scalar C type
my $type;

for ( @$checklist ) {
if ( $sizesref->{$_} < $size ) {
$type = $_;
$size = $sizesref->{$_};
}
}

return $type;
}

sub _find_type_min_ge {
my ($sizesref, $size, $checklist) = @_;
my @reduced_checklist = grep { $sizesref->{$_} >= $size } @$checklist;
return _find_type_min($sizesref, \@reduced_checklist);
}

sub _set_fixed {
my ($conf, $sizesref, $kind, $size, $checklist) = @_;
my $type = _find_type_eq($sizesref, $size, $checklist);
Expand Down Expand Up @@ -244,7 +265,7 @@ sub _handle_ptrcast {
my ($conf, $typesref, $sizesref, $checklist) = @_;
my $intvalsize = $sizesref->{$typesref->{'intval'}};
my $ptrsize = $sizesref->{$typesref->{'ptr'}};
my $intptr = _find_type_ge($sizesref, $ptrsize, $checklist);
my $intptr = _find_type_min_ge($sizesref, $ptrsize, $checklist);

if ( defined $intptr ) {
$conf->data->set( ptrcast => 'unsigned '.$intptr );
Expand Down

0 comments on commit d4760a5

Please sign in to comment.