Skip to content

Commit

Permalink
Merge pull request #15 from spacewander/pass_lua_str_directly
Browse files Browse the repository at this point in the history
pass Lua string directly instead of creating a new copy.
  • Loading branch information
anjia0532 authored Dec 11, 2018
2 parents 6776c70 + db8d966 commit d9dd5bd
Showing 1 changed file with 5 additions and 6 deletions.
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

0 comments on commit d9dd5bd

Please sign in to comment.