swift-db-mysql 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.2.0 (2012-07-30)
2
+
3
+ * cleaup & remove rb_gc_mark outside the mark phase.
4
+
1
5
  == 0.1.2 (2012-07-29)
2
6
 
3
7
  * gc guard bind parameters during execute.
@@ -30,8 +30,8 @@ Adapter* db_mysql_adapter_handle_safe(VALUE self) {
30
30
  }
31
31
 
32
32
  void db_mysql_adapter_mark(Adapter *a) {
33
- if (a)
34
- rb_gc_mark_maybe(a->io);
33
+ if (a && a->io)
34
+ rb_gc_mark(a->io);
35
35
  }
36
36
 
37
37
  VALUE db_mysql_adapter_deallocate(Adapter *a) {
@@ -43,26 +43,27 @@ VALUE db_mysql_adapter_deallocate(Adapter *a) {
43
43
 
44
44
  VALUE db_mysql_adapter_allocate(VALUE klass) {
45
45
  Adapter *a = (Adapter*)malloc(sizeof(Adapter));
46
-
47
- a->connection = 0;
48
- a->t_nesting = 0;
49
- a->io = Qnil;
46
+ memset(a, 0, sizeof(Adapter));
50
47
  return Data_Wrap_Struct(klass, db_mysql_adapter_mark, db_mysql_adapter_deallocate, a);
51
48
  }
52
49
 
53
50
  int db_mysql_adapter_infile_init(void **ptr, const char *filename, void *self) {
54
51
  Adapter *a = db_mysql_adapter_handle_safe((VALUE)self);
55
52
  *ptr = (void *)self;
56
- return NIL_P(a->io) ? -1 : 0;
53
+ return a->io ? 0 : -1;
57
54
  }
58
55
 
59
56
  int db_mysql_adapter_infile_read(void *ptr, char *buffer, unsigned int size) {
60
57
  VALUE data;
61
58
  Adapter *a = db_mysql_adapter_handle_safe((VALUE)ptr);
62
59
 
60
+ if (!a->io)
61
+ return 0;
62
+
63
63
  data = rb_funcall(a->io, rb_intern("read"), 1, INT2NUM(size));
64
64
 
65
- if (NIL_P(data)) return 0;
65
+ if (NIL_P(data))
66
+ return 0;
66
67
 
67
68
  memcpy(buffer, RSTRING_PTR(data), RSTRING_LEN(data));
68
69
  return RSTRING_LEN(data);
@@ -70,12 +71,12 @@ int db_mysql_adapter_infile_read(void *ptr, char *buffer, unsigned int size) {
70
71
 
71
72
  void db_mysql_adapter_infile_end(void *ptr) {
72
73
  Adapter *a = db_mysql_adapter_handle_safe((VALUE)ptr);
73
- a->io = Qnil;
74
+ a->io = 0;
74
75
  }
75
76
 
76
77
  int db_mysql_adapter_infile_error(void *ptr, char *error, unsigned int size) {
77
78
  Adapter *a = db_mysql_adapter_handle_safe((VALUE)ptr);
78
- a->io = Qnil;
79
+ a->io = 0;
79
80
  snprintf(error, size, "error loading data using LOAD INFILE");
80
81
  return 0;
81
82
  }
@@ -402,10 +403,9 @@ VALUE db_mysql_adapter_write(int argc, VALUE *argv, VALUE self) {
402
403
  CSTRING(table), CSTRING(rb_ary_join(fields, rb_str_new2(", "))));
403
404
 
404
405
  a->io = rb_respond_to(io, rb_intern("read")) ? io : rb_funcall(cStringIO, rb_intern("new"), 1, TO_S(io));
405
- rb_gc_mark(a->io);
406
406
  if (mysql_real_query(a->connection, sql, strlen(sql)) != 0) {
407
407
  free(sql);
408
- a->io = Qnil;
408
+ a->io = 0;
409
409
  rb_raise(eSwiftRuntimeError, "%s", mysql_error(a->connection));
410
410
  }
411
411
 
@@ -19,7 +19,6 @@ typedef struct Result {
19
19
 
20
20
  VALUE fields;
21
21
  VALUE types;
22
- VALUE rows;
23
22
  VALUE statement;
24
23
 
25
24
  size_t cols;
@@ -43,14 +42,12 @@ Result* db_mysql_result_handle(VALUE self) {
43
42
 
44
43
  void db_mysql_result_mark(Result *r) {
45
44
  if (r) {
46
- if (!NIL_P(r->fields))
47
- rb_gc_mark_maybe(r->fields);
48
- if (!NIL_P(r->types))
49
- rb_gc_mark_maybe(r->types);
50
- if (!NIL_P(r->rows))
51
- rb_gc_mark_maybe(r->rows);
52
- if (!NIL_P(r->rows))
53
- rb_gc_mark_maybe(r->statement);
45
+ if (r->fields)
46
+ rb_gc_mark(r->fields);
47
+ if (r->types)
48
+ rb_gc_mark(r->types);
49
+ if (r->statement)
50
+ rb_gc_mark(r->statement);
54
51
  }
55
52
  }
56
53
 
@@ -86,7 +83,6 @@ VALUE db_mysql_result_load(VALUE self, MYSQL_RES *result, size_t insert_id, size
86
83
  Result *r = db_mysql_result_handle(self);
87
84
  r->fields = rb_ary_new();
88
85
  r->types = rb_ary_new();
89
- r->rows = rb_ary_new();
90
86
  r->r = result;
91
87
  r->affected = affected;
92
88
  r->insert_id = insert_id;
@@ -33,7 +33,7 @@ Statement* db_mysql_statement_handle_safe(VALUE self) {
33
33
 
34
34
  void db_mysql_statement_mark(Statement *s) {
35
35
  if (s && s->adapter)
36
- rb_gc_mark_maybe(s->adapter);
36
+ rb_gc_mark(s->adapter);
37
37
  }
38
38
 
39
39
  VALUE db_mysql_statement_deallocate(Statement *s) {
@@ -54,9 +54,7 @@ VALUE db_mysql_statement_initialize(VALUE self, VALUE adapter, VALUE sql) {
54
54
  MYSQL *connection;
55
55
  Statement *s = db_mysql_statement_handle(self);
56
56
 
57
- s->adapter = adapter;
58
- rb_gc_mark(s->adapter);
59
-
57
+ s->adapter = adapter;
60
58
  connection = db_mysql_adapter_handle_safe(adapter)->connection;
61
59
  s->statement = mysql_stmt_init(connection);
62
60
  sql = TO_S(sql);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift-db-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-29 00:00:00.000000000 Z
12
+ date: 2012-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -37,11 +37,11 @@ extra_rdoc_files: []
37
37
  files:
38
38
  - ext/swift/db/mysql/datetime.c
39
39
  - ext/swift/db/mysql/main.c
40
- - ext/swift/db/mysql/adapter.c
41
40
  - ext/swift/db/mysql/result.c
42
41
  - ext/swift/db/mysql/typecast.c
43
42
  - ext/swift/db/mysql/statement.c
44
43
  - ext/swift/db/mysql/common.c
44
+ - ext/swift/db/mysql/adapter.c
45
45
  - ext/swift/db/mysql/typecast.h
46
46
  - ext/swift/db/mysql/datetime.h
47
47
  - ext/swift/db/mysql/adapter.h