/
memalign.pm
124 lines (94 loc) · 2.56 KB
/
memalign.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright (C) 2001-2009, Parrot Foundation.
=head1 NAME
config/auto/memalign.pm - Memory Alignment
=head1 DESCRIPTION
Determines if the C library supports C<memalign()>.
=cut
package auto::memalign;
use strict;
use warnings;
use base qw(Parrot::Configure::Step);
use Parrot::Configure::Utils ':auto';
sub _init {
my $self = shift;
my %data;
$data{description} = q{Does your C library support memalign};
$data{result} = q{};
return \%data;
}
sub runstep {
my ( $self, $conf ) = @_;
if ( defined $conf->data->get('memalign') ) {
# already set; leave it alone
$self->set_result('already set');
return 1;
}
my $test = 0;
_set_malloc_header($conf);
_set_ptrcast($conf);
$conf->cc_gen('config/auto/memalign/test_c.in');
eval { $conf->cc_build(); };
unless ( $@ || $conf->cc_run_capture() !~ /ok/ ) {
$test = 1;
}
$conf->cc_clean();
my $test2 = 0;
$conf->cc_gen('config/auto/memalign/test2_c.in');
eval { $conf->cc_build(); };
unless ( $@ || $conf->cc_run_capture() !~ /ok/ ) {
$test2 = 1;
}
$conf->cc_clean();
$self->_set_memalign($conf, $test, $test2);
return 1;
}
sub _set_malloc_header {
my $conf = shift;
if ( $conf->data->get('i_malloc') ) {
$conf->data->set( malloc_header => 'malloc.h' );
}
else {
$conf->data->set( malloc_header => 'stdlib.h' );
}
}
sub _set_ptrcast {
my $conf = shift;
my $ptrsize = $conf->data->get('ptrsize');
my $ptrcast = $conf->data->get("int${ptrsize}_t");
# FIXME: find out if this actually does the right thing if intXX_t is
# not available
if ( defined $ptrcast ) {}
elsif ( $ptrsize == $conf->data->get('intsize') ) {
$ptrcast = 'int';
}
elsif ( $ptrsize == $conf->data->get('longsize') ) {
$ptrcast = 'long';
}
elsif ( $ptrsize == $conf->data->get('longlongsize') ) {
$ptrcast = 'long long';
}
else {
# TODO: fail properly
}
$conf->data->set( ptrcast => $ptrcast );
}
sub _set_memalign {
my $self = shift;
my ($conf, $test, $test2) = @_;
$conf->data->set( malloc_header => undef );
my $f =
$test2 ? 'posix_memalign'
: $test ? 'memalign'
: '';
$conf->data->set( memalign => $f );
my $test_str = $test ? " (Yep:$f) " : " (no) ";
$conf->debug($test_str);
$self->set_result( $test ? 'yes' : 'no' );
}
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: