couchbase 1.2.0.z.beta4-x86-mingw32 → 1.2.0.z.beta5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.markdown +9 -0
- data/ext/couchbase_ext/arguments.c +132 -128
- data/ext/couchbase_ext/arithmetic.c +25 -22
- data/ext/couchbase_ext/bucket.c +147 -114
- data/ext/couchbase_ext/couchbase_ext.c +419 -399
- data/ext/couchbase_ext/couchbase_ext.h +195 -189
- data/ext/couchbase_ext/delete.c +22 -19
- data/ext/couchbase_ext/extconf.rb +9 -2
- data/ext/couchbase_ext/get.c +32 -29
- data/ext/couchbase_ext/http.c +73 -59
- data/ext/couchbase_ext/observe.c +30 -27
- data/ext/couchbase_ext/result.c +13 -13
- data/ext/couchbase_ext/stats.c +22 -20
- data/ext/couchbase_ext/store.c +37 -30
- data/ext/couchbase_ext/timer.c +10 -10
- data/ext/couchbase_ext/touch.c +22 -19
- data/ext/couchbase_ext/unlock.c +22 -19
- data/ext/couchbase_ext/utils.c +78 -78
- data/ext/couchbase_ext/version.c +21 -18
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view.rb +18 -0
- data/tasks/compile.rake +1 -1
- data/tasks/test.rake +40 -33
- data/test/setup.rb +4 -0
- data/test/test_arithmetic.rb +37 -0
- metadata +4 -25
data/HISTORY.markdown
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 1.2.0.z.beta5 / 2012-11-29
|
2
|
+
|
3
|
+
* Reduce probability name conflict: use "cb_" prefix
|
4
|
+
* Fix function prefixes
|
5
|
+
* Make error message about dependency more verbose
|
6
|
+
* Allow to setup default initial value for INCR/DECR
|
7
|
+
* Fix memory leaks: in async mode context wasn't freed
|
8
|
+
* RCBC-95 Use response body to clarify Couchbase::Error::HTTP
|
9
|
+
|
1
10
|
## 1.2.0.z.beta4 / 2012-11-21
|
2
11
|
|
3
12
|
* Do not hide ValueFormat reason
|
@@ -17,22 +17,21 @@
|
|
17
17
|
|
18
18
|
#include "couchbase_ext.h"
|
19
19
|
|
20
|
-
|
21
20
|
/* TOUCH */
|
22
21
|
|
23
22
|
static void
|
24
|
-
cb_params_touch_alloc(struct
|
23
|
+
cb_params_touch_alloc(struct cb_params_st *params, lcb_size_t size)
|
25
24
|
{
|
26
25
|
lcb_size_t ii;
|
27
26
|
|
28
27
|
params->cmd.touch.num = size;
|
29
28
|
params->cmd.touch.items = xcalloc(size, sizeof(lcb_touch_cmd_t));
|
30
29
|
if (params->cmd.touch.items == NULL) {
|
31
|
-
rb_raise(
|
30
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
32
31
|
}
|
33
32
|
params->cmd.touch.ptr = xcalloc(size, sizeof(lcb_touch_cmd_t *));
|
34
33
|
if (params->cmd.touch.ptr == NULL) {
|
35
|
-
rb_raise(
|
34
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
36
35
|
}
|
37
36
|
for (ii = 0; ii < size; ++ii) {
|
38
37
|
params->cmd.touch.ptr[ii] = params->cmd.touch.items + ii;
|
@@ -40,9 +39,9 @@ cb_params_touch_alloc(struct params_st *params, lcb_size_t size)
|
|
40
39
|
}
|
41
40
|
|
42
41
|
static void
|
43
|
-
cb_params_touch_init_item(struct
|
42
|
+
cb_params_touch_init_item(struct cb_params_st *params, lcb_size_t idx, VALUE key_obj, lcb_time_t exptime)
|
44
43
|
{
|
45
|
-
key_obj =
|
44
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
46
45
|
params->cmd.touch.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
47
46
|
params->cmd.touch.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
48
47
|
params->cmd.touch.items[idx].v.v0.exptime = exptime;
|
@@ -52,30 +51,30 @@ cb_params_touch_init_item(struct params_st *params, lcb_size_t idx, VALUE key_ob
|
|
52
51
|
static int
|
53
52
|
cb_params_touch_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
54
53
|
{
|
55
|
-
struct
|
54
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
56
55
|
cb_params_touch_init_item(params, params->idx++, key, NUM2ULONG(value));
|
57
56
|
return ST_CONTINUE;
|
58
57
|
}
|
59
58
|
|
60
59
|
static void
|
61
|
-
cb_params_touch_parse_options(struct
|
60
|
+
cb_params_touch_parse_options(struct cb_params_st *params, VALUE options)
|
62
61
|
{
|
63
62
|
VALUE tmp;
|
64
63
|
|
65
64
|
if (NIL_P(options)) {
|
66
65
|
return;
|
67
66
|
}
|
68
|
-
tmp = rb_hash_aref(options,
|
67
|
+
tmp = rb_hash_aref(options, cb_sym_ttl);
|
69
68
|
if (tmp != Qnil) {
|
70
69
|
params->cmd.touch.ttl = NUM2ULONG(tmp);
|
71
70
|
}
|
72
|
-
if (RTEST(rb_funcall(options,
|
73
|
-
params->cmd.touch.quiet = RTEST(rb_hash_aref(options,
|
71
|
+
if (RTEST(rb_funcall(options, cb_id_has_key_p, 1, cb_sym_quiet))) {
|
72
|
+
params->cmd.touch.quiet = RTEST(rb_hash_aref(options, cb_sym_quiet));
|
74
73
|
}
|
75
74
|
}
|
76
75
|
|
77
76
|
static void
|
78
|
-
cb_params_touch_parse_arguments(struct
|
77
|
+
cb_params_touch_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
79
78
|
{
|
80
79
|
lcb_size_t ii;
|
81
80
|
|
@@ -117,18 +116,18 @@ cb_params_touch_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
117
116
|
/* REMOVE */
|
118
117
|
|
119
118
|
static void
|
120
|
-
cb_params_remove_alloc(struct
|
119
|
+
cb_params_remove_alloc(struct cb_params_st *params, lcb_size_t size)
|
121
120
|
{
|
122
121
|
lcb_size_t ii;
|
123
122
|
|
124
123
|
params->cmd.remove.num = size;
|
125
124
|
params->cmd.remove.items = xcalloc(size, sizeof(lcb_remove_cmd_t));
|
126
125
|
if (params->cmd.remove.items == NULL) {
|
127
|
-
rb_raise(
|
126
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
128
127
|
}
|
129
128
|
params->cmd.remove.ptr = xcalloc(size, sizeof(lcb_remove_cmd_t *));
|
130
129
|
if (params->cmd.remove.ptr == NULL) {
|
131
|
-
rb_raise(
|
130
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
132
131
|
}
|
133
132
|
for (ii = 0; ii < size; ++ii) {
|
134
133
|
params->cmd.remove.ptr[ii] = params->cmd.remove.items + ii;
|
@@ -136,9 +135,9 @@ cb_params_remove_alloc(struct params_st *params, lcb_size_t size)
|
|
136
135
|
}
|
137
136
|
|
138
137
|
static void
|
139
|
-
cb_params_remove_init_item(struct
|
138
|
+
cb_params_remove_init_item(struct cb_params_st *params, lcb_size_t idx, VALUE key_obj, lcb_cas_t cas)
|
140
139
|
{
|
141
|
-
key_obj =
|
140
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
142
141
|
params->cmd.remove.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
143
142
|
params->cmd.remove.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
144
143
|
params->cmd.remove.items[idx].v.v0.cas = cas;
|
@@ -148,30 +147,30 @@ cb_params_remove_init_item(struct params_st *params, lcb_size_t idx, VALUE key_o
|
|
148
147
|
static int
|
149
148
|
cb_params_remove_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
150
149
|
{
|
151
|
-
struct
|
150
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
152
151
|
cb_params_remove_init_item(params, params->idx++, key, NUM2ULL(value));
|
153
152
|
return ST_CONTINUE;
|
154
153
|
}
|
155
154
|
|
156
155
|
static void
|
157
|
-
cb_params_remove_parse_options(struct
|
156
|
+
cb_params_remove_parse_options(struct cb_params_st *params, VALUE options)
|
158
157
|
{
|
159
158
|
VALUE tmp;
|
160
159
|
|
161
160
|
if (NIL_P(options)) {
|
162
161
|
return;
|
163
162
|
}
|
164
|
-
if (RTEST(rb_funcall(options,
|
165
|
-
params->cmd.remove.quiet = RTEST(rb_hash_aref(options,
|
163
|
+
if (RTEST(rb_funcall(options, cb_id_has_key_p, 1, cb_sym_quiet))) {
|
164
|
+
params->cmd.remove.quiet = RTEST(rb_hash_aref(options, cb_sym_quiet));
|
166
165
|
}
|
167
|
-
tmp = rb_hash_aref(options,
|
166
|
+
tmp = rb_hash_aref(options, cb_sym_cas);
|
168
167
|
if (tmp != Qnil) {
|
169
168
|
params->cmd.remove.cas = NUM2ULL(tmp);
|
170
169
|
}
|
171
170
|
}
|
172
171
|
|
173
172
|
static void
|
174
|
-
cb_params_remove_parse_arguments(struct
|
173
|
+
cb_params_remove_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
175
174
|
{
|
176
175
|
lcb_size_t ii;
|
177
176
|
|
@@ -212,18 +211,18 @@ cb_params_remove_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
212
211
|
|
213
212
|
/* STORE */
|
214
213
|
static void
|
215
|
-
cb_params_store_alloc(struct
|
214
|
+
cb_params_store_alloc(struct cb_params_st *params, lcb_size_t size)
|
216
215
|
{
|
217
216
|
lcb_size_t ii;
|
218
217
|
|
219
218
|
params->cmd.store.num = size;
|
220
219
|
params->cmd.store.items = xcalloc(size, sizeof(lcb_store_cmd_t));
|
221
220
|
if (params->cmd.store.items == NULL) {
|
222
|
-
rb_raise(
|
221
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
223
222
|
}
|
224
223
|
params->cmd.store.ptr = xcalloc(size, sizeof(lcb_store_cmd_t *));
|
225
224
|
if (params->cmd.store.ptr == NULL) {
|
226
|
-
rb_raise(
|
225
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
227
226
|
}
|
228
227
|
for (ii = 0; ii < size; ++ii) {
|
229
228
|
params->cmd.store.ptr[ii] = params->cmd.store.items + ii;
|
@@ -231,24 +230,24 @@ cb_params_store_alloc(struct params_st *params, lcb_size_t size)
|
|
231
230
|
}
|
232
231
|
|
233
232
|
static void
|
234
|
-
cb_params_store_init_item(struct
|
233
|
+
cb_params_store_init_item(struct cb_params_st *params, lcb_size_t idx,
|
235
234
|
VALUE key_obj, VALUE value_obj, lcb_uint32_t flags, lcb_cas_t cas,
|
236
235
|
lcb_time_t exptime)
|
237
236
|
{
|
238
|
-
key_obj =
|
239
|
-
value_obj =
|
237
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
238
|
+
value_obj = cb_encode_value(value_obj, params->cmd.store.flags);
|
240
239
|
if (rb_obj_is_kind_of(value_obj, rb_eStandardError)) {
|
241
|
-
VALUE exc_str = rb_funcall(value_obj,
|
242
|
-
VALUE msg = rb_funcall(rb_mKernel,
|
240
|
+
VALUE exc_str = rb_funcall(value_obj, cb_id_to_s, 0);
|
241
|
+
VALUE msg = rb_funcall(rb_mKernel, cb_id_sprintf, 3,
|
243
242
|
rb_str_new2("unable to convert value for key '%s': %s"), key_obj, exc_str);
|
244
|
-
VALUE exc = rb_exc_new3(
|
245
|
-
rb_ivar_set(exc,
|
243
|
+
VALUE exc = rb_exc_new3(cb_eValueFormatError, msg);
|
244
|
+
rb_ivar_set(exc, cb_id_iv_inner_exception, value_obj);
|
246
245
|
rb_exc_raise(exc);
|
247
246
|
}
|
248
247
|
/* the value must be string after conversion */
|
249
248
|
if (TYPE(value_obj) != T_STRING) {
|
250
249
|
VALUE val = rb_any_to_s(value_obj);
|
251
|
-
rb_raise(
|
250
|
+
rb_raise(cb_eValueFormatError, "unable to convert value for key '%s' to string: %s", RSTRING_PTR(key_obj), RSTRING_PTR(val));
|
252
251
|
}
|
253
252
|
params->cmd.store.items[idx].v.v0.datatype = params->cmd.store.datatype;
|
254
253
|
params->cmd.store.items[idx].v.v0.operation = params->cmd.store.operation;
|
@@ -265,50 +264,50 @@ cb_params_store_init_item(struct params_st *params, lcb_size_t idx,
|
|
265
264
|
static int
|
266
265
|
cb_params_store_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
267
266
|
{
|
268
|
-
struct
|
267
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
269
268
|
cb_params_store_init_item(params, params->idx++, key, value,
|
270
269
|
params->cmd.store.flags, 0, params->cmd.store.ttl);
|
271
270
|
return ST_CONTINUE;
|
272
271
|
}
|
273
272
|
|
274
273
|
static void
|
275
|
-
cb_params_store_parse_options(struct
|
274
|
+
cb_params_store_parse_options(struct cb_params_st *params, VALUE options)
|
276
275
|
{
|
277
276
|
VALUE tmp;
|
278
277
|
|
279
278
|
if (NIL_P(options)) {
|
280
279
|
return;
|
281
280
|
}
|
282
|
-
tmp = rb_hash_aref(options,
|
281
|
+
tmp = rb_hash_aref(options, cb_sym_flags);
|
283
282
|
if (tmp != Qnil) {
|
284
283
|
params->cmd.store.flags = (lcb_uint32_t)NUM2ULONG(tmp);
|
285
284
|
}
|
286
|
-
tmp = rb_hash_aref(options,
|
285
|
+
tmp = rb_hash_aref(options, cb_sym_format);
|
287
286
|
if (tmp != Qnil) { /* rewrite format bits */
|
288
|
-
params->cmd.store.flags =
|
287
|
+
params->cmd.store.flags = cb_flags_set_format(params->cmd.store.flags, tmp);
|
289
288
|
}
|
290
|
-
tmp = rb_hash_aref(options,
|
289
|
+
tmp = rb_hash_aref(options, cb_sym_ttl);
|
291
290
|
if (tmp != Qnil) {
|
292
291
|
params->cmd.store.ttl = NUM2ULONG(tmp);
|
293
292
|
}
|
294
|
-
tmp = rb_hash_aref(options,
|
293
|
+
tmp = rb_hash_aref(options, cb_sym_cas);
|
295
294
|
if (tmp != Qnil) {
|
296
295
|
params->cmd.store.cas = NUM2ULL(tmp);
|
297
296
|
}
|
298
|
-
tmp = rb_hash_aref(options,
|
297
|
+
tmp = rb_hash_aref(options, cb_sym_observe);
|
299
298
|
if (tmp != Qnil) {
|
300
299
|
Check_Type(tmp, T_HASH);
|
301
|
-
rb_funcall(params->bucket->self,
|
300
|
+
rb_funcall(params->bucket->self, cb_id_verify_observe_options, 1, tmp);
|
302
301
|
params->cmd.store.observe = tmp;
|
303
302
|
}
|
304
|
-
if (
|
303
|
+
if (cb_flags_get_format(params->cmd.store.flags) == cb_sym_document) {
|
305
304
|
/* just amend datatype for now */
|
306
305
|
params->cmd.store.datatype = 0x01;
|
307
306
|
}
|
308
307
|
}
|
309
308
|
|
310
309
|
static void
|
311
|
-
cb_params_store_parse_arguments(struct
|
310
|
+
cb_params_store_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
312
311
|
{
|
313
312
|
VALUE keys;
|
314
313
|
|
@@ -344,7 +343,7 @@ cb_params_store_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
344
343
|
|
345
344
|
/* GET */
|
346
345
|
static void
|
347
|
-
cb_params_get_alloc(struct
|
346
|
+
cb_params_get_alloc(struct cb_params_st *params, lcb_size_t size)
|
348
347
|
{
|
349
348
|
lcb_size_t ii;
|
350
349
|
|
@@ -352,11 +351,11 @@ cb_params_get_alloc(struct params_st *params, lcb_size_t size)
|
|
352
351
|
if (params->cmd.get.replica) {
|
353
352
|
params->cmd.get.items = xcalloc(size, sizeof(lcb_get_replica_cmd_t));
|
354
353
|
if (params->cmd.get.items_gr == NULL) {
|
355
|
-
rb_raise(
|
354
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
356
355
|
}
|
357
356
|
params->cmd.get.ptr = xcalloc(size, sizeof(lcb_get_replica_cmd_t *));
|
358
357
|
if (params->cmd.get.ptr_gr == NULL) {
|
359
|
-
rb_raise(
|
358
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
360
359
|
}
|
361
360
|
for (ii = 0; ii < size; ++ii) {
|
362
361
|
params->cmd.get.ptr_gr[ii] = params->cmd.get.items_gr + ii;
|
@@ -364,11 +363,11 @@ cb_params_get_alloc(struct params_st *params, lcb_size_t size)
|
|
364
363
|
} else {
|
365
364
|
params->cmd.get.items = xcalloc(size, sizeof(lcb_get_cmd_t));
|
366
365
|
if (params->cmd.get.items == NULL) {
|
367
|
-
rb_raise(
|
366
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
368
367
|
}
|
369
368
|
params->cmd.get.ptr = xcalloc(size, sizeof(lcb_get_cmd_t *));
|
370
369
|
if (params->cmd.get.ptr == NULL) {
|
371
|
-
rb_raise(
|
370
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
372
371
|
}
|
373
372
|
for (ii = 0; ii < size; ++ii) {
|
374
373
|
params->cmd.get.ptr[ii] = params->cmd.get.items + ii;
|
@@ -377,10 +376,10 @@ cb_params_get_alloc(struct params_st *params, lcb_size_t size)
|
|
377
376
|
}
|
378
377
|
|
379
378
|
static void
|
380
|
-
cb_params_get_init_item(struct
|
379
|
+
cb_params_get_init_item(struct cb_params_st *params, lcb_size_t idx,
|
381
380
|
VALUE key_obj, lcb_time_t exptime)
|
382
381
|
{
|
383
|
-
key_obj =
|
382
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
384
383
|
if (params->cmd.get.replica) {
|
385
384
|
params->cmd.get.items_gr[idx].v.v0.key = RSTRING_PTR(key_obj);
|
386
385
|
params->cmd.get.items_gr[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
@@ -397,37 +396,37 @@ cb_params_get_init_item(struct params_st *params, lcb_size_t idx,
|
|
397
396
|
static int
|
398
397
|
cb_params_get_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
399
398
|
{
|
400
|
-
struct
|
399
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
401
400
|
rb_ary_push(params->cmd.get.keys_ary, key);
|
402
401
|
cb_params_get_init_item(params, params->idx++, key, NUM2ULONG(value));
|
403
402
|
return ST_CONTINUE;
|
404
403
|
}
|
405
404
|
|
406
405
|
static void
|
407
|
-
cb_params_get_parse_options(struct
|
406
|
+
cb_params_get_parse_options(struct cb_params_st *params, VALUE options)
|
408
407
|
{
|
409
408
|
VALUE tmp;
|
410
409
|
|
411
410
|
if (NIL_P(options)) {
|
412
411
|
return;
|
413
412
|
}
|
414
|
-
params->cmd.get.replica = RTEST(rb_hash_aref(options,
|
415
|
-
params->cmd.get.extended = RTEST(rb_hash_aref(options,
|
416
|
-
params->cmd.get.assemble_hash = RTEST(rb_hash_aref(options,
|
417
|
-
if (RTEST(rb_funcall(options,
|
418
|
-
params->cmd.get.quiet = RTEST(rb_hash_aref(options,
|
413
|
+
params->cmd.get.replica = RTEST(rb_hash_aref(options, cb_sym_replica));
|
414
|
+
params->cmd.get.extended = RTEST(rb_hash_aref(options, cb_sym_extended));
|
415
|
+
params->cmd.get.assemble_hash = RTEST(rb_hash_aref(options, cb_sym_assemble_hash));
|
416
|
+
if (RTEST(rb_funcall(options, cb_id_has_key_p, 1, cb_sym_quiet))) {
|
417
|
+
params->cmd.get.quiet = RTEST(rb_hash_aref(options, cb_sym_quiet));
|
419
418
|
}
|
420
|
-
tmp = rb_hash_aref(options,
|
419
|
+
tmp = rb_hash_aref(options, cb_sym_format);
|
421
420
|
if (tmp != Qnil) {
|
422
421
|
Check_Type(tmp, T_SYMBOL);
|
423
422
|
params->cmd.get.forced_format = tmp;
|
424
423
|
}
|
425
|
-
tmp = rb_hash_aref(options,
|
424
|
+
tmp = rb_hash_aref(options, cb_sym_ttl);
|
426
425
|
if (tmp != Qnil) {
|
427
426
|
params->cmd.get.ttl = NUM2ULONG(tmp);
|
428
427
|
}
|
429
428
|
/* boolean or number of seconds to lock */
|
430
|
-
tmp = rb_hash_aref(options,
|
429
|
+
tmp = rb_hash_aref(options, cb_sym_lock);
|
431
430
|
if (tmp != Qnil) {
|
432
431
|
params->cmd.get.lock = RTEST(tmp);
|
433
432
|
if (TYPE(tmp) == T_FIXNUM) {
|
@@ -437,7 +436,7 @@ cb_params_get_parse_options(struct params_st *params, VALUE options)
|
|
437
436
|
}
|
438
437
|
|
439
438
|
static void
|
440
|
-
cb_params_get_parse_arguments(struct
|
439
|
+
cb_params_get_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
441
440
|
{
|
442
441
|
lcb_size_t ii;
|
443
442
|
|
@@ -484,18 +483,18 @@ cb_params_get_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
484
483
|
|
485
484
|
/* ARITH */
|
486
485
|
static void
|
487
|
-
cb_params_arith_alloc(struct
|
486
|
+
cb_params_arith_alloc(struct cb_params_st *params, lcb_size_t size)
|
488
487
|
{
|
489
488
|
lcb_size_t ii;
|
490
489
|
|
491
490
|
params->cmd.arith.num = size;
|
492
491
|
params->cmd.arith.items = xcalloc(size, sizeof(lcb_arithmetic_cmd_t));
|
493
492
|
if (params->cmd.arith.items == NULL) {
|
494
|
-
rb_raise(
|
493
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
495
494
|
}
|
496
495
|
params->cmd.arith.ptr = xcalloc(size, sizeof(lcb_arithmetic_cmd_t *));
|
497
496
|
if (params->cmd.arith.ptr == NULL) {
|
498
|
-
rb_raise(
|
497
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
499
498
|
}
|
500
499
|
for (ii = 0; ii < size; ++ii) {
|
501
500
|
params->cmd.arith.ptr[ii] = params->cmd.arith.items + ii;
|
@@ -503,10 +502,10 @@ cb_params_arith_alloc(struct params_st *params, lcb_size_t size)
|
|
503
502
|
}
|
504
503
|
|
505
504
|
static void
|
506
|
-
cb_params_arith_init_item(struct
|
505
|
+
cb_params_arith_init_item(struct cb_params_st *params, lcb_size_t idx,
|
507
506
|
VALUE key_obj, lcb_int64_t delta)
|
508
507
|
{
|
509
|
-
key_obj =
|
508
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
510
509
|
params->cmd.arith.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
511
510
|
params->cmd.arith.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
512
511
|
params->cmd.arith.items[idx].v.v0.delta = delta * params->cmd.arith.sign;
|
@@ -519,46 +518,49 @@ cb_params_arith_init_item(struct params_st *params, lcb_size_t idx,
|
|
519
518
|
static int
|
520
519
|
cb_params_arith_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
521
520
|
{
|
522
|
-
struct
|
521
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
523
522
|
cb_params_arith_init_item(params, params->idx++, key, NUM2ULONG(value) & INT64_MAX);
|
524
523
|
return ST_CONTINUE;
|
525
524
|
}
|
526
525
|
|
527
526
|
static void
|
528
|
-
cb_params_arith_parse_options(struct
|
527
|
+
cb_params_arith_parse_options(struct cb_params_st *params, VALUE options)
|
529
528
|
{
|
530
529
|
VALUE tmp;
|
531
530
|
|
532
531
|
if (NIL_P(options)) {
|
533
532
|
return;
|
534
533
|
}
|
535
|
-
|
536
|
-
|
537
|
-
|
534
|
+
tmp = rb_hash_aref(options, cb_sym_create);
|
535
|
+
if (tmp != Qnil) {
|
536
|
+
params->cmd.arith.create = RTEST(tmp);
|
537
|
+
}
|
538
|
+
params->cmd.arith.extended = RTEST(rb_hash_aref(options, cb_sym_extended));
|
539
|
+
tmp = rb_hash_aref(options, cb_sym_ttl);
|
538
540
|
if (tmp != Qnil) {
|
539
541
|
params->cmd.arith.ttl = NUM2ULONG(tmp);
|
540
542
|
}
|
541
|
-
tmp = rb_hash_aref(options,
|
543
|
+
tmp = rb_hash_aref(options, cb_sym_initial);
|
542
544
|
if (tmp != Qnil) {
|
543
545
|
params->cmd.arith.initial = NUM2ULL(tmp);
|
544
546
|
params->cmd.arith.create = 1;
|
545
547
|
}
|
546
|
-
tmp = rb_hash_aref(options,
|
548
|
+
tmp = rb_hash_aref(options, cb_sym_delta);
|
547
549
|
if (tmp != Qnil) {
|
548
550
|
params->cmd.arith.delta = NUM2ULL(tmp) & INT64_MAX;
|
549
551
|
}
|
550
|
-
tmp = rb_hash_aref(options,
|
552
|
+
tmp = rb_hash_aref(options, cb_sym_format);
|
551
553
|
if (tmp != Qnil) { /* rewrite format bits */
|
552
554
|
params->cmd.arith.format = tmp;
|
553
555
|
}
|
554
|
-
if (params->cmd.arith.format ==
|
556
|
+
if (params->cmd.arith.format == cb_sym_document) {
|
555
557
|
/* just amend datatype for now */
|
556
558
|
params->cmd.arith.datatype = 0x01;
|
557
559
|
}
|
558
560
|
}
|
559
561
|
|
560
562
|
static void
|
561
|
-
cb_params_arith_parse_arguments(struct
|
563
|
+
cb_params_arith_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
562
564
|
{
|
563
565
|
lcb_size_t ii;
|
564
566
|
|
@@ -598,18 +600,18 @@ cb_params_arith_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
598
600
|
|
599
601
|
/* STATS */
|
600
602
|
static void
|
601
|
-
cb_params_stats_alloc(struct
|
603
|
+
cb_params_stats_alloc(struct cb_params_st *params, lcb_size_t size)
|
602
604
|
{
|
603
605
|
lcb_size_t ii;
|
604
606
|
|
605
607
|
params->cmd.stats.num = size;
|
606
608
|
params->cmd.stats.items = xcalloc(size, sizeof(lcb_server_stats_cmd_t));
|
607
609
|
if (params->cmd.stats.items == NULL) {
|
608
|
-
rb_raise(
|
610
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
609
611
|
}
|
610
612
|
params->cmd.stats.ptr = xcalloc(size, sizeof(lcb_server_stats_cmd_t *));
|
611
613
|
if (params->cmd.stats.ptr == NULL) {
|
612
|
-
rb_raise(
|
614
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
613
615
|
}
|
614
616
|
for (ii = 0; ii < size; ++ii) {
|
615
617
|
params->cmd.stats.ptr[ii] = params->cmd.stats.items + ii;
|
@@ -617,17 +619,17 @@ cb_params_stats_alloc(struct params_st *params, lcb_size_t size)
|
|
617
619
|
}
|
618
620
|
|
619
621
|
static void
|
620
|
-
cb_params_stats_init_item(struct
|
622
|
+
cb_params_stats_init_item(struct cb_params_st *params, lcb_size_t idx,
|
621
623
|
VALUE key_obj)
|
622
624
|
{
|
623
|
-
key_obj =
|
625
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
624
626
|
params->cmd.stats.items[idx].v.v0.name = RSTRING_PTR(key_obj);
|
625
627
|
params->cmd.stats.items[idx].v.v0.nname = RSTRING_LEN(key_obj);
|
626
628
|
params->npayload += RSTRING_LEN(key_obj);
|
627
629
|
}
|
628
630
|
|
629
631
|
static void
|
630
|
-
cb_params_stats_parse_arguments(struct
|
632
|
+
cb_params_stats_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
631
633
|
{
|
632
634
|
lcb_size_t ii;
|
633
635
|
|
@@ -663,18 +665,18 @@ cb_params_stats_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
663
665
|
/* REMOVE */
|
664
666
|
|
665
667
|
static void
|
666
|
-
cb_params_observe_alloc(struct
|
668
|
+
cb_params_observe_alloc(struct cb_params_st *params, lcb_size_t size)
|
667
669
|
{
|
668
670
|
lcb_size_t ii;
|
669
671
|
|
670
672
|
params->cmd.observe.num = size;
|
671
673
|
params->cmd.observe.items = xcalloc(size, sizeof(lcb_observe_cmd_t));
|
672
674
|
if (params->cmd.observe.items == NULL) {
|
673
|
-
rb_raise(
|
675
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
674
676
|
}
|
675
677
|
params->cmd.observe.ptr = xcalloc(size, sizeof(lcb_observe_cmd_t *));
|
676
678
|
if (params->cmd.observe.ptr == NULL) {
|
677
|
-
rb_raise(
|
679
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
678
680
|
}
|
679
681
|
for (ii = 0; ii < size; ++ii) {
|
680
682
|
params->cmd.observe.ptr[ii] = params->cmd.observe.items + ii;
|
@@ -682,16 +684,16 @@ cb_params_observe_alloc(struct params_st *params, lcb_size_t size)
|
|
682
684
|
}
|
683
685
|
|
684
686
|
static void
|
685
|
-
cb_params_observe_init_item(struct
|
687
|
+
cb_params_observe_init_item(struct cb_params_st *params, lcb_size_t idx, VALUE key_obj)
|
686
688
|
{
|
687
|
-
key_obj =
|
689
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
688
690
|
params->cmd.observe.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
689
691
|
params->cmd.observe.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
690
692
|
params->npayload += RSTRING_LEN(key_obj);
|
691
693
|
}
|
692
694
|
|
693
695
|
static void
|
694
|
-
cb_params_observe_parse_arguments(struct
|
696
|
+
cb_params_observe_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
695
697
|
{
|
696
698
|
lcb_size_t ii;
|
697
699
|
|
@@ -726,18 +728,18 @@ cb_params_observe_parse_arguments(struct params_st *params, int argc, VALUE argv
|
|
726
728
|
|
727
729
|
/* UNLOCK */
|
728
730
|
static void
|
729
|
-
cb_params_unlock_alloc(struct
|
731
|
+
cb_params_unlock_alloc(struct cb_params_st *params, lcb_size_t size)
|
730
732
|
{
|
731
733
|
lcb_size_t ii;
|
732
734
|
|
733
735
|
params->cmd.unlock.num = size;
|
734
736
|
params->cmd.unlock.items = xcalloc(size, sizeof(lcb_unlock_cmd_t));
|
735
737
|
if (params->cmd.unlock.items == NULL) {
|
736
|
-
rb_raise(
|
738
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
737
739
|
}
|
738
740
|
params->cmd.unlock.ptr = xcalloc(size, sizeof(lcb_unlock_cmd_t *));
|
739
741
|
if (params->cmd.unlock.ptr == NULL) {
|
740
|
-
rb_raise(
|
742
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
741
743
|
}
|
742
744
|
for (ii = 0; ii < size; ++ii) {
|
743
745
|
params->cmd.unlock.ptr[ii] = params->cmd.unlock.items + ii;
|
@@ -745,9 +747,9 @@ cb_params_unlock_alloc(struct params_st *params, lcb_size_t size)
|
|
745
747
|
}
|
746
748
|
|
747
749
|
static void
|
748
|
-
cb_params_unlock_init_item(struct
|
750
|
+
cb_params_unlock_init_item(struct cb_params_st *params, lcb_size_t idx, VALUE key_obj, lcb_cas_t cas)
|
749
751
|
{
|
750
|
-
key_obj =
|
752
|
+
key_obj = cb_unify_key(params->bucket, key_obj, 1);
|
751
753
|
params->cmd.unlock.items[idx].v.v0.key = RSTRING_PTR(key_obj);
|
752
754
|
params->cmd.unlock.items[idx].v.v0.nkey = RSTRING_LEN(key_obj);
|
753
755
|
params->cmd.unlock.items[idx].v.v0.cas = cas;
|
@@ -757,30 +759,30 @@ cb_params_unlock_init_item(struct params_st *params, lcb_size_t idx, VALUE key_o
|
|
757
759
|
static int
|
758
760
|
cb_params_unlock_extract_keys_i(VALUE key, VALUE value, VALUE arg)
|
759
761
|
{
|
760
|
-
struct
|
762
|
+
struct cb_params_st *params = (struct cb_params_st *)arg;
|
761
763
|
cb_params_unlock_init_item(params, params->idx++, key, NUM2ULL(value));
|
762
764
|
return ST_CONTINUE;
|
763
765
|
}
|
764
766
|
|
765
767
|
static void
|
766
|
-
cb_params_unlock_parse_options(struct
|
768
|
+
cb_params_unlock_parse_options(struct cb_params_st *params, VALUE options)
|
767
769
|
{
|
768
770
|
VALUE tmp;
|
769
771
|
|
770
772
|
if (NIL_P(options)) {
|
771
773
|
return;
|
772
774
|
}
|
773
|
-
tmp = rb_hash_aref(options,
|
775
|
+
tmp = rb_hash_aref(options, cb_sym_cas);
|
774
776
|
if (tmp != Qnil) {
|
775
777
|
params->cmd.unlock.cas = NUM2ULL(tmp);
|
776
778
|
}
|
777
|
-
if (RTEST(rb_funcall(options,
|
778
|
-
params->cmd.unlock.quiet = RTEST(rb_hash_aref(options,
|
779
|
+
if (RTEST(rb_funcall(options, cb_id_has_key_p, 1, cb_sym_quiet))) {
|
780
|
+
params->cmd.unlock.quiet = RTEST(rb_hash_aref(options, cb_sym_quiet));
|
779
781
|
}
|
780
782
|
}
|
781
783
|
|
782
784
|
static void
|
783
|
-
cb_params_unlock_parse_arguments(struct
|
785
|
+
cb_params_unlock_parse_arguments(struct cb_params_st *params, int argc, VALUE argv)
|
784
786
|
{
|
785
787
|
if (argc == 1) {
|
786
788
|
VALUE keys = RARRAY_PTR(argv)[0];
|
@@ -803,16 +805,16 @@ cb_params_unlock_parse_arguments(struct params_st *params, int argc, VALUE argv)
|
|
803
805
|
|
804
806
|
/* VERSION */
|
805
807
|
static void
|
806
|
-
cb_params_version_alloc(struct
|
808
|
+
cb_params_version_alloc(struct cb_params_st *params)
|
807
809
|
{
|
808
810
|
params->cmd.version.num = 1;
|
809
811
|
params->cmd.version.items = xcalloc(1, sizeof(lcb_server_version_cmd_t));
|
810
812
|
if (params->cmd.version.items == NULL) {
|
811
|
-
rb_raise(
|
813
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
812
814
|
}
|
813
815
|
params->cmd.version.ptr = xcalloc(1, sizeof(lcb_server_version_cmd_t *));
|
814
816
|
if (params->cmd.version.ptr == NULL) {
|
815
|
-
rb_raise(
|
817
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for arguments");
|
816
818
|
}
|
817
819
|
params->cmd.version.ptr[0] = params->cmd.version.items;
|
818
820
|
}
|
@@ -820,40 +822,40 @@ cb_params_version_alloc(struct params_st *params)
|
|
820
822
|
|
821
823
|
/* common stuff */
|
822
824
|
void
|
823
|
-
cb_params_destroy(struct
|
825
|
+
cb_params_destroy(struct cb_params_st *params)
|
824
826
|
{
|
825
827
|
#define _release_data_for(type) \
|
826
828
|
xfree(params->cmd.type.items); \
|
827
829
|
xfree(params->cmd.type.ptr);
|
828
830
|
|
829
831
|
switch (params->type) {
|
830
|
-
case
|
832
|
+
case cb_cmd_get:
|
831
833
|
_release_data_for(get);
|
832
834
|
xfree(params->cmd.get.items_gr);
|
833
835
|
xfree(params->cmd.get.ptr_gr);
|
834
836
|
break;
|
835
|
-
case
|
837
|
+
case cb_cmd_touch:
|
836
838
|
_release_data_for(touch);
|
837
839
|
break;
|
838
|
-
case
|
840
|
+
case cb_cmd_arith:
|
839
841
|
_release_data_for(arith);
|
840
842
|
break;
|
841
|
-
case
|
843
|
+
case cb_cmd_remove:
|
842
844
|
_release_data_for(remove);
|
843
845
|
break;
|
844
|
-
case
|
846
|
+
case cb_cmd_store:
|
845
847
|
_release_data_for(store);
|
846
848
|
break;
|
847
|
-
case
|
849
|
+
case cb_cmd_stats:
|
848
850
|
_release_data_for(stats);
|
849
851
|
break;
|
850
|
-
case
|
852
|
+
case cb_cmd_version:
|
851
853
|
_release_data_for(version);
|
852
854
|
break;
|
853
|
-
case
|
855
|
+
case cb_cmd_observe:
|
854
856
|
_release_data_for(observe);
|
855
857
|
break;
|
856
|
-
case
|
858
|
+
case cb_cmd_unlock:
|
857
859
|
_release_data_for(unlock);
|
858
860
|
break;
|
859
861
|
}
|
@@ -862,7 +864,7 @@ cb_params_destroy(struct params_st *params)
|
|
862
864
|
|
863
865
|
struct build_params_st
|
864
866
|
{
|
865
|
-
struct
|
867
|
+
struct cb_params_st *params;
|
866
868
|
int argc;
|
867
869
|
VALUE argv;
|
868
870
|
};
|
@@ -873,7 +875,7 @@ do_params_build(VALUE ptr)
|
|
873
875
|
VALUE opts;
|
874
876
|
/* unpack arguments */
|
875
877
|
struct build_params_st *p = (struct build_params_st *)ptr;
|
876
|
-
struct
|
878
|
+
struct cb_params_st *params = p->params;
|
877
879
|
int argc = p->argc;
|
878
880
|
VALUE argv = p->argv;
|
879
881
|
|
@@ -885,15 +887,15 @@ do_params_build(VALUE ptr)
|
|
885
887
|
opts = Qnil;
|
886
888
|
}
|
887
889
|
|
888
|
-
params->npayload =
|
890
|
+
params->npayload = CB_PACKET_HEADER_SIZE; /* size of packet header */
|
889
891
|
switch (params->type) {
|
890
|
-
case
|
892
|
+
case cb_cmd_touch:
|
891
893
|
params->cmd.touch.quiet = params->bucket->quiet;
|
892
894
|
params->cmd.touch.ttl = params->bucket->default_ttl;
|
893
895
|
cb_params_touch_parse_options(params, opts);
|
894
896
|
cb_params_touch_parse_arguments(params, argc, argv);
|
895
897
|
break;
|
896
|
-
case
|
898
|
+
case cb_cmd_remove:
|
897
899
|
params->cmd.remove.quiet = params->bucket->quiet;
|
898
900
|
if (argc == 2) {
|
899
901
|
int type = TYPE(RARRAY_PTR(argv)[1]);
|
@@ -906,7 +908,7 @@ do_params_build(VALUE ptr)
|
|
906
908
|
cb_params_remove_parse_options(params, opts);
|
907
909
|
cb_params_remove_parse_arguments(params, argc, argv);
|
908
910
|
break;
|
909
|
-
case
|
911
|
+
case cb_cmd_store:
|
910
912
|
if (argc == 1 && opts != Qnil) {
|
911
913
|
/* put last hash back because it is the value */
|
912
914
|
rb_ary_push(argv, opts);
|
@@ -915,18 +917,20 @@ do_params_build(VALUE ptr)
|
|
915
917
|
}
|
916
918
|
params->cmd.store.datatype = 0x00;
|
917
919
|
params->cmd.store.ttl = params->bucket->default_ttl;
|
918
|
-
params->cmd.store.flags =
|
920
|
+
params->cmd.store.flags = cb_flags_set_format(params->bucket->default_flags,
|
919
921
|
params->bucket->default_format);
|
920
922
|
params->cmd.store.observe = Qnil;
|
921
923
|
cb_params_store_parse_options(params, opts);
|
922
924
|
cb_params_store_parse_arguments(params, argc, argv);
|
923
925
|
break;
|
924
|
-
case
|
926
|
+
case cb_cmd_get:
|
925
927
|
params->cmd.get.quiet = params->bucket->quiet;
|
926
928
|
cb_params_get_parse_options(params, opts);
|
927
929
|
cb_params_get_parse_arguments(params, argc, argv);
|
928
930
|
break;
|
929
|
-
case
|
931
|
+
case cb_cmd_arith:
|
932
|
+
params->cmd.arith.create = params->bucket->default_arith_create;
|
933
|
+
params->cmd.arith.initial = params->bucket->default_arith_init;
|
930
934
|
params->cmd.arith.delta = 1;
|
931
935
|
params->cmd.arith.format = params->bucket->default_format;
|
932
936
|
params->cmd.arith.ttl = params->bucket->default_ttl;
|
@@ -938,16 +942,16 @@ do_params_build(VALUE ptr)
|
|
938
942
|
cb_params_arith_parse_options(params, opts);
|
939
943
|
cb_params_arith_parse_arguments(params, argc, argv);
|
940
944
|
break;
|
941
|
-
case
|
945
|
+
case cb_cmd_stats:
|
942
946
|
cb_params_stats_parse_arguments(params, argc, argv);
|
943
947
|
break;
|
944
|
-
case
|
948
|
+
case cb_cmd_version:
|
945
949
|
cb_params_version_alloc(params);
|
946
950
|
break;
|
947
|
-
case
|
951
|
+
case cb_cmd_observe:
|
948
952
|
cb_params_observe_parse_arguments(params, argc, argv);
|
949
953
|
break;
|
950
|
-
case
|
954
|
+
case cb_cmd_unlock:
|
951
955
|
params->cmd.unlock.quiet = params->bucket->quiet;
|
952
956
|
if (argc == 2) {
|
953
957
|
int type = TYPE(RARRAY_PTR(argv)[1]);
|
@@ -966,7 +970,7 @@ do_params_build(VALUE ptr)
|
|
966
970
|
}
|
967
971
|
|
968
972
|
void
|
969
|
-
cb_params_build(struct
|
973
|
+
cb_params_build(struct cb_params_st *params, int argc, VALUE argv)
|
970
974
|
{
|
971
975
|
int fail = 0;
|
972
976
|
struct build_params_st args;
|