Cleanup: various non-functional changes for C++

This commit is contained in:
Campbell Barton
2025-02-13 13:29:41 +11:00
parent 84358c5a3e
commit 640e70b6e8
45 changed files with 227 additions and 231 deletions

View File

@@ -885,7 +885,7 @@ void action_group_colors_set(bActionGroup *grp, const BoneColor *color)
{
const blender::animrig::BoneColor &bone_color = color->wrap();
grp->customCol = (int)bone_color.palette_index;
grp->customCol = int(bone_color.palette_index);
const ThemeWireColor *effective_color = bone_color.effective_color();
if (effective_color) {

View File

@@ -448,7 +448,7 @@ enum ePF_FileCompare BKE_packedfile_compare_to_file(const char *ref_file_name,
for (int i = 0; i < pf->size; i += sizeof(buf)) {
int len = pf->size - i;
len = std::min<unsigned long>(len, sizeof(buf));
len = std::min<ulong>(len, sizeof(buf));
if (BLI_read(file, buf, len) != len) {
/* read error ... */

View File

@@ -22,7 +22,7 @@ static char NO_DOCS[] = "NO DOCUMENTATION SPECIFIED";
struct bArgDoc;
struct bArgDoc {
struct bArgDoc *next, *prev;
bArgDoc *next, *prev;
const char *short_arg;
const char *long_arg;
const char *documentation;
@@ -198,7 +198,7 @@ static void internalAdd(
case_str == 1 ? "not " : "");
printf("\tconflict with '%s' on pass %i, %scase sensitive\n\n",
a->key->arg,
(int)a->key->pass,
int(a->key->pass),
a->key->case_str == 1 ? "not " : "");
}

View File

@@ -33,14 +33,14 @@ void _BLI_assert_unreachable_print(const char *file, const int line, const char
fprintf(stderr, "Error found at %s:%d in %s.\n", file, line, function);
}
void _BLI_assert_print_backtrace(void)
void _BLI_assert_print_backtrace()
{
#ifndef NDEBUG
BLI_system_backtrace(stderr);
#endif
}
void _BLI_assert_abort(void)
void _BLI_assert_abort()
{
/* Wrap to remove 'noreturn' attribute since this suppresses missing return statements,
* allowing changes to debug builds to accidentally to break release builds.

View File

@@ -73,7 +73,7 @@ float BLI_dial_angle(Dial *dial, const float current_position[2])
/* change of sign, we passed the 180 degree threshold. This means we need to add a turn.
* to distinguish between transition from 0 to -1 and -PI to +PI,
* use comparison with PI/2 */
if ((angle * dial->last_angle < 0.0f) && (fabsf(dial->last_angle) > (float)M_PI_2)) {
if ((angle * dial->last_angle < 0.0f) && (fabsf(dial->last_angle) > float(M_PI_2))) {
if (dial->last_angle < 0.0f) {
dial->rotations--;
}
@@ -83,7 +83,7 @@ float BLI_dial_angle(Dial *dial, const float current_position[2])
}
dial->last_angle = angle;
return angle + 2.0f * (float)M_PI * dial->rotations;
return angle + 2.0f * float(M_PI) * dial->rotations;
}
return dial->last_angle;

View File

@@ -33,12 +33,12 @@ struct DynStr {
/***/
DynStr *BLI_dynstr_new(void)
DynStr *BLI_dynstr_new()
{
return MEM_cnew<DynStr>("DynStr");
}
DynStr *BLI_dynstr_new_memarena(void)
DynStr *BLI_dynstr_new_memarena()
{
DynStr *ds = MEM_cnew<DynStr>("DynStr");
ds->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);

View File

@@ -62,7 +62,7 @@ BLI_STATIC_ASSERT(ARRAY_SIZE(hashsizes) == GHASH_MAX_SIZE, "Invalid 'hashsizes'
/* WARNING! Keep in sync with ugly _gh_Entry in header!!! */
struct Entry {
struct Entry *next;
Entry *next;
void *key;
};
@@ -849,7 +849,7 @@ void BLI_ghash_clear_ex(GHash *gh,
}
ghash_buckets_reset(gh, nentries_reserve);
BLI_mempool_clear_ex(gh->entrypool, nentries_reserve ? (int)nentries_reserve : -1);
BLI_mempool_clear_ex(gh->entrypool, nentries_reserve ? int(nentries_reserve) : -1);
}
void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
@@ -1082,7 +1082,7 @@ void *BLI_gset_pop_key(GSet *gs, const void *key)
int BLI_ghash_buckets_len(const GHash *gh)
{
return (int)gh->nbuckets;
return int(gh->nbuckets);
}
int BLI_gset_buckets_len(const GSet *gs)
{
@@ -1119,7 +1119,7 @@ double BLI_ghash_calc_quality_ex(const GHash *gh,
return 0.0;
}
mean = (double)gh->nentries / (double)gh->nbuckets;
mean = double(gh->nentries) / double(gh->nbuckets);
if (r_load) {
*r_load = mean;
}
@@ -1138,14 +1138,14 @@ double BLI_ghash_calc_quality_ex(const GHash *gh,
for (e = gh->buckets[i]; e; e = e->next) {
count++;
}
sum += ((double)count - mean) * ((double)count - mean);
sum += (double(count) - mean) * (double(count) - mean);
}
*r_variance = sum / (double)(gh->nbuckets - 1);
*r_variance = sum / double(gh->nbuckets - 1);
}
{
uint64_t sum = 0;
uint64_t overloaded_buckets_threshold = (uint64_t)max_ii(GHASH_LIMIT_GROW(1), 1);
uint64_t overloaded_buckets_threshold = uint64_t(max_ii(GHASH_LIMIT_GROW(1), 1));
uint64_t sum_overloaded = 0;
uint64_t sum_empty = 0;
@@ -1156,7 +1156,7 @@ double BLI_ghash_calc_quality_ex(const GHash *gh,
count++;
}
if (r_biggest_bucket) {
*r_biggest_bucket = max_ii(*r_biggest_bucket, (int)count);
*r_biggest_bucket = max_ii(*r_biggest_bucket, int(count));
}
if (r_prop_overloaded_buckets && (count > overloaded_buckets_threshold)) {
sum_overloaded++;
@@ -1167,13 +1167,13 @@ double BLI_ghash_calc_quality_ex(const GHash *gh,
sum += count * (count + 1);
}
if (r_prop_overloaded_buckets) {
*r_prop_overloaded_buckets = (double)sum_overloaded / (double)gh->nbuckets;
*r_prop_overloaded_buckets = double(sum_overloaded) / double(gh->nbuckets);
}
if (r_prop_empty_buckets) {
*r_prop_empty_buckets = (double)sum_empty / (double)gh->nbuckets;
*r_prop_empty_buckets = double(sum_empty) / double(gh->nbuckets);
}
return ((double)sum * (double)gh->nbuckets /
((double)gh->nentries * (gh->nentries + 2 * gh->nbuckets - 1)));
return (double(sum) * double(gh->nbuckets) /
(double(gh->nentries) * (gh->nentries + 2 * gh->nbuckets - 1)));
}
}
double BLI_gset_calc_quality_ex(const GSet *gs,

View File

@@ -41,7 +41,7 @@ struct HeapNode_Chunk {
* \note keep type in sync with nodes_num in heap_node_alloc_chunk.
*/
#define HEAP_CHUNK_DEFAULT_NUM \
(uint)(MEM_SIZE_OPTIMAL((1 << 16) - sizeof(HeapNode_Chunk)) / sizeof(HeapNode))
uint(MEM_SIZE_OPTIMAL((1 << 16) - sizeof(HeapNode_Chunk)) / sizeof(HeapNode))
struct Heap {
uint size;
@@ -183,7 +183,7 @@ Heap *BLI_heap_new_ex(uint reserve_num)
return heap;
}
Heap *BLI_heap_new(void)
Heap *BLI_heap_new()
{
return BLI_heap_new_ex(1);
}

View File

@@ -52,7 +52,7 @@ static void heapsimple_down(HeapSimple *heap, uint start_i, const HeapSimpleNode
* using index here can be modified to work with byte offset. */
uint8_t *const tree_buf = (uint8_t *)heap->tree;
# define OFFSET(i) (i * (uint)sizeof(HeapSimpleNode))
# define OFFSET(i) (i * uint(sizeof(HeapSimpleNode)))
# define NODE(offset) (*(HeapSimpleNode *)(tree_buf + (offset)))
#else
HeapSimpleNode *const tree = heap->tree;
@@ -146,7 +146,7 @@ HeapSimple *BLI_heapsimple_new_ex(uint reserve_num)
return heap;
}
HeapSimple *BLI_heapsimple_new(void)
HeapSimple *BLI_heapsimple_new()
{
return BLI_heapsimple_new_ex(1);
}

View File

@@ -35,14 +35,14 @@
#include "BLI_strict_flags.h" /* IWYU pragma: keep. Keep last. */
struct MemBuf {
struct MemBuf *next;
MemBuf *next;
uchar data[0];
};
struct MemArena {
uchar *curbuf;
const char *name;
struct MemBuf *bufs;
MemBuf *bufs;
size_t bufsize, cursize;
size_t align;
@@ -50,13 +50,13 @@ struct MemArena {
bool use_calloc;
};
static void memarena_buf_free_all(struct MemBuf *mb)
static void memarena_buf_free_all(MemBuf *mb)
{
while (mb != nullptr) {
struct MemBuf *mb_next = mb->next;
MemBuf *mb_next = mb->next;
/* Unpoison memory because #MEM_freeN might overwrite it. */
BLI_asan_unpoison(mb, (uint)MEM_allocN_len(mb));
BLI_asan_unpoison(mb, uint(MEM_allocN_len(mb)));
MEM_freeN(mb);
mb = mb_next;
@@ -110,8 +110,8 @@ static void memarena_curbuf_align(MemArena *ma)
{
uchar *tmp;
tmp = (uchar *)PADUP((intptr_t)ma->curbuf, (int)ma->align);
ma->cursize -= (size_t)(tmp - ma->curbuf);
tmp = (uchar *)PADUP(intptr_t(ma->curbuf), int(ma->align));
ma->cursize -= size_t(tmp - ma->curbuf);
ma->curbuf = tmp;
}
@@ -130,7 +130,7 @@ void *BLI_memarena_alloc(MemArena *ma, size_t size)
ma->cursize = ma->bufsize;
}
struct MemBuf *mb = static_cast<MemBuf *>(
MemBuf *mb = static_cast<MemBuf *>(
(ma->use_calloc ? MEM_callocN : MEM_mallocN)(sizeof(*mb) + ma->cursize, ma->name));
ma->curbuf = mb->data;
mb->next = ma->bufs;
@@ -190,7 +190,7 @@ void BLI_memarena_merge(MemArena *ma_dst, MemArena *ma_src)
if (ma_dst->bufs->next != nullptr) {
/* Loop over `ma_src` instead of `ma_dst` since it's likely the destination is larger
* when used for accumulating from multiple sources. */
struct MemBuf *mb_src = ma_src->bufs;
MemBuf *mb_src = ma_src->bufs;
while (mb_src->next) {
mb_src = mb_src->next;
}
@@ -220,7 +220,7 @@ void BLI_memarena_clear(MemArena *ma)
memarena_curbuf_align(ma);
/* restore to original size */
const size_t curbuf_used = (size_t)(curbuf_prev - ma->curbuf);
const size_t curbuf_used = size_t(curbuf_prev - ma->curbuf);
ma->cursize += curbuf_used;
if (ma->use_calloc) {

View File

@@ -48,14 +48,14 @@ BLI_memblock *BLI_memblock_create_ex(uint elem_size, uint chunk_size)
BLI_assert(elem_size < chunk_size);
BLI_memblock *mblk = MEM_cnew<BLI_memblock>("BLI_memblock");
mblk->elem_size = (int)elem_size;
mblk->elem_size = int(elem_size);
mblk->elem_next = 0;
mblk->elem_last = -1;
mblk->chunk_size = (int)chunk_size;
mblk->chunk_size = int(chunk_size);
mblk->chunk_len = CHUNK_LIST_SIZE;
mblk->chunk_list = MEM_cnew_array<void *>((size_t)mblk->chunk_len, "chunk list");
mblk->chunk_list[0] = MEM_mallocN_aligned((size_t)mblk->chunk_size, 32, "BLI_memblock chunk");
memset(mblk->chunk_list[0], 0x0, (uint)mblk->chunk_size);
mblk->chunk_list = MEM_cnew_array<void *>(size_t(mblk->chunk_len), "chunk list");
mblk->chunk_list[0] = MEM_mallocN_aligned(size_t(mblk->chunk_size), 32, "BLI_memblock chunk");
memset(mblk->chunk_list[0], 0x0, uint(mblk->chunk_size));
mblk->chunk_max_ofs = (mblk->chunk_size / mblk->elem_size) * mblk->elem_size;
mblk->elem_next_ofs = 0;
mblk->chunk_next = 0;
@@ -103,7 +103,7 @@ void BLI_memblock_clear(BLI_memblock *mblk, MemblockValFreeFP free_callback)
if (UNLIKELY(last_used_chunk + 1 < mblk->chunk_len - CHUNK_LIST_SIZE)) {
mblk->chunk_len -= CHUNK_LIST_SIZE;
mblk->chunk_list = static_cast<void **>(
MEM_recallocN(mblk->chunk_list, sizeof(void *) * (uint)mblk->chunk_len));
MEM_recallocN(mblk->chunk_list, sizeof(void *) * uint(mblk->chunk_len)));
}
mblk->elem_last = mblk->elem_next - 1;
@@ -129,13 +129,13 @@ void *BLI_memblock_alloc(BLI_memblock *mblk)
if (UNLIKELY(mblk->chunk_next >= mblk->chunk_len)) {
mblk->chunk_len += CHUNK_LIST_SIZE;
mblk->chunk_list = static_cast<void **>(
MEM_recallocN(mblk->chunk_list, sizeof(void *) * (uint)mblk->chunk_len));
MEM_recallocN(mblk->chunk_list, sizeof(void *) * uint(mblk->chunk_len)));
}
if (UNLIKELY(mblk->chunk_list[mblk->chunk_next] == nullptr)) {
mblk->chunk_list[mblk->chunk_next] = MEM_mallocN_aligned(
(uint)mblk->chunk_size, 32, "BLI_memblock chunk");
memset(mblk->chunk_list[mblk->chunk_next], 0x0, (uint)mblk->chunk_size);
uint(mblk->chunk_size), 32, "BLI_memblock chunk");
memset(mblk->chunk_list[mblk->chunk_next], 0x0, uint(mblk->chunk_size));
}
}
return ptr;

View File

@@ -58,7 +58,7 @@ struct BLI_memiter_elem {
};
struct BLI_memiter_chunk {
struct BLI_memiter_chunk *next;
BLI_memiter_chunk *next;
/**
* internal format is:
* `[next_pointer, size:data, size:data, ..., negative_offset]`
@@ -84,7 +84,7 @@ struct BLI_memiter {
BLI_INLINE uint data_offset_from_size(uint size)
{
return PADUP(size, (uint)sizeof(data_t)) / (uint)sizeof(data_t);
return PADUP(size, uint(sizeof(data_t))) / uint(sizeof(data_t));
}
static void memiter_set_rewind_offset(BLI_memiter *mi)
@@ -144,8 +144,8 @@ void *BLI_memiter_alloc(BLI_memiter *mi, uint elem_size)
#endif
uint chunk_size_in_bytes = mi->chunk_size_in_bytes_min;
if (UNLIKELY(chunk_size_in_bytes < elem_size + (uint)sizeof(data_t[2]))) {
chunk_size_in_bytes = elem_size + (uint)sizeof(data_t[2]);
if (UNLIKELY(chunk_size_in_bytes < elem_size + uint(sizeof(data_t[2])))) {
chunk_size_in_bytes = elem_size + uint(sizeof(data_t[2]));
}
uint chunk_size = data_offset_from_size(chunk_size_in_bytes);
BLI_memiter_chunk *chunk = static_cast<BLI_memiter_chunk *>(MEM_mallocN(
@@ -255,7 +255,7 @@ void *BLI_memiter_elem_first_size(BLI_memiter *mi, uint *r_size)
if (mi->head != nullptr) {
BLI_memiter_chunk *chunk = mi->head;
BLI_memiter_elem *elem = (BLI_memiter_elem *)chunk->data;
*r_size = (uint)elem->size;
*r_size = uint(elem->size);
return elem->data;
}
return nullptr;
@@ -302,7 +302,7 @@ void *BLI_memiter_iter_step_size(BLI_memiter_handle *iter, uint *r_size)
memiter_chunk_step(iter);
}
BLI_assert(iter->elem->size >= 0);
uint size = (uint)iter->elem->size;
uint size = uint(iter->elem->size);
*r_size = size; /* <-- only difference */
data_t *data = iter->elem->data;
iter->elem = (BLI_memiter_elem *)&data[data_offset_from_size(size)];
@@ -319,7 +319,7 @@ void *BLI_memiter_iter_step(BLI_memiter_handle *iter)
memiter_chunk_step(iter);
}
BLI_assert(iter->elem->size >= 0);
uint size = (uint)iter->elem->size;
uint size = uint(iter->elem->size);
data_t *data = iter->elem->data;
iter->elem = (BLI_memiter_elem *)&data[data_offset_from_size(size)];
return (void *)data;

View File

@@ -53,10 +53,10 @@
(int64_t)(e) << 24 | (int64_t)(f) << 16 | (int64_t)(g) << 8 | (h))
#else
/* Little Endian */
# define MAKE_ID(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a))
# define MAKE_ID(a, b, c, d) (int(d) << 24 | int(c) << 16 | (b) << 8 | (a))
# define MAKE_ID_8(a, b, c, d, e, f, g, h) \
((int64_t)(h) << 56 | (int64_t)(g) << 48 | (int64_t)(f) << 40 | (int64_t)(e) << 32 | \
(int64_t)(d) << 24 | (int64_t)(c) << 16 | (int64_t)(b) << 8 | (a))
(int64_t(h) << 56 | int64_t(g) << 48 | int64_t(f) << 40 | int64_t(e) << 32 | \
int64_t(d) << 24 | int64_t(c) << 16 | int64_t(b) << 8 | (a))
#endif
/**
@@ -88,7 +88,7 @@ static bool mempool_debug_memset = false;
* Each element represents a block which BLI_mempool_alloc may return.
*/
struct BLI_freenode {
struct BLI_freenode *next;
BLI_freenode *next;
/** Used to identify this as a freed node. */
intptr_t freeword;
};
@@ -98,7 +98,7 @@ struct BLI_freenode {
* #BLI_mempool.chunks as a double linked list.
*/
struct BLI_mempool_chunk {
struct BLI_mempool_chunk *next;
BLI_mempool_chunk *next;
};
/**
@@ -140,7 +140,7 @@ struct BLI_mempool {
#define NODE_STEP_PREV(node) ((BLI_freenode *)((char *)(node)-esize))
/** Extra bytes implicitly used for every chunk alloc. */
#define CHUNK_OVERHEAD (uint)(MEM_SIZE_OVERHEAD + sizeof(BLI_mempool_chunk))
#define CHUNK_OVERHEAD uint(MEM_SIZE_OVERHEAD + sizeof(BLI_mempool_chunk))
static void mempool_asan_unlock(BLI_mempool *pool)
{
@@ -195,7 +195,7 @@ BLI_INLINE uint mempool_maxchunks(const uint elem_num, const uint pchunk)
static BLI_mempool_chunk *mempool_chunk_alloc(const BLI_mempool *pool)
{
return static_cast<BLI_mempool_chunk *>(
MEM_mallocN(sizeof(BLI_mempool_chunk) + (size_t)pool->csize, "mempool chunk"));
MEM_mallocN(sizeof(BLI_mempool_chunk) + size_t(pool->csize), "mempool chunk"));
}
/**
@@ -347,10 +347,10 @@ BLI_mempool *BLI_mempool_create(uint esize, uint elem_num, uint pchunk, uint fla
#endif
/* set the elem size */
esize = std::max(esize, (uint)MEMPOOL_ELEM_SIZE_MIN);
esize = std::max(esize, uint(MEMPOOL_ELEM_SIZE_MIN));
if (flag & BLI_MEMPOOL_ALLOW_ITER) {
esize = std::max(esize, (uint)sizeof(BLI_freenode));
esize = std::max(esize, uint(sizeof(BLI_freenode)));
}
esize += POISON_REDZONE_SIZE;
@@ -445,7 +445,7 @@ void *BLI_mempool_calloc(BLI_mempool *pool)
{
void *retval = BLI_mempool_alloc(pool);
memset(retval, 0, (size_t)pool->esize - POISON_REDZONE_SIZE);
memset(retval, 0, size_t(pool->esize) - POISON_REDZONE_SIZE);
return retval;
}
@@ -545,7 +545,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
int BLI_mempool_len(const BLI_mempool *pool)
{
int ret = (int)pool->totused;
int ret = int(pool->totused);
return ret;
}
@@ -575,7 +575,7 @@ void *BLI_mempool_findelem(BLI_mempool *pool, uint index)
void BLI_mempool_as_array(BLI_mempool *pool, void *data)
{
const uint esize = pool->esize - (uint)POISON_REDZONE_SIZE;
const uint esize = pool->esize - uint(POISON_REDZONE_SIZE);
BLI_mempool_iter iter;
const char *elem;
char *p = static_cast<char *>(data);
@@ -585,7 +585,7 @@ void BLI_mempool_as_array(BLI_mempool *pool, void *data)
mempool_asan_lock(pool);
BLI_mempool_iternew(pool, &iter);
while ((elem = static_cast<const char *>(BLI_mempool_iterstep(&iter)))) {
memcpy(p, elem, (size_t)esize);
memcpy(p, elem, size_t(esize));
p = reinterpret_cast<char *>(NODE_STEP_NEXT(p));
}
mempool_asan_unlock(pool);
@@ -594,7 +594,7 @@ void BLI_mempool_as_array(BLI_mempool *pool, void *data)
void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr)
{
char *data = static_cast<char *>(
MEM_malloc_arrayN((size_t)pool->totused, pool->esize, allocstr));
MEM_malloc_arrayN(size_t(pool->totused), pool->esize, allocstr));
BLI_mempool_as_array(pool, data);
return data;
}
@@ -826,7 +826,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int elem_num_reserve)
maxchunks = pool->maxchunks;
}
else {
maxchunks = mempool_maxchunks((uint)elem_num_reserve, pool->pchunk);
maxchunks = mempool_maxchunks(uint(elem_num_reserve), pool->pchunk);
}
/* Free all after 'pool->maxchunks'. */

View File

@@ -134,7 +134,7 @@ BLI_mmap_file *BLI_mmap_open(int fd)
{
void *memory, *handle = nullptr;
const size_t length = BLI_lseek(fd, 0, SEEK_END);
if (UNLIKELY(length == (size_t)-1)) {
if (UNLIKELY(length == size_t(-1))) {
return nullptr;
}

View File

@@ -15,7 +15,7 @@
#define GET_TIME() BLI_time_now_seconds()
struct TimedFunction {
struct TimedFunction *next, *prev;
TimedFunction *next, *prev;
BLI_timer_func func;
BLI_timer_data_free user_data_free;
void *user_data;
@@ -117,13 +117,13 @@ static void remove_tagged_functions()
}
}
void BLI_timer_execute(void)
void BLI_timer_execute()
{
execute_functions_if_necessary();
remove_tagged_functions();
}
void BLI_timer_free(void)
void BLI_timer_free()
{
LISTBASE_FOREACH (TimedFunction *, timed_func, &GlobalTimer.funcs) {
timed_func->tag_removal = true;

View File

@@ -26,7 +26,7 @@
void _bli_array_reverse(void *arr_v, uint arr_len, size_t arr_stride)
{
const uint arr_stride_uint = (uint)arr_stride;
const uint arr_stride_uint = uint(arr_stride);
const uint arr_half_stride = (arr_len / 2) * arr_stride_uint;
uint i, i_end;
char *arr = static_cast<char *>(arr_v);
@@ -65,7 +65,7 @@ void _bli_array_permute(
void *arr, const uint arr_len, const size_t arr_stride, const uint *order, void *arr_temp)
{
const size_t len = arr_len * arr_stride;
const uint arr_stride_uint = (uint)arr_stride;
const uint arr_stride_uint = uint(arr_stride);
void *arr_orig;
uint i;
@@ -96,7 +96,7 @@ uint _bli_array_deduplicate_ordered(void *arr, uint arr_len, size_t arr_stride)
return arr_len;
}
const uint arr_stride_uint = (uint)arr_stride;
const uint arr_stride_uint = uint(arr_stride);
uint j = 0;
for (uint i = 0; i < arr_len; i++) {
if ((i == j) || (memcmp(POINTER_OFFSET(arr, arr_stride_uint * i),
@@ -118,7 +118,7 @@ int _bli_array_findindex(const void *arr, uint arr_len, size_t arr_stride, const
const char *arr_step = (const char *)arr;
for (uint i = 0; i < arr_len; i++, arr_step += arr_stride) {
if (memcmp(arr_step, p, arr_stride) == 0) {
return (int)i;
return int(i);
}
}
return -1;
@@ -130,7 +130,7 @@ int _bli_array_rfindindex(const void *arr, uint arr_len, size_t arr_stride, cons
for (uint i = arr_len; i-- != 0;) {
arr_step -= arr_stride;
if (memcmp(arr_step, p, arr_stride) == 0) {
return (int)i;
return int(i);
}
}
return -1;
@@ -179,7 +179,7 @@ bool _bli_array_iter_span(const void *arr,
return false;
}
const uint arr_stride_uint = (uint)arr_stride;
const uint arr_stride_uint = uint(arr_stride);
const void *item_prev;
bool test_prev;
@@ -295,7 +295,7 @@ bool _bli_array_iter_spiral_square(const void *arr_v,
center[1] < arr_shape[1]);
const char *arr = static_cast<const char *>(arr_v);
const int stride[2] = {arr_shape[0] * (int)elem_size, (int)elem_size};
const int stride[2] = {arr_shape[0] * int(elem_size), int(elem_size)};
/* Test center first. */
int ofs[2] = {center[0] * stride[1], center[1] * stride[0]};

View File

@@ -69,7 +69,7 @@ void BLI_astar_solution_init(BLI_AStarGraph *as_graph,
void *custom_data)
{
MemArena *mem = as_solution->mem;
size_t node_num = (size_t)as_graph->node_num;
size_t node_num = size_t(as_graph->node_num);
if (mem == nullptr) {
mem = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
@@ -124,7 +124,7 @@ void BLI_astar_graph_init(BLI_AStarGraph *as_graph, const int node_num, void *cu
/* else memarena should be cleared */
as_graph->node_num = node_num;
as_graph->nodes = BLI_memarena_calloc<BLI_AStarGNode>(mem, (size_t)node_num);
as_graph->nodes = BLI_memarena_calloc<BLI_AStarGNode>(mem, size_t(node_num));
as_graph->custom_data = custom_data;
}

View File

@@ -291,13 +291,13 @@ void BLI_box_pack_2d(
if (sort_boxes) {
/* Sort boxes, biggest first.
* Be careful, qsort is not deterministic! */
qsort(boxarray, (size_t)len, sizeof(BoxPack), box_areasort);
qsort(boxarray, size_t(len), sizeof(BoxPack), box_areasort);
}
/* Add verts to the boxes, these are only used internally. */
vert = static_cast<BoxVert *>(MEM_mallocN(sizeof(BoxVert[4]) * (size_t)len, "BoxPack Verts"));
vert = static_cast<BoxVert *>(MEM_mallocN(sizeof(BoxVert[4]) * size_t(len), "BoxPack Verts"));
vertex_pack_indices = static_cast<uint *>(
MEM_mallocN(sizeof(int[3]) * (size_t)len, "BoxPack Indices"));
MEM_mallocN(sizeof(int[3]) * size_t(len), "BoxPack Indices"));
vs_ctx.vertarray = vert;
@@ -375,7 +375,7 @@ void BLI_box_pack_2d(
vs_ctx.box_width = box->w;
vs_ctx.box_height = box->h;
qsort_r(vertex_pack_indices, (size_t)verts_pack_len, sizeof(int), vertex_sort, &vs_ctx);
qsort_r(vertex_pack_indices, size_t(verts_pack_len), sizeof(int), vertex_sort, &vs_ctx);
#ifdef USE_FREE_STRIP
/* strip free vertices */

View File

@@ -168,11 +168,11 @@ float BLI_easing_elastic_ease_in(
amplitude = change;
}
else {
s = period / (2 * (float)M_PI) * asinf(change / amplitude);
s = period / (2 * float(M_PI)) * asinf(change / amplitude);
}
return (-f * (amplitude * powf(2, 10 * time) *
sinf((time * duration - s) * (2 * (float)M_PI) / period))) +
sinf((time * duration - s) * (2 * float(M_PI)) / period))) +
begin;
}
@@ -200,11 +200,11 @@ float BLI_easing_elastic_ease_out(
amplitude = change;
}
else {
s = period / (2 * (float)M_PI) * asinf(change / amplitude);
s = period / (2 * float(M_PI)) * asinf(change / amplitude);
}
return (f * (amplitude * powf(2, 10 * time) *
sinf((time * duration - s) * (2 * (float)M_PI) / period))) +
sinf((time * duration - s) * (2 * float(M_PI)) / period))) +
change + begin;
}
@@ -232,20 +232,20 @@ float BLI_easing_elastic_ease_in_out(
amplitude = change;
}
else {
s = period / (2 * (float)M_PI) * asinf(change / amplitude);
s = period / (2 * float(M_PI)) * asinf(change / amplitude);
}
if (time < 0.0f) {
f *= -0.5f;
return (f * (amplitude * powf(2, 10 * time) *
sinf((time * duration - s) * (2 * (float)M_PI) / period))) +
sinf((time * duration - s) * (2 * float(M_PI)) / period))) +
begin;
}
time = -time;
f *= 0.5f;
return (f * (amplitude * powf(2, 10 * time) *
sinf((time * duration - s) * (2 * (float)M_PI) / period))) +
sinf((time * duration - s) * (2 * float(M_PI)) / period))) +
change + begin;
}
@@ -347,15 +347,15 @@ float BLI_easing_quint_ease_in_out(float time, float begin, float change, float
float BLI_easing_sine_ease_in(float time, float begin, float change, float duration)
{
return -change * cosf(time / duration * (float)M_PI_2) + change + begin;
return -change * cosf(time / duration * float(M_PI_2)) + change + begin;
}
float BLI_easing_sine_ease_out(float time, float begin, float change, float duration)
{
return change * sinf(time / duration * (float)M_PI_2) + begin;
return change * sinf(time / duration * float(M_PI_2)) + begin;
}
float BLI_easing_sine_ease_in_out(float time, float begin, float change, float duration)
{
return -change / 2 * (cosf((float)M_PI * time / duration) - 1) + begin;
return -change / 2 * (cosf(float(M_PI) * time / duration) - 1) + begin;
}

View File

@@ -29,7 +29,7 @@ static int64_t memory_read_raw(FileReader *reader, void *buffer, size_t size)
MemoryReader *mem = (MemoryReader *)reader;
/* Don't read more bytes than there are available in the buffer. */
size_t readsize = std::min(size, (size_t)(mem->length - mem->reader.offset));
size_t readsize = std::min(size, size_t(mem->length - mem->reader.offset));
memcpy(buffer, mem->data + mem->reader.offset, readsize);
mem->reader.offset += readsize;
@@ -93,7 +93,7 @@ static int64_t memory_read_mmap(FileReader *reader, void *buffer, size_t size)
MemoryReader *mem = (MemoryReader *)reader;
/* Don't read more bytes than there are available in the buffer. */
size_t readsize = std::min(size, (size_t)(mem->length - mem->reader.offset));
size_t readsize = std::min(size, size_t(mem->length - mem->reader.offset));
if (!BLI_mmap_read(mem->mmap, buffer, mem->reader.offset, readsize)) {
return 0;

View File

@@ -24,19 +24,19 @@
#define CHUNK_ELEM_MIN 32
struct QueueChunk {
struct QueueChunk *next;
QueueChunk *next;
char data[0];
};
struct _GSQueue {
struct QueueChunk *chunk_first; /* first active chunk to pop from */
struct QueueChunk *chunk_last; /* last active chunk to push onto */
struct QueueChunk *chunk_free; /* free chunks to reuse */
size_t chunk_first_index; /* index into 'chunk_first' */
size_t chunk_last_index; /* index into 'chunk_last' */
size_t chunk_elem_max; /* number of elements per chunk */
size_t elem_size; /* memory size of elements */
size_t elem_num; /* total number of elements */
QueueChunk *chunk_first; /* first active chunk to pop from */
QueueChunk *chunk_last; /* last active chunk to push onto */
QueueChunk *chunk_free; /* free chunks to reuse */
size_t chunk_first_index; /* index into 'chunk_first' */
size_t chunk_last_index; /* index into 'chunk_last' */
size_t chunk_elem_max; /* number of elements per chunk */
size_t elem_size; /* memory size of elements */
size_t elem_num; /* total number of elements */
};
static void *queue_get_first_elem(GSQueue *queue)
@@ -64,7 +64,7 @@ static size_t queue_chunk_elem_max_calc(const size_t elem_size, size_t chunk_siz
}
/* account for slop-space */
chunk_size -= (sizeof(struct QueueChunk) + MEM_SIZE_OVERHEAD);
chunk_size -= (sizeof(QueueChunk) + MEM_SIZE_OVERHEAD);
return chunk_size / elem_size;
}
@@ -81,10 +81,10 @@ GSQueue *BLI_gsqueue_new(const size_t elem_size)
return queue;
}
static void queue_free_chunk(struct QueueChunk *data)
static void queue_free_chunk(QueueChunk *data)
{
while (data) {
struct QueueChunk *data_next = data->next;
QueueChunk *data_next = data->next;
MEM_freeN(data);
data = data_next;
}
@@ -103,7 +103,7 @@ void BLI_gsqueue_push(GSQueue *queue, const void *item)
queue->elem_num++;
if (UNLIKELY(queue->chunk_last_index == queue->chunk_elem_max)) {
struct QueueChunk *chunk;
QueueChunk *chunk;
if (queue->chunk_free) {
chunk = queue->chunk_free;
queue->chunk_free = chunk->next;
@@ -141,7 +141,7 @@ void BLI_gsqueue_pop(GSQueue *queue, void *r_item)
queue->elem_num--;
if (UNLIKELY(queue->chunk_first_index == queue->chunk_elem_max || queue->elem_num == 0)) {
struct QueueChunk *chunk_free = queue->chunk_first;
QueueChunk *chunk_free = queue->chunk_first;
queue->chunk_first = queue->chunk_first->next;
queue->chunk_first_index = 0;

View File

@@ -45,7 +45,7 @@
#endif
#if UINT_MAX == UINT_MAX_32_BITS
using md5_uint32 = unsigned int;
using md5_uint32 = uint;
#else
# if USHRT_MAX == UINT_MAX_32_BITS
using md5_uint32 = unsigned short;

View File

@@ -71,7 +71,7 @@ void BLI_jitterate1(float (*jit1)[2], float (*jit2)[2], int num, float radius1)
jit2[i][0] = x;
jit2[i][1] = y;
}
memcpy(jit1, jit2, 2 * (uint)num * sizeof(float));
memcpy(jit1, jit2, 2 * uint(num) * sizeof(float));
}
void BLI_jitterate2(float (*jit1)[2], float (*jit2)[2], int num, float radius2)
@@ -121,7 +121,7 @@ void BLI_jitterate2(float (*jit1)[2], float (*jit2)[2], int num, float radius2)
jit2[i][0] = x;
jit2[i][1] = y;
}
memcpy(jit1, jit2, (uint)num * sizeof(float[2]));
memcpy(jit1, jit2, uint(num) * sizeof(float[2]));
}
void BLI_jitter_init(float (*jitarr)[2], int num)
@@ -136,20 +136,20 @@ void BLI_jitter_init(float (*jitarr)[2], int num)
return;
}
number_fl = (float)num;
number_fl = float(num);
number_fl_sqrt = sqrtf(number_fl);
jit2 = static_cast<float(*)[2]>(MEM_mallocN(12 + (uint)num * sizeof(float[2]), "initjit"));
jit2 = static_cast<float(*)[2]>(MEM_mallocN(12 + uint(num) * sizeof(float[2]), "initjit"));
rad1 = 1.0f / number_fl_sqrt;
rad2 = 1.0f / number_fl;
rad3 = number_fl_sqrt / number_fl;
rng = BLI_rng_new(31415926 + (uint)num);
rng = BLI_rng_new(31415926 + uint(num));
x = 0;
for (i = 0; i < num; i++) {
jitarr[i][0] = x + rad1 * (float)(0.5 - BLI_rng_get_double(rng));
jitarr[i][1] = (float)i / number_fl + rad1 * (float)(0.5 - BLI_rng_get_double(rng));
jitarr[i][0] = x + rad1 * float(0.5 - BLI_rng_get_double(rng));
jitarr[i][1] = float(i) / number_fl + rad1 * float(0.5 - BLI_rng_get_double(rng));
x += rad3;
x -= floorf(x);
}

View File

@@ -887,7 +887,7 @@ uint BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const float n
/* STEP 1: COUNT POLYS */
if (sf_ctx->poly_nr != SF_POLY_UNSET) {
poly = (ushort)(sf_ctx->poly_nr + 1);
poly = ushort(sf_ctx->poly_nr + 1);
sf_ctx->poly_nr = SF_POLY_UNSET;
}
@@ -1025,7 +1025,7 @@ uint BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const float n
*/
/* STEP 3: MAKE POLYFILL STRUCT */
pflist = static_cast<PolyFill *>(MEM_mallocN(sizeof(*pflist) * (size_t)poly, "edgefill"));
pflist = static_cast<PolyFill *>(MEM_mallocN(sizeof(*pflist) * size_t(poly), "edgefill"));
pf = pflist;
for (a = 0; a < poly; a++) {
pf->edges = pf->verts = 0;

View File

@@ -27,7 +27,7 @@ struct PolyInfo {
};
struct ScanFillIsect {
struct ScanFillIsect *next, *prev;
ScanFillIsect *next, *prev;
float co[3];
/* newly created vertex */
@@ -41,7 +41,7 @@ struct ScanFillIsect {
#define EFLAG_SET(eed, val) \
{ \
CHECK_TYPE(eed, ScanFillEdge *); \
(eed)->user_flag = (eed)->user_flag | (uint)val; \
(eed)->user_flag = (eed)->user_flag | uint(val); \
} \
(void)0
#if 0
@@ -56,7 +56,7 @@ struct ScanFillIsect {
#define VFLAG_SET(eve, val) \
{ \
CHECK_TYPE(eve, ScanFillVert *); \
(eve)->user_flag = (eve)->user_flag | (uint)val; \
(eve)->user_flag = (eve)->user_flag | uint(val); \
} \
(void)0
#if 0
@@ -360,7 +360,7 @@ bool BLI_scanfill_calc_self_isect(ScanFillContext *sf_ctx,
ListBase *remvertbase,
ListBase *remedgebase)
{
const uint poly_num = (uint)sf_ctx->poly_nr + 1;
const uint poly_num = uint(sf_ctx->poly_nr) + 1;
bool changed = false;
if (UNLIKELY(sf_ctx->poly_nr == SF_POLY_UNSET)) {

View File

@@ -19,7 +19,7 @@ static const SessionUID global_session_uid_none = {BLI_session_uid_NONE};
* It might eventually overflow, and easiest is to add more bits to it. */
static SessionUID global_session_uid = {BLI_session_uid_NONE};
SessionUID BLI_session_uid_generate(void)
SessionUID BLI_session_uid_generate()
{
SessionUID result;
result.uid_ = atomic_add_and_fetch_uint64(&global_session_uid.uid_, 1);

View File

@@ -18,7 +18,7 @@
#define USE_TOTELEM
#define CHUNK_EMPTY ((size_t)-1)
#define CHUNK_EMPTY size_t(-1)
/* target chunks size: 64kb */
#define CHUNK_SIZE_DEFAULT (1 << 16)
/* ensure we get at least this many elems per chunk */

View File

@@ -164,9 +164,9 @@ size_t BLI_vsnprintf(char *__restrict dst,
BLI_assert(dst_maxncpy > 0);
BLI_assert(format != nullptr);
n = (size_t)vsnprintf(dst, dst_maxncpy, format, arg);
n = size_t(vsnprintf(dst, dst_maxncpy, format, arg));
if (n != (size_t)-1 && n < dst_maxncpy) {
if (n != size_t(-1) && n < dst_maxncpy) {
dst[n] = '\0';
}
else {
@@ -189,9 +189,9 @@ size_t BLI_vsnprintf_rlen(char *__restrict dst,
BLI_assert(dst_maxncpy > 0);
BLI_assert(format != nullptr);
n = (size_t)vsnprintf(dst, dst_maxncpy, format, arg);
n = size_t(vsnprintf(dst, dst_maxncpy, format, arg));
if (n != (size_t)-1 && n < dst_maxncpy) {
if (n != size_t(-1) && n < dst_maxncpy) {
/* pass */
}
else {
@@ -249,13 +249,13 @@ char *BLI_sprintfN_with_buffer(
*fixed_buf = '\0';
return fixed_buf;
}
*result_len = (size_t)retval;
if ((size_t)retval < fixed_buf_size) {
*result_len = size_t(retval);
if (size_t(retval) < fixed_buf_size) {
return fixed_buf;
}
/* `retval` doesn't include null terminator. */
const size_t size = (size_t)retval + 1;
const size_t size = size_t(retval) + 1;
char *result = static_cast<char *>(MEM_mallocN(sizeof(char) * size, __func__));
va_start(args, format);
retval = vsnprintf(result, size, format, args);
@@ -284,13 +284,13 @@ char *BLI_vsprintfN_with_buffer(char *fixed_buf,
*fixed_buf = '\0';
return fixed_buf;
}
*result_len = (size_t)retval;
if ((size_t)retval < fixed_buf_size) {
*result_len = size_t(retval);
if (size_t(retval) < fixed_buf_size) {
return fixed_buf;
}
/* `retval` doesn't include null terminator. */
const size_t size = (size_t)retval + 1;
const size_t size = size_t(retval) + 1;
char *result = static_cast<char *>(MEM_mallocN(sizeof(char) * size, __func__));
retval = vsnprintf(result, size, format, args);
BLI_assert((size_t)(retval + 1) == size);
@@ -480,8 +480,8 @@ bool BLI_str_quoted_substr_range(const char *__restrict str,
return false;
}
*r_start = (int)(str_start - str);
*r_end = (int)(str_end - str);
*r_start = int(str_start - str);
*r_end = int(str_end - str);
return true;
}
@@ -526,7 +526,7 @@ bool BLI_str_quoted_substr(const char *__restrict str,
if (!BLI_str_quoted_substr_range(str, prefix, &start_match_ofs, &end_match_ofs)) {
return false;
}
const size_t escaped_len = (size_t)(end_match_ofs - start_match_ofs);
const size_t escaped_len = size_t(end_match_ofs - start_match_ofs);
bool is_complete;
BLI_str_unescape_ex(result, str + start_match_ofs, escaped_len, result_maxncpy, &is_complete);
if (is_complete == false) {
@@ -552,14 +552,14 @@ char *BLI_strcasestr(const char *s, const char *find)
size_t len;
if ((c = *find++) != 0) {
c = (char)tolower(c);
c = char(tolower(c));
len = strlen(find);
do {
do {
if ((sc = *s++) == 0) {
return nullptr;
}
sc = (char)tolower(sc);
sc = char(tolower(sc));
} while (sc != c);
} while (BLI_strncasecmp(s, find, len) != 0);
s--;
@@ -591,7 +591,7 @@ bool BLI_string_all_words_matched(const char *name,
{
int index;
for (index = 0; index < words_len; index++) {
if (!BLI_string_has_word_prefix(name, str + words[index][0], (size_t)words[index][1])) {
if (!BLI_string_has_word_prefix(name, str + words[index][0], size_t(words[index][1]))) {
break;
}
}
@@ -605,14 +605,14 @@ char *BLI_strncasestr(const char *s, const char *find, size_t len)
char c, sc;
if ((c = *find++) != 0) {
c = (char)tolower(c);
c = char(tolower(c));
if (len > 1) {
do {
do {
if ((sc = *s++) == 0) {
return nullptr;
}
sc = (char)tolower(sc);
sc = char(tolower(sc));
} while (sc != c);
} while (BLI_strncasecmp(s, find, len - 1) != 0);
}
@@ -622,7 +622,7 @@ char *BLI_strncasestr(const char *s, const char *find, size_t len)
if ((sc = *s++) == 0) {
return nullptr;
}
sc = (char)tolower(sc);
sc = char(tolower(sc));
} while (sc != c);
}
}
@@ -637,8 +637,8 @@ int BLI_strcasecmp(const char *s1, const char *s2)
char c1, c2;
for (i = 0;; i++) {
c1 = (char)tolower(s1[i]);
c2 = (char)tolower(s2[i]);
c1 = char(tolower(s1[i]));
c2 = char(tolower(s2[i]));
if (c1 < c2) {
return -1;
@@ -660,8 +660,8 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len)
char c1, c2;
for (i = 0; i < len; i++) {
c1 = (char)tolower(s1[i]);
c2 = (char)tolower(s2[i]);
c1 = char(tolower(s1[i]));
c2 = char(tolower(s2[i]));
if (c1 < c2) {
return -1;
@@ -707,7 +707,7 @@ static int left_number_strcmp(const char *s1, const char *s2, int *tiebreaker)
/* same number of digits, compare size of number */
if (numdigit > 0) {
int compare = strncmp(p1, p2, (size_t)numdigit);
int compare = strncmp(p1, p2, size_t(numdigit));
if (compare != 0) {
return compare;
@@ -761,8 +761,8 @@ int BLI_strcasecmp_natural(const char *s1, const char *s2)
break;
}
c1 = (char)tolower(s1[d1]);
c2 = (char)tolower(s2[d2]);
c1 = char(tolower(s1[d1]));
c2 = char(tolower(s2[d2]));
if (c1 == c2) {
/* Continue iteration */
@@ -976,7 +976,7 @@ void BLI_str_toupper_ascii(char *str, const size_t len)
void BLI_str_rstrip(char *str)
{
for (int i = (int)strlen(str) - 1; i >= 0; i--) {
for (int i = int(strlen(str)) - 1; i >= 0; i--) {
if (isspace(str[i])) {
str[i] = '\0';
}
@@ -1009,7 +1009,7 @@ int BLI_str_rstrip_float_zero(char *str, const char pad)
int BLI_str_rstrip_digits(char *str)
{
int totstrip = 0;
int str_len = (int)strlen(str);
int str_len = int(strlen(str));
while (str_len > 0 && isdigit(str[--str_len])) {
str[str_len] = '\0';
totstrip++;
@@ -1076,10 +1076,10 @@ size_t BLI_str_partition_ex(const char *str,
if (*sep) {
*suf = *sep + 1;
return (size_t)(*sep - str);
return size_t(*sep - str);
}
return end ? (size_t)(end - str) : strlen(str);
return end ? size_t(end - str) : strlen(str);
}
int BLI_string_find_split_words(
@@ -1089,13 +1089,13 @@ int BLI_string_find_split_words(
bool charsearch = true;
/* Skip leading spaces */
for (i = 0; (i < (int)str_maxlen) && (str[i] != '\0'); i++) {
for (i = 0; (i < int(str_maxlen)) && (str[i] != '\0'); i++) {
if (str[i] != delim) {
break;
}
}
for (; (i < (int)str_maxlen) && (str[i] != '\0') && (n < words_max); i++) {
for (; (i < int(str_maxlen)) && (str[i] != '\0') && (n < words_max); i++) {
if ((str[i] != delim) && (charsearch == true)) {
r_words[n][0] = i;
charsearch = false;
@@ -1124,7 +1124,7 @@ bool BLI_string_elem_split_by_delim(const char *haystack, const char delim, cons
const char *p = haystack;
while (true) {
const char *p_next = BLI_strchr_or_end(p, delim);
if (((size_t)(p_next - p) == needle_len) && (memcmp(p, needle, needle_len) == 0)) {
if ((size_t(p_next - p) == needle_len) && (memcmp(p, needle, needle_len) == 0)) {
return true;
}
if (*p_next == '\0') {
@@ -1162,7 +1162,7 @@ static size_t BLI_str_format_int_grouped_ex(char *src, char *dst, int num_len)
}
*--p_dst = '\0';
return (size_t)(p_dst - dst);
return size_t(p_dst - dst);
}
size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], int num)
@@ -1172,7 +1172,7 @@ size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], i
UNUSED_VARS_NDEBUG(dst_maxncpy);
char src[BLI_STR_FORMAT_INT32_GROUPED_SIZE];
const int num_len = (int)SNPRINTF(src, "%d", num);
const int num_len = int(SNPRINTF(src, "%d", num));
return BLI_str_format_int_grouped_ex(src, dst, num_len);
}
@@ -1184,7 +1184,7 @@ size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE
UNUSED_VARS_NDEBUG(dst_maxncpy);
char src[BLI_STR_FORMAT_UINT64_GROUPED_SIZE];
const int num_len = (int)SNPRINTF(src, "%" PRIu64 "", num);
const int num_len = int(SNPRINTF(src, "%" PRIu64 "", num));
return BLI_str_format_int_grouped_ex(src, dst, num_len);
}
@@ -1196,7 +1196,7 @@ void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE],
const size_t dst_maxncpy = BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE;
BLI_string_debug_size(dst, dst_maxncpy);
double bytes_converted = (double)bytes;
double bytes_converted = double(bytes);
int order = 0;
int decimals;
const int base = base_10 ? 1000 : 1024;
@@ -1214,7 +1214,7 @@ void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE],
/* Format value first, stripping away floating zeroes. */
size_t len = BLI_snprintf_rlen(dst, dst_maxncpy, "%.*f", decimals, bytes_converted);
len -= (size_t)BLI_str_rstrip_float_zero(dst, '\0');
len -= size_t(BLI_str_rstrip_float_zero(dst, '\0'));
dst[len++] = ' ';
BLI_strncpy(dst + len, base_10 ? units_base_10[order] : units_base_2[order], dst_maxncpy - len);
}
@@ -1226,7 +1226,7 @@ void BLI_str_format_byte_unit_compact(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_CO
const size_t dst_maxncpy = BLI_STR_FORMAT_INT64_BYTE_UNIT_COMPACT_SIZE;
BLI_string_debug_size(dst, dst_maxncpy);
float number_to_format_converted = (float)bytes;
float number_to_format_converted = float(bytes);
int order = 0;
const float base = base_10 ? 1000.0f : 1024.0f;
const char *units[] = {"B", "K", "M", "G", "T", "P"};
@@ -1248,7 +1248,7 @@ void BLI_str_format_byte_unit_compact(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_CO
dst_maxncpy,
"%s%d%s",
add_dot ? "." : "",
(int)floorf(fabsf(number_to_format_converted)),
int(floorf(fabsf(number_to_format_converted))),
units[order]);
}
@@ -1257,7 +1257,7 @@ void BLI_str_format_decimal_unit(char dst[BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE
{
BLI_string_debug_size(dst, BLI_STR_FORMAT_INT32_DECIMAL_UNIT_SIZE);
float number_to_format_converted = (float)number_to_format;
float number_to_format_converted = float(number_to_format);
int order = 0;
const float base = 1000.0f;
const char *units[] = {"", "K", "M", "B"};
@@ -1282,7 +1282,7 @@ void BLI_str_format_integer_unit(char dst[BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE
const size_t dst_maxncpy = BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE;
BLI_string_debug_size(dst, dst_maxncpy);
float number_to_format_converted = (float)number_to_format;
float number_to_format_converted = float(number_to_format);
int order = 0;
const float base = 1000;
const char *units[] = {"", "K", "M", "B"};
@@ -1305,7 +1305,7 @@ void BLI_str_format_integer_unit(char dst[BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE
"%s%s%d%s",
number_to_format < 0 ? "-" : "",
add_dot ? "." : "",
(int)floorf(fabsf(number_to_format_converted)),
int(floorf(fabsf(number_to_format_converted))),
units[order]);
}

View File

@@ -130,8 +130,8 @@ static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8,
BLI_assert(ch_utf8_len >= 0);
/* for full unicode support we really need to have large lookup tables to figure
* out what's what in every possible char set - and python, glib both have these. */
size_t index = (size_t)pos;
uint uch = BLI_str_utf8_as_unicode_step_or_error(ch_utf8, (size_t)ch_utf8_len, &index);
size_t index = size_t(pos);
uint uch = BLI_str_utf8_as_unicode_step_or_error(ch_utf8, size_t(ch_utf8_len), &index);
return cursor_delim_type_unicode(uch);
}
@@ -151,7 +151,7 @@ bool BLI_str_cursor_step_next_utf8(const char *str, const int str_maxlen, int *p
str_next = BLI_str_find_next_char_utf8(str_next, str_end);
} while ((str_next < str_end) && (str_next[0] != 0) &&
(BLI_str_utf8_char_width_or_error(str_next) == 0));
*pos += (int)(str_next - str_pos);
*pos += int(str_next - str_pos);
*pos = std::min(*pos, str_maxlen);
return true;
@@ -169,7 +169,7 @@ bool BLI_str_cursor_step_prev_utf8(const char *str, const int str_maxlen, int *p
do {
str_prev = BLI_str_find_prev_char_utf8(str_prev, str);
} while ((str_prev > str) && (BLI_str_utf8_char_width_or_error(str_prev) == 0));
*pos -= (int)(str_pos - str_prev);
*pos -= int(str_pos - str_prev);
return true;
}
@@ -310,7 +310,7 @@ void BLI_str_cursor_step_utf32(const char32_t *str,
if (jump != STRCUR_JUMP_NONE) {
const eStrCursorDelimType delim_type = (*pos < str_maxlen) ?
cursor_delim_type_unicode((uint)str[*pos]) :
cursor_delim_type_unicode(uint(str[*pos])) :
STRCUR_DELIM_NONE;
/* jump between special characters (/,\,_,-, etc.),
* look at function cursor_delim_type_unicode() for complete
@@ -318,7 +318,7 @@ void BLI_str_cursor_step_utf32(const char32_t *str,
while (*pos < str_maxlen) {
if (BLI_str_cursor_step_next_utf32(str, str_maxlen, pos)) {
if ((jump != STRCUR_JUMP_ALL) &&
(delim_type != cursor_delim_type_unicode((uint)str[*pos])))
(delim_type != cursor_delim_type_unicode(uint(str[*pos]))))
{
break;
}
@@ -339,7 +339,7 @@ void BLI_str_cursor_step_utf32(const char32_t *str,
if (jump != STRCUR_JUMP_NONE) {
const eStrCursorDelimType delim_type = (*pos > 0) ?
cursor_delim_type_unicode((uint)str[(*pos) - 1]) :
cursor_delim_type_unicode(uint(str[(*pos) - 1])) :
STRCUR_DELIM_NONE;
/* jump between special characters (/,\,_,-, etc.),
* look at function cursor_delim_type() for complete
@@ -348,7 +348,7 @@ void BLI_str_cursor_step_utf32(const char32_t *str,
const int pos_prev = *pos;
if (BLI_str_cursor_step_prev_utf32(str, str_maxlen, pos)) {
if ((jump != STRCUR_JUMP_ALL) &&
(delim_type != cursor_delim_type_unicode((uint)str[*pos])))
(delim_type != cursor_delim_type_unicode(uint(str[*pos]))))
{
/* left only: compensate for index/change in direction */
if ((pos_orig - *pos) >= 1) {

View File

@@ -26,7 +26,7 @@
# include <unistd.h>
#endif
int BLI_cpu_support_sse2(void)
int BLI_cpu_support_sse2()
{
#if defined(__x86_64__) || defined(_M_X64)
/* x86_64 always has SSE2 instructions */
@@ -130,13 +130,13 @@ static void __cpuid(
}
#endif
char *BLI_cpu_brand_string(void)
char *BLI_cpu_brand_string()
{
#if !defined(_M_ARM64)
char buf[49] = {0};
int result[4] = {0};
__cpuid(result, 0x80000000);
if (result[0] >= (int)0x80000004) {
if (result[0] >= int(0x80000004)) {
__cpuid((int *)(buf + 0), 0x80000002);
__cpuid((int *)(buf + 16), 0x80000003);
__cpuid((int *)(buf + 32), 0x80000004);
@@ -162,7 +162,7 @@ char *BLI_cpu_brand_string(void)
return nullptr;
}
int BLI_cpu_support_sse42(void)
int BLI_cpu_support_sse42()
{
#if !defined(_M_ARM64)
int result[4], num;
@@ -171,7 +171,7 @@ int BLI_cpu_support_sse42(void)
if (num >= 1) {
__cpuid(result, 0x00000001);
return (result[2] & ((int)1 << 20)) != 0;
return (result[2] & (int(1) << 20)) != 0;
}
#endif
return 0;
@@ -193,19 +193,19 @@ void BLI_hostname_get(char *buffer, size_t bufsize)
#endif
}
size_t BLI_system_memory_max_in_megabytes(void)
size_t BLI_system_memory_max_in_megabytes()
{
/* Maximum addressable bytes on this platform.
*
* NOTE: Due to the shift arithmetic this is a half of the memory. */
const size_t limit_bytes_half = (((size_t)1) << (sizeof(size_t[8]) - 1));
const size_t limit_bytes_half = size_t(1) << (sizeof(size_t[8]) - 1);
/* Convert it to megabytes and return. */
return (limit_bytes_half >> 20) * 2;
}
int BLI_system_memory_max_in_megabytes_int(void)
int BLI_system_memory_max_in_megabytes_int()
{
const size_t limit_megabytes = BLI_system_memory_max_in_megabytes();
/* NOTE: The result will fit into integer. */
return (int)min_zz(limit_megabytes, (size_t)INT_MAX);
return int(min_zz(limit_megabytes, size_t(INT_MAX)));
}

View File

@@ -111,7 +111,7 @@ void BLI_task_parallel_mempool(BLI_mempool *mempool,
}
ParallelMempoolTaskData *mempool_iterator_data = mempool_iter_threadsafe_create(
mempool, (size_t)tasks_num);
mempool, size_t(tasks_num));
for (int i = 0; i < tasks_num; i++) {
void *userdata_chunk_local = nullptr;

View File

@@ -62,20 +62,20 @@ void BLI_time_sleep_ms(int ms)
# include <sys/time.h>
# include <unistd.h>
double BLI_time_now_seconds(void)
double BLI_time_now_seconds()
{
struct timeval tv;
struct timezone tz;
timeval tv;
timezone tz;
gettimeofday(&tv, &tz);
return ((double)tv.tv_sec + tv.tv_usec / 1000000.0);
return (double(tv.tv_sec) + tv.tv_usec / 1000000.0);
}
long int BLI_time_now_seconds_i(void)
long int BLI_time_now_seconds_i()
{
struct timeval tv;
struct timezone tz;
timeval tv;
timezone tz;
gettimeofday(&tv, &tz);

View File

@@ -44,13 +44,13 @@ size_t BLI_timecode_string_from_time(char *str,
* VERY UNLIKELY to be more than 1-2 hours max? However, that would
* go against conventions...
*/
hours = (int)time / 3600;
hours = int(time) / 3600;
time = fmodf(time, 3600);
}
if (time >= 60.0f) {
/* minutes */
minutes = (int)time / 60;
minutes = int(time) / 60;
time = fmodf(time, 60);
}
@@ -59,8 +59,8 @@ size_t BLI_timecode_string_from_time(char *str,
* Frames are derived from 'fraction' of second. We need to perform some additional rounding
* to cope with 'half' frames, etc., which should be fine in most cases
*/
seconds = (int)time;
frames = round_fl_to_int((float)(((double)time - (double)seconds) * fps));
seconds = int(time);
frames = round_fl_to_int(float((double(time) - double(seconds)) * fps));
}
else {
/* seconds (with pixel offset rounding) */
@@ -138,7 +138,7 @@ size_t BLI_timecode_string_from_time(char *str,
/* precision of decimal part */
const int ms_dp = (brevity_level <= 0) ? (1 - brevity_level) : 1;
const int ms = round_fl_to_int((time - (float)seconds) * 1000.0f);
const int ms = round_fl_to_int((time - float(seconds)) * 1000.0f);
rlen = BLI_snprintf_rlen(
str, maxncpy, "%s%02d:%02d:%02d,%0*d", neg, hours, minutes, seconds, ms_dp, ms);
@@ -174,10 +174,10 @@ size_t BLI_timecode_string_from_time_simple(char *str,
size_t rlen;
/* format 00:00:00.00 (hr:min:sec) string has to be 12 long */
const int hr = ((int)time_seconds) / (60 * 60);
const int min = (((int)time_seconds) / 60) % 60;
const int sec = ((int)time_seconds) % 60;
const int hun = (int)(fmod(time_seconds, 1.0) * 100);
const int hr = int(time_seconds) / (60 * 60);
const int min = (int(time_seconds) / 60) % 60;
const int sec = int(time_seconds) % 60;
const int hun = int(fmod(time_seconds, 1.0) * 100);
if (hr) {
rlen = BLI_snprintf_rlen(str, maxncpy, "%.2d:%.2d:%.2d.%.2d", hr, min, sec, hun);

View File

@@ -24,8 +24,8 @@ BLI_INLINE float D(const float *data, const int res[3], int x, int y, int z)
/* returns highest integer <= x as integer (slightly faster than floor()) */
BLI_INLINE int FLOORI(float x)
{
const int r = (int)x;
return ((x >= 0.0f) || (float)r == x) ? r : (r - 1);
const int r = int(x);
return ((x >= 0.0f) || float(r) == x) ? r : (r - 1);
}
/**
@@ -45,9 +45,9 @@ float BLI_voxel_sample_trilinear(const float *data, const int res[3], const floa
{
if (data) {
const float xf = co[0] * (float)res[0] - 0.5f;
const float yf = co[1] * (float)res[1] - 0.5f;
const float zf = co[2] * (float)res[2] - 0.5f;
const float xf = co[0] * float(res[0]) - 0.5f;
const float yf = co[1] * float(res[1]) - 0.5f;
const float zf = co[2] * float(res[2]) - 0.5f;
const int x = FLOORI(xf), y = FLOORI(yf), z = FLOORI(zf);
@@ -64,9 +64,9 @@ float BLI_voxel_sample_trilinear(const float *data, const int res[3], const floa
_clamp(z + 1, 0, res[2] - 1) * res[0] * res[1],
};
const float dx = xf - (float)x;
const float dy = yf - (float)y;
const float dz = zf - (float)z;
const float dx = xf - float(x);
const float dy = yf - float(y);
const float dz = zf - float(z);
const float u[2] = {1.0f - dx, dx};
const float v[2] = {1.0f - dy, dy};

View File

@@ -401,7 +401,7 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene)
}
if (ts->sculpt) {
ts->sculpt->flags = (DNA_struct_default_get(Sculpt))->flags;
ts->sculpt->flags = DNA_struct_default_get(Sculpt)->flags;
}
/* Correct default startup UVs. */

View File

@@ -105,11 +105,11 @@ void RenderBuffers::acquire(int2 extent)
else if (cryptomatte_layer_len == 3) {
cryptomatte_format = GPU_RGBA32F;
}
cryptomatte_tx.acquire(
pass_extent((EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT | EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET |
EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL)),
cryptomatte_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_SHADER_WRITE);
cryptomatte_tx.acquire(pass_extent(EEVEE_RENDER_PASS_CRYPTOMATTE_OBJECT |
EEVEE_RENDER_PASS_CRYPTOMATTE_ASSET |
EEVEE_RENDER_PASS_CRYPTOMATTE_MATERIAL),
cryptomatte_format,
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_SHADER_WRITE);
}
void RenderBuffers::release()

View File

@@ -499,7 +499,7 @@ bool eyedropper_color_sample_fl(bContext *C,
}
/* Outside the Blender window if we support it. */
if ((WM_capabilities_flag() & WM_CAPABILITY_DESKTOP_SAMPLE)) {
if (WM_capabilities_flag() & WM_CAPABILITY_DESKTOP_SAMPLE) {
if (WM_desktop_cursor_sample_read(r_col)) {
IMB_colormanagement_srgb_to_scene_linear_v3(r_col, r_col);
return true;

View File

@@ -1324,7 +1324,7 @@ bool ED_mesh_pick_edge(bContext *C, Object *ob, const int mval[2], uint dist_px,
edge_idx_best--;
if ((edge_idx_best != ORIGINDEX_NONE)) {
if (edge_idx_best != ORIGINDEX_NONE) {
*r_index = edge_idx_best;
return true;
}

View File

@@ -1826,7 +1826,7 @@ static int shade_auto_smooth_exec(bContext *C, wmOperator *op)
break;
}
/* Remove the weak library reference, since the already loaded group is not valid anymore. */
MEM_SAFE_FREE((node_group_id->library_weak_reference));
MEM_SAFE_FREE(node_group_id->library_weak_reference);
/* Stay in the loop and load the asset again. */
node_group = nullptr;
}

View File

@@ -141,7 +141,7 @@ static void scale_factors_by_height_and_depth(const float height,
const MutableSpan<float3> local_positions,
const MutableSpan<float> factors)
{
if (height != 1.0f && height != 0.0f) {
if (!ELEM(height, 1.0f, 0.0f)) {
for (const int i : factors.index_range()) {
if (local_positions[i].z > 0.0f) {
factors[i] *= height;

View File

@@ -420,7 +420,7 @@ static int transform_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* XXX insert keys are called here, and require context. */
t->context = C;
if ((t->helpline != HLP_ERROR)) {
if (t->helpline != HLP_ERROR) {
ED_workspace_status_text(t->context, nullptr);
}

View File

@@ -79,7 +79,7 @@ static void unique_name(bNode *node)
else {
suffix = 0;
new_len = len + 4;
new_len = std::min<unsigned long>(new_len, sizeof(tno->name) - 1);
new_len = std::min<ulong>(new_len, sizeof(tno->name) - 1);
}
STRNCPY(new_name, name);

View File

@@ -1325,7 +1325,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
ret = -1;
}
else {
tmp_val_len = std::min<unsigned long>(tmp_val_len, sizeof(mstring->s));
tmp_val_len = std::min<ulong>(tmp_val_len, sizeof(mstring->s));
memcpy(mstring->s, tmp_val, tmp_val_len);
mstring->s_len = tmp_val_len;
}

View File

@@ -590,12 +590,8 @@ static void sequencer_preprocess_transform_crop(
break;
}
IMB_transform(in,
out,
IMB_TRANSFORM_MODE_CROP_SRC,
filter,
(float(*)[4])(matrix.base_ptr()),
&source_crop);
IMB_transform(
in, out, IMB_TRANSFORM_MODE_CROP_SRC, filter, (float(*)[4])matrix.base_ptr(), &source_crop);
if (is_strip_covering_screen(context, strip)) {
out->planes = in->planes;

View File

@@ -624,7 +624,7 @@ void WM_window_decoration_style_flags_set(const wmWindow *win,
eWM_WindowDecorationStyleFlag style_flags)
{
BLI_assert(WM_capabilities_flag() & WM_CAPABILITY_WINDOW_DECORATION_STYLES);
unsigned int ghost_style_flags = GHOST_kDecorationNone;
uint ghost_style_flags = GHOST_kDecorationNone;
if (style_flags & WM_WINDOW_DECORATION_STYLE_COLORED_TITLEBAR) {
ghost_style_flags |= GHOST_kDecorationColoredTitleBar;