Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rurban/perl-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Reini Urban committed Jan 22, 2012
2 parents bcd4648 + ac98a7f commit b45ea35
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 34 deletions.
70 changes: 45 additions & 25 deletions lib/B/CC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright (c) 1996, 1997, 1998 Malcolm Beattie
# Copyright (c) 2009, 2010, 2011 Reini Urban
# Copyright (c) 2010 Heinz Knutzen
# Copyright (c) 2012 cPanel Inc
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the README file.
Expand Down Expand Up @@ -63,6 +64,13 @@ have subs in which need compiling but the current version doesn't do
it very well. In particular, it is confused by nested packages (i.e.
of the form C<A::B>) where package C<A> does not contain any subs.
=item B<-UPackname> "unuse" skip Package
Ignore all subs from Package to be compiled.
Certain packages might not be needed at run-time, even if the pessimistic
walker detects it.
=item B<-mModulename>
Instead of generating source for a runnable executable, generate
Expand Down Expand Up @@ -241,6 +249,9 @@ package B::CC;

our $VERSION = '1.12';

# Start registering the L<types> namespaces.
$int::VERSION = $double::VERSION = $string::VERSION = '0.01';

use Config;
use strict;
#use 5.008;
Expand Down Expand Up @@ -869,44 +880,45 @@ sub error {

# run-time eval is too late for attrs being checked by perlcore. BEGIN does not help.
# use types is the right approach. But until types is fixed we use this hack.
# Note that we also need a new CHECK_SCALAR_ATTRIBUTES hook, starting with v5.18.
sub init_type_attrs {
if ($type_attr) {
eval q[
eval q[
our $valid_attr = '^(int|double|string|unsigned|register|temporary|ro|readonly)$';
our $valid_attr = '^(int|double|string|unsigned|register|temporary|ro|readonly|const)$';
sub MODIFY_SCALAR_ATTRIBUTES {
my $pkg = shift;
my $v = shift;
my @bad;
my $attr = $valid_attr;
my $attr = $B::CC::valid_attr;
$attr =~ s/\b$pkg\b//;
if (@bad = grep !/$attr/, @_) { return @bad; }
else {
no strict 'refs'; push @{"$pkg\::$v\::attributes"}, @_; # create a magic glob
if (my @bad = grep !/$attr/, @_) {
return @bad;
} else {
no strict 'refs';
push @{"$pkg\::$v\::attributes"}, @_; # create a magic glob
return ();
}
}
sub FETCH_SCALAR_ATTRIBUTES {
my ($pkg, $v) = @_;
no strict 'refs';
my $pkg = shift;
my $v = shift;
return @{"$pkg\::$v\::attributes"};
}
# pollute our callers namespace for attributes to be accepted with -MB::CC
sub main::MODIFY_SCALAR_ATTRIBUTES { B::CC::MODIFY_SCALAR_ATTRIBUTES(@_)}
sub main::FETCH_SCALAR_ATTRIBUTES { B::CC::FETCH_SCALAR_ATTRIBUTES(@_) };
package int; # my int $i : register : ro;
sub MODIFY_SCALAR_ATTRIBUTES { B::CC::MODIFY_SCALAR_ATTRIBUTES(@_)}
sub FETCH_SCALAR_ATTRIBUTES { B::CC::FETCH_SCALAR_ATTRIBUTES(@_) };
# my int $i : register : ro;
sub int::MODIFY_SCALAR_ATTRIBUTES { B::CC::MODIFY_SCALAR_ATTRIBUTES(@_)}
sub int::FETCH_SCALAR_ATTRIBUTES { B::CC::FETCH_SCALAR_ATTRIBUTES(@_) };
package double; # my double $d : ro;
sub MODIFY_SCALAR_ATTRIBUTES { B::CC::MODIFY_SCALAR_ATTRIBUTES(@_)}
sub FETCH_SCALAR_ATTRIBUTES { B::CC::FETCH_SCALAR_ATTRIBUTES(@_) };
];
# my double $d : ro;
sub double::MODIFY_SCALAR_ATTRIBUTES { B::CC::MODIFY_SCALAR_ATTRIBUTES(@_)}
sub double::FETCH_SCALAR_ATTRIBUTES { B::CC::FETCH_SCALAR_ATTRIBUTES(@_) };
}
sub string::MODIFY_SCALAR_ATTRIBUTES { B::CC::MODIFY_SCALAR_ATTRIBUTES(@_)}
sub string::FETCH_SCALAR_ATTRIBUTES { B::CC::FETCH_SCALAR_ATTRIBUTES(@_) };
];
}

=head2 load_pad
Expand Down Expand Up @@ -952,7 +964,7 @@ sub load_pad {
# my int $i; my double $d; compiled code only, unless the source provides the int and double packages.
# With Ctypes it is easier. my c_int $i; defines an external Ctypes int, which can be efficiently
# compiled in Perl also.
# Better use attributes, like my $i:int; my $d:double; which works un-compiled also.
# XXX Better use attributes, like my $i:int; my $d:double; which works un-compiled also.
if (ref($namesv) eq 'B::PVMG' and ref($namesv->SvSTASH) eq 'B::HV') { # my int
$class = $namesv->SvSTASH->NAME;
if ($class eq 'int') {
Expand All @@ -975,10 +987,13 @@ sub load_pad {
}

# Valid scalar type attributes:
# int double ro readonly unsigned
# int double string ro readonly const unsigned
# Note: PVMG from above also.
# Typed arrays and hashes later. We need to add string also.
if (class($namesv) =~ /^(I|P|S|N)V/ and UNIVERSAL::can($class, "MODIFY_SCALAR_ATTRIBUTES")) {
# Typed arrays and hashes later.
if (0 and $class =~ /^(I|P|S|N)V/
and $type_attr
and UNIVERSAL::can($class,"CHECK_SCALAR_ATTRIBUTES")) # with 5.18
{
require attributes;
#my $svtype = uc reftype ($namesv);
# test 105
Expand Down Expand Up @@ -2987,7 +3002,12 @@ OPTION:
}
elsif ( $opt eq "u" ) {
$arg ||= shift @options;
mark_unused( $arg, undef );
eval "require $arg;";
mark_unused( $arg, 1 );
}
elsif ( $opt eq "U" ) {
$arg ||= shift @options;
mark_skip( $arg );
}
elsif ( $opt eq "strict" ) {
$arg ||= shift @options;
Expand Down Expand Up @@ -3020,10 +3040,10 @@ OPTION:
}
if ($arg >= 2) {
$freetmps_each_loop = 1;
$type_attr = 1;
$B::C::destruct = 0 unless $] < 5.008; # fast_destruct
}
if ( $arg >= 1 ) {
$type_attr = 1;
$freetmps_each_bblock = 1 unless $freetmps_each_loop;
}
}
Expand Down Expand Up @@ -3124,7 +3144,7 @@ OPTION:
$B::C::av_init = 0 unless $c_optimise{av_init};
$B::C::av_init2 = 1 unless $c_optimise{av_init2};
}
init_type_attrs if $type_attr; # but too late for -MB::CC=-O2 on import. attrs are checked before
init_type_attrs() if $type_attr; # but too late for -MB::CC=-O2 on import. attrs are checked before
@options;
}

Expand Down
2 changes: 1 addition & 1 deletion log.modules-5.008004d-nt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# B::C::VERSION = 1.37 83cbc9f 2012-01-20 | add inc_cleanup to CC also
# B::C::VERSION = 1.37 0bfce30 2012-01-21 | revise share_hek to bypass hv.c hek assert on DEBUGGING
# perlversion = 5.008004d-nt
# path = /usr/local/bin/perl5.8.4d-nt
# platform = linux 64bit non-threaded debug
Expand Down
2 changes: 1 addition & 1 deletion log.modules-5.008005d-nt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# B::C::VERSION = 1.37 83cbc9f 2012-01-20 | add inc_cleanup to CC also
# B::C::VERSION = 1.37 0bfce30 2012-01-21 | revise share_hek to bypass hv.c hek assert on DEBUGGING
# perlversion = 5.008005d-nt
# path = /usr/local/bin/perl5.8.5d-nt
# platform = linux 64bit non-threaded debug
Expand Down
2 changes: 1 addition & 1 deletion log.modules-5.008009d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# B::C::VERSION = 1.37 83cbc9f 2012-01-20 | add inc_cleanup to CC also
# B::C::VERSION = 1.37 0bfce30 2012-01-21 | revise share_hek to bypass hv.c hek assert on DEBUGGING
# perlversion = 5.008009d
# path = /usr/local/bin/perl5.8.9d
# platform = linux 64bit threaded debug
Expand Down
2 changes: 1 addition & 1 deletion log.modules-5.008009d-nt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# B::C::VERSION = 1.37 83cbc9f 2012-01-20 | add inc_cleanup to CC also
# B::C::VERSION = 1.37 0bfce30 2012-01-21 | revise share_hek to bypass hv.c hek assert on DEBUGGING
# perlversion = 5.008009d-nt
# path = /usr/local/bin/perl5.8.9d-nt
# platform = linux 64bit non-threaded debug
Expand Down
2 changes: 1 addition & 1 deletion log.modules-5.012004
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# B::C::VERSION = 1.37 83cbc9f 2012-01-20 | add inc_cleanup to CC also
# B::C::VERSION = 1.37 0bfce30 2012-01-21 | revise share_hek to bypass hv.c hek assert on DEBUGGING
# perlversion = 5.012004
# path = /usr/bin/perl5.12.4
# platform = linux 64bit threaded
Expand Down
2 changes: 1 addition & 1 deletion log.modules-5.014002-nt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# B::C::VERSION = 1.37 83cbc9f 2012-01-20 | add inc_cleanup to CC also
# B::C::VERSION = 1.37 0bfce30 2012-01-21 | revise share_hek to bypass hv.c hek assert on DEBUGGING
# perlversion = 5.014002-nt
# path = /usr/local/bin/perl5.14.2-nt
# platform = linux 64bit non-threaded
Expand Down
2 changes: 1 addition & 1 deletion log.modules-5.014002d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# B::C::VERSION = 1.37 83cbc9f 2012-01-20 | add inc_cleanup to CC also
# B::C::VERSION = 1.37 0bfce30 2012-01-21 | revise share_hek to bypass hv.c hek assert on DEBUGGING
# perlversion = 5.014002d
# path = /usr/local/bin/perl5.14.2d
# platform = linux 64bit threaded debug
Expand Down
109 changes: 109 additions & 0 deletions log.modules-5.015007d-nt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# B::C::VERSION = 1.37 0bfce30 2012-01-21 | revise share_hek to bypass hv.c hek assert on DEBUGGING
# perlversion = 5.015007d-nt
# path = /usr/local/bin/perl5.15.7d-nt
# platform = linux 64bit non-threaded debug
pass Exporter
pass Text::Tabs
pass Text::Wrap
pass Test::Harness
pass Pod::Escapes
pass Pod::Simple
pass IO
pass Scalar::Util
pass Getopt::Long
pass Pod::Parser
pass ExtUtils::MakeMaker
pass Test::Simple
pass ExtUtils::Manifest
pass Pod::Text
pass constant
pass Test
pass Data::Dumper
pass File::Spec
pass File::Temp
pass ExtUtils::Install
pass Text::ParseWords
pass ExtUtils::CBuilder
pass ExtUtils::ParseXS
pass Module::Build
pass File::Path
pass XSLoader
pass MIME::Base64
pass Digest
pass Digest::MD5
pass Sub::Uplevel
pass URI
pass HTML::Tagset
pass HTML::Parser
pass Test::Exception
pass Net::Cmd
pass Compress::Raw::Zlib
pass Compress::Raw::Bzip2
pass IO::Compress::Base
pass LWP
pass Storable
pass base
pass List::MoreUtils
pass Params::Util
pass Task::Weaken
pass Class::Accessor
pass Test::Tester
pass Sub::Install
pass Attribute::Handlers
pass Data::OptList
pass Sub::Exporter
pass Test::NoWarnings
pass version
pass Params::Validate
pass Sub::Name
pass Filter::Util::Call
pass Algorithm::C3
pass Class::C3
pass Scope::Guard
pass MRO::Compat
pass Time::HiRes
pass Class::Data::Inheritable
pass Try::Tiny
pass Devel::GlobalDestruction
pass Class::MOP
fail Moose
pass Test::Deep
pass Carp::Clan
pass Module::Pluggable
pass if(1) => "Sys::Hostname"
pass Text::Balanced
pass DBI
pass Time::Local
pass IO::Scalar
pass Sub::Identify
pass Class::ISA
pass FCGI
pass Tree::DAG_Node
pass Path::Class
pass Test::Warn
pass Encode
pass Variable::Magic
pass CGI
pass B::Hooks::EndOfScope
pass Test::Pod
pass Digest::SHA1
pass namespace::clean
pass Class::Inspector
pass Clone
pass XML::NamespaceSupport
pass XML::SAX
pass YAML
fail MooseX::Types
pass Class::Singleton
fail DateTime::TimeZone
pass DateTime::Locale
fail DateTime
pass IO::String
pass AppConfig
pass UNIVERSAL::require
pass Template::Stash
# 100 / 100 modules tested with B-C-1.37 - perl-5.015007d-nt
# pass 96 / 100 (96.0%)
# fail 4 / 100 (4.0%)
# todo 0 / 4 (0.0%)
# skip 0 / 100 (0.0% not installed)
5 changes: 3 additions & 2 deletions t/testc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ result[103]='B::PV'
# CC reset
tests[104]='@a=(1..4);while($a=shift@a){print $a;}continue{$a=~/2/ and reset q(a);}'
result[104]='12'
# CC attrs. requires -MB::CC with pure perl
tests[105]='use blib;use B::CC;my int $r;my $i:int=2;our double $d=3.0; $r=$i*$i; $r*=$d; print $r;'
# CC -ftype-attr
#tests[105]='$int::dummy=0;$double::dummy=0;my int $r;my $i:int=2;our double $d=3.0; $r=$i*$i; $r*=$d; print $r;'
tests[105]='$int::dummy=0;$double::dummy=0;my int $r;my $i_i=2;our double $d=3.0; $r=$i*$i; $r*=$d; print $r;'
result[105]='12'

# issue35
Expand Down

0 comments on commit b45ea35

Please sign in to comment.