lib/repo: Add some assertions for ABI sizes

Things like https://sourceware.org/libabigail/manual/abidiff.html
look interesting but in a brief look I couldn't work out
how to conveniently use them for quick ABI sanity checking without
doing a diff from a previous build (which we could do but would be
more involved).

This way will at least catch struct ABI breaks on x86_64 which
I think we'd be most likely to do accidentally when trying
to use one of the previous unused values.

I found the hole values via gdb's `pahole` command.

Closes: #1108
Approved by: jlebon
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2017-08-24 14:58:51 +00:00
1 parent 882fa906e2
commit 95bac299e5
2 files changed
+32

No files matched your search

+27
View File
@@ -47,6 +47,33 @@
#include <sys/file.h>
#include <sys/statvfs.h>
/* ABI Size checks for ostree-repo.h, only for LP64 systems;
* https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models
*/
#if __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 8 && __SIZEOF_INT__ == 4
G_STATIC_ASSERT(sizeof(OstreeRepoTransactionStats) == sizeof(int) * 4 + 8 * 5);
G_STATIC_ASSERT(sizeof(OstreeRepoImportArchiveOptions) == sizeof(int) * 9 + 4 + sizeof(void*) * 8);
G_STATIC_ASSERT(sizeof(OstreeRepoExportArchiveOptions) == sizeof(int) * 9 + 4 + 8 + sizeof(void*) * 8);
G_STATIC_ASSERT(sizeof(OstreeRepoCheckoutAtOptions) ==
sizeof(OstreeRepoCheckoutMode) + sizeof(OstreeRepoCheckoutOverwriteMode) +
sizeof(int)*6 +
sizeof(int)*5 +
sizeof(int) +
sizeof(void*)*2 +
sizeof(int)*6 +
sizeof(void*)*7);
G_STATIC_ASSERT(sizeof(OstreeRepoCommitTraverseIter) ==
sizeof(int) + sizeof(int) +
sizeof(void*) * 10 +
130 + 6); /* 6 byte hole */
G_STATIC_ASSERT(sizeof(OstreeRepoPruneOptions) ==
sizeof(OstreeRepoPruneFlags) +
4 +
sizeof(void*) +
sizeof(int) * 12 +
sizeof(void*) * 7);
#endif
/**
* SECTION:ostree-repo
* @title: Content-addressed object store