From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- drivers/unix/os_unix.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) (limited to 'drivers/unix/os_unix.cpp') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 53c60951b7..920d594ea1 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -91,7 +91,6 @@ static void _setup_clock() { #endif void OS_Unix::debug_break() { - assert(false); }; @@ -104,7 +103,6 @@ static void handle_interrupt(int sig) { } void OS_Unix::initialize_debugging() { - if (EngineDebugger::is_active()) { struct sigaction action; memset(&action, 0, sizeof(action)); @@ -114,12 +112,10 @@ void OS_Unix::initialize_debugging() { } int OS_Unix::unix_initialize_audio(int p_audio_driver) { - return 0; } void OS_Unix::initialize_core() { - #ifdef NO_THREADS ThreadDummy::make_default(); RWLockDummy::make_default(); @@ -144,17 +140,14 @@ void OS_Unix::initialize_core() { } void OS_Unix::finalize_core() { - NetSocketPosix::cleanup(); } void OS_Unix::alert(const String &p_alert, const String &p_title) { - fprintf(stderr, "ERROR: %s\n", p_alert.utf8().get_data()); } String OS_Unix::get_stdin_string(bool p_block) { - if (p_block) { char buff[1024]; String ret = stdin_buf + fgets(buff, 1024, stdin); @@ -166,12 +159,10 @@ String OS_Unix::get_stdin_string(bool p_block) { } String OS_Unix::get_name() const { - return "Unix"; } uint64_t OS_Unix::get_unix_time() const { - return time(nullptr); }; @@ -188,7 +179,6 @@ uint64_t OS_Unix::get_system_time_msecs() const { } OS::Date OS_Unix::get_date(bool utc) const { - time_t t = time(nullptr); struct tm *lt; if (utc) @@ -250,13 +240,11 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const { } void OS_Unix::delay_usec(uint32_t p_usec) const { - struct timespec rem = { static_cast(p_usec / 1000000), (static_cast(p_usec) % 1000000) * 1000 }; while (nanosleep(&rem, &rem) == EINTR) { } } uint64_t OS_Unix::get_ticks_usec() const { - #if defined(__APPLE__) uint64_t longtime = mach_absolute_time() * _clock_scale; #else @@ -272,19 +260,16 @@ uint64_t OS_Unix::get_ticks_usec() const { } Error OS_Unix::execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex) { - #ifdef __EMSCRIPTEN__ // Don't compile this code at all to avoid undefined references. // Actual virtual call goes to OS_JavaScript. ERR_FAIL_V(ERR_BUG); #else if (p_blocking && r_pipe) { - String argss; argss = "\"" + p_path + "\""; for (int i = 0; i < p_arguments.size(); i++) { - argss += String(" \"") + p_arguments[i] + "\""; } @@ -300,7 +285,6 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, bo char buf[65535]; while (fgets(buf, 65535, f)) { - if (p_pipe_mutex) { p_pipe_mutex->lock(); } @@ -345,14 +329,12 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, bo } if (p_blocking) { - int status; waitpid(pid, &status, 0); if (r_exitcode) *r_exitcode = WEXITSTATUS(status); } else { - if (r_child_id) *r_child_id = pid; } @@ -362,7 +344,6 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, bo } Error OS_Unix::kill(const ProcessID &p_pid) { - int ret = ::kill(p_pid, SIGKILL); if (!ret) { //avoid zombie process @@ -373,17 +354,14 @@ Error OS_Unix::kill(const ProcessID &p_pid) { } int OS_Unix::get_process_id() const { - return getpid(); }; bool OS_Unix::has_environment(const String &p_var) const { - return getenv(p_var.utf8().get_data()) != nullptr; } String OS_Unix::get_locale() const { - if (!has_environment("LANG")) return "en"; @@ -395,7 +373,6 @@ String OS_Unix::get_locale() const { } Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { - String path = p_path; if (FileAccess::exists(path) && path.is_rel_path()) { @@ -442,7 +419,6 @@ Error OS_Unix::get_dynamic_library_symbol_handle(void *p_library_handle, const S } Error OS_Unix::set_cwd(const String &p_cwd) { - if (chdir(p_cwd.utf8().get_data()) != 0) return ERR_CANT_OPEN; @@ -450,24 +426,20 @@ Error OS_Unix::set_cwd(const String &p_cwd) { } String OS_Unix::get_environment(const String &p_var) const { - if (getenv(p_var.utf8().get_data())) return getenv(p_var.utf8().get_data()); return ""; } bool OS_Unix::set_environment(const String &p_var, const String &p_value) const { - return setenv(p_var.utf8().get_data(), p_value.utf8().get_data(), /* overwrite: */ true) == 0; } int OS_Unix::get_processor_count() const { - return sysconf(_SC_NPROCESSORS_CONF); } String OS_Unix::get_user_data_dir() const { - String appname = get_safe_dir_name(ProjectSettings::get_singleton()->get("application/config/name")); if (appname != "") { bool use_custom_dir = ProjectSettings::get_singleton()->get("application/config/use_custom_user_dir"); @@ -486,7 +458,6 @@ String OS_Unix::get_user_data_dir() const { } String OS_Unix::get_executable_path() const { - #ifdef __linux__ //fix for running from a symlink char buf[256]; -- cgit v1.2.3 From 07bc4e2f96f8f47991339654ff4ab16acc19d44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 14:29:06 +0200 Subject: Style: Enforce separation line between function definitions I couldn't find a tool that enforces it, so I went the manual route: ``` find -name "thirdparty" -prune \ -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \ -o -name "*.glsl" > files perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files) misc/scripts/fix_style.sh -c ``` This adds a newline after all `}` on the first column, unless they are followed by `#` (typically `#endif`). This leads to having lots of places with two lines between function/class definitions, but clang-format then fixes it as we enforce max one line of separation. This doesn't fix potential occurrences of function definitions which are indented (e.g. for a helper class defined in a .cpp), but it's better than nothing. Also can't be made to run easily on CI/hooks so we'll have to be careful with new code. Part of #33027. --- drivers/unix/os_unix.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/unix/os_unix.cpp') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 920d594ea1..3ba667b2f7 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -244,6 +244,7 @@ void OS_Unix::delay_usec(uint32_t p_usec) const { while (nanosleep(&rem, &rem) == EINTR) { } } + uint64_t OS_Unix::get_ticks_usec() const { #if defined(__APPLE__) uint64_t longtime = mach_absolute_time() * _clock_scale; -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- drivers/unix/os_unix.cpp | 50 +++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'drivers/unix/os_unix.cpp') diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 3ba667b2f7..083cd64116 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -95,8 +95,9 @@ void OS_Unix::debug_break() { }; static void handle_interrupt(int sig) { - if (!EngineDebugger::is_active()) + if (!EngineDebugger::is_active()) { return; + } EngineDebugger::get_script_debugger()->set_depth(-1); EngineDebugger::get_script_debugger()->set_lines_left(1); @@ -181,10 +182,11 @@ uint64_t OS_Unix::get_system_time_msecs() const { OS::Date OS_Unix::get_date(bool utc) const { time_t t = time(nullptr); struct tm *lt; - if (utc) + if (utc) { lt = gmtime(&t); - else + } else { lt = localtime(&t); + } Date ret; ret.year = 1900 + lt->tm_year; // Index starting at 1 to match OS_Unix::get_date @@ -201,10 +203,11 @@ OS::Date OS_Unix::get_date(bool utc) const { OS::Time OS_Unix::get_time(bool utc) const { time_t t = time(nullptr); struct tm *lt; - if (utc) + if (utc) { lt = gmtime(&t); - else + } else { lt = localtime(&t); + } Time ret; ret.hour = lt->tm_hour; ret.min = lt->tm_min; @@ -231,10 +234,11 @@ OS::TimeZoneInfo OS_Unix::get_time_zone_info() const { // convert from ISO 8601 (1 minute=1, 1 hour=100) to minutes int hour = (int)bias / 100; int minutes = bias % 100; - if (bias < 0) + if (bias < 0) { ret.bias = hour * 60 - minutes; - else + } else { ret.bias = hour * 60 + minutes; + } return ret; } @@ -295,8 +299,9 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, bo } } int rv = pclose(f); - if (r_exitcode) + if (r_exitcode) { *r_exitcode = WEXITSTATUS(rv); + } return OK; } @@ -315,12 +320,14 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, bo Vector cs; cs.push_back(p_path.utf8()); - for (int i = 0; i < p_arguments.size(); i++) + for (int i = 0; i < p_arguments.size(); i++) { cs.push_back(p_arguments[i].utf8()); + } Vector args; - for (int i = 0; i < cs.size(); i++) + for (int i = 0; i < cs.size(); i++) { args.push_back((char *)cs[i].get_data()); + } args.push_back(0); execvp(p_path.utf8().get_data(), &args[0]); @@ -332,12 +339,14 @@ Error OS_Unix::execute(const String &p_path, const List &p_arguments, bo if (p_blocking) { int status; waitpid(pid, &status, 0); - if (r_exitcode) + if (r_exitcode) { *r_exitcode = WEXITSTATUS(status); + } } else { - if (r_child_id) + if (r_child_id) { *r_child_id = pid; + } } return OK; @@ -363,13 +372,15 @@ bool OS_Unix::has_environment(const String &p_var) const { } String OS_Unix::get_locale() const { - if (!has_environment("LANG")) + if (!has_environment("LANG")) { return "en"; + } String locale = get_environment("LANG"); int tp = locale.find("."); - if (tp != -1) + if (tp != -1) { locale = locale.substr(0, tp); + } return locale; } @@ -420,15 +431,17 @@ Error OS_Unix::get_dynamic_library_symbol_handle(void *p_library_handle, const S } Error OS_Unix::set_cwd(const String &p_cwd) { - if (chdir(p_cwd.utf8().get_data()) != 0) + if (chdir(p_cwd.utf8().get_data()) != 0) { return ERR_CANT_OPEN; + } return OK; } String OS_Unix::get_environment(const String &p_var) const { - if (getenv(p_var.utf8().get_data())) + if (getenv(p_var.utf8().get_data())) { return getenv(p_var.utf8().get_data()); + } return ""; } @@ -516,10 +529,11 @@ void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, i } const char *err_details; - if (p_rationale && p_rationale[0]) + if (p_rationale && p_rationale[0]) { err_details = p_rationale; - else + } else { err_details = p_code; + } // Disable color codes if stdout is not a TTY. // This prevents Godot from writing ANSI escape codes when redirecting -- cgit v1.2.3