The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Changes 08
META.json 22
META.yml 77
README 11
XS.xs 254
lib/Geo/Distance/XS.pm 46
ppport.h 16152
t/01_new.t 21
8 files changed (This is a version diff) 57181
@@ -1,5 +1,13 @@
 Revision history for Geo-Distance-XS
 
+0.13  Fri Jun 20 07:10:41 UTC 2014
+    - Restored support for 5.6.2.
+
+0.12  Wed Jun 18 19:01:04 UTC 2014
+    - Remove deprecated usage defined(@array) from a test case.
+    - Optimized the case where both coordinates are identical.
+    - Updated ppport.h.
+
 0.11  Sat Apr 14 03:45:08 UTC 2012
     - Adjusted constants for better accuracy.
 
@@ -4,7 +4,7 @@
       "gray <gray@cpan.org>"
    ],
    "dynamic_config" : 1,
-   "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921",
+   "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.141520",
    "license" : [
       "perl_5"
    ],
@@ -43,5 +43,5 @@
          "url" : "http://github.com/gray/geo-distance-xs"
       }
    },
-   "version" : "0.11"
+   "version" : "0.13"
 }
@@ -3,23 +3,23 @@ abstract: 'speed up Geo::Distance'
 author:
   - 'gray <gray@cpan.org>'
 build_requires:
-  Test::More: 0.82
+  Test::More: '0.82'
 configure_requires:
-  ExtUtils::MakeMaker: 0
+  ExtUtils::MakeMaker: '0'
 dynamic_config: 1
-generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921'
+generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.141520'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
-  version: 1.4
+  version: '1.4'
 name: Geo-Distance-XS
 no_index:
   directory:
     - t
     - inc
 requires:
-  Geo::Distance: 0.16
-  XSLoader: 0
+  Geo::Distance: '0.16'
+  XSLoader: '0'
 resources:
   repository: http://github.com/gray/geo-distance-xs
-version: 0.11
+version: '0.13'
@@ -24,7 +24,7 @@ A C compiler is required to build this module.
 
 COPYRIGHT AND LICENCE
 
-Copyright (C) 2009-2012 by gray <gray@cpan.org>
+Copyright (C) 2009-2014 by gray <gray@cpan.org>
 
 This library is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.
@@ -24,8 +24,6 @@ const double A = 6378137.;
 const double B = 6356752.314245;
 const double F = 1. / 298.257223563;
 
-static HV *formula_indexes;
-
 static void
 my_croak (char* pat, ...) {
     va_list args;
@@ -211,24 +209,6 @@ MODULE = Geo::Distance::XS    PACKAGE = Geo::Distance::XS
 
 PROTOTYPES: DISABLE
 
-BOOT:
-    formula_indexes = newHV();
-    (void)hv_stores(formula_indexes, "hsin", newSViv(1));
-    (void)hv_stores(formula_indexes, "cos", newSViv(2));
-    (void)hv_stores(formula_indexes, "mt", newSViv(2));
-    (void)hv_stores(formula_indexes, "tv", newSViv(3));
-    (void)hv_stores(formula_indexes, "gcd", newSViv(4));
-    (void)hv_stores(formula_indexes, "polar", newSViv(5));
-    (void)hv_stores(formula_indexes, "alt", newSViv(6));
-
-    /* Set the package variable @FORMULAS */
-    AV *formulas = get_av("Geo::Distance::XS::FORMULAS", GV_ADD);
-    (void)hv_iterinit(formula_indexes);
-    HE *ent;
-    while ((ent = hv_iternext(formula_indexes)))
-        av_push(formulas, SvREFCNT_inc(HeSVKEY_force(ent)));
-    sortsv(AvARRAY(formulas), av_len(formulas) + 1, Perl_sv_cmp);
-
 void
 distance (self, unit, lon1, lat1, lon2, lat2)
     SV *self
@@ -242,11 +222,10 @@ PREINIT:
     int index = 1;
     double (*func)(double, double, double, double);
 CODE:
-    key = hv_fetchs((HV *)SvRV(self), "formula", 0);
-    if (key) {
-        HE *ent = hv_fetch_ent(formula_indexes, *key, 0, 0);
-        if (ent) index = SvIV(HeVAL(ent));
-    }
+    if (lat2 == lat1 && lon2 == lon1)
+        XSRETURN_NV(0.);
+    key = hv_fetchs((HV *)SvRV(self), "formula_index", 0);
+    if (key) index = SvIV(*key);
     switch (index) {
         case 1: func = &haversine; break;
         case 2: func = &cosines; break;
@@ -7,7 +7,7 @@ use Carp qw(croak);
 use Geo::Distance;
 use XSLoader;
 
-our $VERSION    = '0.11';
+our $VERSION    = '0.13';
 our $XS_VERSION = $VERSION;
 $VERSION = eval $VERSION;
 
@@ -19,12 +19,13 @@ BEGIN {
     $orig_formula_sub  = \&Geo::Distance::formula;
 }
 
+my %formulas; @formulas{qw(hsin cos mt tv gcd polar alt)} = (1, 2, 2..6);
+our @FORMULAS = sort keys %formulas;
+
 sub import {
     no warnings qw(redefine);
     no strict qw(refs);
 
-    my %formulas = map { $_ => undef } @{__PACKAGE__.'::FORMULAS'};
-
     *Geo::Distance::distance = \&{__PACKAGE__.'::distance'};
     *Geo::Distance::formula = sub {
         my $self = shift;
@@ -33,6 +34,7 @@ sub import {
             croak "Invalid formula: $formula"
                 unless exists $formulas{$formula};
             $self->{formula} = $formula;
+            $self->{formula_index} = $formulas{$formula};
         }
         return $self->{formula};
     };
@@ -250,7 +252,7 @@ L<http://search.cpan.org/dist/Geo-Distance-XS/>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (C) 2009-2012 gray <gray at cpan.org>, all rights reserved.
+Copyright (C) 2009-2014 gray <gray at cpan.org>, all rights reserved.
 
 This library is free software; you can redistribute it and/or modify it
 under the same terms as Perl itself.
@@ -4,11 +4,11 @@
 /*
 ----------------------------------------------------------------------
 
-    ppport.h -- Perl/Pollution/Portability Version 3.19
+    ./ppport.h -- Perl/Pollution/Portability Version 3.24
 
-    Automatically created by Devel::PPPort running under perl 5.012002.
+    Automatically created by Devel::PPPort running under perl 5.018002.
 
-    Version 3.x, Copyright (c) 2004-2009, Marcus Holland-Moritz.
+    Version 3.x, Copyright (c) 2004-2013, Marcus Holland-Moritz.
 
     Version 2.x, Copyright (C) 2001, Paul Marquess.
 
@@ -23,8 +23,8 @@ SKIP
 if (@ARGV && $ARGV[0] eq '--unstrip') {
   eval { require Devel::PPPort };
   $@ and die "Cannot require Devel::PPPort, please install.\n";
-  if (eval $Devel::PPPort::VERSION < 3.19) {
-    die "ppport.h was originally generated with Devel::PPPort 3.19.\n"
+  if (eval $Devel::PPPort::VERSION < 3.24) {
+    die "./ppport.h was originally generated with Devel::PPPort 3.24.\n"
       . "Your Devel::PPPort is only version $Devel::PPPort::VERSION.\n"
       . "Please install a newer version, or --unstrip will not work.\n";
   }
@@ -66,7 +66,7 @@ __DATA__*/
 #define _dpppDEC2BCD(dec) ((((dec)/100)<<8)|((((dec)%100)/10)<<4)|((dec)%10))
 #define PERL_BCDVERSION ((_dpppDEC2BCD(PERL_REVISION)<<24)|(_dpppDEC2BCD(PERL_VERSION)<<12)|_dpppDEC2BCD(PERL_SUBVERSION))
 #if PERL_REVISION != 5
-#error ppport.h only works with Perl version 5
+#error ./ppport.h only works with Perl version 5
 #endif
 #ifndef dTHR
 #define dTHR dNOOP
@@ -351,6 +351,9 @@ __DATA__*/
 #ifndef IVSIZE
 #define IVSIZE 8
 #endif
+#ifndef LONGSIZE
+#define LONGSIZE 8
+#endif
 #ifndef PERL_QUAD_MIN
 #define PERL_QUAD_MIN IV_MIN
 #endif
@@ -367,6 +370,9 @@ __DATA__*/
 #ifndef IVTYPE
 #define IVTYPE long
 #endif
+#ifndef LONGSIZE
+#define LONGSIZE 4
+#endif
 #ifndef IV_MIN
 #define IV_MIN PERL_LONG_MIN
 #endif
@@ -454,6 +460,13 @@ sv_setnv(sv, (double)TeMpUv); \
 #define memEQ(s1,s2,l) (!bcmp(s1,s2,l))
 #endif
 #endif
+#ifndef memEQs
+#define memEQs(s1, l, s2) \
+(sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1)))
+#endif
+#ifndef memNEs
+#define memNEs(s1, l, s2) !memEQs(s1, l, s2)
+#endif
 #ifndef MoveD
 #define MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t))
 #endif
@@ -748,14 +761,19 @@ typedef OP* (CPERLscope(*Perl_check_t)) (pTHX_ OP*);
 #if (PERL_BCDVERSION < 0x5010000)
 #undef isPRINT
 #endif
+#ifdef HAS_QUAD
+#define WIDEST_UTYPE U64TYPE
+#else
+#define WIDEST_UTYPE U32
+#endif
 #ifndef isALNUMC
 #define isALNUMC(c) (isALPHA(c) || isDIGIT(c))
 #endif
 #ifndef isASCII
-#define isASCII(c) ((c) <= 127)
+#define isASCII(c) ((WIDEST_UTYPE) (c) <= 127)
 #endif
 #ifndef isCNTRL
-#define isCNTRL(c) ((c) < ' ' || (c) == 127)
+#define isCNTRL(c) ((WIDEST_UTYPE) (c) < ' ' || (c) == 127)
 #endif
 #ifndef isGRAPH
 #define isGRAPH(c) (isALNUM(c) || isPUNCT(c))
@@ -770,6 +788,13 @@ typedef OP* (CPERLscope(*Perl_check_t)) (pTHX_ OP*);
 #define isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'))
 #endif
 #endif
+#if (PERL_BCDVERSION >= 0x5008000)
+#ifndef HeUTF8
+#define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \
+SvUTF8(HeKEY_sv(he)) : \
+(U32)HeKUTF8(he))
+#endif
+#endif
 #ifndef PERL_SIGNALS_UNSAFE_FLAG
 #define PERL_SIGNALS_UNSAFE_FLAG 0x0001
 #if (PERL_BCDVERSION < 0x5008000)
@@ -1024,6 +1049,9 @@ const int oexpect = PL_expect;
 #if (PERL_BCDVERSION >= 0x5004000)
 utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0),
 veop, modname, imop);
+#elif (PERL_BCDVERSION > 0x5003000)
+utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(),
+veop, modname, imop);
 #else
 utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(),
 modname, imop);
@@ -1188,14 +1216,14 @@ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
 #define UVof "lo"
 #define UVxf "lx"
 #define UVXf "lX"
-#else
-#if IVSIZE == INTSIZE
+#elif IVSIZE == INTSIZE
 #define IVdf "d"
 #define UVuf "u"
 #define UVof "o"
 #define UVxf "x"
 #define UVXf "X"
-#endif
+#else
+#error "cannot define IV/UV formats"
 #endif
 #endif
 #ifndef NVef
@@ -1531,6 +1559,10 @@ sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN))
 #ifndef SvPV_nomg_const_nolen
 #define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0)
 #endif
+#ifndef SvPV_nomg_nolen
+#define SvPV_nomg_nolen(sv) ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
+? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, 0))
+#endif
 #ifndef SvPV_renew
 #define SvPV_renew(sv,n) STMT_START { SvLEN_set(sv, n); \
 SvPV_set((sv), (char *) saferealloc( \
@@ -1774,6 +1806,15 @@ return sv;
 #ifndef isGV_with_GP
 #define isGV_with_GP(gv) isGV(gv)
 #endif
+#ifndef gv_fetchpvn_flags
+#define gv_fetchpvn_flags(name, len, flags, svt) gv_fetchpv(name, flags, svt)
+#endif
+#ifndef gv_fetchsv
+#define gv_fetchsv(name, flags, svt) gv_fetchpv(SvPV_nolen_const(name), flags, svt)
+#endif
+#ifndef get_cvn_flags
+#define get_cvn_flags(name, namelen, flags) get_cv(name, flags)
+#endif
 #ifndef WARN_ALL
 #define WARN_ALL 0
 #endif
@@ -1959,6 +2000,9 @@ warn("%s", SvPV_nolen(sv));
 #ifndef newSVpvs_flags
 #define newSVpvs_flags(str, flags) newSVpvn_flags(str "", sizeof(str) - 1, flags)
 #endif
+#ifndef newSVpvs_share
+#define newSVpvs_share(str) newSVpvn_share(str "", sizeof(str) - 1, 0)
+#endif
 #ifndef sv_catpvs
 #define sv_catpvs(sv, str) sv_catpvn(sv, str "", sizeof(str) - 1)
 #endif
@@ -1971,18 +2015,27 @@ warn("%s", SvPV_nolen(sv));
 #ifndef hv_stores
 #define hv_stores(hv, key, val) hv_store(hv, key "", sizeof(key) - 1, val, 0)
 #endif
-#ifndef gv_fetchpvn_flags
-#define gv_fetchpvn_flags(name, len, flags, svt) gv_fetchpv(name, flags, svt)
-#endif
 #ifndef gv_fetchpvs
 #define gv_fetchpvs(name, flags, svt) gv_fetchpvn_flags(name "", sizeof(name) - 1, flags, svt)
 #endif
 #ifndef gv_stashpvs
 #define gv_stashpvs(name, flags) gv_stashpvn(name "", sizeof(name) - 1, flags)
 #endif
+#ifndef get_cvs
+#define get_cvs(name, flags) get_cvn_flags(name "", sizeof(name)-1, flags)
+#endif
 #ifndef SvGETMAGIC
 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
 #endif
+#ifndef HEf_SVKEY
+#define HEf_SVKEY -2
+#endif
+#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
+#define MUTABLE_PTR(p) ({ void *_p = (p); _p; })
+#else
+#define MUTABLE_PTR(p) ((void *) (p))
+#endif
+#define MUTABLE_SV(p) ((SV *)MUTABLE_PTR(p))
 #ifndef PERL_MAGIC_sv
 #define PERL_MAGIC_sv '\0'
 #endif
@@ -2224,6 +2277,89 @@ sv_magic(SvMp_sv, obj, how, SvMp_name, SvMp_namlen); \
 #else
 #define sv_magic_portable(a, b, c, d, e) sv_magic(a, b, c, d, e)
 #endif
+#if !defined(mg_findext)
+#if defined(NEED_mg_findext)
+static MAGIC * DPPP_(my_mg_findext)(pTHX_ SV * sv, int type, const MGVTBL *vtbl);
+static
+#else
+extern MAGIC * DPPP_(my_mg_findext)(pTHX_ SV * sv, int type, const MGVTBL *vtbl);
+#endif
+#ifdef mg_findext
+#undef mg_findext
+#endif
+#define mg_findext(a,b,c) DPPP_(my_mg_findext)(aTHX_ a,b,c)
+#define Perl_mg_findext DPPP_(my_mg_findext)
+#if defined(NEED_mg_findext) || defined(NEED_mg_findext_GLOBAL)
+MAGIC *
+DPPP_(my_mg_findext)(pTHX_ SV * sv, int type, const MGVTBL *vtbl) {
+if (sv) {
+MAGIC *mg;
+#ifdef AvPAD_NAMELIST
+assert(!(SvTYPE(sv) == SVt_PVAV && AvPAD_NAMELIST(sv)));
+#endif
+for (mg = SvMAGIC (sv); mg; mg = mg->mg_moremagic) {
+if (mg->mg_type == type && mg->mg_virtual == vtbl)
+return mg;
+}
+}
+return NULL;
+}
+#endif
+#endif
+#if !defined(sv_unmagicext)
+#if defined(NEED_sv_unmagicext)
+static int DPPP_(my_sv_unmagicext)(pTHX_ SV * const sv, const int type, MGVTBL * vtbl);
+static
+#else
+extern int DPPP_(my_sv_unmagicext)(pTHX_ SV * const sv, const int type, MGVTBL * vtbl);
+#endif
+#ifdef sv_unmagicext
+#undef sv_unmagicext
+#endif
+#define sv_unmagicext(a,b,c) DPPP_(my_sv_unmagicext)(aTHX_ a,b,c)
+#define Perl_sv_unmagicext DPPP_(my_sv_unmagicext)
+#if defined(NEED_sv_unmagicext) || defined(NEED_sv_unmagicext_GLOBAL)
+int
+DPPP_(my_sv_unmagicext)(pTHX_ SV *const sv, const int type, MGVTBL *vtbl)
+{
+MAGIC* mg;
+MAGIC** mgp;
+if (SvTYPE(sv) < SVt_PVMG || !SvMAGIC(sv))
+return 0;
+mgp = &(SvMAGIC(sv));
+for (mg = *mgp; mg; mg = *mgp) {
+const MGVTBL* const virt = mg->mg_virtual;
+if (mg->mg_type == type && virt == vtbl) {
+*mgp = mg->mg_moremagic;
+if (virt && virt->svt_free)
+virt->svt_free(aTHX_ sv, mg);
+if (mg->mg_ptr && mg->mg_type != PERL_MAGIC_regex_global) {
+if (mg->mg_len > 0)
+Safefree(mg->mg_ptr);
+else if (mg->mg_len == HEf_SVKEY)
+SvREFCNT_dec(MUTABLE_SV(mg->mg_ptr));
+else if (mg->mg_type == PERL_MAGIC_utf8)
+Safefree(mg->mg_ptr);
+}
+if (mg->mg_flags & MGf_REFCOUNTED)
+SvREFCNT_dec(mg->mg_obj);
+Safefree(mg);
+}
+else
+mgp = &mg->mg_moremagic;
+}
+if (SvMAGIC(sv)) {
+if (SvMAGICAL(sv))
+mg_magical(sv);
+}
+else {
+SvMAGICAL_off(sv);
+SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
+}
+return 0;
+}
+#endif
+#endif
 #ifdef USE_ITHREADS
 #ifndef CopFILE
 #define CopFILE(c) ((c)->cop_file)
@@ -3006,10 +3142,10 @@ const U8 c = (U8)u & 0xFF;
 if (u > 255 || (flags & PERL_PV_ESCAPE_ALL)) {
 if (flags & PERL_PV_ESCAPE_FIRSTCHAR)
 chsize = my_snprintf(octbuf, sizeof octbuf,
-"%"UVxf, u);
+"%" UVxf, u);
 else
 chsize = my_snprintf(octbuf, sizeof octbuf,
-"%cx{%"UVxf"}", esc, u);
+"%cx{%" UVxf "}", esc, u);
 } else if (flags & PERL_PV_ESCAPE_NOBACKSLASH) {
 chsize = 1;
 } else {
@@ -6,7 +6,6 @@ use Test::More;
 my $geo = Geo::Distance->new;
 isa_ok $geo, 'Geo::Distance', 'new';
 can_ok 'Geo::Distance', qw(distance formula);
-ok defined @Geo::Distance::XS::FORMULAS;
-cmp_ok scalar @Geo::Distance::XS::FORMULAS, '>', 2;
+cmp_ok scalar @Geo::Distance::XS::FORMULAS, '>', 2, '@FORMULAS exists';
 
 done_testing;