[Bf-blender-cvs] [7ba82f3f0a8] master: Fix T62707: opening blend files over 2gb on win32 fails

Campbell Barton noreply at git.blender.org
Tue Mar 19 10:18:37 CET 2019


Commit: 7ba82f3f0a848aedcc0f3b3f73a429f740792dbe
Author: Campbell Barton
Date:   Tue Mar 19 20:04:23 2019 +1100
Branches: master
https://developer.blender.org/rB7ba82f3f0a848aedcc0f3b3f73a429f740792dbe

Fix T62707: opening blend files over 2gb on win32 fails

Regression in 358e07f447e9ed7 for ms-windows since off_t is an int32_t
even on 64bit systems causing files over 2gb not to load.

Poison off_t so this doesn't happen again.

===================================================================

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 93ef7fe5b73..b8131c8abbb 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -264,7 +264,7 @@ typedef struct BHeadN {
 	struct BHeadN *next, *prev;
 #ifdef USE_BHEAD_READ_ON_DEMAND
 	/** Use to read the data from the file directly into memory as needed. */
-	off_t file_offset;
+	off64_t file_offset;
 	/** When set, the remainder of this allocation is the data, otherwise it needs to be read. */
 	bool has_data;
 #endif
@@ -838,7 +838,7 @@ static BHeadN *get_bhead(FileData *fd)
 					new_bhead->file_offset = fd->file_offset;
 					new_bhead->has_data = false;
 					new_bhead->bhead = bhead;
-					off_t seek_new = fd->seek(fd, bhead.len, SEEK_CUR);
+					off64_t seek_new = fd->seek(fd, bhead.len, SEEK_CUR);
 					if (seek_new == -1) {
 						fd->is_eof = true;
 						MEM_freeN(new_bhead);
@@ -946,7 +946,7 @@ static bool blo_bhead_read_data(FileData *fd, BHead *thisblock, void *buf)
 	bool success = true;
 	BHeadN *new_bhead = BHEADN_FROM_BHEAD(thisblock);
 	BLI_assert(new_bhead->has_data == false && new_bhead->file_offset != 0);
-	off_t offset_backup = fd->file_offset;
+	off64_t offset_backup = fd->file_offset;
 	if (UNLIKELY(fd->seek(fd, new_bhead->file_offset, SEEK_SET) == -1)) {
 		success = false;
 	}
@@ -1136,7 +1136,7 @@ static int fd_read_data_from_file(FileData *filedata, void *buffer, uint size)
 	return (readsize);
 }
 
-static off_t fd_seek_data_from_file(FileData *filedata, off_t offset, int whence)
+static off64_t fd_seek_data_from_file(FileData *filedata, off64_t offset, int whence)
 {
 	filedata->file_offset = lseek(filedata->filedes, offset, whence);
 	return filedata->file_offset;
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 9e970b9ae5d..a1af4bfad16 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -48,10 +48,17 @@ enum eFileDataFlag {
 	FD_FLAGS_NOT_MY_LIBMAP         = 1 << 5,
 };
 
+/* Disallow since it's 32bit on ms-windows. */
+#ifdef __GNUC__
+#  pragma GCC poison off_t
+#endif
 
+#if defined(_MSC_VER)
+typedef int64_t off64_t;
+#endif
 
 typedef int (FileDataReadFn)(struct FileData *filedata, void *buffer, unsigned int size);
-typedef off_t (FileDataSeekFn)(struct FileData *filedata, off_t offset, int whence);
+typedef off64_t (FileDataSeekFn)(struct FileData *filedata, off64_t offset, int whence);
 
 typedef struct FileData {
 	/** Linked list of BHeadN's. */
@@ -59,7 +66,7 @@ typedef struct FileData {
 	enum eFileDataFlag flags;
 	bool is_eof;
 	int buffersize;
-	off_t file_offset;
+	int64_t file_offset;
 
 	FileDataReadFn *read;
 	FileDataSeekFn *seek;



More information about the Bf-blender-cvs mailing list