pbwire 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/ext/pbwire_ext/pbwire_ext.c +83 -29
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ad30ac9faae27fbdc594301b069fc94f73c2a31f361ee166af48461e3b6bad95
|
|
4
|
+
data.tar.gz: 47e7270855389b63c84958a310dbfa070165fcd6129da7cb8ef7174250e05955
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8778428e622e26ce0b9296f397df25bddac8b49e343739e19f342f3b780393607622bbe01cf66a6ec3edc1e4219e7806a79ffa50551740e4bdb4d821e6a648bf
|
|
7
|
+
data.tar.gz: 95926579ae088274eae6ff6eff71f2dd78367e72b64dd077c81cd0e0153430c7760a0c5cdcac64e882aa340f54897cf5b8b2eba4471371797ebcb5e04d62432a
|
data/README.md
CHANGED
|
@@ -51,6 +51,11 @@ back["inner"]["s"] # => "nested"
|
|
|
51
51
|
back.encode == wire # => true: byte-exact re-encode
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
`Pbwire::Type` is not part of the Ruby API: it is the C-side holder for one
|
|
55
|
+
message's field table (memoized per schema and kept alive by the messages that
|
|
56
|
+
reference it). Reach a type through the schema — `schema.message("pkg.Msg")`
|
|
57
|
+
returns a builder of that type, and `Message#type` returns its full name.
|
|
58
|
+
|
|
54
59
|
## Build and run
|
|
55
60
|
|
|
56
61
|
The extension is compiled once per interpreter with `sh build.sh` (or
|
|
@@ -214,9 +219,9 @@ official `conformance_test_runner` through this binding
|
|
|
214
219
|
`make conformance-setup`):
|
|
215
220
|
|
|
216
221
|
```
|
|
217
|
-
CONFORMANCE SUITE PASSED:
|
|
222
|
+
CONFORMANCE SUITE PASSED: 2747 successes, 0 skipped, 0 expected failures,
|
|
218
223
|
0 unexpected failures.
|
|
219
|
-
CONFORMANCE SUITE PASSED:
|
|
224
|
+
CONFORMANCE SUITE PASSED: 443 successes, 0 skipped, 0 expected failures,
|
|
220
225
|
0 unexpected failures.
|
|
221
226
|
```
|
|
222
227
|
|
data/ext/pbwire_ext/pbwire_ext.c
CHANGED
|
@@ -258,6 +258,8 @@ type_free(void *ptr)
|
|
|
258
258
|
if (type == NULL) {
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
261
|
+
holder_release(type->holder);
|
|
262
|
+
type->holder = NULL;
|
|
261
263
|
xfree(type->fields);
|
|
262
264
|
xfree(type->by_number);
|
|
263
265
|
xfree(type);
|
|
@@ -410,38 +412,27 @@ packable(pbw_type type)
|
|
|
410
412
|
}
|
|
411
413
|
}
|
|
412
414
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
type_for(
|
|
417
|
-
{
|
|
418
|
-
|
|
415
|
+
static VALUE type_for(VALUE schema_obj, const pbw_descriptor *desc);
|
|
416
|
+
|
|
417
|
+
/* Fill one Type's field table. Runs under rb_protect, so every rb_* call
|
|
418
|
+
* here may raise and type_for() can drop the half-built Type afterwards. */
|
|
419
|
+
typedef struct {
|
|
420
|
+
VALUE schema_obj;
|
|
419
421
|
VALUE types;
|
|
420
422
|
VALUE key;
|
|
421
|
-
|
|
422
|
-
VALUE obj;
|
|
423
|
-
type_t *type;
|
|
423
|
+
const pbw_descriptor *desc;
|
|
424
424
|
size_t count;
|
|
425
|
-
|
|
425
|
+
type_t *type;
|
|
426
|
+
} type_fill_args;
|
|
426
427
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if (!NIL_P(found)) {
|
|
436
|
-
return found;
|
|
437
|
-
}
|
|
438
|
-
count = pbw_descriptor_field_count(desc);
|
|
439
|
-
obj = typed_object_alloc(cType, &type_data_type, (void **)&type);
|
|
440
|
-
type->desc = desc;
|
|
441
|
-
type->count = count;
|
|
442
|
-
type->fields = count == 0 ? NULL : ZALLOC_N(field_t, count);
|
|
443
|
-
type->by_name = rb_hash_new();
|
|
444
|
-
rb_hash_aset(types, key, obj); /* before the subs: recursive schemas */
|
|
428
|
+
static VALUE
|
|
429
|
+
type_fill(VALUE argp)
|
|
430
|
+
{
|
|
431
|
+
type_fill_args *a = (type_fill_args *)(void *)argp;
|
|
432
|
+
const pbw_descriptor *desc = a->desc;
|
|
433
|
+
type_t *type = a->type;
|
|
434
|
+
size_t count = a->count;
|
|
435
|
+
size_t i;
|
|
445
436
|
|
|
446
437
|
for (i = 0; i < count; i++) {
|
|
447
438
|
const pbw_field *field = pbw_descriptor_field_at(desc, i);
|
|
@@ -471,7 +462,7 @@ type_for(VALUE schema_obj, const pbw_descriptor *desc)
|
|
|
471
462
|
field_t *f = &type->fields[i];
|
|
472
463
|
|
|
473
464
|
if (f->type == PBW_TYPE_MESSAGE || f->type == PBW_TYPE_GROUP) {
|
|
474
|
-
f->sub = type_for(schema_obj, pbw_field_message_type(field));
|
|
465
|
+
f->sub = type_for(a->schema_obj, pbw_field_message_type(field));
|
|
475
466
|
}
|
|
476
467
|
}
|
|
477
468
|
{
|
|
@@ -493,6 +484,65 @@ type_for(VALUE schema_obj, const pbw_descriptor *desc)
|
|
|
493
484
|
}
|
|
494
485
|
}
|
|
495
486
|
}
|
|
487
|
+
return Qnil;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/* A Type object for `desc`, cached on the Schema; recursive schemas resolve
|
|
491
|
+
* because the Type is published before its sub-types are built. */
|
|
492
|
+
static VALUE
|
|
493
|
+
type_for(VALUE schema_obj, const pbw_descriptor *desc)
|
|
494
|
+
{
|
|
495
|
+
schema_t *schema;
|
|
496
|
+
VALUE types;
|
|
497
|
+
VALUE key;
|
|
498
|
+
VALUE found;
|
|
499
|
+
VALUE obj;
|
|
500
|
+
type_t *type;
|
|
501
|
+
size_t count;
|
|
502
|
+
|
|
503
|
+
TypedData_Get_Struct(schema_obj, schema_t, &schema_data_type, schema);
|
|
504
|
+
types = schema->types;
|
|
505
|
+
if (NIL_P(types)) {
|
|
506
|
+
types = rb_hash_new();
|
|
507
|
+
schema->types = types;
|
|
508
|
+
}
|
|
509
|
+
key = rb_utf8_str_new_cstr(pbw_descriptor_name(desc));
|
|
510
|
+
found = rb_hash_aref(types, key);
|
|
511
|
+
if (!NIL_P(found)) {
|
|
512
|
+
return found;
|
|
513
|
+
}
|
|
514
|
+
count = pbw_descriptor_field_count(desc);
|
|
515
|
+
obj = typed_object_alloc(cType, &type_data_type, (void **)&type);
|
|
516
|
+
type->desc = desc;
|
|
517
|
+
/* A Type outlives the Schema object it came from: it keeps the C schema
|
|
518
|
+
* alive (the descriptor pointers it holds point into it). */
|
|
519
|
+
type->holder = schema->holder;
|
|
520
|
+
holder_ref(type->holder);
|
|
521
|
+
type->count = count;
|
|
522
|
+
type->fields = count == 0 ? NULL : ZALLOC_N(field_t, count);
|
|
523
|
+
type->by_name = rb_hash_new();
|
|
524
|
+
rb_hash_aset(types, key, obj); /* before the subs: recursive schemas */
|
|
525
|
+
{
|
|
526
|
+
type_fill_args args;
|
|
527
|
+
int state = 0;
|
|
528
|
+
|
|
529
|
+
args.schema_obj = schema_obj;
|
|
530
|
+
args.types = types;
|
|
531
|
+
args.key = key;
|
|
532
|
+
args.desc = desc;
|
|
533
|
+
args.count = count;
|
|
534
|
+
args.type = type;
|
|
535
|
+
rb_protect(type_fill, (VALUE)(void *)&args, &state);
|
|
536
|
+
if (state != 0) {
|
|
537
|
+
/* A half-built Type must not stay reachable: a later lookup would
|
|
538
|
+
* hand out one whose field names or sub-types are still unset, and
|
|
539
|
+
* the codec would take those as real values. Drop the entry (the
|
|
540
|
+
* key stays, mapped to nil, so the next lookup rebuilds it) and
|
|
541
|
+
* carry on unwinding. */
|
|
542
|
+
rb_hash_aset(types, key, Qnil);
|
|
543
|
+
rb_jump_tag(state);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
496
546
|
return obj;
|
|
497
547
|
}
|
|
498
548
|
|
|
@@ -1248,6 +1298,10 @@ message_wire_new(VALUE type, VALUE buffer, size_t off, size_t len,
|
|
|
1248
1298
|
(void **)&message);
|
|
1249
1299
|
message->kind = MSG_WIRE;
|
|
1250
1300
|
message->type = type;
|
|
1301
|
+
/* A decoded message reads its descriptor on every call, so it must keep
|
|
1302
|
+
* the C schema alive exactly like a builder does. */
|
|
1303
|
+
message->holder = t->holder;
|
|
1304
|
+
holder_ref(t->holder);
|
|
1251
1305
|
message->buffer = buffer;
|
|
1252
1306
|
message->data = (const uint8_t *)RSTRING_PTR(buffer);
|
|
1253
1307
|
message->off = off;
|