Merge branch 'blender-v4.0-release'

This commit is contained in:
Campbell Barton
2023-10-10 14:57:00 +11:00
7 changed files with 39 additions and 29 deletions

View File

@@ -183,15 +183,12 @@ PackedFile *BKE_packedfile_new_from_memory(void *mem, int memlen)
PackedFile *BKE_packedfile_new(ReportList *reports, const char *filepath_rel, const char *basepath)
{
PackedFile *pf = nullptr;
int file, filelen;
char filepath[FILE_MAX];
void *data;
/* render result has no filepath and can be ignored
* any other files with no name can be ignored too */
if (filepath_rel[0] == '\0') {
return pf;
return nullptr;
}
// XXX waitcursor(1);
@@ -204,31 +201,34 @@ PackedFile *BKE_packedfile_new(ReportList *reports, const char *filepath_rel, co
/* open the file
* and create a PackedFile structure */
file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
if (file == -1) {
BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path '%s' not found", filepath);
return nullptr;
}
PackedFile *pf = nullptr;
const size_t file_size = BLI_file_descriptor_size(file);
if (file_size == size_t(-1)) {
BKE_reportf(reports, RPT_ERROR, "Unable to access the size of, source path '%s'", filepath);
}
else if (file_size > INT_MAX) {
BKE_reportf(reports, RPT_ERROR, "Unable to pack files over 2gb, source path '%s'", filepath);
}
else {
filelen = BLI_file_descriptor_size(file);
if (filelen == 0) {
/* MEM_mallocN complains about MEM_mallocN(0, "bla");
* we don't care.... */
data = MEM_mallocN(1, "packFile");
}
else {
data = MEM_mallocN(filelen, "packFile");
}
if (read(file, data, filelen) == filelen) {
pf = BKE_packedfile_new_from_memory(data, filelen);
/* #MEM_mallocN complains about `MEM_mallocN(0, "...")`,
* a single allocation is harmless and doesn't cause any complications. */
void *data = MEM_mallocN(std::max(file_size, size_t(1)), "packFile");
if (read(file, data, file_size) == file_size) {
pf = BKE_packedfile_new_from_memory(data, file_size);
}
else {
MEM_freeN(data);
}
close(file);
}
close(file);
// XXX waitcursor(0);
return pf;

View File

@@ -323,11 +323,11 @@ size_t BLI_file_unzstd_to_mem_at_pos(void *buf, size_t len, FILE *file, size_t f
bool BLI_file_magic_is_zstd(const char header[4]);
/**
* Returns the file size of an opened file descriptor.
* Returns the file size of an opened file descriptor or `size_t(-1)` on failure.
*/
size_t BLI_file_descriptor_size(int file) ATTR_WARN_UNUSED_RESULT;
/**
* Returns the size of a file.
* Returns the size of a file or `size_t(-1)` on failure..
*/
size_t BLI_file_size(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();

View File

@@ -709,7 +709,7 @@ static uchar *prefetch_read_file_to_memory(
}
const size_t size = BLI_file_descriptor_size(file);
if (size < 1) {
if (UNLIKELY(ELEM(size, 0, size_t(-1)))) {
close(file);
return nullptr;
}

View File

@@ -1308,7 +1308,6 @@ static uchar *proxy_thread_next_frame(ProxyQueue *queue,
if (!*queue->stop && queue->cfra <= queue->efra) {
MovieClipUser user = *DNA_struct_default_get(MovieClipUser);
char filepath[FILE_MAX];
size_t size;
int file;
user.framenr = queue->cfra;
@@ -1321,8 +1320,8 @@ static uchar *proxy_thread_next_frame(ProxyQueue *queue,
return nullptr;
}
size = BLI_file_descriptor_size(file);
if (size < 1) {
const size_t size = BLI_file_descriptor_size(file);
if (UNLIKELY(ELEM(size, 0, size_t(-1)))) {
close(file);
BLI_spin_unlock(&queue->spin);
return nullptr;

View File

@@ -153,12 +153,18 @@ class IMMapStream : public Imf::IStream {
public:
IMMapStream(const char *filepath) : IStream(filepath)
{
int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
if (file < 0) {
throw IEX_NAMESPACE::InputExc("file not found");
}
const size_t file_size = BLI_file_descriptor_size(file);
if (UNLIKELY(file_size == size_t(-1))) {
close(file);
throw IEX_NAMESPACE::InputExc("file size could not be accessed");
}
_exrpos = 0;
_exrsize = BLI_file_descriptor_size(file);
_exrsize = file_size;
imb_mmap_lock();
_mmap_file = BLI_mmap_open(file);
imb_mmap_unlock();

View File

@@ -119,13 +119,15 @@ ImBuf *IMB_loadifffile(int file, int flags, char colorspace[IM_MAX_SPACE], const
{
ImBuf *ibuf;
uchar *mem;
size_t size;
if (file == -1) {
return nullptr;
}
size = BLI_file_descriptor_size(file);
const size_t size = BLI_file_descriptor_size(file);
if (size == size_t(-1)) {
return nullptr;
}
imb_mmap_lock();
BLI_mmap_file *mmap_file = BLI_mmap_open(file);

View File

@@ -89,6 +89,9 @@ ImBuf *imb_load_filepath_thumbnail_webp(const char *filepath,
}
const size_t data_size = BLI_file_descriptor_size(file);
if (UNLIKELY(data_size == size_t(-1))) {
return nullptr;
}
imb_mmap_lock();
BLI_mmap_file *mmap_file = BLI_mmap_open(file);