--- Geo-LatLon2Place/LatLon2Place.xs 2022/03/15 07:33:40 1.4 +++ Geo-LatLon2Place/LatLon2Place.xs 2022/03/17 00:32:54 1.5 @@ -35,6 +35,12 @@ return a > b ? a : b; } +static inline int +get_u16 (const U8 *ptr) +{ + return ptr[0] | (ptr[1] << 8); +} + MODULE = Geo::LatLon2Place PACKAGE = Geo::LatLon2Place PROTOTYPES: ENABLE @@ -82,7 +88,7 @@ y, y >> 8, }; - printf ("x,y %4d,%4d blat %d %d %g %02x%02x%02x%02x %d\n", rx, y, blat, (int)glat, TORAD(glat), key[0],key[1],key[2],key[3], sizeof(key)); + //printf ("x,y %4d,%4d blat %d %d %g %02x%02x%02x%02x %d\n", rx, y, blat, (int)glat, TORAD(glat), key[0],key[1],key[2],key[3], sizeof(key)); if (cdb_find (db, key, sizeof (key)) <= 0) continue; @@ -94,14 +100,14 @@ { int datalen = ptr[5]; - double plat = ptr[0] | (ptr[1] << 8) * ( 90. / 32767.); - double plon = ptr[2] | (ptr[3] << 8) * (180. / 32767.); + double plat = get_u16 (ptr + 0) * ( 90. / 32767.); + double plon = get_u16 (ptr + 2) * (180. / 32767.); int w = ptr[4]; double dx = TORAD (lon - plon) * coslat; double dy = TORAD (lat - plat); double d2 = (dx * dx + dy * dy) * w; - printf ("%g,%g %g %.*s\n", plat,plon,d2, datalen,ptr+6); + //printf ("%g,%g %g %.*s\n", plat,plon,d2, datalen,ptr+6); if (d2 < mind) { @@ -129,6 +135,7 @@ cdb_init (SV *self, int fd) CODE: sv_upgrade (self, SVt_PV); + sv_grow (self, sizeof (struct cdb)); SvCUR_set (self, sizeof (struct cdb)); SvPOK_only (self); RETVAL = cdb_init ((struct cdb *)SvPVX (self), fd);