mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-26 13:47:12 +01:00
Added HAS_TRIVIAL_CONSTRUCTOR, HAS_TRIVIAL_DESTRUCTOR, and HAS_TRIVIAL_COPY macros to typedefs to fix new clang deprecations.
This commit is contained in:
parent
dd5e6b19df
commit
326bd9a1e9
@ -209,7 +209,7 @@ void CowData<T>::_unref(void *p_data) {
|
|||||||
}
|
}
|
||||||
// clean up
|
// clean up
|
||||||
|
|
||||||
if (!__has_trivial_destructor(T)) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
uint32_t *count = _get_size();
|
uint32_t *count = _get_size();
|
||||||
T *data = (T *)(count + 1);
|
T *data = (T *)(count + 1);
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ uint32_t CowData<T>::_copy_on_write() {
|
|||||||
T *_data = (T *)(mem_new);
|
T *_data = (T *)(mem_new);
|
||||||
|
|
||||||
// initialize new elements
|
// initialize new elements
|
||||||
if (__has_trivial_copy(T)) {
|
if (HAS_TRIVIAL_COPY(T)) {
|
||||||
memcpy(mem_new, _ptr, current_size * sizeof(T));
|
memcpy(mem_new, _ptr, current_size * sizeof(T));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -307,7 +307,7 @@ Error CowData<T>::resize(int p_size) {
|
|||||||
|
|
||||||
// construct the newly created elements
|
// construct the newly created elements
|
||||||
|
|
||||||
if (!__has_trivial_constructor(T)) {
|
if (!HAS_TRIVIAL_CONSTRUCTOR(T)) {
|
||||||
for (int i = *_get_size(); i < p_size; i++) {
|
for (int i = *_get_size(); i < p_size; i++) {
|
||||||
memnew_placement(&_ptr[i], T);
|
memnew_placement(&_ptr[i], T);
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ Error CowData<T>::resize(int p_size) {
|
|||||||
*_get_size() = p_size;
|
*_get_size() = p_size;
|
||||||
|
|
||||||
} else if (p_size < current_size) {
|
} else if (p_size < current_size) {
|
||||||
if (!__has_trivial_destructor(T)) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
// deinitialize no longer needed elements
|
// deinitialize no longer needed elements
|
||||||
for (uint32_t i = p_size; i < *_get_size(); i++) {
|
for (uint32_t i = p_size; i < *_get_size(); i++) {
|
||||||
T *t = &_ptr[i];
|
T *t = &_ptr[i];
|
||||||
|
@ -63,7 +63,7 @@ public:
|
|||||||
CRASH_COND_MSG(!data, "Out of memory");
|
CRASH_COND_MSG(!data, "Out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__has_trivial_constructor(T) && !force_trivial) {
|
if (!HAS_TRIVIAL_CONSTRUCTOR(T) && !force_trivial) {
|
||||||
memnew_placement(&data[count++], T(p_elem));
|
memnew_placement(&data[count++], T(p_elem));
|
||||||
} else {
|
} else {
|
||||||
data[count++] = p_elem;
|
data[count++] = p_elem;
|
||||||
@ -76,7 +76,7 @@ public:
|
|||||||
for (U i = p_index; i < count; i++) {
|
for (U i = p_index; i < count; i++) {
|
||||||
data[i] = data[i + 1];
|
data[i] = data[i + 1];
|
||||||
}
|
}
|
||||||
if (!__has_trivial_destructor(T) && !force_trivial) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T) && !force_trivial) {
|
||||||
data[count].~T();
|
data[count].~T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ public:
|
|||||||
if (count > p_index) {
|
if (count > p_index) {
|
||||||
data[p_index] = data[count];
|
data[p_index] = data[count];
|
||||||
}
|
}
|
||||||
if (!__has_trivial_destructor(T) && !force_trivial) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T) && !force_trivial) {
|
||||||
data[count].~T();
|
data[count].~T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ public:
|
|||||||
_FORCE_INLINE_ U size() const { return count; }
|
_FORCE_INLINE_ U size() const { return count; }
|
||||||
void resize(U p_size) {
|
void resize(U p_size) {
|
||||||
if (p_size < count) {
|
if (p_size < count) {
|
||||||
if (!__has_trivial_destructor(T) && !force_trivial) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T) && !force_trivial) {
|
||||||
for (U i = p_size; i < count; i++) {
|
for (U i = p_size; i < count; i++) {
|
||||||
data[i].~T();
|
data[i].~T();
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ public:
|
|||||||
data = (T *)memrealloc(data, capacity * sizeof(T));
|
data = (T *)memrealloc(data, capacity * sizeof(T));
|
||||||
CRASH_COND_MSG(!data, "Out of memory");
|
CRASH_COND_MSG(!data, "Out of memory");
|
||||||
}
|
}
|
||||||
if (!__has_trivial_constructor(T) && !force_trivial) {
|
if (!HAS_TRIVIAL_CONSTRUCTOR(T) && !force_trivial) {
|
||||||
for (U i = count; i < p_size; i++) {
|
for (U i = count; i < p_size; i++) {
|
||||||
memnew_placement(&data[i], T);
|
memnew_placement(&data[i], T);
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reset(bool p_allow_unfreed = false) {
|
void reset(bool p_allow_unfreed = false) {
|
||||||
if (!p_allow_unfreed || !__has_trivial_destructor(T)) {
|
if (!p_allow_unfreed || !HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
ERR_FAIL_COND(allocs_available < pages_allocated * page_size);
|
ERR_FAIL_COND(allocs_available < pages_allocated * page_size);
|
||||||
}
|
}
|
||||||
if (pages_allocated) {
|
if (pages_allocated) {
|
||||||
|
@ -197,7 +197,7 @@ public:
|
|||||||
uint32_t page = count >> page_size_shift;
|
uint32_t page = count >> page_size_shift;
|
||||||
uint32_t offset = count & page_size_mask;
|
uint32_t offset = count & page_size_mask;
|
||||||
|
|
||||||
if (!__has_trivial_constructor(T)) {
|
if (!HAS_TRIVIAL_CONSTRUCTOR(T)) {
|
||||||
memnew_placement(&page_data[page][offset], T(p_value));
|
memnew_placement(&page_data[page][offset], T(p_value));
|
||||||
} else {
|
} else {
|
||||||
page_data[page][offset] = p_value;
|
page_data[page][offset] = p_value;
|
||||||
@ -209,7 +209,7 @@ public:
|
|||||||
_FORCE_INLINE_ void pop_back() {
|
_FORCE_INLINE_ void pop_back() {
|
||||||
ERR_FAIL_COND(count == 0);
|
ERR_FAIL_COND(count == 0);
|
||||||
|
|
||||||
if (!__has_trivial_destructor(T)) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
uint32_t page = (count - 1) >> page_size_shift;
|
uint32_t page = (count - 1) >> page_size_shift;
|
||||||
uint32_t offset = (count - 1) & page_size_mask;
|
uint32_t offset = (count - 1) & page_size_mask;
|
||||||
page_data[page][offset].~T();
|
page_data[page][offset].~T();
|
||||||
@ -226,7 +226,7 @@ public:
|
|||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
//destruct if needed
|
//destruct if needed
|
||||||
if (!__has_trivial_destructor(T)) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
for (uint64_t i = 0; i < count; i++) {
|
for (uint64_t i = 0; i < count; i++) {
|
||||||
uint32_t page = i >> page_size_shift;
|
uint32_t page = i >> page_size_shift;
|
||||||
uint32_t offset = i & page_size_mask;
|
uint32_t offset = i & page_size_mask;
|
||||||
@ -309,13 +309,13 @@ public:
|
|||||||
uint32_t to_copy = MIN(page_size - new_remainder, remainder);
|
uint32_t to_copy = MIN(page_size - new_remainder, remainder);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < to_copy; i++) {
|
for (uint32_t i = 0; i < to_copy; i++) {
|
||||||
if (!__has_trivial_constructor(T)) {
|
if (!HAS_TRIVIAL_CONSTRUCTOR(T)) {
|
||||||
memnew_placement(&dst_page[i + new_remainder], T(remainder_page[i + remainder - to_copy]));
|
memnew_placement(&dst_page[i + new_remainder], T(remainder_page[i + remainder - to_copy]));
|
||||||
} else {
|
} else {
|
||||||
dst_page[i + new_remainder] = remainder_page[i + remainder - to_copy];
|
dst_page[i + new_remainder] = remainder_page[i + remainder - to_copy];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__has_trivial_destructor(T)) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
remainder_page[i + remainder - to_copy].~T();
|
remainder_page[i + remainder - to_copy].~T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
CRASH_COND_MSG(!data, "Out of memory");
|
CRASH_COND_MSG(!data, "Out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr (!__has_trivial_constructor(T) && !force_trivial) {
|
if constexpr (!HAS_TRIVIAL_CONSTRUCTOR(T) && !force_trivial) {
|
||||||
memnew_placement(&data[count++], T(p_elem));
|
memnew_placement(&data[count++], T(p_elem));
|
||||||
} else {
|
} else {
|
||||||
data[count++] = p_elem;
|
data[count++] = p_elem;
|
||||||
@ -78,7 +78,7 @@ public:
|
|||||||
for (U i = p_index; i < count; i++) {
|
for (U i = p_index; i < count; i++) {
|
||||||
data[i] = data[i + 1];
|
data[i] = data[i + 1];
|
||||||
}
|
}
|
||||||
if constexpr (!__has_trivial_destructor(T) && !force_trivial) {
|
if constexpr (!HAS_TRIVIAL_DESTRUCTOR(T) && !force_trivial) {
|
||||||
data[count].~T();
|
data[count].~T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ public:
|
|||||||
if (count > p_index) {
|
if (count > p_index) {
|
||||||
data[p_index] = data[count];
|
data[p_index] = data[count];
|
||||||
}
|
}
|
||||||
if constexpr (!__has_trivial_destructor(T) && !force_trivial) {
|
if constexpr (!HAS_TRIVIAL_DESTRUCTOR(T) && !force_trivial) {
|
||||||
data[count].~T();
|
data[count].~T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ public:
|
|||||||
_FORCE_INLINE_ U size() const { return count; }
|
_FORCE_INLINE_ U size() const { return count; }
|
||||||
void resize(U p_size) {
|
void resize(U p_size) {
|
||||||
if (p_size < count) {
|
if (p_size < count) {
|
||||||
if (!__has_trivial_destructor(T) && !force_trivial) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T) && !force_trivial) {
|
||||||
for (U i = p_size; i < count; i++) {
|
for (U i = p_size; i < count; i++) {
|
||||||
data[i].~T();
|
data[i].~T();
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ public:
|
|||||||
data = (T *)memrealloc(data, capacity * sizeof(T));
|
data = (T *)memrealloc(data, capacity * sizeof(T));
|
||||||
CRASH_COND_MSG(!data, "Out of memory");
|
CRASH_COND_MSG(!data, "Out of memory");
|
||||||
}
|
}
|
||||||
if (!__has_trivial_constructor(T) && !force_trivial) {
|
if (!HAS_TRIVIAL_CONSTRUCTOR(T) && !force_trivial) {
|
||||||
for (U i = count; i < p_size; i++) {
|
for (U i = count; i < p_size; i++) {
|
||||||
memnew_placement(&data[i], T);
|
memnew_placement(&data[i], T);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ void memdelete(T *p_class) {
|
|||||||
if (!predelete_handler(p_class)) {
|
if (!predelete_handler(p_class)) {
|
||||||
return; // doesn't want to be deleted
|
return; // doesn't want to be deleted
|
||||||
}
|
}
|
||||||
if (!__has_trivial_destructor(T)) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
p_class->~T();
|
p_class->~T();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ void memdelete_allocator(T *p_class) {
|
|||||||
if (!predelete_handler(p_class)) {
|
if (!predelete_handler(p_class)) {
|
||||||
return; // doesn't want to be deleted
|
return; // doesn't want to be deleted
|
||||||
}
|
}
|
||||||
if (!__has_trivial_destructor(T)) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
p_class->~T();
|
p_class->~T();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
|
|||||||
ERR_FAIL_COND_V(!mem, failptr);
|
ERR_FAIL_COND_V(!mem, failptr);
|
||||||
*(mem - 1) = p_elements;
|
*(mem - 1) = p_elements;
|
||||||
|
|
||||||
if (!__has_trivial_constructor(T)) {
|
if (!HAS_TRIVIAL_CONSTRUCTOR(T)) {
|
||||||
T *elems = (T *)mem;
|
T *elems = (T *)mem;
|
||||||
|
|
||||||
/* call operator new */
|
/* call operator new */
|
||||||
@ -177,7 +177,7 @@ template <typename T>
|
|||||||
void memdelete_arr(T *p_class) {
|
void memdelete_arr(T *p_class) {
|
||||||
uint64_t *ptr = (uint64_t *)p_class;
|
uint64_t *ptr = (uint64_t *)p_class;
|
||||||
|
|
||||||
if (!__has_trivial_destructor(T)) {
|
if (!HAS_TRIVIAL_DESTRUCTOR(T)) {
|
||||||
uint64_t elem_count = *(ptr - 1);
|
uint64_t elem_count = *(ptr - 1);
|
||||||
|
|
||||||
for (uint64_t i = 0; i < elem_count; i++) {
|
for (uint64_t i = 0; i < elem_count; i++) {
|
||||||
|
@ -393,4 +393,34 @@ struct _GlobalLock {
|
|||||||
// Limit the depth of recursive algorithms when dealing with Array/Dictionary
|
// Limit the depth of recursive algorithms when dealing with Array/Dictionary
|
||||||
#define MAX_RECURSION 100
|
#define MAX_RECURSION 100
|
||||||
|
|
||||||
|
//HAS_TRIVIAL_CONSTRUCTOR
|
||||||
|
|
||||||
|
#if defined(__llvm__) && _llvm_has_builtin(__is_trivially_constructible)
|
||||||
|
#define HAS_TRIVIAL_CONSTRUCTOR(T) __is_trivially_constructible(T)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAS_TRIVIAL_CONSTRUCTOR
|
||||||
|
#define HAS_TRIVIAL_CONSTRUCTOR(T) __has_trivial_constructor(T)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//HAS_TRIVIAL_DESTRUCTOR
|
||||||
|
|
||||||
|
#if defined(__llvm__) && _llvm_has_builtin(__is_trivially_destructible)
|
||||||
|
#define HAS_TRIVIAL_DESTRUCTOR(T) __is_trivially_destructible(T)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAS_TRIVIAL_DESTRUCTOR
|
||||||
|
#define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//HAS_TRIVIAL_COPY
|
||||||
|
|
||||||
|
#if defined(__llvm__) && _llvm_has_builtin(__is_trivially_copyable)
|
||||||
|
#define HAS_TRIVIAL_COPY(T) __is_trivially_copyable(T)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAS_TRIVIAL_COPY
|
||||||
|
#define HAS_TRIVIAL_COPY(T) __has_trivial_copy(T)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // TYPEDEFS_H
|
#endif // TYPEDEFS_H
|
||||||
|
Loading…
Reference in New Issue
Block a user