libcdb-ruby 0.0.2-x86-mswin32-60 → 0.0.3-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,5 +1,10 @@
1
1
  = Revision history for libcdb-ruby
2
2
 
3
+ == 0.0.3 [2012-04-02]
4
+
5
+ * Fixed linking error on Mac OS X. (Issue #1 reported by minaguib)
6
+ * Some internal refactoring.
7
+
3
8
  == 0.0.2 [2012-01-20]
4
9
 
5
10
  * Refactored C code to DRY.
data/ext/libcdb/libcdb.c CHANGED
@@ -1,10 +1,9 @@
1
1
  #include "ruby_libcdb.h"
2
2
 
3
+ VALUE mLibCDB;
4
+
3
5
  void
4
6
  Init_libcdb_ruby(void) {
5
- char libcdb_version[8];
6
- snprintf(libcdb_version, 7, "%g", TINYCDB_VERSION);
7
-
8
7
  /*
9
8
  * LibCDB namespace.
10
9
  */
@@ -1,5 +1,7 @@
1
1
  #include "ruby_libcdb.h"
2
2
 
3
+ VALUE cCDB;
4
+
3
5
  void
4
6
  rcdb_init_cdb(void) {
5
7
  char libcdb_version[8];
@@ -7,24 +7,23 @@
7
7
  #define RCDB_GET_FD(fptr) fileno((fptr)->f)
8
8
  #endif
9
9
 
10
- #define RCDB_GET_STRUCT(what, _struct, obj, ptr) {\
10
+ #define RCDB_GET_STRUCT(what, _struct, obj, ptr) \
11
11
  if (RTEST(rcdb_##what##er_closed_p(obj))) {\
12
12
  rb_raise(rb_eIOError, "closed stream");\
13
13
  }\
14
14
  else {\
15
15
  Data_Get_Struct((obj), struct _struct, (ptr));\
16
16
  }\
17
- }
18
17
 
19
18
  #define RCDB_DEFINE_ALLOC(what, _struct) \
20
19
  static void \
21
20
  rcdb_##what##er_free(void *ptr) {\
22
- free(ptr);\
21
+ xfree(ptr);\
23
22
  }\
24
23
  \
25
24
  static VALUE \
26
25
  rcdb_##what##er_alloc(VALUE klass) {\
27
- struct _struct *ptr = ALLOC_N(struct _struct, 1);\
26
+ struct _struct *ptr = ALLOC(struct _struct);\
28
27
  return Data_Wrap_Struct(klass, NULL, rcdb_##what##er_free, ptr);\
29
28
  }
30
29
 
@@ -45,6 +44,17 @@ rcdb_##what##er_alloc(VALUE klass) {\
45
44
  rb_sys_fail(0);\
46
45
  }
47
46
 
47
+ #define RCDB_RAISE_ARGS(min, max) \
48
+ rb_raise(rb_eArgError,\
49
+ "wrong number of arguments (%d for " #min "-" #max ")", argc);
50
+
51
+ #define RCDB_RETURN_ENUMERATOR(self, argc, argv, max) \
52
+ if (argc > max) {\
53
+ RCDB_RAISE_ARGS(0, max)\
54
+ }\
55
+ \
56
+ RETURN_ENUMERATOR(self, argc, argv)
57
+
48
58
  #define RCDB_DEFINE_INSPECT(what) \
49
59
  static VALUE \
50
60
  rcdb_##what##er_inspect(VALUE self) {\
@@ -58,7 +68,7 @@ rcdb_##what##er_inspect(VALUE self) {\
58
68
  return str;\
59
69
  }
60
70
 
61
- VALUE cCDB;
71
+ extern VALUE cCDB;
62
72
  void rcdb_init_cdb(void);
63
73
 
64
74
  #endif /* __RUBY_CDB_H__ */
@@ -1,5 +1,7 @@
1
1
  #include "ruby_libcdb.h"
2
2
 
3
+ VALUE cCDBReader;
4
+
3
5
  RCDB_DEFINE_ALLOC(read, cdb)
4
6
 
5
7
  /*
@@ -62,23 +64,13 @@ _rcdb_reader_iter_aset(VALUE pair, VALUE hash) {
62
64
  /* Helper method */
63
65
  static VALUE
64
66
  _rcdb_reader_break_equal(VALUE val, VALUE ary) {
65
- if (RCDB_READER_EQUAL(val)) {
66
- rb_ary_store(ary, 0, Qtrue);
67
- rb_iter_break();
68
- }
69
-
70
- return Qnil;
67
+ RCDB_READER_BREAK_EQUAL(val, Qtrue)
71
68
  }
72
69
 
73
70
  /* Helper method */
74
71
  static VALUE
75
72
  _rcdb_reader_break_equal2(VALUE pair, VALUE ary) {
76
- if (RCDB_READER_EQUAL(rb_ary_entry(pair, 1))) {
77
- rb_ary_store(ary, 0, rb_ary_entry(pair, 0));
78
- rb_iter_break();
79
- }
80
-
81
- return Qnil;
73
+ RCDB_READER_BREAK_EQUAL(rb_ary_entry(pair, 1), rb_ary_entry(pair, 0))
82
74
  }
83
75
 
84
76
  /* Helper method */
@@ -92,8 +84,8 @@ _rcdb_reader_break_shift(VALUE val, VALUE ary) {
92
84
 
93
85
  /* Helper method */
94
86
  static VALUE
95
- _rcdb_reader_iter_inc(VALUE val, VALUE ary) {
96
- rb_ary_store(ary, 0, rb_funcall(rb_ary_entry(ary, 0), rb_intern("succ"), 0));
87
+ _rcdb_reader_iter_inc(VALUE val, long *i) {
88
+ ++*i;
97
89
  return Qnil;
98
90
  }
99
91
 
@@ -157,12 +149,7 @@ rcdb_reader_each(int argc, VALUE *argv, VALUE self) {
157
149
  unsigned cdbp;
158
150
  VALUE key;
159
151
 
160
- if (argc > 1) {
161
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-1)", argc);
162
- }
163
-
164
- RETURN_ENUMERATOR(self, argc, argv);
165
-
152
+ RCDB_RETURN_ENUMERATOR(self, argc, argv, 1);
166
153
  RCDB_READER_GET(self, cdb);
167
154
 
168
155
  if (rb_scan_args(argc, argv, "01", &key) == 1 && !NIL_P(key)) {
@@ -203,11 +190,7 @@ rcdb_reader_each_dump(int argc, VALUE *argv, VALUE self) {
203
190
  VALUE key, args = rb_ary_new3(1, self), ary = rb_ary_new();
204
191
  VALUE (*block)(ANYARGS) = _rcdb_reader_yield_dump;
205
192
 
206
- if (argc > 1) {
207
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 0-1)", argc);
208
- }
209
-
210
- RETURN_ENUMERATOR(self, argc, argv);
193
+ RCDB_RETURN_ENUMERATOR(self, argc, argv, 1);
211
194
 
212
195
  if (rb_scan_args(argc, argv, "01", &key) == 1 && !NIL_P(key)) {
213
196
  rb_ary_push(ary, key);
@@ -438,8 +421,9 @@ rcdb_reader_empty_p(VALUE self) {
438
421
  */
439
422
  static VALUE
440
423
  rcdb_reader_size(VALUE self) {
441
- RCDB_READER_ITERATE_ARY(each_key, iter_inc,
442
- rb_ary_new3(1, INT2FIX(0)))
424
+ long i = 0;
425
+ RCDB_READER_ITERATE1(each_key, iter_inc, (VALUE)&i)
426
+ return LONG2NUM(i);
443
427
  }
444
428
 
445
429
  /*
@@ -458,7 +442,7 @@ rcdb_reader_total(VALUE self) {
458
442
  cdb_seqinit(&cdbp, cdb);
459
443
 
460
444
  while (cdb_seqnext(&cdbp, cdb) > 0) {
461
- i++;
445
+ ++i;
462
446
  }
463
447
 
464
448
  return LONG2NUM(i);
@@ -26,8 +26,13 @@ _rcdb_reader_call_##iter(VALUE args) {\
26
26
  RCDB_READER_ITERATE1(method, block, arg1)\
27
27
  return rb_ary_entry(arg, 0);
28
28
 
29
- #define RCDB_READER_EQUAL(val) \
30
- RTEST(rb_funcall((val), rb_intern("=="), 1, rb_ary_entry(ary, 1)))
29
+ #define RCDB_READER_BREAK_EQUAL(val, ret) \
30
+ if (RTEST(rb_funcall(val, rb_intern("=="), 1, rb_ary_entry(ary, 1)))) {\
31
+ rb_ary_store(ary, 0, ret);\
32
+ rb_iter_break();\
33
+ }\
34
+ \
35
+ return Qnil;
31
36
 
32
37
  #define RCDB_READER_DEFINE_READ(what) \
33
38
  static VALUE \
@@ -44,7 +49,7 @@ _rcdb_reader_read_##what(struct cdb *cdb) {\
44
49
  return ret;\
45
50
  }
46
51
 
47
- VALUE cCDBReader;
52
+ extern VALUE cCDBReader;
48
53
  void rcdb_init_reader(void);
49
54
 
50
55
  #endif /* __RCDB_READER_H__ */
@@ -1,5 +1,7 @@
1
1
  #include "ruby_libcdb.h"
2
2
 
3
+ VALUE cCDBWriter;
4
+
3
5
  RCDB_DEFINE_ALLOC(writ, cdb_make)
4
6
 
5
7
  /*
@@ -154,7 +156,7 @@ rcdb_writer_put(int argc, VALUE *argv, VALUE self, enum cdb_put_mode mode) {
154
156
  rcdb_writer_put_value(cdbm, argv[0], argv[1], mode);
155
157
  break;
156
158
  default:
157
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1-2)", argc);
159
+ RCDB_RAISE_ARGS(1, 2)
158
160
  break;
159
161
  }
160
162
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  #define RCDB_WRITER_GET(obj, ptr) RCDB_GET_STRUCT(writ, cdb_make, obj, ptr)
5
5
 
6
- VALUE cCDBWriter;
6
+ extern VALUE cCDBWriter;
7
7
  void rcdb_init_writer(void);
8
8
 
9
9
  #endif /* __RCDB_WRITER_H__ */
@@ -22,6 +22,6 @@
22
22
  #include "ruby_cdb_reader.h"
23
23
  #include "ruby_cdb_writer.h"
24
24
 
25
- VALUE mLibCDB;
25
+ extern VALUE mLibCDB;
26
26
 
27
27
  #endif /* __RUBY_LIBCDB_H__ */
Binary file
Binary file
@@ -6,7 +6,7 @@ module LibCDB
6
6
 
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
- TINY = 2
9
+ TINY = 3
10
10
 
11
11
  class << self
12
12
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libcdb-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: x86-mswin32-60
12
12
  authors:
13
13
  - Jens Wille
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-20 00:00:00 Z
18
+ date: 2012-04-02 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Ruby bindings for CDB Constant Databases.
@@ -65,11 +65,11 @@ post_install_message:
65
65
  rdoc_options:
66
66
  - --main
67
67
  - README
68
- - --all
69
68
  - --charset
70
69
  - UTF-8
71
70
  - --title
72
- - libcdb-ruby Application documentation (v0.0.2)
71
+ - libcdb-ruby Application documentation (v0.0.3)
72
+ - --all
73
73
  - --line-numbers
74
74
  require_paths:
75
75
  - lib
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  requirements: []
95
95
 
96
96
  rubyforge_project:
97
- rubygems_version: 1.8.15
97
+ rubygems_version: 1.8.21
98
98
  signing_key:
99
99
  specification_version: 3
100
100
  summary: Ruby bindings for CDB Constant Databases.