From 61d82105f14abe49feaf642b92975b082f5347b0 Mon Sep 17 00:00:00 2001 From: Roman Tsisyk Date: Tue, 7 May 2019 08:40:22 +0300 Subject: [PATCH] Fix "missing declaration for symbol ''pj_get_errno''" Closes #11 --- gis/projection.lua | 28 +++++++++++++++++----------- tests/projection.test.lua | 15 ++++++++++++++- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/gis/projection.lua b/gis/projection.lua index c11729e..7798121 100644 --- a/gis/projection.lua +++ b/gis/projection.lua @@ -28,21 +28,27 @@ if proj_path == nil then error("Failed to find internal library") end local lib = ffi.load(proj_path) --- local ctx = lib.pj_ctx_alloc() --- if ctx == nil then --- error('Failed to create proj4 context') --- end --- ffi.gc(ctx, lib.pj_ctx_free) +local ctx = lib.pj_ctx_alloc() +if ctx == nil then + error('Failed to create proj4 context') +end +ffi.gc(ctx, lib.pj_ctx_free) local projections = {} local PROJ_VERSION = ffi.string(lib.libproj_version()) projections.PROJ_VERSION = PROJ_VERSION +local function ctx_raise_errno(errno) + assert(errno ~= 0) + local errstr = lib.pj_strerrno(errno) + local errstr = errstr ~= nil and ffi.string(errstr) or "Unknown error" + error('PROJ: '..errstr) +end + local function ctx_raise() - -- local errno = lib.pj_ctx_get_errno(ctx) - local errno = lib.pj_get_errno(ctx) - error('PROJ: '..ffi.string(lib.pj_strerrno(errno))) + local errno = lib.pj_ctx_get_errno(ctx) + return ctx_raise_errno(errno) end local proj_t = ffi.typeof('struct PJ') @@ -105,9 +111,9 @@ local function proj_transformv(src, dst, count, xvec, yvec, zvec) "xvec: double[], yvec: double[], zvec: double[])") end proj_arg(src) - local rc = lib.pj_transform(src, dst, count, 1, xvec, yvec, zvec) - if rc ~= 0 then - ctx_raise() + local errno = lib.pj_transform(src, dst, count, 1, xvec, yvec, zvec) + if errno ~= 0 then + ctx_raise_errno(errno) end return true end diff --git a/tests/projection.test.lua b/tests/projection.test.lua index eac369c..05ba9e1 100755 --- a/tests/projection.test.lua +++ b/tests/projection.test.lua @@ -8,7 +8,7 @@ local gis = require('gis') gis.install() local projection = require('gis.projection') local test = require('tap').test('gis.projection') -test:plan(23) +test:plan(25) local status, reason local latlong = projection[4326] @@ -81,4 +81,17 @@ test:ok(dist(x - x1, y - y1, z - z1) < 1e-3, "transform(utm, geocent)") local a1, b1 = geocent:transform(utm44n, x, y, z) test:ok(dist(a - a1, b - b1) < 1e-3, "transform(geocent, utm)") +-- +-- Bugs +-- + +-- missing declaration for symbol ''pj_get_errno'' +-- https://github.com/tarantool/gis/issues/11 +local second = gis.Point({43.035657, 131.891867}, 4326) +local first = gis.Point({43.165000, 131.906750}, 4326) +local linec = gis.LineString({first, second}, 4326) +local err, reason = pcall(linec.transform, linec, 32644) +test:is(err, false, "transform error 1") +test:like(reason, "exceeded limits", "transform error 2") + os.exit(test:check() == true and 0 or -1)