diff --git a/SConstruct b/SConstruct index f336680a79b..e3c7d2498b1 100644 --- a/SConstruct +++ b/SConstruct @@ -295,10 +295,23 @@ if selected_platform in platform_list: # must happen after the flags, so when flags are used by configure, stuff happens (ie, ssl on x11) detect.configure(env) + # Set our C and C++ standard requirements. + # Prepending to make it possible to override. + is_msvc = os.name == "nt" and os.getenv("VCINSTALLDIR") and (platform_arg == "windows" or platform_arg == "uwp") + if (not is_msvc): + # Specifying GNU extensions support explicitly, which are supported by both GCC and Clang. + # We don't support C++17 so stick to earlier standards. + # When 2.1 was actively worked on, we were using GCC 5 which defaults to C++98, so use that. + env.Prepend(CFLAGS=["-std=gnu11"]) + env.Prepend(CXXFLAGS=["-std=gnu++98"]) + else: + # MSVC doesn't support setting C++ to pre-C++14 standards, so do nothing and hope it works. + pass + if (env["warnings"] == 'yes'): print("WARNING: warnings=yes is deprecated; assuming warnings=all") - if (os.name == "nt" and os.getenv("VCINSTALLDIR") and (platform_arg == "windows" or platform_arg == "uwp")): # MSVC, needs to stand out of course + if (is_msvc): # MSVC disable_nonessential_warnings = ['/wd4267', '/wd4244', '/wd4305', '/wd4800'] # Truncations, narrowing conversions... if (env["warnings"] == 'extra'): env.Append(CCFLAGS=['/Wall']) # Implies /W4 diff --git a/doc/tools/doc_merge.py b/doc/tools/doc_merge.py index 57ac4bdcddf..16616f2608c 100644 --- a/doc/tools/doc_merge.py +++ b/doc/tools/doc_merge.py @@ -213,3 +213,5 @@ for c in list(old_doc): for c in list(new_doc): write_class(c) write_string(f, '\n') + +f.close() diff --git a/doc/tools/makemd.py b/doc/tools/makemd.py index b2444eb47b6..95475206f55 100644 --- a/doc/tools/makemd.py +++ b/doc/tools/makemd.py @@ -86,6 +86,7 @@ def make_class_list(class_list, columns): s += '\n' f.write(s) + f.close() def dokuize_text(txt): @@ -324,6 +325,7 @@ def make_doku_class(node): f.write('\n') f.write(dokuize_text(d.text.strip())) f.write('\n') + f.close() for file in input_list: diff --git a/doc/tools/makerst.py b/doc/tools/makerst.py index d2e20462631..2e82bf27c72 100644 --- a/doc/tools/makerst.py +++ b/doc/tools/makerst.py @@ -99,6 +99,7 @@ def make_class_list(class_list, columns): for n in range(0, columns): f.write("--+-------+") f.write("\n") + f.close() def rstize_text(text, cclass): @@ -504,6 +505,7 @@ def make_rst_class(node): f.write(rstize_text(d.text.strip(), name)) f.write("\n\n") f.write('\n') + f.close() for file in input_list: diff --git a/methods.py b/methods.py index bf1cd99a50a..688c0d3b095 100755 --- a/methods.py +++ b/methods.py @@ -43,6 +43,7 @@ def build_shader_header(target, source, env): line = fs.readline() fd.write(";\n") + fd.close() return 0 @@ -1105,6 +1106,7 @@ def update_version(): f.write("#define VERSION_STATUS " + str(version.status) + "\n") import datetime f.write("#define VERSION_YEAR " + str(datetime.datetime.now().year) + "\n") + f.close() def parse_cg_file(fname, uniforms, sizes, conditionals): @@ -1175,6 +1177,7 @@ def build_cg_shader(sname): fd.write('\t\tVP_%s,\n' % vp_uniforms[i].upper()) fd.write("\t};\n") + fd.close() import glob @@ -1230,6 +1233,7 @@ void unregister_module_types() { f = open("modules/register_module_types.gen.cpp", "w") f.write(modules_cpp) + f.close() return module_list @@ -1464,6 +1468,7 @@ def save_active_platforms(apnames, ap): wf = x + "/logo.gen.h" logow = open(wf, "w") logow.write(str) + logow.close() def no_verbose(sys, env): diff --git a/misc/scripts/make_glwrapper.py b/misc/scripts/make_glwrapper.py index 5694d2327e2..519e1772324 100644 --- a/misc/scripts/make_glwrapper.py +++ b/misc/scripts/make_glwrapper.py @@ -176,3 +176,4 @@ for x in functions: f.write("\n\n") f.write("}\n") f.write("\n\n") +f.close() diff --git a/platform/android/SCsub b/platform/android/SCsub index f1047839057..e8bcfcdd438 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -2,7 +2,6 @@ import shutil from compat import open_utf8 -from distutils.version import LooseVersion from detect import get_ndk_version Import('env') @@ -143,6 +142,7 @@ manifest = manifest.replace("$$ADD_APPLICATION_CHUNKS$$", env.android_manifest_c manifest = manifest.replace("$$ADD_PERMISSION_CHUNKS$$", env.android_permission_chunk) manifest = manifest.replace("$$ADD_APPATTRIBUTE_CHUNKS$$", env.android_appattributes_chunk) pp_baseout.write(manifest) +pp_baseout.close() lib = env_android.add_shared_library("#bin/libgodot", [android_objects], SHLIBSUFFIX=env["SHLIBSUFFIX"]) @@ -167,10 +167,16 @@ if lib_arch_dir != '': else: # release_debug, debug lib_type_dir = 'debug' + # HACK: Replaced use of now obsoleted distutils.version.LooseVersion with this simple method, + # which isn't bullet proof but should be sufficient here with "x.y.z" parameters. + # Alternatives imply adding more dependencies. + def version_tuple(v): + return tuple(map(int, (v.split(".")))) + out_dir = '#platform/android/java/libs/' + lib_type_dir + '/' + lib_arch_dir env_android.Command(out_dir + '/libgodot_android.so', '#bin/libgodot' + env['SHLIBSUFFIX'], Move("$TARGET", "$SOURCE")) ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"]) - if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"): + if ndk_version != None and version_tuple(ndk_version) >= version_tuple("15.0.4075724"): if env['android_stl'] == 'yes': stl_lib_path = str(env['ANDROID_NDK_ROOT']) + '/sources/cxx-stl/llvm-libc++/libs/' + lib_arch_dir + '/libc++_shared.so' env_android.Command(out_dir + '/libc++_shared.so', stl_lib_path, Copy("$TARGET", "$SOURCE")) diff --git a/platform/android/detect.py b/platform/android/detect.py index b62b8e443ac..428d88c0aa5 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -2,7 +2,6 @@ import os import sys import string import platform -from distutils.version import LooseVersion def is_active(): return True @@ -193,8 +192,14 @@ def configure(env): lib_sysroot = env["ANDROID_NDK_ROOT"] + "/platforms/" + env['ndk_platform'] + "/" + env['ARCH'] + # HACK: Replaced use of now obsoleted distutils.version.LooseVersion with this simple method, + # which isn't bullet proof but should be sufficient here with "x.y.z" parameters. + # Alternatives imply adding more dependencies. + def version_tuple(v): + return tuple(map(int, (v.split(".")))) + ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"]) - if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"): + if ndk_version != None and version_tuple(ndk_version) >= version_tuple("15.0.4075724"): print("Using NDK unified headers") sysroot = env["ANDROID_NDK_ROOT"] + "/sysroot" env.Append(CPPFLAGS=["--sysroot="+sysroot]) @@ -251,9 +256,9 @@ def configure(env): if (sys.platform.startswith("darwin")): env['SHLIBSUFFIX'] = '.so' - if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"): + if ndk_version != None and version_tuple(ndk_version) >= version_tuple("15.0.4075724"): if env['android_stl'] == 'yes': - if LooseVersion(ndk_version) >= LooseVersion("17.1.4828580"): + if version_tuple(ndk_version) >= version_tuple("17.1.4828580"): env.Append(LINKFLAGS=['-Wl,--exclude-libs,libgcc.a','-Wl,--exclude-libs,libatomic.a','-nostdlib++']) else: env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"] +"/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/libandroid_support.a"]) diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py index 3e94767b195..091e95d146d 100644 --- a/platform/javascript/detect.py +++ b/platform/javascript/detect.py @@ -54,8 +54,6 @@ def configure(env): env['OBJSUFFIX'] = '.bc' env['LIBSUFFIX'] = '.bc' - env['CCCOM'] = "$CC -o $TARGET $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES" - env['CXXCOM'] = "$CC -o $TARGET $CFLAGS $CCFLAGS $_CCCOMCOM $SOURCES" # env.Append(LIBS=['c','m','stdc++','log','GLESv1_CM','GLESv2']) diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index e2dba1f9761..389cce623b1 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -716,7 +716,10 @@ bool OS_JavaScript::main_loop_iterate() { /* clang-format on */ } } - process_joysticks(); + + if (emscripten_sample_gamepad_data() == EMSCRIPTEN_RESULT_SUCCESS) + process_joysticks(); + return Main::iteration(); } @@ -805,8 +808,11 @@ void OS_JavaScript::process_joysticks() { int joy_count = emscripten_get_num_gamepads(); for (int i = 0; i < joy_count; i++) { EmscriptenGamepadEvent state; - emscripten_get_gamepad_status(i, &state); - if (state.connected) { + EMSCRIPTEN_RESULT query_result = emscripten_get_gamepad_status(i, &state); + // Chromium reserves gamepads slots, so NO_DATA is an expected result. + ERR_CONTINUE(query_result != EMSCRIPTEN_RESULT_SUCCESS && + query_result != EMSCRIPTEN_RESULT_NO_DATA); + if (query_result == EMSCRIPTEN_RESULT_SUCCESS && state.connected) { int num_buttons = MIN(state.numButtons, 18); int num_axes = MIN(state.numAxes, 8); diff --git a/platform/server/detect.py b/platform/server/detect.py index 3afbd01133b..28f0956746a 100644 --- a/platform/server/detect.py +++ b/platform/server/detect.py @@ -40,16 +40,6 @@ def configure(env): env["CC"] = "clang" env["CXX"] = "clang++" env["LD"] = "clang++" - elif (os.system("gcc --version > /dev/null 2>&1") == 0): # GCC - # Hack to prevent building this branch with GCC 6+, which trigger segfaults due to UB when dereferencing pointers in Object::cast_to - # This is fixed in the master branch, for 2.1 we just prevent using too recent GCC versions. - import subprocess - gcc_major = subprocess.check_output(['gcc', '-dumpversion']).decode('ascii').split('.')[0] - if (int(gcc_major) > 5): - print("Your configured compiler appears to be GCC %s, which triggers issues in release builds for this version of Godot (fixed in Godot 3.0+)." % gcc_major) - print("You can use the Clang compiler instead with the `use_llvm=yes` option, or configure another compiler such as GCC 5 using the CC, CXX and LD flags.") - print("Aborting..") - sys.exit(255) is64 = sys.maxsize > 2**32 diff --git a/platform/windows/detect.py b/platform/windows/detect.py index a7151235a52..40aa51cac4d 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -326,6 +326,18 @@ def configure(env): if (env["bits"] == "64"): env.Append(CCFLAGS=['-O3']) + + if (os.system(mingw_prefix + "gcc --version > /dev/null 2>&1") == 0): # GCC + # Hack to prevent segfaults due to UB when dereferencing NULL `this` in `Object::cast_to` with `-O3`. + # This is fixed in 3.0, for 2.1 we just prevent using the known affected GCC versions (6 and 7). + # GCC 5 or GCC 8 and later seem to be fine. + import subprocess + gcc_major = int(subprocess.check_output([mingw_prefix + 'gcc', '-dumpversion']).decode('ascii').split('.')[0]) + if (gcc_major == 6 or gcc_major == 7): + print("Your configured compiler appears to be GCC %d, which triggers issues in release builds for this version of Godot (fixed in Godot 3.0+)." % gcc_major) + print("You can use the Clang compiler instead with the `use_llvm=yes` option, or configure another compiler such as GCC 5 using the CC, CXX and LD flags.") + print("Aborting..") + sys.exit(255) else: env.Append(CCFLAGS=['-O2']) diff --git a/platform/x11/detect.py b/platform/x11/detect.py index ab791f357f7..0dfbca11f8b 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -86,16 +86,6 @@ def configure(env): env["LD"] = "clang++" env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND']) env.extra_suffix = ".llvm" - elif (os.system("gcc --version > /dev/null 2>&1") == 0): # GCC - # Hack to prevent building this branch with GCC 6+, which trigger segfaults due to UB when dereferencing pointers in Object::cast_to - # This is fixed in the master branch, for 2.1 we just prevent using too recent GCC versions. - import subprocess - gcc_major = subprocess.check_output(['gcc', '-dumpversion']).decode('ascii').split('.')[0] - if (int(gcc_major) > 5): - print("Your configured compiler appears to be GCC %s, which triggers issues in release builds for this version of Godot (fixed in Godot 3.0+)." % gcc_major) - print("You can use the Clang compiler instead with the `use_llvm=yes` option, or configure another compiler such as GCC 5 using the CC, CXX and LD flags.") - print("Aborting..") - sys.exit(255) if (env["use_sanitizer"] == "yes"): env.Append(CCFLAGS=['-fsanitize=address', '-fno-omit-frame-pointer']) @@ -125,6 +115,18 @@ def configure(env): if (env["debug_release"] == "yes"): env.Prepend(CCFLAGS=['-g2']) + if (os.system("gcc --version > /dev/null 2>&1") == 0): # GCC + # Hack to prevent segfaults due to UB when dereferencing NULL `this` in `Object::cast_to` with `-O3`. + # This is fixed in 3.0, for 2.1 we just prevent using the known affected GCC versions (6 and 7). + # GCC 5 or GCC 8 and later seem to be fine. + import subprocess + gcc_major = int(subprocess.check_output(['gcc', '-dumpversion']).decode('ascii').split('.')[0]) + if (gcc_major == 6 or gcc_major == 7): + print("Your configured compiler appears to be GCC %d, which triggers issues in release builds for this version of Godot (fixed in Godot 3.0+)." % gcc_major) + print("You can use the Clang compiler instead with the `use_llvm=yes` option, or configure another compiler such as GCC 5 using the CC, CXX and LD flags.") + print("Aborting..") + sys.exit(255) + elif (env["target"] == "release_debug"): env.Prepend(CCFLAGS=['-O2', '-ffast-math', '-DDEBUG_ENABLED']) diff --git a/thirdparty/freetype/patches/xcode16-compat.patch b/thirdparty/freetype/patches/xcode16-compat.patch new file mode 100644 index 00000000000..d68e451101e --- /dev/null +++ b/thirdparty/freetype/patches/xcode16-compat.patch @@ -0,0 +1,13 @@ +diff --git a/thirdparty/freetype/src/gzip/ftzconf.h b/thirdparty/freetype/src/gzip/ftzconf.h +index 3abf0ba03b..d88a82a2ee 100644 +--- a/thirdparty/freetype/src/gzip/ftzconf.h ++++ b/thirdparty/freetype/src/gzip/ftzconf.h +@@ -215,7 +215,7 @@ + # define FAR + #endif + +-#if !defined(MACOS) && !defined(TARGET_OS_MAC) ++#if !defined(__MACTYPES__) + typedef unsigned char Byte; /* 8 bits */ + #endif + typedef unsigned int uInt; /* 16 bits or more */ diff --git a/thirdparty/freetype/src/gzip/ftzconf.h b/thirdparty/freetype/src/gzip/ftzconf.h index 3abf0ba03b0..d88a82a2eec 100644 --- a/thirdparty/freetype/src/gzip/ftzconf.h +++ b/thirdparty/freetype/src/gzip/ftzconf.h @@ -215,7 +215,7 @@ # define FAR #endif -#if !defined(MACOS) && !defined(TARGET_OS_MAC) +#if !defined(__MACTYPES__) typedef unsigned char Byte; /* 8 bits */ #endif typedef unsigned int uInt; /* 16 bits or more */ diff --git a/thirdparty/libmpcdec/mpc_bits_reader.c b/thirdparty/libmpcdec/mpc_bits_reader.c index 5281288d255..c4199eb3fa4 100644 --- a/thirdparty/libmpcdec/mpc_bits_reader.c +++ b/thirdparty/libmpcdec/mpc_bits_reader.c @@ -98,7 +98,7 @@ const mpc_uint32_t Cnk_lost[MAX_ENUM / 2][MAX_ENUM] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 103, 55, 3347, 12419, 56459, 16987, 313105, 54177, 3076873, 3739321, 3132677, 66353813, 123012781, 236330717} }; -static const mpc_uint8_t log2[32] = +static const mpc_uint8_t mpc_log2[32] = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6}; static const mpc_uint8_t log2_lost[32] = @@ -136,8 +136,8 @@ mpc_int32_t mpc_bits_golomb_dec(mpc_bits_reader * r, const mpc_uint_t k) mpc_uint32_t mpc_bits_log_dec(mpc_bits_reader * r, mpc_uint_t max) { mpc_uint32_t value = 0; - if (log2[max - 1] > 1) - value = mpc_bits_read(r, log2[max - 1] - 1); + if (mpc_log2[max - 1] > 1) + value = mpc_bits_read(r, mpc_log2[max - 1] - 1); if (value >= log2_lost[max - 1]) value = ((value << 1) | mpc_bits_read(r, 1)) - log2_lost[max - 1]; return value; diff --git a/thirdparty/libmpcdec/patches/msvc-log2.patch b/thirdparty/libmpcdec/patches/msvc-log2.patch new file mode 100644 index 00000000000..09363fc9a5d Binary files /dev/null and b/thirdparty/libmpcdec/patches/msvc-log2.patch differ diff --git a/thirdparty/speex/fftwrap.c b/thirdparty/speex/fftwrap.c index ac71bbfcb7f..9765630e128 100644 --- a/thirdparty/speex/fftwrap.c +++ b/thirdparty/speex/fftwrap.c @@ -330,7 +330,11 @@ void spx_fft_float(void *table, float *in, float *out) #endif for (i=0;i