Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass Lua string directly instead of creating a new copy. #15

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/resty/maxminddb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ end

function _M.init(dbfile)
if not initted then
local file_name_ip2 = ffi_new('char[?]',#dbfile,dbfile)
local maxmind_ready = maxm.MMDB_open(file_name_ip2,0,mmdb)
local maxmind_ready = maxm.MMDB_open(dbfile,0,mmdb)

if maxmind_ready ~= MMDB_SUCCESS then
return nil, mmdb_strerror(maxmind_ready)
end

ffi_gc(mmdb, maxm.MMDB_close)

initted = true

ffi_gc(mmdb, maxm.MMDB_close)
end
return initted
end
Expand Down Expand Up @@ -316,11 +316,10 @@ function _M.lookup(ip)
return nil, "not initialized"
end

local ip_str = ffi_cast('const char *',ffi_new('char[?]',#ip+1,ip))
local gai_error = ffi_new('int[1]')
local mmdb_error = ffi_new('int[1]')

local result = maxm.MMDB_lookup_string(mmdb,ip_str,gai_error,mmdb_error)
local result = maxm.MMDB_lookup_string(mmdb,ip,gai_error,mmdb_error)

if mmdb_error[0] ~= MMDB_SUCCESS then
return nil,'fail when lookup'
Expand Down