Skip to content

Commit e389f7a

Browse files
authored
Merge pull request #1261 from dsnopek/4.1-cherrypicks-4
Cherry-picks for the godot-cpp 4.1 branch - 4th batch
2 parents 3b3f357 + 0b1c8bc commit e389f7a

File tree

20 files changed

+99
-41
lines changed

20 files changed

+99
-41
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,18 @@ jobs:
7878
run-tests: false
7979
cache-name: ios-arm64
8080

81+
- name: 🌐 Web (wasm32)
82+
os: ubuntu-20.04
83+
platform: javascript
84+
artifact-name: godot-cpp-javascript-wasm32-release
85+
artifact-path: bin/libgodot-cpp.javascript.template_release.wasm32.a
86+
run-tests: false
87+
cache-name: javascript-wasm32
88+
8189
env:
8290
SCONS_CACHE: ${{ github.workspace }}/.scons-cache/
91+
EM_VERSION: 3.1.45
92+
EM_CACHE_FOLDER: "emsdk-cache"
8393

8494
steps:
8595
- name: Checkout
@@ -104,6 +114,13 @@ jobs:
104114
sudo apt-get update -qq
105115
sudo apt-get install -qqq build-essential pkg-config
106116
117+
- name: Web dependencies
118+
if: ${{ matrix.platform == 'javascript' }}
119+
uses: mymindstorm/setup-emsdk@v12
120+
with:
121+
version: ${{env.EM_VERSION}}
122+
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
123+
107124
- name: Install scons
108125
run: |
109126
python -m pip install scons==4.0.0

SConstruct

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ env.PrependENVPath("PATH", os.getenv("PATH"))
2121

2222
# Custom options and profile flags.
2323
customs = ["custom.py"]
24+
try:
25+
customs += Import("customs")
26+
except:
27+
pass
2428
profile = ARGUMENTS.get("profile", "")
2529
if profile:
2630
if os.path.isfile(profile):

binding_generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,13 +1519,13 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
15191519
f"\t\tGDExtensionObjectPtr singleton_obj = internal::gdextension_interface_global_get_singleton({class_name}::get_class_static()._native_ptr());"
15201520
)
15211521
result.append("#ifdef DEBUG_ENABLED")
1522-
result.append("\t\tERR_FAIL_COND_V(singleton_obj == nullptr, nullptr);")
1522+
result.append("\t\tERR_FAIL_NULL_V(singleton_obj, nullptr);")
15231523
result.append("#endif // DEBUG_ENABLED")
15241524
result.append(
15251525
f"\t\tsingleton = reinterpret_cast<{class_name} *>(internal::gdextension_interface_object_get_instance_binding(singleton_obj, internal::token, &{class_name}::_gde_binding_callbacks));"
15261526
)
15271527
result.append("#ifdef DEBUG_ENABLED")
1528-
result.append("\t\tERR_FAIL_COND_V(singleton == nullptr, nullptr);")
1528+
result.append("\t\tERR_FAIL_NULL_V(singleton, nullptr);")
15291529
result.append("#endif // DEBUG_ENABLED")
15301530
result.append("\t}")
15311531
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
@@ -257,7 +257,7 @@ MethodBind *ClassDB::bind_static_method(StringName p_class, N p_method_name, M p
257257
template <class M>
258258
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) {
259259
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
260-
ERR_FAIL_COND_V(!bind, nullptr);
260+
ERR_FAIL_NULL_V(bind, nullptr);
261261

262262
bind->set_name(p_name);
263263
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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ class CowData {
102102
}
103103

104104
_FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const {
105+
if (unlikely(p_elements == 0)) {
106+
*out = 0;
107+
return true;
108+
}
105109
#if defined(__GNUC__)
106110
size_t o;
107111
size_t p;
@@ -113,13 +117,12 @@ class CowData {
113117
if (__builtin_add_overflow(o, static_cast<size_t>(32), &p)) {
114118
return false; // No longer allocated here.
115119
}
116-
return true;
117120
#else
118121
// Speed is more important than correctness here, do the operations unchecked
119122
// and hope for the best.
120123
*out = _get_alloc_size(p_elements);
121-
return true;
122124
#endif
125+
return *out;
123126
}
124127

125128
void _unref(void *p_data);
@@ -294,15 +297,15 @@ Error CowData<T>::resize(int p_size) {
294297
if (current_size == 0) {
295298
// alloc from scratch
296299
uint32_t *ptr = (uint32_t *)Memory::alloc_static(alloc_size, true);
297-
ERR_FAIL_COND_V(!ptr, ERR_OUT_OF_MEMORY);
300+
ERR_FAIL_NULL_V(ptr, ERR_OUT_OF_MEMORY);
298301
*(ptr - 1) = 0; // size, currently none
299302
new (ptr - 2) SafeNumeric<uint32_t>(1); // refcount
300303

301304
_ptr = (T *)ptr;
302305

303306
} else {
304307
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
305-
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
308+
ERR_FAIL_NULL_V(_ptrnew, ERR_OUT_OF_MEMORY);
306309
new (_ptrnew - 2) SafeNumeric<uint32_t>(rc); // refcount
307310

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

333336
if (alloc_size != current_alloc_size) {
334337
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
335-
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
338+
ERR_FAIL_NULL_V(_ptrnew, ERR_OUT_OF_MEMORY);
336339
new (_ptrnew - 2) SafeNumeric<uint32_t>(rc); // refcount
337340

338341
_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;

0 commit comments

Comments
 (0)