Skip to content

Commit 1e57676

Browse files
Replace ERR_FAIL_COND with ERR_FAIL_NULL where applicable
1 parent 6caf490 commit 1e57676

File tree

11 files changed

+21
-21
lines changed

11 files changed

+21
-21
lines changed

binding_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,13 +1505,13 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
15051505
f"\t\tGDExtensionObjectPtr singleton_obj = internal::gdextension_interface_global_get_singleton({class_name}::get_class_static()._native_ptr());"
15061506
)
15071507
result.append("#ifdef DEBUG_ENABLED")
1508-
result.append("\t\tERR_FAIL_COND_V(singleton_obj == nullptr, nullptr);")
1508+
result.append("\t\tERR_FAIL_NULL_V(singleton_obj, nullptr);")
15091509
result.append("#endif // DEBUG_ENABLED")
15101510
result.append(
15111511
f"\t\tsingleton = reinterpret_cast<{class_name} *>(internal::gdextension_interface_object_get_instance_binding(singleton_obj, internal::token, &{class_name}::_gde_binding_callbacks));"
15121512
)
15131513
result.append("#ifdef DEBUG_ENABLED")
1514-
result.append("\t\tERR_FAIL_COND_V(singleton == nullptr, nullptr);")
1514+
result.append("\t\tERR_FAIL_NULL_V(singleton, nullptr);")
15151515
result.append("#endif // DEBUG_ENABLED")
15161516
result.append("\t}")
15171517
result.append("\treturn singleton;")

include/godot_cpp/classes/ref.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Ref {
6363
}
6464

6565
void ref_pointer(T *p_ref) {
66-
ERR_FAIL_COND(!p_ref);
66+
ERR_FAIL_NULL(p_ref);
6767

6868
if (p_ref->init_ref()) {
6969
reference = p_ref;

include/godot_cpp/core/class_db.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ MethodBind *ClassDB::bind_static_method(StringName p_class, N p_method_name, M p
253253
template <class M>
254254
MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info, const std::vector<Variant> &p_default_args, bool p_return_nil_is_variant) {
255255
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
256-
ERR_FAIL_COND_V(!bind, nullptr);
256+
ERR_FAIL_NULL_V(bind, nullptr);
257257

258258
bind->set_name(p_name);
259259
bind->set_default_arguments(p_default_args);

include/godot_cpp/core/memory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
146146
size_t len = sizeof(T) * p_elements;
147147
uint64_t *mem = (uint64_t *)Memory::alloc_static(len, true);
148148
T *failptr = nullptr; // Get rid of a warning.
149-
ERR_FAIL_COND_V(!mem, failptr);
149+
ERR_FAIL_NULL_V(mem, failptr);
150150
*(mem - 1) = p_elements;
151151

152152
if (!std::is_trivially_destructible<T>::value) {

include/godot_cpp/templates/cowdata.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,15 @@ Error CowData<T>::resize(int p_size) {
294294
if (current_size == 0) {
295295
// alloc from scratch
296296
uint32_t *ptr = (uint32_t *)Memory::alloc_static(alloc_size, true);
297-
ERR_FAIL_COND_V(!ptr, ERR_OUT_OF_MEMORY);
297+
ERR_FAIL_NULL_V(ptr, ERR_OUT_OF_MEMORY);
298298
*(ptr - 1) = 0; // size, currently none
299299
new (ptr - 2) SafeNumeric<uint32_t>(1); // refcount
300300

301301
_ptr = (T *)ptr;
302302

303303
} else {
304304
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
305-
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
305+
ERR_FAIL_NULL_V(_ptrnew, ERR_OUT_OF_MEMORY);
306306
new (_ptrnew - 2) SafeNumeric<uint32_t>(rc); // refcount
307307

308308
_ptr = (T *)(_ptrnew);
@@ -332,7 +332,7 @@ Error CowData<T>::resize(int p_size) {
332332

333333
if (alloc_size != current_alloc_size) {
334334
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
335-
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
335+
ERR_FAIL_NULL_V(_ptrnew, ERR_OUT_OF_MEMORY);
336336
new (_ptrnew - 2) SafeNumeric<uint32_t>(rc); // refcount
337337

338338
_ptr = (T *)(_ptrnew);

include/godot_cpp/templates/list.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class List {
221221
int size_cache = 0;
222222

223223
bool erase(const Element *p_I) {
224-
ERR_FAIL_COND_V(!p_I, false);
224+
ERR_FAIL_NULL_V(p_I, false);
225225
ERR_FAIL_COND_V(p_I->data != this, false);
226226

227227
if (first == p_I) {

include/godot_cpp/templates/rid_owner.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ class RID_Alloc {
186186
}
187187
void initialize_rid(RID p_rid) {
188188
T *mem = get_or_null(p_rid, true);
189-
ERR_FAIL_COND(!mem);
189+
ERR_FAIL_NULL(mem);
190190
memnew_placement(mem, T);
191191
}
192192
void initialize_rid(RID p_rid, const T &p_value) {
193193
T *mem = get_or_null(p_rid, true);
194-
ERR_FAIL_COND(!mem);
194+
ERR_FAIL_NULL(mem);
195195
memnew_placement(mem, T(p_value));
196196
}
197197

@@ -374,7 +374,7 @@ class RID_PtrOwner {
374374

375375
_FORCE_INLINE_ void replace(const RID &p_rid, T *p_new_ptr) {
376376
T **ptr = alloc.get_or_null(p_rid);
377-
ERR_FAIL_COND(!ptr);
377+
ERR_FAIL_NULL(ptr);
378378
*ptr = p_new_ptr;
379379
}
380380

include/godot_cpp/templates/thread_work_pool.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ThreadWorkPool {
9696
public:
9797
template <class C, class M, class U>
9898
void begin_work(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
99-
ERR_FAIL_COND(!threads); // never initialized
99+
ERR_FAIL_NULL(threads); // Never initialized.
100100
ERR_FAIL_COND(current_work != nullptr);
101101

102102
index.store(0, std::memory_order_release);
@@ -123,18 +123,18 @@ class ThreadWorkPool {
123123
}
124124

125125
bool is_done_dispatching() const {
126-
ERR_FAIL_COND_V(current_work == nullptr, true);
126+
ERR_FAIL_NULL_V(current_work, true);
127127
return index.load(std::memory_order_acquire) >= current_work->max_elements;
128128
}
129129

130130
uint32_t get_work_index() const {
131-
ERR_FAIL_COND_V(current_work == nullptr, 0);
131+
ERR_FAIL_NULL_V(current_work, 0);
132132
uint32_t idx = index.load(std::memory_order_acquire);
133133
return Math::min(idx, current_work->max_elements);
134134
}
135135

136136
void end_work() {
137-
ERR_FAIL_COND(current_work == nullptr);
137+
ERR_FAIL_NULL(current_work);
138138
for (uint32_t i = 0; i < threads_working; i++) {
139139
threads[i].completed.wait();
140140
threads[i].work = nullptr;

src/core/class_db.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf
7777
if (p_setter != String("")) {
7878
setter = get_method(p_class, p_setter);
7979

80-
ERR_FAIL_COND_MSG(!setter, String("Setter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_setter, p_class, p_pinfo.name)));
80+
ERR_FAIL_NULL_MSG(setter, String("Setter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_setter, p_class, p_pinfo.name)));
8181

8282
size_t exp_args = 1 + (p_index >= 0 ? 1 : 0);
8383
ERR_FAIL_COND_MSG((int)exp_args != setter->get_argument_count(), String("Setter method '{0}::{1}()' must take a single argument.").format(Array::make(p_class, p_setter)));
@@ -86,7 +86,7 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf
8686
ERR_FAIL_COND_MSG(p_getter == String(""), String("Getter method must be specified for '{0}::{1}'.").format(Array::make(p_class, p_pinfo.name)));
8787

8888
MethodBind *getter = get_method(p_class, p_getter);
89-
ERR_FAIL_COND_MSG(!getter, String("Getter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_getter, p_class, p_pinfo.name)));
89+
ERR_FAIL_NULL_MSG(getter, String("Getter method '{0}::{1}()' not found for property '{2}::{3}'.").format(Array::make(p_class, p_getter, p_class, p_pinfo.name)));
9090
{
9191
size_t exp_args = 0 + (p_index >= 0 ? 1 : 0);
9292
ERR_FAIL_COND_MSG((int)exp_args != getter->get_argument_count(), String("Getter method '{0}::{1}()' must not take any argument.").format(Array::make(p_class, p_getter)));

src/core/memory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
4242
#endif
4343

4444
void *mem = internal::gdextension_interface_mem_alloc(p_bytes + (prepad ? PAD_ALIGN : 0));
45-
ERR_FAIL_COND_V(!mem, nullptr);
45+
ERR_FAIL_NULL_V(mem, nullptr);
4646

4747
if (prepad) {
4848
uint8_t *s8 = (uint8_t *)mem;
@@ -71,7 +71,7 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
7171
if (prepad) {
7272
mem -= PAD_ALIGN;
7373
mem = (uint8_t *)internal::gdextension_interface_mem_realloc(mem, p_bytes + PAD_ALIGN);
74-
ERR_FAIL_COND_V(!mem, nullptr);
74+
ERR_FAIL_NULL_V(mem, nullptr);
7575
return mem + PAD_ALIGN;
7676
} else {
7777
return (uint8_t *)internal::gdextension_interface_mem_realloc(mem, p_bytes);

0 commit comments

Comments
 (0)