diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/dir_access.cpp | 2 | ||||
-rw-r--r-- | core/os/file_access.cpp | 4 | ||||
-rw-r--r-- | core/os/input.cpp | 2 | ||||
-rw-r--r-- | core/os/keyboard.cpp | 2 | ||||
-rw-r--r-- | core/os/keyboard.h | 1 | ||||
-rw-r--r-- | core/os/memory.cpp | 40 | ||||
-rw-r--r-- | core/os/memory.h | 12 | ||||
-rw-r--r-- | core/os/os.cpp | 7 | ||||
-rw-r--r-- | core/os/os.h | 15 |
9 files changed, 51 insertions, 34 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 484942bad5..391ae78c85 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "dir_access.h" -#include "project_settings.h" #include "os/file_access.h" #include "os/memory.h" #include "os/os.h" +#include "project_settings.h" String DirAccess::_get_root_path() const { diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 2bb676381f..3bd5ac3f41 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -31,8 +31,8 @@ #include "core/io/file_access_pack.h" #include "core/io/marshalls.h" -#include "project_settings.h" #include "os/os.h" +#include "project_settings.h" #include "thirdparty/misc/md5.h" #include "thirdparty/misc/sha256.h" @@ -300,6 +300,8 @@ Vector<String> FileAccess::get_csv_line(String delim) const { String l; int qc = 0; do { + ERR_FAIL_COND_V(eof_reached(), Vector<String>()); + l += get_line() + "\n"; qc = 0; for (int i = 0; i < l.length(); i++) { diff --git a/core/os/input.cpp b/core/os/input.cpp index 18d644668c..a90a552d1d 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -28,9 +28,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "input.h" -#include "project_settings.h" #include "input_map.h" #include "os/os.h" +#include "project_settings.h" Input *Input::singleton = NULL; Input *Input::get_singleton() { diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 2f5dc03614..e154b1934d 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -81,7 +81,6 @@ static const _KeyCodeText _keycodes[] = { {KEY_F14 ,"F14"}, {KEY_F15 ,"F15"}, {KEY_F16 ,"F16"}, - {KEY_KP_ENTER ,"Kp Enter"}, {KEY_KP_MULTIPLY ,"Kp Multiply"}, {KEY_KP_DIVIDE ,"Kp Divide"}, {KEY_KP_SUBTRACT ,"Kp Subtract"}, @@ -334,7 +333,6 @@ bool keycode_has_unicode(uint32_t p_keycode) { case KEY_F14: case KEY_F15: case KEY_F16: - case KEY_KP_ENTER: case KEY_SUPER_L: case KEY_SUPER_R: case KEY_MENU: diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 0a72663867..c6985c887d 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -96,7 +96,6 @@ enum KeyList { KEY_F14 = SPKEY | 0x29, KEY_F15 = SPKEY | 0x2A, KEY_F16 = SPKEY | 0x2B, - KEY_KP_ENTER = SPKEY | 0x80, KEY_KP_MULTIPLY = SPKEY | 0x81, KEY_KP_DIVIDE = SPKEY | 0x82, KEY_KP_SUBTRACT = SPKEY | 0x83, diff --git a/core/os/memory.cpp b/core/os/memory.cpp index 069ee48fae..acc960acd9 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "memory.h" #include "copymem.h" +#include "core/safe_refcount.h" #include "error_macros.h" #include <stdio.h> #include <stdlib.h> @@ -43,14 +44,12 @@ void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) { return p_allocfunc(p_size); } -#include <stdio.h> - #ifdef DEBUG_ENABLED -size_t Memory::mem_usage = 0; -size_t Memory::max_usage = 0; +uint64_t Memory::mem_usage = 0; +uint64_t Memory::max_usage = 0; #endif -size_t Memory::alloc_count = 0; +uint64_t Memory::alloc_count = 0; void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) { @@ -62,10 +61,10 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) { void *mem = malloc(p_bytes + (prepad ? PAD_ALIGN : 0)); - alloc_count++; - ERR_FAIL_COND_V(!mem, NULL); + atomic_increment(&alloc_count); + if (prepad) { uint64_t *s = (uint64_t *)mem; *s = p_bytes; @@ -73,10 +72,8 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) { uint8_t *s8 = (uint8_t *)mem; #ifdef DEBUG_ENABLED - mem_usage += p_bytes; - if (mem_usage > max_usage) { - max_usage = mem_usage; - } + atomic_add(&mem_usage, p_bytes); + atomic_exchange_if_greater(&max_usage, mem_usage); #endif return s8 + PAD_ALIGN; } else { @@ -103,8 +100,12 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) { uint64_t *s = (uint64_t *)mem; #ifdef DEBUG_ENABLED - mem_usage -= *s; - mem_usage += p_bytes; + if (p_bytes > *s) { + atomic_add(&mem_usage, p_bytes - *s); + atomic_exchange_if_greater(&max_usage, mem_usage); + } else { + atomic_sub(&mem_usage, *s - p_bytes); + } #endif if (p_bytes == 0) { @@ -144,14 +145,14 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) { bool prepad = p_pad_align; #endif - alloc_count--; + atomic_decrement(&alloc_count); if (prepad) { mem -= PAD_ALIGN; uint64_t *s = (uint64_t *)mem; #ifdef DEBUG_ENABLED - mem_usage -= *s; + atomic_sub(&mem_usage, *s); #endif free(mem); @@ -161,19 +162,20 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) { } } -size_t Memory::get_mem_available() { +uint64_t Memory::get_mem_available() { - return 0xFFFFFFFFFFFFF; + return -1; // 0xFFFF... } -size_t Memory::get_mem_usage() { +uint64_t Memory::get_mem_usage() { #ifdef DEBUG_ENABLED return mem_usage; #else return 0; #endif } -size_t Memory::get_mem_max_usage() { + +uint64_t Memory::get_mem_max_usage() { #ifdef DEBUG_ENABLED return max_usage; #else diff --git a/core/os/memory.h b/core/os/memory.h index b3eb599955..e1d7138ad5 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -45,20 +45,20 @@ class Memory { Memory(); #ifdef DEBUG_ENABLED - static size_t mem_usage; - static size_t max_usage; + static uint64_t mem_usage; + static uint64_t max_usage; #endif - static size_t alloc_count; + static uint64_t alloc_count; public: static void *alloc_static(size_t p_bytes, bool p_pad_align = false); static void *realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align = false); static void free_static(void *p_ptr, bool p_pad_align = false); - static size_t get_mem_available(); - static size_t get_mem_usage(); - static size_t get_mem_max_usage(); + static uint64_t get_mem_available(); + static uint64_t get_mem_usage(); + static uint64_t get_mem_max_usage(); }; class DefaultAllocator { diff --git a/core/os/os.cpp b/core/os/os.cpp index 5a9766891d..8e4c357195 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -512,7 +512,13 @@ bool OS::check_feature_support(const String &p_feature) { return false; } +void *OS::get_stack_bottom() const { + return _stack_bottom; +} + OS::OS() { + void *volatile stack_bottom; + last_error = NULL; singleton = this; _keep_screen_on = true; // set default value to true, because this had been true before godot 2.0. @@ -525,6 +531,7 @@ OS::OS() { _render_thread_mode = RENDER_THREAD_SAFE; _allow_hidpi = true; + _stack_bottom = (void *)(&stack_bottom); } OS::~OS() { diff --git a/core/os/os.h b/core/os/os.h index 362fec8a9e..703c6a6bcd 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -60,6 +60,8 @@ class OS { char *last_error; + void *_stack_bottom; + public: enum RenderThreadMode { @@ -182,9 +184,9 @@ public: virtual void set_ime_position(const Point2 &p_pos) {} - virtual Error open_dynamic_library(const String p_path, void *&p_library_handle) { return ERR_UNAVAILABLE; }; - virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; }; - virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle) { return ERR_UNAVAILABLE; }; + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle) { return ERR_UNAVAILABLE; } + virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; } + virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; } virtual void set_keep_screen_on(bool p_enabled); virtual bool is_keep_screen_on() const; @@ -411,6 +413,13 @@ public: bool check_feature_support(const String &p_feature); + /** + * Returns the stack bottom of the main thread of the application. + * This may be of use when integrating languages with garbage collectors that + * need to check whether a pointer is on the stack. + */ + virtual void *get_stack_bottom() const; + bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); virtual ~OS(); |