static inline unsigned
flsw(machine_word_t v)
{
- BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+ STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
if (WORDSIZE == 4)
return fls32(v);
else
static inline unsigned
ffsw(machine_word_t v)
{
- BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+ STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
if (WORDSIZE == 4)
return ffs32(v);
else
# define _force_attr
#endif
-#ifndef BUILD_BUG_ON
-# define BUILD_BUG_ON(expr) ((void)sizeof(char[1 - 2*!!(expr)]))
+/* STATIC_ASSERT() - verify the truth of an expression at compilation time. */
+#if __STDC_VERSION__ >= 201112L
+# define STATIC_ASSERT(expr) _Static_assert((expr), "")
+#else
+# define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)]))
#endif
#endif /* _WIMLIB_COMPILER_H */
{
machine_word_t v;
- BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+ STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
v = b;
v |= v << 8;
static inline void
lzms_update_probability_entry(struct lzms_probability_entry *entry, int bit)
{
- BUILD_BUG_ON(LZMS_PROBABILITY_DENOMINATOR != sizeof(entry->recent_bits) * 8);
+ STATIC_ASSERT(LZMS_PROBABILITY_DENOMINATOR == sizeof(entry->recent_bits) * 8);
#ifdef __x86_64__
if (__builtin_constant_p(bit)) {
static inline void
check_reparse_buffer_disk(void)
{
- BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, rpdata) != 8);
- BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, link.junction.data) != 16);
- BUILD_BUG_ON(offsetof(struct reparse_buffer_disk, link.symlink.data) != 20);
- BUILD_BUG_ON(sizeof(struct reparse_buffer_disk) != REPARSE_POINT_MAX_SIZE);
+ STATIC_ASSERT(offsetof(struct reparse_buffer_disk, rpdata) == 8);
+ STATIC_ASSERT(offsetof(struct reparse_buffer_disk, link.junction.data) == 16);
+ STATIC_ASSERT(offsetof(struct reparse_buffer_disk, link.symlink.data) == 20);
+ STATIC_ASSERT(sizeof(struct reparse_buffer_disk) == REPARSE_POINT_MAX_SIZE);
}
/* Wrapper around a symbolic link or junction reparse point
static inline void
wof_check_structs(void)
{
- BUILD_BUG_ON(sizeof(struct WimOverlay_dat_header) != 24);
- BUILD_BUG_ON(sizeof(struct WimOverlay_dat_entry_1) != 40);
- BUILD_BUG_ON(sizeof(struct WimOverlay_dat_entry_2) != 104);
+ STATIC_ASSERT(sizeof(struct WimOverlay_dat_header) == 24);
+ STATIC_ASSERT(sizeof(struct WimOverlay_dat_entry_1) == 40);
+ STATIC_ASSERT(sizeof(struct WimOverlay_dat_entry_2) == 104);
}
/*****************************************************************************
struct blob_descriptor *
new_blob_descriptor(void)
{
- BUILD_BUG_ON(BLOB_NONEXISTENT != 0);
+ STATIC_ASSERT(BLOB_NONEXISTENT == 0);
return CALLOC(1, sizeof(struct blob_descriptor));
}
#endif
#ifdef WITH_FUSE
case BLOB_IN_STAGING_FILE:
- BUILD_BUG_ON((void*)&old->file_on_disk !=
- (void*)&old->staging_file_name);
+ STATIC_ASSERT((void*)&old->file_on_disk ==
+ (void*)&old->staging_file_name);
#endif
new->file_on_disk = TSTRDUP(old->file_on_disk);
if (new->file_on_disk == NULL)
#endif
#ifdef WITH_FUSE
case BLOB_IN_STAGING_FILE:
- BUILD_BUG_ON((void*)&blob->file_on_disk !=
- (void*)&blob->staging_file_name);
+ STATIC_ASSERT((void*)&blob->file_on_disk ==
+ (void*)&blob->staging_file_name);
#endif
case BLOB_IN_ATTACHED_BUFFER:
- BUILD_BUG_ON((void*)&blob->file_on_disk !=
- (void*)&blob->attached_buffer);
+ STATIC_ASSERT((void*)&blob->file_on_disk ==
+ (void*)&blob->attached_buffer);
FREE(blob->file_on_disk);
break;
#ifdef WITH_NTFS_3G
/* Compression format numbers must be the same as in
* WIMGAPI to be compatible here. */
- BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_NONE != 0);
- BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_XPRESS != 1);
- BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_LZX != 2);
- BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_LZMS != 3);
+ STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_NONE == 0);
+ STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_XPRESS == 1);
+ STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_LZX == 2);
+ STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_LZMS == 3);
rdesc->compression_type = le32_to_cpu(hdr.compression_format);
rdesc->chunk_size = le32_to_cpu(hdr.chunk_size);
}
* Note: we expect that this function produces patterns that can be used
* for both filesystem paths and WIM paths, so the desired path
* separators must be the same. */
- BUILD_BUG_ON(OS_PREFERRED_PATH_SEPARATOR != WIM_PATH_SEPARATOR);
+ STATIC_ASSERT(OS_PREFERRED_PATH_SEPARATOR == WIM_PATH_SEPARATOR);
do_canonicalize_path(pat, pat);
/* Relative patterns can only match file names, so they must be
aliased_word_t *p;
unsigned n;
- BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+ STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
v = MAKE_DIRECT_ENTRY(sorted_syms[sym_idx], codeword_len);
v |= v << 16;
u64 calculated_size;
int ret;
- BUILD_BUG_ON(sizeof(struct wim_dentry_on_disk) != WIM_DENTRY_DISK_SIZE);
+ STATIC_ASSERT(sizeof(struct wim_dentry_on_disk) == WIM_DENTRY_DISK_SIZE);
/* Before reading the whole dentry, we need to read just the length.
* This is because a dentry of length 8 (that is, just the length field)
filename = pipe_str;
}
- BUILD_BUG_ON(sizeof(struct wim_header_disk) != WIM_HEADER_DISK_SIZE);
+ STATIC_ASSERT(sizeof(struct wim_header_disk) == WIM_HEADER_DISK_SIZE);
ret = full_read(in_fd, &disk_hdr, sizeof(disk_hdr));
if (ret)
static inline void
check_that_powers_fit_in_bitfield(void)
{
- BUILD_BUG_ON(LZMS_NUM_DELTA_POWER_SYMS > (1 << (31 - DELTA_SOURCE_POWER_SHIFT)));
+ STATIC_ASSERT(LZMS_NUM_DELTA_POWER_SYMS <= (1 << (31 - DELTA_SOURCE_POWER_SHIFT)));
}
/* A stripped-down version of the adaptive state in LZMS which excludes the
check_cost_shift(void)
{
/* lzms_bit_costs is hard-coded to the current COST_SHIFT. */
- BUILD_BUG_ON(COST_SHIFT != 6);
+ STATIC_ASSERT(COST_SHIFT == 6);
}
#if 0
lzms_init_delta_matchfinder(struct lzms_compressor *c)
{
/* Set all entries to use an invalid power, which will never match. */
- BUILD_BUG_ON(NUM_POWERS_TO_CONSIDER >= (1 << (32 - DELTA_SOURCE_POWER_SHIFT)));
+ STATIC_ASSERT(NUM_POWERS_TO_CONSIDER < (1 << (32 - DELTA_SOURCE_POWER_SHIFT)));
memset(c->delta_hash_table, 0xFF, sizeof(c->delta_hash_table));
/* Initialize the next hash code for each power. We can just use zeroes
* include in the hash code computation the span and the low-order bits
* of the current position. */
- BUILD_BUG_ON(NBYTES_HASHED_FOR_DELTA != 3);
+ STATIC_ASSERT(NBYTES_HASHED_FOR_DELTA == 3);
u8 d0 = *(p + 0) - *(p + 0 - span);
u8 d1 = *(p + 1) - *(p + 1 - span);
u8 d2 = *(p + 2) - *(p + 2 - span);
const u32 pos = in_next - c->in_buffer;
/* Consider each possible power (log2 of span) */
- BUILD_BUG_ON(NUM_POWERS_TO_CONSIDER > LZMS_NUM_DELTA_POWER_SYMS);
+ STATIC_ASSERT(NUM_POWERS_TO_CONSIDER <= LZMS_NUM_DELTA_POWER_SYMS);
for (u32 power = 0; power < NUM_POWERS_TO_CONSIDER; power++) {
const u32 span = (u32)1 << power;
/* Check the first 3 bytes before entering the
* extension loop. */
- BUILD_BUG_ON(NBYTES_HASHED_FOR_DELTA != 3);
+ STATIC_ASSERT(NBYTES_HASHED_FOR_DELTA == 3);
if (((u8)(*(in_next + 0) - *(in_next + 0 - span)) !=
(u8)(*(matchptr + 0) - *(matchptr + 0 - span))) ||
((u8)(*(in_next + 1) - *(in_next + 1 - span)) !=
if (pending_lz_offset != 0 &&
out_next != lz_offset_still_pending)
{
- BUILD_BUG_ON(LZMS_NUM_LZ_REPS != 3);
+ STATIC_ASSERT(LZMS_NUM_LZ_REPS == 3);
recent_lz_offsets[3] = recent_lz_offsets[2];
recent_lz_offsets[2] = recent_lz_offsets[1];
recent_lz_offsets[1] = recent_lz_offsets[0];
pending_lz_offset = 0;
}
- BUILD_BUG_ON(LZMS_NUM_LZ_REPS != 3);
+ STATIC_ASSERT(LZMS_NUM_LZ_REPS == 3);
if (!lzms_decode_bit(&rd, &lz_rep_states[0],
LZMS_NUM_LZ_REP_PROBS,
d->probs.lz_rep[0]))
}
if (pending_lz_offset != 0) {
- BUILD_BUG_ON(LZMS_NUM_LZ_REPS != 3);
+ STATIC_ASSERT(LZMS_NUM_LZ_REPS == 3);
recent_lz_offsets[3] = recent_lz_offsets[2];
recent_lz_offsets[2] = recent_lz_offsets[1];
recent_lz_offsets[1] = recent_lz_offsets[0];
if (pending_delta_pair != 0 &&
out_next != delta_pair_still_pending)
{
- BUILD_BUG_ON(LZMS_NUM_DELTA_REPS != 3);
+ STATIC_ASSERT(LZMS_NUM_DELTA_REPS == 3);
recent_delta_pairs[3] = recent_delta_pairs[2];
recent_delta_pairs[2] = recent_delta_pairs[1];
recent_delta_pairs[1] = recent_delta_pairs[0];
pending_delta_pair = 0;
}
- BUILD_BUG_ON(LZMS_NUM_DELTA_REPS != 3);
+ STATIC_ASSERT(LZMS_NUM_DELTA_REPS == 3);
if (!lzms_decode_bit(&rd, &delta_rep_states[0],
LZMS_NUM_DELTA_REP_PROBS,
d->probs.delta_rep[0]))
}
if (pending_delta_pair != 0) {
- BUILD_BUG_ON(LZMS_NUM_DELTA_REPS != 3);
+ STATIC_ASSERT(LZMS_NUM_DELTA_REPS == 3);
recent_delta_pairs[3] = recent_delta_pairs[2];
recent_delta_pairs[2] = recent_delta_pairs[1];
recent_delta_pairs[1] = recent_delta_pairs[0];
extra_bits = (offset + LZX_OFFSET_ADJUSTMENT) -
lzx_offset_slot_base[offset_slot];
- BUILD_BUG_ON(LZX_MAINCODE_MAX_NUM_SYMBOLS > (1 << 10));
- BUILD_BUG_ON(LZX_LENCODE_NUM_SYMBOLS > (1 << 8));
+ STATIC_ASSERT(LZX_MAINCODE_MAX_NUM_SYMBOLS <= (1 << 10));
+ STATIC_ASSERT(LZX_LENCODE_NUM_SYMBOLS <= (1 << 8));
*(*next_chosen_item)++ = (struct lzx_item) {
.data = (u64)main_symbol |
((u64)len_symbol << 10) |
* it is no longer needed. */
struct lzx_lru_queue queues[512];
- BUILD_BUG_ON(ARRAY_LEN(queues) < LZX_MAX_MATCH_LEN + 1);
+ STATIC_ASSERT(ARRAY_LEN(queues) >= LZX_MAX_MATCH_LEN + 1);
#define QUEUE(in) (queues[(uintptr_t)(in) % ARRAY_LEN(queues)])
/* Initially, the cost to reach each node is "infinity". */
matchptr = in_next - lzx_lru_queue_R0(QUEUE(in_next));
if (load_u16_unaligned(matchptr) != load_u16_unaligned(in_next))
goto R0_done;
- BUILD_BUG_ON(LZX_MIN_MATCH_LEN != 2);
+ STATIC_ASSERT(LZX_MIN_MATCH_LEN == 2);
do {
u32 cost = cur_node->cost +
c->costs.match_cost[0][
unsigned num_used_bytes;
/* The costs below are hard coded to use a scaling factor of 16. */
- BUILD_BUG_ON(LZX_BIT_COST != 16);
+ STATIC_ASSERT(LZX_BIT_COST == 16);
/*
* Heuristics:
struct lzx_lru_queue queue,
unsigned *rep_max_idx_ret)
{
- BUILD_BUG_ON(LZX_NUM_RECENT_OFFSETS != 3);
+ STATIC_ASSERT(LZX_NUM_RECENT_OFFSETS == 3);
LZX_ASSERT(bytes_remaining >= 2);
const unsigned max_len = min(bytes_remaining, LZX_MAX_MATCH_LEN);
match_offset -= LZX_OFFSET_ADJUSTMENT;
/* Update the match offset LRU queue. */
- BUILD_BUG_ON(LZX_NUM_RECENT_OFFSETS != 3);
+ STATIC_ASSERT(LZX_NUM_RECENT_OFFSETS == 3);
queue->R[2] = queue->R[1];
queue->R[1] = queue->R[0];
queue->R[0] = match_offset;
if (ret)
goto out_free_branch;
- BUILD_BUG_ON(WIM_PATH_SEPARATOR != OS_PREFERRED_PATH_SEPARATOR);
+ STATIC_ASSERT(WIM_PATH_SEPARATOR == OS_PREFERRED_PATH_SEPARATOR);
ret = dentry_set_name(branch, path_basename(target_tstr));
if (ret)
goto out_free_target;
}
if (part_info->PartitionStyle == PARTITION_STYLE_GPT) {
- BUILD_BUG_ON(sizeof(part_info->Gpt.PartitionId) !=
- sizeof(drive_info->Gpt.DiskId));
+ STATIC_ASSERT(sizeof(part_info->Gpt.PartitionId) ==
+ sizeof(drive_info->Gpt.DiskId));
if (!memcmp(&part_info->Gpt.PartitionId,
&drive_info->Gpt.DiskId,
sizeof(drive_info->Gpt.DiskId)))
new_entry_1->entry_2_length = new_entry_2_size;
new_entry_1->wim_type = WIM_BOOT_NOT_OS_WIM;
new_entry_1->wim_index = image;
- BUILD_BUG_ON(sizeof(new_entry_1->guid) != GUID_SIZE);
+ STATIC_ASSERT(sizeof(new_entry_1->guid) == GUID_SIZE);
copy_guid(new_entry_1->guid, wim_guid);
p += sizeof(struct WimOverlay_dat_entry_1);
new_entry_2->disk.mbr.padding[1] = 0x00000000;
new_entry_2->disk.mbr.padding[2] = 0x00000000;
} else {
- BUILD_BUG_ON(sizeof(new_entry_2->partition.gpt.part_unique_guid) !=
- sizeof(part_info->Gpt.PartitionId));
+ STATIC_ASSERT(sizeof(new_entry_2->partition.gpt.part_unique_guid) ==
+ sizeof(part_info->Gpt.PartitionId));
memcpy(new_entry_2->partition.gpt.part_unique_guid,
&part_info->Gpt.PartitionId,
sizeof(part_info->Gpt.PartitionId));
new_entry_2->partition_table_type = WIMOVERLAY_PARTITION_TYPE_GPT;
- BUILD_BUG_ON(sizeof(new_entry_2->disk.gpt.disk_guid) !=
- sizeof(disk_info->Gpt.DiskId));
+ STATIC_ASSERT(sizeof(new_entry_2->disk.gpt.disk_guid) ==
+ sizeof(disk_info->Gpt.DiskId));
memcpy(new_entry_2->disk.gpt.disk_guid,
&disk_info->Gpt.DiskId,
sizeof(disk_info->Gpt.DiskId));
- BUILD_BUG_ON(sizeof(new_entry_2->disk.gpt.disk_guid) !=
- sizeof(new_entry_2->partition.gpt.part_unique_guid));
+ STATIC_ASSERT(sizeof(new_entry_2->disk.gpt.disk_guid) ==
+ sizeof(new_entry_2->partition.gpt.part_unique_guid));
}
new_entry_2->unknown_0x58[0] = 0x00000000;
new_entry_2->unknown_0x58[1] = 0x00000000;
struct wim_provider_rpdata wim_info;
} in;
- BUILD_BUG_ON(sizeof(in) != 8 +
- sizeof(struct wof_external_info) +
- sizeof(struct wim_provider_rpdata));
+ STATIC_ASSERT(sizeof(in) == 8 +
+ sizeof(struct wof_external_info) +
+ sizeof(struct wim_provider_rpdata));
in.hdr.rptag = WIM_IO_REPARSE_TAG_WOF;
in.hdr.rpdatalen = sizeof(in) - sizeof(in.hdr);
LOAD_TEXT_FILE_REMOVE_QUOTES |
LOAD_TEXT_FILE_NO_WARNINGS,
mangle_pat);
- BUILD_BUG_ON(OS_PREFERRED_PATH_SEPARATOR != WIM_PATH_SEPARATOR);
+ STATIC_ASSERT(OS_PREFERRED_PATH_SEPARATOR == WIM_PATH_SEPARATOR);
FREE(buf);
if (ret) {
FREE(s);
hdr.chunk_size = cpu_to_le32(ctx->out_chunk_size);
hdr.compression_format = cpu_to_le32(ctx->out_ctype);
- BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_XPRESS != 1);
- BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_LZX != 2);
- BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_LZMS != 3);
+ STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_XPRESS == 1);
+ STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_LZX == 2);
+ STATIC_ASSERT(WIMLIB_COMPRESSION_TYPE_LZMS == 3);
ret = full_pwrite(ctx->out_fd, &hdr, sizeof(hdr),
chunk_table_offset - sizeof(hdr));