File Coverage

File:config/auto/memalign.pm
Coverage:93.3%

linestmtbrancondsubcode
1# Copyright (C) 2001-2009, Parrot Foundation.
2# $Id: memalign.pm 37201 2009-03-08 12:07:48Z fperrad $
3
4 - 12
=head1 NAME

config/auto/memalign.pm - Memory Alignment

=head1 DESCRIPTION

Determines if the C library supports C<memalign()>.

=cut
13
14package auto::memalign;
15
16
81
81
81
use strict;
17
81
81
81
use warnings;
18
19
81
81
81
use base qw(Parrot::Configure::Step);
20
21
81
81
81
use Parrot::Configure::Utils ':auto';
22
23
24sub _init {
25
83
    my $self = shift;
26
83
    my %data;
27
83
    $data{description} = q{Does your C library support memalign};
28
83
    $data{result} = q{};
29
83
    return \%data;
30}
31
32sub runstep {
33
81
    my ( $self, $conf ) = @_;
34
35
81
    if ( defined $conf->data->get('memalign') ) {
36
37        # already set; leave it alone
38
1
        $self->set_result('already set');
39
1
        return 1;
40    }
41
80
    my $test = 0;
42
43
80
    _set_malloc_header($conf);
44
45
80
    _set_ptrcast($conf);
46
47
80
    $conf->cc_gen('config/auto/memalign/test_c.in');
48
80
80
    eval { $conf->cc_build(); };
49
80
    unless ( $@ || $conf->cc_run_capture() !~ /ok/ ) {
50
80
        $test = 1;
51    }
52
80
    $conf->cc_clean();
53
54
80
    my $test2 = 0;
55
56
80
    $conf->cc_gen('config/auto/memalign/test2_c.in');
57
80
80
    eval { $conf->cc_build(); };
58
80
    unless ( $@ || $conf->cc_run_capture() !~ /ok/ ) {
59
80
        $test2 = 1;
60    }
61
80
    $conf->cc_clean();
62
63
80
    $self->_set_memalign($conf, $test, $test2);
64
65
80
    return 1;
66}
67
68sub _set_malloc_header {
69
82
    my $conf = shift;
70
82
    if ( $conf->data->get('i_malloc') ) {
71
81
        $conf->data->set( malloc_header => 'malloc.h' );
72    }
73    else {
74
1
        $conf->data->set( malloc_header => 'stdlib.h' );
75    }
76}
77
78sub _set_ptrcast {
79
82
    my $conf = shift;
80
82
    if ( $conf->data->get('ptrsize') == $conf->data->get('intsize') ) {
81
81
        $conf->data->set( ptrcast => 'int' );
82    }
83    else {
84
1
        $conf->data->set( ptrcast => 'long' );
85    }
86}
87
88sub _set_memalign {
89
88
    my $self = shift;
90
88
    my ($conf, $test, $test2) = @_;
91
88
    $conf->data->set( malloc_header => undef );
92
93
88
    my $f =
94          $test2 ? 'posix_memalign'
95        : $test ? 'memalign'
96        : '';
97
88
    $conf->data->set( memalign => $f );
98
88
    print( $test ? " (Yep:$f) " : " (no) " ) if $conf->options->get('verbose');
99
88
    $self->set_result( $test ? 'yes' : 'no' );
100}
101
1021;
103
104# Local Variables:
105# mode: cperl
106# cperl-indent-level: 4
107# fill-column: 100
108# End:
109# vim: expandtab shiftwidth=4: