mmdb 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/mmdb/extconf.rb +3 -0
  3. data/ext/mmdb/mmdb.c +25 -19
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c003d1a3bcc65bfd788940aee81b4e4e5d68bf9b
4
- data.tar.gz: 1d0b0c279059882fae061b885b68386a8bcb910f
3
+ metadata.gz: 5c277732d781d5af075093218d48ca835861c071
4
+ data.tar.gz: 9bcdfc506dbaef0e3266f41fb3dcac470cbce7f6
5
5
  SHA512:
6
- metadata.gz: 88c2e1f0674ec8978be22616318dc6ed024b66f22fc973ab00913c31d20ccbf0aa2953535d98fbb589df3504a2d23fc6e6259ea0089d9a940f2d0e514511a8c7
7
- data.tar.gz: 8492961a442761eb29507316adbb6926bf5efe85ac70a505bb2e3a1feeef6f3cd2e1b760852f0dc03fcf5bc04ef30423712c6d7ee860aecb22517cd202f13dcd
6
+ metadata.gz: 6d29a077fb62a5a3fe7c88fb7de3c93c8f06bce27c0ae9ae717e5a270a8b0b6f3b8c6b02fdb2381f03eca94f485c3703b828eacad8e0f41e5b5864c83f6d2287
7
+ data.tar.gz: 3efa13c0ae818c60b62234649fdf852226eaf8fa1ffeee3803ff7907d35079e91f2dae8703b35b0319da274200e616441797659a7b5162a9ec906a1f3b2ea3f5
@@ -1,5 +1,8 @@
1
1
  require 'mkmf'
2
2
 
3
3
  if have_header("maxminddb.h") && have_library("maxminddb")
4
+ if enable_config("debug")
5
+ CONFIG["debugflags"] << " -g3 -O0"
6
+ end
4
7
  create_makefile("mmdb")
5
8
  end
@@ -70,15 +70,6 @@ static const rb_data_type_t mmdb_data_type = {
70
70
  RUBY_TYPED_FREE_IMMEDIATELY,
71
71
  };
72
72
 
73
- // Supported 2.1 later
74
- #if RUBY_API_VERSION_CODE <= 20100
75
- VALUE
76
- rb_utf8_str_new(const char *ptr, long len) {
77
- VALUE str = rb_str_new(ptr, len);
78
- rb_enc_associate_index(str, rb_utf8_encindex());
79
- return str;
80
- }
81
- #endif
82
73
  #define check_maxminddb(self) ((struct MaxMindDB*)rb_check_typeddata((self), &mmdb_data_type))
83
74
  #define number_of_digits(n, count) do { \
84
75
  n /= 10; \
@@ -103,6 +94,16 @@ maxminddb_alloc(VALUE klass) {
103
94
  return TypedData_Wrap_Struct(klass, &mmdb_data_type, 0);
104
95
  }
105
96
 
97
+ // Supported 2.1 later
98
+ #if (defined RUBY_API_VERSION_CODE) && (RUBY_API_VERSION_CODE <= 20100)
99
+ static VALUE
100
+ rb_utf8_str_new(const char *ptr, long len) {
101
+ VALUE str = rb_str_new(ptr, len);
102
+ rb_enc_associate_index(str, rb_utf8_encindex());
103
+ return str;
104
+ }
105
+ #endif
106
+
106
107
  static void
107
108
  maxminddb_set_result(VALUE hash, VALUE key, MMDB_entry_data_s *data) {
108
109
  if (data->has_data) {
@@ -164,10 +165,10 @@ maxminddb_lookup(VALUE self, VALUE ip) {
164
165
 
165
166
  lookuped = MMDB_lookup_string(ptr->mmdb, StringValuePtr(ip), &gai_error, &mmdb_error);
166
167
  if (gai_error) {
167
- rb_raise(rb_eTypeError, gai_strerror(gai_error));
168
+ rb_raise(rb_eTypeError, "%s", gai_strerror(gai_error));
168
169
  }
169
170
  if (mmdb_error) {
170
- rb_raise(rb_eTypeError, MMDB_strerror(mmdb_error));
171
+ rb_raise(rb_eTypeError, "%s", MMDB_strerror(mmdb_error));
171
172
  }
172
173
 
173
174
  if (lookuped.found_entry) {
@@ -200,14 +201,17 @@ maxminddb_lookup(VALUE self, VALUE ip) {
200
201
  // subdivisions fields is basically array
201
202
  if (data.type == MMDB_DATA_TYPE_ARRAY) {
202
203
  VALUE ary = rb_ary_new();
203
- int i;
204
- int n, data_size;
205
- int count = 0;
206
- n = data_size = data.data_size;
207
- number_of_digits(n, count);
208
- char index[count+1];
209
-
210
- for (i = 0; i < data_size; i++) {
204
+ unsigned int i, n;
205
+ unsigned int cnt = 0;
206
+ char *index;
207
+
208
+ // need to specify index as char*
209
+ n = data.data_size;
210
+ number_of_digits(n, cnt);
211
+ index = (char *)malloc(sizeof(char)*cnt+1);
212
+ memset(index, 0, sizeof(char)*cnt+1);
213
+
214
+ for (i = 0; i < data.data_size; i++) {
211
215
  sprintf(index, "%d", i);
212
216
  MMDB_get_value(entry, &data, subdivisions, index, names, en, NULL);
213
217
  if (data.has_data) {
@@ -217,6 +221,8 @@ maxminddb_lookup(VALUE self, VALUE ip) {
217
221
  }
218
222
  }
219
223
 
224
+ free(index);
225
+
220
226
  rb_hash_aset(ret, rb_sym_subdivisions, ary);
221
227
  }
222
228
  } else {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoppi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-09 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler