swift-db-postgres 0.2.6 → 0.2.7

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.7 (2012-11-22)
2
+
3
+ * rb_gc_register_address() the bind values.
4
+
1
5
  == 0.2.6 (2012-11-14)
2
6
 
3
7
  * Ruby 2.x build fixes.
@@ -127,15 +127,18 @@ VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
127
127
  char **bind_args_data = 0;
128
128
  int n, *bind_args_size = 0, *bind_args_fmt = 0;
129
129
  PGresult *result;
130
- VALUE sql, bind, data;
130
+ VALUE sql, bind, data, typecast_bind;
131
131
  Adapter *a = db_postgres_adapter_handle_safe(self);
132
132
 
133
133
  rb_scan_args(argc, argv, "10*", &sql, &bind);
134
134
  if (!a->native)
135
135
  sql = db_postgres_normalized_sql(sql);
136
136
 
137
+ typecast_bind = rb_ary_new();
138
+ rb_gc_register_address(&typecast_bind);
137
139
  rb_gc_register_address(&sql);
138
140
  rb_gc_register_address(&bind);
141
+
139
142
  if (RARRAY_LEN(bind) > 0) {
140
143
  bind_args_size = (int *) malloc(sizeof(int) * RARRAY_LEN(bind));
141
144
  bind_args_fmt = (int *) malloc(sizeof(int) * RARRAY_LEN(bind));
@@ -155,8 +158,9 @@ VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
155
158
  bind_args_fmt[n] = 0;
156
159
 
157
160
  data = typecast_to_string(data);
161
+ rb_ary_push(typecast_bind, data);
158
162
  bind_args_size[n] = RSTRING_LEN(data);
159
- bind_args_data[n] = CSTRING_PTR(data);
163
+ bind_args_data[n] = RSTRING_PTR(data);
160
164
  }
161
165
  }
162
166
 
@@ -170,9 +174,6 @@ VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
170
174
  };
171
175
 
172
176
  result = (PGresult *)GVL_NOLOCK(nogvl_pq_exec_params, &q, RUBY_UBF_IO, 0);
173
- for (n = 0; n < RARRAY_LEN(bind); n++)
174
- if (bind_args_data[n])
175
- free(bind_args_data[n]);
176
177
  free(bind_args_size);
177
178
  free(bind_args_data);
178
179
  free(bind_args_fmt);
@@ -182,6 +183,7 @@ VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
182
183
  result = (PGresult *)GVL_NOLOCK(nogvl_pq_exec, &q, RUBY_UBF_IO, 0);
183
184
  }
184
185
 
186
+ rb_gc_unregister_address(&typecast_bind);
185
187
  rb_gc_unregister_address(&sql);
186
188
  rb_gc_unregister_address(&bind);
187
189
  db_postgres_check_result(result);
@@ -6,12 +6,6 @@
6
6
  #include <math.h>
7
7
  #include <uuid/uuid.h>
8
8
 
9
- char* CSTRING_PTR(VALUE value) {
10
- char* result = malloc(RSTRING_LEN(value) + 1);
11
- memcpy(result, RSTRING_PTR(value), RSTRING_LEN(value) + 1);
12
- return result;
13
- }
14
-
15
9
  VALUE rb_uuid_string() {
16
10
  size_t n;
17
11
  uuid_t uuid;
@@ -22,7 +22,6 @@ extern VALUE cDPA, cDPS, cDPR;
22
22
  extern VALUE eSwiftError, eSwiftArgumentError, eSwiftRuntimeError, eSwiftConnectionError;
23
23
  extern VALUE cStringIO;
24
24
 
25
- DLL_PRIVATE char* CSTRING_PTR(VALUE);
26
25
  DLL_PRIVATE VALUE rb_uuid_string();
27
26
  DLL_PRIVATE VALUE db_postgres_normalized_sql(VALUE);
28
27
  DLL_PRIVATE void db_postgres_check_result(PGresult *);
@@ -100,14 +100,17 @@ VALUE db_postgres_statement_execute(int argc, VALUE *argv, VALUE self) {
100
100
  PGconn *connection;
101
101
  char **bind_args_data = 0;
102
102
  int n, *bind_args_size = 0, *bind_args_fmt = 0;
103
- VALUE bind, data;
103
+ VALUE bind, data, typecast_bind;
104
104
 
105
105
  Statement *s = db_postgres_statement_handle_safe(self);
106
106
  connection = db_postgres_adapter_handle_safe(s->adapter)->connection;
107
107
 
108
108
  rb_scan_args(argc, argv, "00*", &bind);
109
109
 
110
+ typecast_bind = rb_ary_new();
111
+ rb_gc_register_address(&typecast_bind);
110
112
  rb_gc_register_address(&bind);
113
+
111
114
  if (RARRAY_LEN(bind) > 0) {
112
115
  bind_args_size = (int *) malloc(sizeof(int) * RARRAY_LEN(bind));
113
116
  bind_args_fmt = (int *) malloc(sizeof(int) * RARRAY_LEN(bind));
@@ -126,8 +129,9 @@ VALUE db_postgres_statement_execute(int argc, VALUE *argv, VALUE self) {
126
129
  else
127
130
  bind_args_fmt[n] = 0;
128
131
  data = typecast_to_string(data);
132
+ rb_ary_push(typecast_bind, data);
129
133
  bind_args_size[n] = RSTRING_LEN(data);
130
- bind_args_data[n] = CSTRING_PTR(data);
134
+ bind_args_data[n] = RSTRING_PTR(data);
131
135
  }
132
136
  }
133
137
 
@@ -141,9 +145,6 @@ VALUE db_postgres_statement_execute(int argc, VALUE *argv, VALUE self) {
141
145
  };
142
146
 
143
147
  result = (PGresult *)GVL_NOLOCK(nogvl_pq_exec_prepared, &q, RUBY_UBF_IO, 0);
144
- for (n = 0; n < RARRAY_LEN(bind); n++)
145
- if (bind_args_data[n])
146
- free(bind_args_data[n]);
147
148
  free(bind_args_fmt);
148
149
  free(bind_args_size);
149
150
  free(bind_args_data);
@@ -160,6 +161,7 @@ VALUE db_postgres_statement_execute(int argc, VALUE *argv, VALUE self) {
160
161
  result = (PGresult *)GVL_NOLOCK(nogvl_pq_exec_prepared, &q, RUBY_UBF_IO, 0);
161
162
  }
162
163
 
164
+ rb_gc_unregister_address(&typecast_bind);
163
165
  rb_gc_unregister_address(&bind);
164
166
  db_postgres_check_result(result);
165
167
  return db_postgres_result_load(db_postgres_result_allocate(cDPR), result);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift-db-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
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-11-19 00:00:00.000000000 Z
12
+ date: 2012-11-22 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/postgres/datetime.c
39
39
  - ext/swift/db/postgres/result.c
40
- - ext/swift/db/postgres/common.c
41
40
  - ext/swift/db/postgres/adapter.c
42
41
  - ext/swift/db/postgres/typecast.c
43
- - ext/swift/db/postgres/statement.c
42
+ - ext/swift/db/postgres/common.c
44
43
  - ext/swift/db/postgres/main.c
44
+ - ext/swift/db/postgres/statement.c
45
45
  - ext/swift/db/postgres/typecast.h
46
46
  - ext/swift/db/postgres/datetime.h
47
47
  - ext/swift/db/postgres/result.h