This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
vector: fix support for odd-sized structures #21
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
During implementing a fix for LostArtefacts/TRX#1463, I've discovered a problem with our design of the Vector module. Since the vector items are now implemented as
void*
pointers and we encourage a direct interaction withvector->items
by the user, it turns out that the only effectiveitem_size
is that of a(void*)
pointer.I've changed the vector internals to use a linear byte buffer underneath and to require always passing values around through a pointer. This makes it a bit more cumbersome to use for primitive types:
But the new version allows us to use the vector with structures:
Output:
Fortunately we don't use it anywhere so there's no need to test for regressions.
I'm not sure about whether I've implemented every function correctly, though, and would appreciate additional verification – I did test them, but I'm just not confident I've covered every corner case.