Browse Source

Fix vector padding

A Vector must be padded properly, or a Vector with, for example, an odd
number of Int elements will cause the rest of the containing Atom to be
invalid.
zrythm_meson
Hanspeter Portner 6 years ago committed by David Robillard
parent
commit
bb2fdc70a6
  1. 3
      NEWS
  2. 7
      src/sratom.c
  3. 18
      tests/sratom_test.c

3
NEWS

@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
sratom (0.4.10) unstable;
* Fix padding of constructed vectors (thanks Hanspeter Portner)
* Support round-trip serialisation of relative paths
* Support sequences with beat time stamps
* Fix warnings when building with ISO C++ compilers
* Upgrade to waf 1.8.14
-- David Robillard <d@drobilla.net> Sun, 10 Jul 2016 18:57:29 -0400
-- David Robillard <d@drobilla.net> Sun, 24 Jul 2016 09:50:32 -0400
sratom (0.4.6) stable;

7
src/sratom.c

@ -709,8 +709,12 @@ read_node(Sratom* sratom, @@ -709,8 +709,12 @@ read_node(Sratom* sratom,
map->handle, (const char*)sord_node_get_string(child_type_node));
uint32_t child_size = atom_size(sratom, child_type);
if (child_size > 0) {
lv2_atom_forge_vector_head(forge, &frame, child_size, child_type);
LV2_Atom_Forge_Ref ref = lv2_atom_forge_vector_head(
forge, &frame, child_size, child_type);
read_list_value(sratom, forge, world, model, value, MODE_BODY);
lv2_atom_forge_pop(forge, &frame);
frame.ref = 0;
lv2_atom_forge_pad(forge, lv2_atom_forge_deref(forge, ref)->size);
}
sord_node_free(world, child_type_node);
} else if (value && sord_node_equals(sord_node_get_datatype(value),
@ -730,6 +734,7 @@ read_node(Sratom* sratom, @@ -730,6 +734,7 @@ read_node(Sratom* sratom,
lv2_atom_forge_object(forge, &frame, 0, type_urid);
read_resource(sratom, forge, world, model, node, type_urid);
}
if (frame.ref) {
lv2_atom_forge_pop(forge, &frame);
}

18
tests/sratom_test.c

@ -238,30 +238,30 @@ test(bool top_level, bool pretty_numbers) @@ -238,30 +238,30 @@ test(bool top_level, bool pretty_numbers)
lv2_atom_forge_pop(&forge, &subrectup_frame);
lv2_atom_forge_pop(&forge, &rectup_frame);
// eg_ivector = (Vector<Int>)1,2,3,4
// eg_ivector = (Vector<Int>)1,2,3,4,5
lv2_atom_forge_key(&forge, eg_ivector);
int32_t ielems[] = { 1, 2, 3, 4 };
lv2_atom_forge_vector(&forge, sizeof(int32_t), forge.Int, 4, ielems);
int32_t ielems[] = { 1, 2, 3, 4, 5 };
lv2_atom_forge_vector(&forge, sizeof(int32_t), forge.Int, 5, ielems);
// eg_lvector = (Vector<Long>)1,2,3,4
lv2_atom_forge_key(&forge, eg_lvector);
int64_t lelems[] = { 1, 2, 3, 4 };
lv2_atom_forge_vector(&forge, sizeof(int64_t), forge.Long, 4, lelems);
// eg_fvector = (Vector<Float>)1.0,2.0,3.0,4.0
// eg_fvector = (Vector<Float>)1.0,2.0,3.0,4.0,5.0
lv2_atom_forge_key(&forge, eg_fvector);
float felems[] = { 1, 2, 3, 4 };
lv2_atom_forge_vector(&forge, sizeof(float), forge.Float, 4, felems);
float felems[] = { 1, 2, 3, 4, 5 };
lv2_atom_forge_vector(&forge, sizeof(float), forge.Float, 5, felems);
// eg_dvector = (Vector<Double>)1.0,2.0,3.0,4.0
lv2_atom_forge_key(&forge, eg_dvector);
double delems[] = { 1, 2, 3, 4 };
lv2_atom_forge_vector(&forge, sizeof(double), forge.Double, 4, delems);
// eg_bvector = (Vector<Bool>)1,0
// eg_bvector = (Vector<Bool>)1,0,1
lv2_atom_forge_key(&forge, eg_bvector);
int32_t belems[] = { true, false };
lv2_atom_forge_vector(&forge, sizeof(int32_t), forge.Bool, 2, belems);
int32_t belems[] = { true, false , true };
lv2_atom_forge_vector(&forge, sizeof(int32_t), forge.Bool, 3, belems);
// eg_fseq = (Sequence)1, 2
LV2_URID midi_midiEvent = map.map(map.handle, LV2_MIDI__MidiEvent);

Loading…
Cancel
Save