diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2019-03-26 18:51:13 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2021-05-17 15:06:19 +0200 |
commit | 469fa47e0646d8f2ca3237dede8a04568039c7c6 (patch) | |
tree | 2efd036166f999a84e303cde32f91c4f9cf212e9 /platform | |
parent | 9cc17a8439d4909324da014a1d2e90cfaa9fb979 (diff) |
Make all file access 64-bit (uint64_t)
This changes the types of a big number of variables.
General rules:
- Using `uint64_t` in general. We also considered `int64_t` but eventually
settled on keeping it unsigned, which is also closer to what one would expect
with `size_t`/`off_t`.
- We only keep `int64_t` for `seek_end` (takes a negative offset from the end)
and for the `Variant` bindings, since `Variant::INT` is `int64_t`. This means
we only need to guard against passing negative values in `core_bind.cpp`.
- Using `uint32_t` integers for concepts not needing such a huge range, like
pages, blocks, etc.
In addition:
- Improve usage of integer types in some related places; namely, `DirAccess`,
core binds.
Note:
- On Windows, `_ftelli64` reports invalid values when using 32-bit MinGW with
version < 8.0. This was an upstream bug fixed in 8.0. It breaks support for
big files on 32-bit Windows builds made with that toolchain. We might add a
workaround.
Fixes #44363.
Fixes godotengine/godot-proposals#400.
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/detect.py | 3 | ||||
-rw-r--r-- | platform/android/dir_access_jandroid.cpp | 3 | ||||
-rw-r--r-- | platform/android/dir_access_jandroid.h | 3 | ||||
-rw-r--r-- | platform/android/file_access_android.cpp | 12 | ||||
-rw-r--r-- | platform/android/file_access_android.h | 12 | ||||
-rw-r--r-- | platform/javascript/api/javascript_tools_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | platform/javascript/export/export.cpp | 4 | ||||
-rw-r--r-- | platform/linuxbsd/detect.py | 1 | ||||
-rw-r--r-- | platform/osx/display_server_osx.mm | 2 | ||||
-rw-r--r-- | platform/osx/export/export.cpp | 2 |
10 files changed, 23 insertions, 21 deletions
diff --git a/platform/android/detect.py b/platform/android/detect.py index 2a80a3c45b..8808b032a6 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -285,6 +285,9 @@ def configure(env): ) env.Append(CPPDEFINES=["NO_STATVFS", "GLES_ENABLED"]) + if get_platform(env["ndk_platform"]) >= 24: + env.Append(CPPDEFINES=[("_FILE_OFFSET_BITS", 64)]) + env["neon_enabled"] = False if env["android_arch"] == "x86": target_opts = ["-target", "i686-none-linux-android"] diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index f8ac29c738..0bae090702 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -201,8 +201,7 @@ String DirAccessJAndroid::get_filesystem_type() const { return "APK"; } -//FileType get_file_type() const; -size_t DirAccessJAndroid::get_space_left() { +uint64_t DirAccessJAndroid::get_space_left() { return 0; } diff --git a/platform/android/dir_access_jandroid.h b/platform/android/dir_access_jandroid.h index fed468d051..fe87644fe2 100644 --- a/platform/android/dir_access_jandroid.h +++ b/platform/android/dir_access_jandroid.h @@ -76,8 +76,7 @@ public: virtual String get_filesystem_type() const; - //virtual FileType get_file_type() const; - size_t get_space_left(); + uint64_t get_space_left(); static void setup(jobject p_io); diff --git a/platform/android/file_access_android.cpp b/platform/android/file_access_android.cpp index 705891713f..900d4d9b20 100644 --- a/platform/android/file_access_android.cpp +++ b/platform/android/file_access_android.cpp @@ -71,8 +71,9 @@ bool FileAccessAndroid::is_open() const { return a != nullptr; } -void FileAccessAndroid::seek(size_t p_position) { +void FileAccessAndroid::seek(uint64_t p_position) { ERR_FAIL_COND(!a); + AAsset_seek(a, p_position, SEEK_SET); pos = p_position; if (pos > len) { @@ -89,11 +90,11 @@ void FileAccessAndroid::seek_end(int64_t p_position) { pos = len + p_position; } -size_t FileAccessAndroid::get_position() const { +uint64_t FileAccessAndroid::get_position() const { return pos; } -size_t FileAccessAndroid::get_len() const { +uint64_t FileAccessAndroid::get_len() const { return len; } @@ -113,11 +114,10 @@ uint8_t FileAccessAndroid::get_8() const { return byte; } -int FileAccessAndroid::get_buffer(uint8_t *p_dst, int p_length) const { +uint64_t FileAccessAndroid::get_buffer(uint8_t *p_dst, uint64_t p_length) const { ERR_FAIL_COND_V(!p_dst && p_length > 0, -1); - ERR_FAIL_COND_V(p_length < 0, -1); - off_t r = AAsset_read(a, p_dst, p_length); + int r = AAsset_read(a, p_dst, p_length); if (pos + p_length > len) { eof = true; diff --git a/platform/android/file_access_android.h b/platform/android/file_access_android.h index 56010c918a..9b0f85089d 100644 --- a/platform/android/file_access_android.h +++ b/platform/android/file_access_android.h @@ -40,8 +40,8 @@ class FileAccessAndroid : public FileAccess { static FileAccess *create_android(); mutable AAsset *a = nullptr; - mutable size_t len = 0; - mutable size_t pos = 0; + mutable uint64_t len = 0; + mutable uint64_t pos = 0; mutable bool eof = false; public: @@ -51,15 +51,15 @@ public: virtual void close(); ///< close a file virtual bool is_open() const; ///< true when file is open - virtual void seek(size_t p_position); ///< seek to a given position + virtual void seek(uint64_t p_position); ///< seek to a given position virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file - virtual size_t get_position() const; ///< get position in the file - virtual size_t get_len() const; ///< get size of the file + virtual uint64_t get_position() const; ///< get position in the file + virtual uint64_t get_len() const; ///< get size of the file virtual bool eof_reached() const; ///< reading passed EOF virtual uint8_t get_8() const; ///< get a byte - virtual int get_buffer(uint8_t *p_dst, int p_length) const; + virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const; virtual Error get_error() const; ///< get last error diff --git a/platform/javascript/api/javascript_tools_editor_plugin.cpp b/platform/javascript/api/javascript_tools_editor_plugin.cpp index 7a2c2b2335..015440f5be 100644 --- a/platform/javascript/api/javascript_tools_editor_plugin.cpp +++ b/platform/javascript/api/javascript_tools_editor_plugin.cpp @@ -79,7 +79,7 @@ void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, z return; } Vector<uint8_t> data; - int len = f->get_len(); + uint64_t len = f->get_len(); data.resize(len); f->get_buffer(data.ptrw(), len); f->close(); diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 951d86d09e..e398072312 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -170,8 +170,8 @@ public: while (true) { uint8_t bytes[4096]; - int read = f->get_buffer(bytes, 4096); - if (read < 1) { + uint64_t read = f->get_buffer(bytes, 4096); + if (read == 0) { break; } err = peer->put_data(bytes, read); diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py index 1876960c57..ee59537ee0 100644 --- a/platform/linuxbsd/detect.py +++ b/platform/linuxbsd/detect.py @@ -363,6 +363,7 @@ def configure(env): env.Prepend(CPPPATH=["#platform/linuxbsd"]) env.Append(CPPDEFINES=["X11_ENABLED", "UNIX_ENABLED"]) + env.Append(CPPDEFINES=[("_FILE_OFFSET_BITS", 64)]) env.Append(CPPDEFINES=["VULKAN_ENABLED"]) if not env["builtin_vulkan"]: diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 473ae95036..0a232357b5 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -3467,7 +3467,7 @@ void DisplayServerOSX::set_native_icon(const String &p_filename) { ERR_FAIL_COND(!f); Vector<uint8_t> data; - uint32_t len = f->get_len(); + uint64_t len = f->get_len(); data.resize(len); f->get_buffer((uint8_t *)&data.write[0], len); memdelete(f); diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 51204bc8f6..a7868efaa8 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -312,7 +312,7 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_ } int ofs = data.size(); - uint32_t len = f->get_len(); + uint64_t len = f->get_len(); data.resize(data.size() + len + 8); f->get_buffer(&data.write[ofs + 8], len); memdelete(f); |