From: Vincent Pit Date: Sat, 24 Apr 2010 14:27:22 +0000 (+0200) Subject: Introduce A_THREADSAFE and A_FORKSAFE X-Git-Tag: v0.06~3 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fautovivification.git;a=commitdiff_plain;h=18759ee3da54601e0a475d9f99eed11877bdc49b Introduce A_THREADSAFE and A_FORKSAFE --- diff --git a/Makefile.PL b/Makefile.PL index 01f6293..e33c81c 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,6 +4,20 @@ use strict; use warnings; use ExtUtils::MakeMaker; +my @DEFINES; + +# Threads, Windows and 5.8.x don't seem to be best friends +if ($^O eq 'MSWin32' && $^V lt v5.9.0) { + push @DEFINES, '-DA_MULTIPLICITY=0'; +} + +# Fork emulation got "fixed" in 5.10.1 +if ($^O eq 'MSWin32' && $^V lt v5.10.1) { + push @DEFINES, '-DA_FORKSAFE=0'; +} + +@DEFINES = (DEFINE => join ' ', @DEFINES) if @DEFINES; + my $dist = 'autovivification'; (my $name = $dist) =~ s{-}{::}g; @@ -24,7 +38,7 @@ my %META = ( 'Test::More' => 0, %PREREQ_PM, }, - dynamic_config => 0, + dynamic_config => 1, resources => { bugtracker => "http://rt.cpan.org/NoAuth/ReportBug.html?Queue=$dist", homepage => "http://search.cpan.org/dist/$dist/", @@ -40,6 +54,7 @@ WriteMakefile( VERSION_FROM => $file, ABSTRACT_FROM => $file, PL_FILES => {}, + @DEFINES, PREREQ_PM => \%PREREQ_PM, MIN_PERL_VERSION => 5.008, META_MERGE => \%META, diff --git a/autovivification.xs b/autovivification.xs index d078674..b4c76a1 100644 --- a/autovivification.xs +++ b/autovivification.xs @@ -41,6 +41,15 @@ /* ... Thread safety and multiplicity ...................................... */ +/* Always safe when the workaround isn't needed */ +#if !A_WORKAROUND_REQUIRE_PROPAGATION +# undef A_FORKSAFE +# define A_FORKSAFE 1 +/* Otherwise, safe unless Makefile.PL says it's Win32 */ +#elif !defined(A_FORKSAFE) +# define A_FORKSAFE 1 +#endif + #ifndef A_MULTIPLICITY # if defined(MULTIPLICITY) || defined(PERL_IMPLICIT_CONTEXT) # define A_MULTIPLICITY 1 @@ -1026,6 +1035,8 @@ BOOT: newCONSTSUB(stash, "A_HINT_EXISTS", newSVuv(A_HINT_EXISTS)); newCONSTSUB(stash, "A_HINT_DELETE", newSVuv(A_HINT_DELETE)); newCONSTSUB(stash, "A_HINT_MASK", newSVuv(A_HINT_MASK)); + newCONSTSUB(stash, "A_THREADSAFE", newSVuv(A_THREADSAFE)); + newCONSTSUB(stash, "A_FORKSAFE", newSVuv(A_FORKSAFE)); } } diff --git a/lib/autovivification.pm b/lib/autovivification.pm index 8d56b08..ad2e47e 100644 --- a/lib/autovivification.pm +++ b/lib/autovivification.pm @@ -151,6 +151,17 @@ sub import { (); } +=head1 CONSTANTS + +=head2 C + +True iff the module could have been built with thread-safety features enabled. + +=head2 C + +True iff this module could have been built with fork-safety features enabled. +This will always be true except on Windows where it's false for perl 5.10.0 and below . + =head1 CAVEATS The pragma doesn't apply when one dereferences the returned value of an array or hash slice, as in C<< @array[$id]->{member} >> or C<< @hash{$key}->{member} >>.