diff options
Diffstat (limited to 'drivers/unix')
-rw-r--r-- | drivers/unix/SCsub | 4 | ||||
-rw-r--r-- | drivers/unix/dir_access_unix.cpp | 21 | ||||
-rw-r--r-- | drivers/unix/dir_access_unix.h | 3 | ||||
-rw-r--r-- | drivers/unix/file_access_unix.cpp | 12 | ||||
-rw-r--r-- | drivers/unix/ip_unix.cpp | 18 | ||||
-rw-r--r-- | drivers/unix/mutex_posix.cpp | 73 | ||||
-rw-r--r-- | drivers/unix/mutex_posix.h | 61 | ||||
-rw-r--r-- | drivers/unix/net_socket_posix.cpp | 31 | ||||
-rw-r--r-- | drivers/unix/net_socket_posix.h | 2 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 68 | ||||
-rw-r--r-- | drivers/unix/os_unix.h | 2 | ||||
-rw-r--r-- | drivers/unix/rw_lock_posix.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/semaphore_posix.cpp | 87 | ||||
-rw-r--r-- | drivers/unix/semaphore_posix.h | 58 | ||||
-rw-r--r-- | drivers/unix/syslog_logger.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/thread_posix.cpp | 4 |
16 files changed, 87 insertions, 361 deletions
diff --git a/drivers/unix/SCsub b/drivers/unix/SCsub index 4888f56099..91ef613546 100644 --- a/drivers/unix/SCsub +++ b/drivers/unix/SCsub @@ -1,7 +1,7 @@ #!/usr/bin/env python -Import('env') +Import("env") env.add_source_files(env.drivers_sources, "*.cpp") -env["check_c_headers"] = [ [ "mntent.h", "HAVE_MNTENT" ] ] +env["check_c_headers"] = [["mntent.h", "HAVE_MNTENT"]] diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 02cb4fa956..00103684c7 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -129,7 +129,7 @@ String DirAccessUnix::get_next() { dirent *entry = readdir(dir_stream); - if (entry == NULL) { + if (entry == nullptr) { list_dir_end(); return ""; } @@ -173,7 +173,7 @@ void DirAccessUnix::list_dir_end() { if (dir_stream) closedir(dir_stream); - dir_stream = 0; + dir_stream = nullptr; _cisdir = false; } @@ -207,7 +207,7 @@ static void _get_drives(List<String> *list) { char strings[4096]; while (getmntent_r(mtab, &mnt, strings, sizeof(strings))) { - if (mnt.mnt_dir != NULL && _filter_drive(&mnt)) { + if (mnt.mnt_dir != nullptr && _filter_drive(&mnt)) { // Avoid duplicates if (!list->find(mnt.mnt_dir)) { list->push_back(mnt.mnt_dir); @@ -269,6 +269,11 @@ String DirAccessUnix::get_drive(int p_drive) { return list[p_drive]; } +bool DirAccessUnix::drives_are_shortcuts() { + + return true; +} + Error DirAccessUnix::make_dir(String p_dir) { GLOBAL_LOCK_FUNCTION @@ -301,7 +306,7 @@ Error DirAccessUnix::change_dir(String p_dir) { // prev_dir is the directory we are changing out of String prev_dir; char real_current_dir_name[2048]; - ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == NULL, ERR_BUG); + ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == nullptr, ERR_BUG); if (prev_dir.parse_utf8(real_current_dir_name)) prev_dir = real_current_dir_name; //no utf8, maybe latin? @@ -322,7 +327,7 @@ Error DirAccessUnix::change_dir(String p_dir) { String base = _get_root_path(); if (base != String() && !try_dir.begins_with(base)) { - ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == NULL, ERR_BUG); + ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == nullptr, ERR_BUG); String new_dir; new_dir.parse_utf8(real_current_dir_name); @@ -337,7 +342,7 @@ Error DirAccessUnix::change_dir(String p_dir) { return OK; } -String DirAccessUnix::get_current_dir() { +String DirAccessUnix::get_current_dir(bool p_include_drive) { String base = _get_root_path(); if (base != "") { @@ -405,14 +410,14 @@ String DirAccessUnix::get_filesystem_type() const { DirAccessUnix::DirAccessUnix() { - dir_stream = 0; + dir_stream = nullptr; _cisdir = false; /* determine drive count */ // set current directory to an absolute path of the current directory char real_current_dir_name[2048]; - ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == NULL); + ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == nullptr); if (current_dir.parse_utf8(real_current_dir_name)) current_dir = real_current_dir_name; diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h index 32ddc76638..b403d8e356 100644 --- a/drivers/unix/dir_access_unix.h +++ b/drivers/unix/dir_access_unix.h @@ -63,9 +63,10 @@ public: virtual int get_drive_count(); virtual String get_drive(int p_drive); + virtual bool drives_are_shortcuts(); virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success - virtual String get_current_dir(); ///< return current dir location + virtual String get_current_dir(bool p_include_drive = true); ///< return current dir location virtual Error make_dir(String p_dir); virtual bool file_exists(String p_file); diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 91164dc3f9..4aa408a1f0 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -76,7 +76,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { if (f) fclose(f); - f = NULL; + f = nullptr; path_src = p_path; path = fix_path(p_path); @@ -119,7 +119,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) { f = fopen(path.utf8().get_data(), mode_string); - if (f == NULL) { + if (f == nullptr) { switch (errno) { case ENOENT: { last_error = ERR_FILE_NOT_FOUND; @@ -155,7 +155,7 @@ void FileAccessUnix::close() { return; fclose(f); - f = NULL; + f = nullptr; if (close_notification_func) { close_notification_func(path, flags); @@ -175,7 +175,7 @@ void FileAccessUnix::close() { bool FileAccessUnix::is_open() const { - return (f != NULL); + return (f != nullptr); } String FileAccessUnix::get_path() const { @@ -352,10 +352,10 @@ FileAccess *FileAccessUnix::create_libc() { return memnew(FileAccessUnix); } -CloseNotificationFunc FileAccessUnix::close_notification_func = NULL; +CloseNotificationFunc FileAccessUnix::close_notification_func = nullptr; FileAccessUnix::FileAccessUnix() : - f(NULL), + f(nullptr), flags(0), last_error(OK) { } diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index 08c099f771..5e3dedfc2f 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -107,13 +107,13 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) { }; hints.ai_flags &= ~AI_NUMERICHOST; - int s = getaddrinfo(p_hostname.utf8().get_data(), NULL, &hints, &result); + int s = getaddrinfo(p_hostname.utf8().get_data(), nullptr, &hints, &result); if (s != 0) { ERR_PRINT("getaddrinfo failed! Cannot resolve hostname."); return IP_Address(); }; - if (result == NULL || result->ai_addr == NULL) { + if (result == nullptr || result->ai_addr == nullptr) { ERR_PRINT("Invalid response from getaddrinfo"); if (result) freeaddrinfo(result); @@ -175,7 +175,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co addrs = (IP_ADAPTER_ADDRESSES *)memalloc(buf_size); int err = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_DNS_SERVER | GAA_FLAG_SKIP_FRIENDLY_NAME, - NULL, addrs, &buf_size); + nullptr, addrs, &buf_size); if (err == NO_ERROR) { break; }; @@ -189,7 +189,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co IP_ADAPTER_ADDRESSES *adapter = addrs; - while (adapter != NULL) { + while (adapter != nullptr) { Interface_Info info; info.name = adapter->AdapterName; @@ -197,7 +197,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co info.index = String::num_uint64(adapter->IfIndex); IP_ADAPTER_UNICAST_ADDRESS *address = adapter->FirstUnicastAddress; - while (address != NULL) { + while (address != nullptr) { int family = address->Address.lpSockaddr->sa_family; if (family != AF_INET && family != AF_INET6) continue; @@ -219,13 +219,13 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const { - struct ifaddrs *ifAddrStruct = NULL; - struct ifaddrs *ifa = NULL; + struct ifaddrs *ifAddrStruct = nullptr; + struct ifaddrs *ifa = nullptr; int family; getifaddrs(&ifAddrStruct); - for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { + for (ifa = ifAddrStruct; ifa != nullptr; ifa = ifa->ifa_next) { if (!ifa->ifa_addr) continue; @@ -248,7 +248,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co info.ip_addresses.push_front(_sockaddr2ip(ifa->ifa_addr)); } - if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct); + if (ifAddrStruct != nullptr) freeifaddrs(ifAddrStruct); } #endif diff --git a/drivers/unix/mutex_posix.cpp b/drivers/unix/mutex_posix.cpp deleted file mode 100644 index a9fc12fb06..0000000000 --- a/drivers/unix/mutex_posix.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************/ -/* mutex_posix.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "mutex_posix.h" - -#include "core/os/memory.h" - -#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED) - -void MutexPosix::lock() { - - pthread_mutex_lock(&mutex); -} -void MutexPosix::unlock() { - - pthread_mutex_unlock(&mutex); -} -Error MutexPosix::try_lock() { - - return (pthread_mutex_trylock(&mutex) == 0) ? OK : ERR_BUSY; -} - -Mutex *MutexPosix::create_func_posix(bool p_recursive) { - - return memnew(MutexPosix(p_recursive)); -} - -void MutexPosix::make_default() { - - create_func = create_func_posix; -} - -MutexPosix::MutexPosix(bool p_recursive) { - - pthread_mutexattr_init(&attr); - if (p_recursive) - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&mutex, &attr); -} - -MutexPosix::~MutexPosix() { - - pthread_mutex_destroy(&mutex); -} - -#endif diff --git a/drivers/unix/mutex_posix.h b/drivers/unix/mutex_posix.h deleted file mode 100644 index bd67106836..0000000000 --- a/drivers/unix/mutex_posix.h +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************/ -/* mutex_posix.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef MUTEX_POSIX_H -#define MUTEX_POSIX_H - -#if defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED) - -#include "core/os/mutex.h" - -#include <pthread.h> - -class MutexPosix : public Mutex { - - pthread_mutexattr_t attr; - pthread_mutex_t mutex; - - static Mutex *create_func_posix(bool p_recursive); - -public: - virtual void lock(); - virtual void unlock(); - virtual Error try_lock(); - - static void make_default(); - - MutexPosix(bool p_recursive); - - ~MutexPosix(); -}; - -#endif - -#endif diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index cab5513e0a..7c6543c3a2 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -86,7 +86,7 @@ #define SOCK_CLOSE closesocket // connect is broken on windows under certain conditions, reasons unknown: // See https://github.com/godotengine/webrtc-native/issues/6 -#define SOCK_CONNECT(p_sock, p_addr, p_addr_len) ::WSAConnect(p_sock, p_addr, p_addr_len, NULL, NULL, NULL, NULL) +#define SOCK_CONNECT(p_sock, p_addr, p_addr_len) ::WSAConnect(p_sock, p_addr, p_addr_len, nullptr, nullptr, nullptr, nullptr) // Workaround missing flag in MinGW #if defined(__MINGW32__) && !defined(SIO_UDP_NETRESET) @@ -155,7 +155,7 @@ NetSocket *NetSocketPosix::_create_func() { void NetSocketPosix::make_default() { #if defined(WINDOWS_ENABLED) - if (_create == NULL) { + if (_create == nullptr) { WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); } @@ -165,10 +165,10 @@ void NetSocketPosix::make_default() { void NetSocketPosix::cleanup() { #if defined(WINDOWS_ENABLED) - if (_create != NULL) { + if (_create != nullptr) { WSACleanup(); } - _create = NULL; + _create = nullptr; #endif } @@ -446,15 +446,15 @@ Error NetSocketPosix::poll(PollType p_type, int p_timeout) const { #if defined(WINDOWS_ENABLED) bool ready = false; fd_set rd, wr, ex; - fd_set *rdp = NULL; - fd_set *wrp = NULL; + fd_set *rdp = nullptr; + fd_set *wrp = nullptr; FD_ZERO(&rd); FD_ZERO(&wr); FD_ZERO(&ex); FD_SET(_sock, &ex); struct timeval timeout = { p_timeout, 0 }; - // For blocking operation, pass NULL timeout pointer to select. - struct timeval *tp = NULL; + // For blocking operation, pass nullptr timeout pointer to select. + struct timeval *tp = nullptr; if (p_timeout >= 0) { // If timeout is non-negative, we want to specify the timeout instead. tp = &timeout; @@ -544,14 +544,14 @@ Error NetSocketPosix::recv(uint8_t *p_buffer, int p_len, int &r_read) { return OK; } -Error NetSocketPosix::recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port) { +Error NetSocketPosix::recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port, bool p_peek) { ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED); struct sockaddr_storage from; socklen_t len = sizeof(struct sockaddr_storage); memset(&from, 0, len); - r_read = ::recvfrom(_sock, SOCK_BUF(p_buffer), p_len, 0, (struct sockaddr *)&from, &len); + r_read = ::recvfrom(_sock, SOCK_BUF(p_buffer), p_len, p_peek ? MSG_PEEK : 0, (struct sockaddr *)&from, &len); if (r_read < 0) { NetError err = _get_socket_error(); @@ -673,22 +673,27 @@ void NetSocketPosix::set_tcp_no_delay_enabled(bool p_enabled) { void NetSocketPosix::set_reuse_address_enabled(bool p_enabled) { ERR_FAIL_COND(!is_open()); +// On Windows, enabling SO_REUSEADDR actually would also enable reuse port, very bad on TCP. Denying... +// Windows does not have this option, SO_REUSEADDR in this magical world means SO_REUSEPORT +#ifndef WINDOWS_ENABLED int par = p_enabled ? 1 : 0; if (setsockopt(_sock, SOL_SOCKET, SO_REUSEADDR, SOCK_CBUF(&par), sizeof(int)) < 0) { WARN_PRINT("Unable to set socket REUSEADDR option!"); } +#endif } void NetSocketPosix::set_reuse_port_enabled(bool p_enabled) { -// Windows does not have this option, as it is always ON when setting REUSEADDR. -#ifndef WINDOWS_ENABLED ERR_FAIL_COND(!is_open()); +// See comment above... +#ifdef WINDOWS_ENABLED +#define SO_REUSEPORT SO_REUSEADDR +#endif int par = p_enabled ? 1 : 0; if (setsockopt(_sock, SOL_SOCKET, SO_REUSEPORT, SOCK_CBUF(&par), sizeof(int)) < 0) { WARN_PRINT("Unable to set socket REUSEPORT option!"); } -#endif } bool NetSocketPosix::is_open() const { diff --git a/drivers/unix/net_socket_posix.h b/drivers/unix/net_socket_posix.h index 25ac6e2e56..0a19967265 100644 --- a/drivers/unix/net_socket_posix.h +++ b/drivers/unix/net_socket_posix.h @@ -81,7 +81,7 @@ public: virtual Error connect_to_host(IP_Address p_host, uint16_t p_port); virtual Error poll(PollType p_type, int timeout) const; virtual Error recv(uint8_t *p_buffer, int p_len, int &r_read); - virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port); + virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port, bool p_peek = false); virtual Error send(const uint8_t *p_buffer, int p_len, int &r_sent); virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port); virtual Ref<NetSocket> accept(IP_Address &r_ip, uint16_t &r_port); diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index c5eb343cc8..53c60951b7 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -32,16 +32,16 @@ #ifdef UNIX_ENABLED +#include "core/debugger/engine_debugger.h" +#include "core/debugger/script_debugger.h" #include "core/os/thread_dummy.h" #include "core/project_settings.h" #include "drivers/unix/dir_access_unix.h" #include "drivers/unix/file_access_unix.h" -#include "drivers/unix/mutex_posix.h" #include "drivers/unix/net_socket_posix.h" #include "drivers/unix/rw_lock_posix.h" -#include "drivers/unix/semaphore_posix.h" #include "drivers/unix/thread_posix.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" #ifdef __APPLE__ #include <mach-o/dyld.h> @@ -96,20 +96,20 @@ void OS_Unix::debug_break() { }; static void handle_interrupt(int sig) { - if (ScriptDebugger::get_singleton() == NULL) + if (!EngineDebugger::is_active()) return; - ScriptDebugger::get_singleton()->set_depth(-1); - ScriptDebugger::get_singleton()->set_lines_left(1); + EngineDebugger::get_script_debugger()->set_depth(-1); + EngineDebugger::get_script_debugger()->set_lines_left(1); } void OS_Unix::initialize_debugging() { - if (ScriptDebugger::get_singleton() != NULL) { + if (EngineDebugger::is_active()) { struct sigaction action; memset(&action, 0, sizeof(action)); action.sa_handler = handle_interrupt; - sigaction(SIGINT, &action, NULL); + sigaction(SIGINT, &action, nullptr); } } @@ -122,15 +122,9 @@ void OS_Unix::initialize_core() { #ifdef NO_THREADS ThreadDummy::make_default(); - SemaphoreDummy::make_default(); - MutexDummy::make_default(); RWLockDummy::make_default(); #else ThreadPosix::make_default(); -#if !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED) - SemaphorePosix::make_default(); -#endif - MutexPosix::make_default(); RWLockPosix::make_default(); #endif FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES); @@ -178,24 +172,24 @@ String OS_Unix::get_name() const { uint64_t OS_Unix::get_unix_time() const { - return time(NULL); + return time(nullptr); }; uint64_t OS_Unix::get_system_time_secs() const { struct timeval tv_now; - gettimeofday(&tv_now, NULL); + gettimeofday(&tv_now, nullptr); return uint64_t(tv_now.tv_sec); } uint64_t OS_Unix::get_system_time_msecs() const { struct timeval tv_now; - gettimeofday(&tv_now, NULL); + gettimeofday(&tv_now, nullptr); return uint64_t(tv_now.tv_sec) * 1000 + uint64_t(tv_now.tv_usec) / 1000; } OS::Date OS_Unix::get_date(bool utc) const { - time_t t = time(NULL); + time_t t = time(nullptr); struct tm *lt; if (utc) lt = gmtime(&t); @@ -215,7 +209,7 @@ OS::Date OS_Unix::get_date(bool utc) const { } OS::Time OS_Unix::get_time(bool utc) const { - time_t t = time(NULL); + time_t t = time(nullptr); struct tm *lt; if (utc) lt = gmtime(&t); @@ -230,7 +224,7 @@ OS::Time OS_Unix::get_time(bool utc) const { } OS::TimeZoneInfo OS_Unix::get_time_zone_info() const { - time_t t = time(NULL); + time_t t = time(nullptr); struct tm *lt = localtime(&t); char name[16]; strftime(name, 16, "%Z", lt); @@ -310,7 +304,7 @@ Error OS_Unix::execute(const String &p_path, const List<String> &p_arguments, bo if (p_pipe_mutex) { p_pipe_mutex->lock(); } - (*r_pipe) += buf; + (*r_pipe) += String::utf8(buf); if (p_pipe_mutex) { p_pipe_mutex->unlock(); } @@ -385,7 +379,7 @@ int OS_Unix::get_process_id() const { bool OS_Unix::has_environment(const String &p_var) const { - return getenv(p_var.utf8().get_data()) != NULL; + return getenv(p_var.utf8().get_data()) != nullptr; } String OS_Unix::get_locale() const { @@ -439,7 +433,7 @@ Error OS_Unix::get_dynamic_library_symbol_handle(void *p_library_handle, const S p_symbol_handle = dlsym(p_library_handle, p_name.utf8().get_data()); error = dlerror(); - if (error != NULL) { + if (error != nullptr) { ERR_FAIL_COND_V_MSG(!p_optional, ERR_CANT_RESOLVE, "Can't resolve symbol " + p_name + ". Error: " + error + "."); return ERR_CANT_RESOLVE; @@ -517,7 +511,7 @@ String OS_Unix::get_executable_path() const { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; char buf[MAXPATHLEN]; size_t len = sizeof(buf); - if (sysctl(mib, 4, buf, &len, NULL, 0) != 0) { + if (sysctl(mib, 4, buf, &len, nullptr, 0) != 0) { WARN_PRINT("Couldn't get executable path from sysctl"); return OS::get_executable_path(); } @@ -559,34 +553,34 @@ void UnixTerminalLogger::log_error(const char *p_function, const char *p_file, i // This prevents Godot from writing ANSI escape codes when redirecting // stdout and stderr to a file. const bool tty = isatty(fileno(stdout)); - const char *red = tty ? "\E[0;31m" : ""; + const char *gray = tty ? "\E[0;90m" : ""; + const char *red = tty ? "\E[0;91m" : ""; const char *red_bold = tty ? "\E[1;31m" : ""; - const char *yellow = tty ? "\E[0;33m" : ""; + const char *yellow = tty ? "\E[0;93m" : ""; const char *yellow_bold = tty ? "\E[1;33m" : ""; - const char *magenta = tty ? "\E[0;35m" : ""; + const char *magenta = tty ? "\E[0;95m" : ""; const char *magenta_bold = tty ? "\E[1;35m" : ""; - const char *cyan = tty ? "\E[0;36m" : ""; + const char *cyan = tty ? "\E[0;96m" : ""; const char *cyan_bold = tty ? "\E[1;36m" : ""; const char *reset = tty ? "\E[0m" : ""; - const char *bold = tty ? "\E[1m" : ""; switch (p_type) { case ERR_WARNING: - logf_error("%sWARNING: %s: %s%s%s\n", yellow_bold, p_function, reset, bold, err_details); - logf_error("%s At: %s:%i.%s\n", yellow, p_file, p_line, reset); + logf_error("%sWARNING:%s %s\n", yellow_bold, yellow, err_details); + logf_error("%s at: %s (%s:%i)%s\n", gray, p_function, p_file, p_line, reset); break; case ERR_SCRIPT: - logf_error("%sSCRIPT ERROR: %s: %s%s%s\n", magenta_bold, p_function, reset, bold, err_details); - logf_error("%s At: %s:%i.%s\n", magenta, p_file, p_line, reset); + logf_error("%sSCRIPT ERROR:%s %s\n", magenta_bold, magenta, err_details); + logf_error("%s at: %s (%s:%i)%s\n", gray, p_function, p_file, p_line, reset); break; case ERR_SHADER: - logf_error("%sSHADER ERROR: %s: %s%s%s\n", cyan_bold, p_function, reset, bold, err_details); - logf_error("%s At: %s:%i.%s\n", cyan, p_file, p_line, reset); + logf_error("%sSHADER ERROR:%s %s\n", cyan_bold, cyan, err_details); + logf_error("%s at: %s (%s:%i)%s\n", gray, p_function, p_file, p_line, reset); break; case ERR_ERROR: default: - logf_error("%sERROR: %s: %s%s%s\n", red_bold, p_function, reset, bold, err_details); - logf_error("%s At: %s:%i.%s\n", red, p_file, p_line, reset); + logf_error("%sERROR:%s %s\n", red_bold, red, err_details); + logf_error("%s at: %s (%s:%i)%s\n", gray, p_function, p_file, p_line, reset); break; } } diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index c381890834..90679ddf1d 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -85,7 +85,7 @@ public: virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; - virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false, Mutex *p_pipe_mutex = NULL); + virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = nullptr, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr); virtual Error kill(const ProcessID &p_pid); virtual int get_process_id() const; diff --git a/drivers/unix/rw_lock_posix.cpp b/drivers/unix/rw_lock_posix.cpp index bb3eebd267..f219a0905c 100644 --- a/drivers/unix/rw_lock_posix.cpp +++ b/drivers/unix/rw_lock_posix.cpp @@ -91,7 +91,7 @@ void RWLockPosix::make_default() { RWLockPosix::RWLockPosix() { //rwlock=PTHREAD_RWLOCK_INITIALIZER; fails on OSX - pthread_rwlock_init(&rwlock, NULL); + pthread_rwlock_init(&rwlock, nullptr); } RWLockPosix::~RWLockPosix() { diff --git a/drivers/unix/semaphore_posix.cpp b/drivers/unix/semaphore_posix.cpp deleted file mode 100644 index 5f412adea1..0000000000 --- a/drivers/unix/semaphore_posix.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************/ -/* semaphore_posix.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "semaphore_posix.h" - -#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED) - -#include "core/os/memory.h" -#include <errno.h> -#include <stdio.h> - -Error SemaphorePosix::wait() { - - while (sem_wait(&sem)) { - if (errno == EINTR) { - errno = 0; - continue; - } else { - perror("sem waiting"); - return ERR_BUSY; - } - } - return OK; -} - -Error SemaphorePosix::post() { - - return (sem_post(&sem) == 0) ? OK : ERR_BUSY; -} -int SemaphorePosix::get() const { - - int val; - sem_getvalue(&sem, &val); - - return val; -} - -Semaphore *SemaphorePosix::create_semaphore_posix() { - - return memnew(SemaphorePosix); -} - -void SemaphorePosix::make_default() { - - create_func = create_semaphore_posix; -} - -SemaphorePosix::SemaphorePosix() { - - int r = sem_init(&sem, 0, 0); - if (r != 0) - perror("sem creating"); -} - -SemaphorePosix::~SemaphorePosix() { - - sem_destroy(&sem); -} - -#endif diff --git a/drivers/unix/semaphore_posix.h b/drivers/unix/semaphore_posix.h deleted file mode 100644 index e06f6316db..0000000000 --- a/drivers/unix/semaphore_posix.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************/ -/* semaphore_posix.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef SEMAPHORE_POSIX_H -#define SEMAPHORE_POSIX_H - -#include "core/os/semaphore.h" - -#if (defined(UNIX_ENABLED) || defined(PTHREAD_ENABLED)) && !defined(OSX_ENABLED) && !defined(IPHONE_ENABLED) - -#include <semaphore.h> - -class SemaphorePosix : public Semaphore { - - mutable sem_t sem; - - static Semaphore *create_semaphore_posix(); - -public: - virtual Error wait(); - virtual Error post(); - virtual int get() const; - - static void make_default(); - SemaphorePosix(); - - ~SemaphorePosix(); -}; - -#endif -#endif diff --git a/drivers/unix/syslog_logger.cpp b/drivers/unix/syslog_logger.cpp index 59001f057d..dc9112bf14 100644 --- a/drivers/unix/syslog_logger.cpp +++ b/drivers/unix/syslog_logger.cpp @@ -68,4 +68,4 @@ void SyslogLogger::print_error(const char *p_function, const char *p_file, int p SyslogLogger::~SyslogLogger() { } -#endif
\ No newline at end of file +#endif diff --git a/drivers/unix/thread_posix.cpp b/drivers/unix/thread_posix.cpp index 21f49a7e38..c227aec6d6 100644 --- a/drivers/unix/thread_posix.cpp +++ b/drivers/unix/thread_posix.cpp @@ -75,7 +75,7 @@ void *ThreadPosix::thread_callback(void *userdata) { ScriptServer::thread_exit(); - return NULL; + return nullptr; } Thread *ThreadPosix::create_func_posix(ThreadCreateCallback p_callback, void *p_user, const Settings &) { @@ -108,7 +108,7 @@ void ThreadPosix::wait_to_finish_func_posix(Thread *p_thread) { ERR_FAIL_COND(!tp); ERR_FAIL_COND(tp->pthread == 0); - pthread_join(tp->pthread, NULL); + pthread_join(tp->pthread, nullptr); tp->pthread = 0; } |