geoip2_c 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a385241251a43ddd2d075ae6edf6079eee160022
4
- data.tar.gz: ba99231f74e179e16f3274eda636860123e2923b
3
+ metadata.gz: 2c4c6ed6506390f217b61759fe77b1523f159b7b
4
+ data.tar.gz: 4ea870d8984e94dd182827b07e5ebce843527ce4
5
5
  SHA512:
6
- metadata.gz: 460dc2adc04bb35833fe48b27688a8d1709ad39526e067bc13ce41d64bb85ee10326c6ff5f493668fad85d135ff213aad862f292e9754db518770e023b2e8756
7
- data.tar.gz: 81b9fb3f1b408568894747fe0695d5892250a94dfdc373c663c6fdcd3d6d9def2fc3eacdeffbfdff77fb303b8fff75cb12ae742284eadba62400cf3b0f5a445d
6
+ metadata.gz: 2f051648f8cc6144c5d952d455c70684246ee929c2db8d016c0a8b6ac802cd0638ff3f935c455b0205081aa3767c09b14a0bdb946d6fd58c60c0c0d542400133
7
+ data.tar.gz: 79e2869114777969696d0dcd0f5aeea37dc3245faf734a1595f72cb30543bd7d5e3d1876af313da9f1ba7992ae6377075b8025d2251fa0ef44fb0fba34d13046
data/.gitignore CHANGED
@@ -12,3 +12,6 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.mmdb
16
+ *.dat
17
+ /benchmark/Gemfile.lock
data/.travis.yml CHANGED
@@ -3,7 +3,12 @@ services:
3
3
  - docker
4
4
 
5
5
  env:
6
- DOCKER_COMPOSE_VERSION: 1.8.1
6
+ global:
7
+ DOCKER_COMPOSE_VERSION: 1.8.1
8
+ matrix:
9
+ - TARGET_RUBY_VERSION=2.1
10
+ - TARGET_RUBY_VERSION=2.2
11
+ - TARGET_RUBY_VERSION=2.3
7
12
 
8
13
  before_install:
9
14
  #- sudo apt-get update
@@ -14,12 +19,12 @@ before_install:
14
19
  - sudo mv docker-compose /usr/local/bin/
15
20
 
16
21
  before_script:
17
- - docker-compose build
22
+ - docker-compose build test-ruby${TARGET_RUBY_VERSION}
18
23
  - docker-compose ps
19
- - docker-compose up -d
20
- - docker-compose exec test bundle install
21
- - docker-compose exec test bundle exec rake compile
24
+ - docker-compose up -d test-ruby${TARGET_RUBY_VERSION}
25
+ - docker-compose exec test-ruby${TARGET_RUBY_VERSION} bundle install
26
+ - docker-compose exec test-ruby${TARGET_RUBY_VERSION} bundle exec rake compile
22
27
 
23
28
  script:
24
- - docker-compose exec test bundle exec rake test
29
+ - docker-compose exec test-ruby${TARGET_RUBY_VERSION} bundle exec rake test
25
30
 
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise "ruby 2.2" do
2
+ gem "dig_rb"
3
+ end
4
+
5
+ appraise "ruby 2.1" do
6
+ gem "dig_rb"
7
+ end
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "bundler/setup"
2
3
  require "rake/testtask"
3
4
 
4
5
  Rake::TestTask.new(:test) do |t|
data/docker-compose.yml CHANGED
@@ -1,6 +1,24 @@
1
1
  version: "2"
2
2
  services:
3
- test:
3
+ test-ruby2.3:
4
4
  build:
5
5
  context: .
6
- command: ruby -run -e httpd
6
+ dockerfile: dockerfiles/Dockerfile-ruby2.3
7
+ command: ruby -run -e httpd .
8
+ environment:
9
+ - BUNDLE_GEMFILE=Gemfile
10
+ test-ruby2.2:
11
+ build:
12
+ context: .
13
+ dockerfile: dockerfiles/Dockerfile-ruby2.2
14
+ command: ruby -run -e httpd .
15
+ environment:
16
+ - BUNDLE_GEMFILE=gemfiles/ruby_2.2.gemfile
17
+ test-ruby2.1:
18
+ build:
19
+ context: .
20
+ dockerfile: dockerfiles/Dockerfile-ruby2.1
21
+ command: ruby -run -e httpd .
22
+ environment:
23
+ - BUNDLE_GEMFILE=gemfiles/ruby_2.1.gemfile
24
+
@@ -1,4 +1,6 @@
1
- FROM ruby:2.3.3-alpine
1
+ FROM ruby:2.1-alpine
2
+
3
+ ENV BUNDLE_GEMFILE=$BUNDLE_GEMFILE
2
4
 
3
5
  RUN apk --no-cache --update add build-base ruby-dev libc6-compat libmaxminddb-dev git
4
6
 
@@ -0,0 +1,8 @@
1
+ FROM ruby:2.2-alpine
2
+
3
+ ENV BUNDLE_GEMFILE=$BUNDLE_GEMFILE
4
+
5
+ RUN apk --no-cache --update add build-base ruby-dev libc6-compat libmaxminddb-dev git
6
+
7
+ WORKDIR /app
8
+ COPY . .
@@ -0,0 +1,8 @@
1
+ FROM ruby:2.3-alpine
2
+
3
+ ENV BUNDLE_GEMFILE=$BUNDLE_GEMFILE
4
+
5
+ RUN apk --no-cache --update add build-base ruby-dev libc6-compat libmaxminddb-dev git
6
+
7
+ WORKDIR /app
8
+ COPY . .
@@ -3,6 +3,7 @@ require "mkmf"
3
3
  dir_config("maxminddb")
4
4
  have_header("maxminddb.h")
5
5
  have_library("maxminddb")
6
+ have_func("rb_sym2str", "ruby.h")
6
7
 
7
8
  $CFLAGS << " -std=c99"
8
9
  # $CFLAGS << " -g -O0"
data/ext/geoip2/geoip2.c CHANGED
@@ -1,6 +1,7 @@
1
1
  #include <ruby.h>
2
2
  #include <ruby/encoding.h>
3
3
  #include <maxminddb.h>
4
+ #include "rb_compat.h"
4
5
 
5
6
  VALUE rb_mGeoIP2;
6
7
  VALUE rb_cGeoIP2Database;
@@ -26,9 +27,6 @@ static VALUE rb_geoip2_lr_initialize(VALUE self);
26
27
  static VALUE rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self);
27
28
  static VALUE rb_geoip2_lr_to_h(VALUE self);
28
29
 
29
- // static void lookup_result_free(void *pointer);
30
- // static size_t lookup_result_size(void *pointer);
31
-
32
30
  static const rb_data_type_t rb_mmdb_type = {
33
31
  "geoip2/mmdb", {
34
32
  0, mmdb_free, 0,
@@ -135,8 +133,11 @@ mmdb_entry_data_decode(MMDB_entry_data_s *entry_data)
135
133
  case MMDB_DATA_TYPE_UINT64:
136
134
  return UINT2NUM(entry_data->uint64);
137
135
  case MMDB_DATA_TYPE_UINT128:
138
- /* FIXME I'm not sure */
136
+ #if !(MMDB_UINT128_IS_BYTE_ARRAY)
139
137
  return UINT2NUM(entry_data->uint128);
138
+ #else
139
+ rb_raise(rb_eNotImpError, "TODO: unit8_t[16] -> Integer");
140
+ #endif
140
141
  case MMDB_DATA_TYPE_ARRAY:
141
142
  /* TODO: not implemented */
142
143
  return Qnil;
@@ -306,6 +307,16 @@ rb_geoip2_lr_initialize(VALUE self)
306
307
  return Qnil;
307
308
  }
308
309
 
310
+ static inline char*
311
+ rb_geoip2_lr_arg_convert_to_cstring(VALUE sym_or_str)
312
+ {
313
+ if (TYPE(sym_or_str) == T_SYMBOL) {
314
+ return RSTRING_PTR(rb_sym2str(sym_or_str));
315
+ } else {
316
+ return StringValueCStr(sym_or_str);
317
+ }
318
+ }
319
+
309
320
  static VALUE
310
321
  rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
311
322
  {
@@ -321,7 +332,16 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
321
332
  int status;
322
333
 
323
334
  rb_scan_args(argc, argv, "1*", &arg, &rest);
324
- Check_Type(arg, T_STRING);
335
+ switch(TYPE(arg)) {
336
+ case T_STRING:
337
+ case T_SYMBOL:
338
+ {
339
+ break;
340
+ }
341
+ default:
342
+ rb_raise(rb_eArgError, "Expected a String or a Symbol");
343
+ break;
344
+ }
325
345
  path = malloc(sizeof(char *) * (RARRAY_LEN(rest) + 2));
326
346
 
327
347
  TypedData_Get_Struct(self,
@@ -329,11 +349,11 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
329
349
  &rb_lookup_result_type,
330
350
  result);
331
351
 
332
- path[i] = StringValueCStr(arg);
352
+ path[i] = rb_geoip2_lr_arg_convert_to_cstring(arg);
333
353
  while (RARRAY_LEN(rest) != 0) {
334
354
  ++i;
335
355
  e = rb_ary_shift(rest);
336
- tmp = StringValueCStr(e);
356
+ tmp = rb_geoip2_lr_arg_convert_to_cstring(e);
337
357
  path[i] = tmp;
338
358
  }
339
359
 
@@ -345,7 +365,7 @@ rb_geoip2_lr_get_value(int argc, VALUE *argv, VALUE self)
345
365
 
346
366
  if (status != MMDB_SUCCESS) {
347
367
  free(path);
348
- fprintf(stderr, "%s\n", MMDB_strerror(status));
368
+ /* fprintf(stderr, "%s:%s\n", __FUNCTION__, MMDB_strerror(status)); */
349
369
  return Qnil;
350
370
  }
351
371
 
@@ -379,9 +399,15 @@ rb_geoip2_lr_to_h(VALUE self)
379
399
  MMDB_lookup_result_s *result = NULL;
380
400
  MMDB_entry_data_list_s *entry_data_list = NULL;
381
401
  VALUE hash;
402
+ VALUE cache;
382
403
  int status = 0;
383
404
  int exception = 0;
384
405
 
406
+ cache = rb_ivar_get(self, rb_intern("rb_hash"));
407
+ if (!NIL_P(cache)) {
408
+ return cache;
409
+ }
410
+
385
411
  TypedData_Get_Struct(self,
386
412
  struct MMDB_lookup_result_s,
387
413
  &rb_lookup_result_type,
@@ -398,6 +424,8 @@ rb_geoip2_lr_to_h(VALUE self)
398
424
  rb_jump_tag(exception);
399
425
  }
400
426
 
427
+ rb_ivar_set(self, rb_intern("rb_hash"), hash);
428
+
401
429
  return hash;
402
430
  }
403
431
 
@@ -0,0 +1,10 @@
1
+ #ifndef __RB_COMPAT_H__
2
+ #define __RB_COMPAT_H__
3
+
4
+ #include <ruby.h>
5
+
6
+ #ifndef HAVE_RB_SYM2STR
7
+ # define rb_sym2str(name) (rb_id2str(SYM2ID(name)))
8
+ #endif
9
+
10
+ #endif
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "dig_rb"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "dig_rb"
6
+
7
+ gemspec :path => "../"
data/geoip2_c.gemspec CHANGED
@@ -15,13 +15,14 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "Apache-2.0"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
18
+ f.match(%r{^(test|spec|features|benchmark)/})
19
19
  end
20
20
  spec.bindir = "bin"
21
21
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
  spec.extensions = ["ext/geoip2/extconf.rb"]
24
24
 
25
+ spec.add_development_dependency "appraisal"
25
26
  spec.add_development_dependency "bundler", "~> 1.13"
26
27
  spec.add_development_dependency "rake", "~> 11.0"
27
28
  spec.add_development_dependency "rake-compiler"
@@ -1,3 +1,3 @@
1
1
  module GeoIP2
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoip2_c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okkez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-20 00:00:00.000000000 Z
11
+ date: 2016-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: appraisal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -77,14 +91,20 @@ files:
77
91
  - ".gitignore"
78
92
  - ".gitmodules"
79
93
  - ".travis.yml"
80
- - Dockerfile
94
+ - Appraisals
81
95
  - Gemfile
82
96
  - LICENSE.txt
83
97
  - README.md
84
98
  - Rakefile
85
99
  - docker-compose.yml
100
+ - dockerfiles/Dockerfile-ruby2.1
101
+ - dockerfiles/Dockerfile-ruby2.2
102
+ - dockerfiles/Dockerfile-ruby2.3
86
103
  - ext/geoip2/extconf.rb
87
104
  - ext/geoip2/geoip2.c
105
+ - ext/geoip2/rb_compat.h
106
+ - gemfiles/ruby_2.1.gemfile
107
+ - gemfiles/ruby_2.2.gemfile
88
108
  - geoip2_c.gemspec
89
109
  - lib/geoip2.rb
90
110
  - lib/geoip2/database.rb