Skip to content

Commit 3f95c31

Browse files
rtsisykkostja
authored andcommitted
Fix "missing declaration for symbol ''pj_get_errno''" (#12)
Closes #11
1 parent 1d8efe0 commit 3f95c31

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

gis/projection.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,27 @@ if proj_path == nil then
2828
error("Failed to find internal library")
2929
end
3030
local lib = ffi.load(proj_path)
31-
-- local ctx = lib.pj_ctx_alloc()
32-
-- if ctx == nil then
33-
-- error('Failed to create proj4 context')
34-
-- end
35-
-- ffi.gc(ctx, lib.pj_ctx_free)
31+
local ctx = lib.pj_ctx_alloc()
32+
if ctx == nil then
33+
error('Failed to create proj4 context')
34+
end
35+
ffi.gc(ctx, lib.pj_ctx_free)
3636

3737
local projections = {}
3838

3939
local PROJ_VERSION = ffi.string(lib.libproj_version())
4040
projections.PROJ_VERSION = PROJ_VERSION
4141

42+
local function ctx_raise_errno(errno)
43+
assert(errno ~= 0)
44+
local errstr = lib.pj_strerrno(errno)
45+
local errstr = errstr ~= nil and ffi.string(errstr) or "Unknown error"
46+
error('PROJ: '..errstr)
47+
end
48+
4249
local function ctx_raise()
43-
-- local errno = lib.pj_ctx_get_errno(ctx)
44-
local errno = lib.pj_get_errno(ctx)
45-
error('PROJ: '..ffi.string(lib.pj_strerrno(errno)))
50+
local errno = lib.pj_ctx_get_errno(ctx)
51+
return ctx_raise_errno(errno)
4652
end
4753

4854
local proj_t = ffi.typeof('struct PJ')
@@ -105,9 +111,9 @@ local function proj_transformv(src, dst, count, xvec, yvec, zvec)
105111
"xvec: double[], yvec: double[], zvec: double[])")
106112
end
107113
proj_arg(src)
108-
local rc = lib.pj_transform(src, dst, count, 1, xvec, yvec, zvec)
109-
if rc ~= 0 then
110-
ctx_raise()
114+
local errno = lib.pj_transform(src, dst, count, 1, xvec, yvec, zvec)
115+
if errno ~= 0 then
116+
ctx_raise_errno(errno)
111117
end
112118
return true
113119
end

tests/projection.test.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local gis = require('gis')
88
gis.install()
99
local projection = require('gis.projection')
1010
local test = require('tap').test('gis.projection')
11-
test:plan(23)
11+
test:plan(25)
1212

1313
local status, reason
1414
local latlong = projection[4326]
@@ -81,4 +81,17 @@ test:ok(dist(x - x1, y - y1, z - z1) < 1e-3, "transform(utm, geocent)")
8181
local a1, b1 = geocent:transform(utm44n, x, y, z)
8282
test:ok(dist(a - a1, b - b1) < 1e-3, "transform(geocent, utm)")
8383

84+
--
85+
-- Bugs
86+
--
87+
88+
-- missing declaration for symbol ''pj_get_errno''
89+
-- https://github.com/tarantool/gis/issues/11
90+
local second = gis.Point({43.035657, 131.891867}, 4326)
91+
local first = gis.Point({43.165000, 131.906750}, 4326)
92+
local linec = gis.LineString({first, second}, 4326)
93+
local err, reason = pcall(linec.transform, linec, 32644)
94+
test:is(err, false, "transform error 1")
95+
test:like(reason, "exceeded limits", "transform error 2")
96+
8497
os.exit(test:check() == true and 0 or -1)

0 commit comments

Comments
 (0)