diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index 95cd1c4ef7f5717bd9a5b56457baa1dcd753f434..eddc67474cc13c4d83ee508c1f8de665804735e5 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -51,7 +51,7 @@ void ll_init_apr() if(!LLAPRFile::sAPRFilePoolp) { - LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool(FALSE) ; + LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool("Global APR File Pool", FALSE) ; } LLThreadLocalPointerBase::initAllThreadLocalStorage(); @@ -143,8 +143,9 @@ apr_pool_t* LLAPRPool::getAPRPool() return mPool ; } -LLVolatileAPRPool::LLVolatileAPRPool(BOOL is_local, apr_pool_t *parent, apr_size_t size, BOOL releasePoolFlag) +LLVolatileAPRPool::LLVolatileAPRPool(std::string name, BOOL is_local, apr_pool_t *parent, apr_size_t size, BOOL releasePoolFlag) : LLAPRPool(parent, size, releasePoolFlag), + mName(std::move(name)), mNumActiveRef(0), mNumTotalRef(0) { @@ -211,7 +212,7 @@ void LLVolatileAPRPool::clearVolatileAPRPool() } else { - llassert_always(mNumActiveRef > 0) ; + llassert_always_msg(mNumActiveRef > 0, fmt::format(FMT_STRING("Volatile APR Pool '{:s}' attempted to be cleared with {:d} references"), mName, mNumActiveRef)); } llassert(mNumTotalRef <= (FULL_VOLATILE_APR_POOL << 2)) ; @@ -338,7 +339,7 @@ apr_status_t LLAPRFile::close() return ret ; } -apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool, S32* sizep) +apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool, apr_off_t* sizep) { apr_status_t s ; @@ -361,12 +362,12 @@ apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, LLV } else if (sizep) { - S32 file_size = 0; + apr_off_t file_size = 0; apr_off_t offset = 0; if (apr_file_seek(mFile, APR_END, &offset) == APR_SUCCESS) { - llassert_always(offset <= 0x7fffffff); - file_size = (S32)offset; + llassert_always(offset <= std::numeric_limits<apr_off_t>::max()); + file_size = (apr_off_t)offset; offset = 0; apr_file_seek(mFile, APR_SET, &offset); } @@ -404,7 +405,7 @@ apr_status_t LLAPRFile::open(const std::string& filename, apr_int32_t flags, BOO } // File I/O -S32 LLAPRFile::read(void *buf, S32 nbytes) +apr_size_t LLAPRFile::read(void *buf, apr_size_t nbytes) { if(!mFile) { @@ -421,12 +422,12 @@ S32 LLAPRFile::read(void *buf, S32 nbytes) } else { - llassert_always(sz <= 0x7fffffff); - return (S32)sz; + llassert_always(sz <= std::numeric_limits<apr_size_t>::max()); + return (apr_size_t)sz; } } -S32 LLAPRFile::write(const void *buf, S32 nbytes) +apr_size_t LLAPRFile::write(const void *buf, apr_size_t nbytes) { if(!mFile) { @@ -443,12 +444,12 @@ S32 LLAPRFile::write(const void *buf, S32 nbytes) } else { - llassert_always(sz <= 0x7fffffff); - return (S32)sz; + llassert_always(sz <= std::numeric_limits<apr_size_t>::max()); + return (apr_size_t)sz; } } -S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset) +apr_off_t LLAPRFile::seek(apr_seek_where_t where, apr_off_t offset) { return LLAPRFile::seek(mFile, where, offset) ; } @@ -492,7 +493,7 @@ apr_file_t* LLAPRFile::open(const std::string& filename, apr_pool_t* apr_pool, a } //static -S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset) +apr_off_t LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, apr_off_t offset) { if(!file_handle) { @@ -518,13 +519,13 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset) } else { - llassert_always(apr_offset <= 0x7fffffff); - return (S32)apr_offset; + llassert_always(apr_offset <= std::numeric_limits<apr_off_t>::max()); + return apr_offset; } } //static -S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool) +apr_size_t LLAPRFile::readEx(const std::string& filename, void *buf, apr_off_t offset, apr_size_t nbytes, LLVolatileAPRPool* pool) { //***************************************** LLAPRFilePoolScope scope(pool); @@ -557,18 +558,18 @@ S32 LLAPRFile::readEx(const std::string& filename, void *buf, S32 offset, S32 nb } else { - llassert_always(bytes_read <= 0x7fffffff); + llassert_always(bytes_read <= std::numeric_limits<apr_size_t>::max()); } } //***************************************** close(file_handle) ; //***************************************** - return (S32)bytes_read; + return bytes_read; } //static -S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool) +apr_size_t LLAPRFile::writeEx(const std::string& filename, void *buf, apr_off_t offset, apr_size_t nbytes, LLVolatileAPRPool* pool) { apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY; if (offset < 0) @@ -608,7 +609,7 @@ S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 n } else { - llassert_always(bytes_written <= 0x7fffffff); + llassert_always(bytes_written <= std::numeric_limits<apr_size_t>::max()); } } @@ -616,7 +617,7 @@ S32 LLAPRFile::writeEx(const std::string& filename, void *buf, S32 offset, S32 n LLAPRFile::close(file_handle); //***************************************** - return (S32)bytes_written; + return (apr_size_t)bytes_written; } //static @@ -674,7 +675,7 @@ bool LLAPRFile::isExist(const std::string& filename, LLVolatileAPRPool* pool, ap } //static -S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool) +apr_off_t LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool) { apr_file_t* apr_file; apr_finfo_t info; @@ -689,13 +690,13 @@ S32 LLAPRFile::size(const std::string& filename, LLVolatileAPRPool* pool) } else { - apr_status_t s = apr_file_info_get(&info, APR_FINFO_SIZE, apr_file); + s = apr_file_info_get(&info, APR_FINFO_SIZE, apr_file); apr_file_close(apr_file) ; if (s == APR_SUCCESS) { - return (S32)info.size; + return (apr_off_t)info.size; } else { diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index 1e3d922cb306e9a2acd58ff1caa3134fece2cf03..72896fb0529dd420eb1d7a540c86f93e5e9cb768 100644 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -78,7 +78,7 @@ bool LL_COMMON_API ll_apr_is_initialized(); class LL_COMMON_API LLAPRPool { public: - LLAPRPool(apr_pool_t *parent = NULL, apr_size_t size = 0, BOOL releasePoolFlag = TRUE) ; + LLAPRPool(apr_pool_t *parent = nullptr, apr_size_t size = 0, BOOL releasePoolFlag = TRUE) ; virtual ~LLAPRPool() ; virtual apr_pool_t* getAPRPool() ; @@ -101,19 +101,21 @@ class LL_COMMON_API LLAPRPool //which clears memory automatically. //so it can not hold static data or data after memory is cleared // -class LL_COMMON_API LLVolatileAPRPool : public LLAPRPool +class LL_COMMON_API LLVolatileAPRPool final : public LLAPRPool { public: - LLVolatileAPRPool(BOOL is_local = TRUE, apr_pool_t *parent = NULL, apr_size_t size = 0, BOOL releasePoolFlag = TRUE); + LLVolatileAPRPool(std::string name, BOOL is_local = TRUE, apr_pool_t *parent = nullptr, apr_size_t size = 0, BOOL releasePoolFlag = TRUE); virtual ~LLVolatileAPRPool(); - /*virtual*/ apr_pool_t* getAPRPool() ; //define this virtual function to avoid any mistakenly calling LLAPRPool::getAPRPool(). + /*virtual*/ apr_pool_t* getAPRPool() override; //define this virtual function to avoid any mistakenly calling LLAPRPool::getAPRPool(). apr_pool_t* getVolatileAPRPool() ; void clearVolatileAPRPool() ; BOOL isFull() ; private: + std::string mName; + S32 mNumActiveRef ; //number of active pointers pointing to the apr_pool. S32 mNumTotalRef ; //number of total pointers pointing to the apr_pool since last creating. @@ -145,29 +147,32 @@ class LL_COMMON_API LLVolatileAPRPool : public LLAPRPool // 2, a global pool. // -class LL_COMMON_API LLAPRFile : boost::noncopyable +class LL_COMMON_API LLAPRFile { - // make this non copyable since a copy closes the file private: apr_file_t* mFile ; LLVolatileAPRPool *mCurrentFilePoolp ; //currently in use apr_pool, could be one of them: sAPRFilePoolp, or a temp pool. public: LLAPRFile() ; - LLAPRFile(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool = NULL); + LLAPRFile(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool = nullptr); ~LLAPRFile() ; - apr_status_t open(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool = NULL, S32* sizep = NULL); + // make this non copyable since a copy closes the file + LLAPRFile(const LLAPRFile&) = delete; + LLAPRFile& operator=(const LLAPRFile&) = delete; + + apr_status_t open(const std::string& filename, apr_int32_t flags, LLVolatileAPRPool* pool = nullptr, apr_off_t* sizep = nullptr); apr_status_t open(const std::string& filename, apr_int32_t flags, BOOL use_global_pool); //use gAPRPoolp. apr_status_t close() ; // Returns actual offset, -1 if seek fails - S32 seek(apr_seek_where_t where, S32 offset); + apr_off_t seek(apr_seek_where_t where, apr_off_t offset); apr_status_t eof() { return apr_file_eof(mFile);} // Returns bytes read/written, 0 if read/write fails: - S32 read(void* buf, S32 nbytes); - S32 write(const void* buf, S32 nbytes); + apr_size_t read(void* buf, apr_size_t nbytes); + apr_size_t write(const void* buf, apr_size_t nbytes); apr_file_t* getFileHandle() {return mFile;} @@ -181,19 +186,19 @@ class LL_COMMON_API LLAPRFile : boost::noncopyable private: static apr_file_t* open(const std::string& filename, apr_pool_t* apr_pool, apr_int32_t flags); static apr_status_t close(apr_file_t* file) ; - static S32 seek(apr_file_t* file, apr_seek_where_t where, S32 offset); + static apr_off_t seek(apr_file_t* file, apr_seek_where_t where, apr_off_t offset); public: // returns false if failure: - static bool remove(const std::string& filename, LLVolatileAPRPool* pool = NULL); - static bool rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool = NULL); - static bool isExist(const std::string& filename, LLVolatileAPRPool* pool = NULL, apr_int32_t flags = APR_READ); - static S32 size(const std::string& filename, LLVolatileAPRPool* pool = NULL); - static bool makeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL); - static bool removeDir(const std::string& dirname, LLVolatileAPRPool* pool = NULL); + static bool remove(const std::string& filename, LLVolatileAPRPool* pool = nullptr); + static bool rename(const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool = nullptr); + static bool isExist(const std::string& filename, LLVolatileAPRPool* pool = nullptr, apr_int32_t flags = APR_READ); + static apr_off_t size(const std::string& filename, LLVolatileAPRPool* pool = nullptr); + static bool makeDir(const std::string& dirname, LLVolatileAPRPool* pool = nullptr); + static bool removeDir(const std::string& dirname, LLVolatileAPRPool* pool = nullptr); // Returns bytes read/written, 0 if read/write fails: - static S32 readEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); - static S32 writeEx(const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool = NULL); // offset<0 means append + static apr_size_t readEx(const std::string& filename, void *buf, apr_off_t offset, apr_size_t nbytes, LLVolatileAPRPool* pool = nullptr); + static apr_size_t writeEx(const std::string& filename, void *buf, apr_off_t offset, apr_size_t nbytes, LLVolatileAPRPool* pool = nullptr); // offset<0 means append //******************************************************************************************************************************* }; diff --git a/indra/llcommon/llworkerthread.cpp b/indra/llcommon/llworkerthread.cpp index 774fdb83614f25b7d09aa05869969ec46459b51d..62f8283ba84ccbf0bade0add82035669ea8f38d3 100644 --- a/indra/llcommon/llworkerthread.cpp +++ b/indra/llcommon/llworkerthread.cpp @@ -42,7 +42,7 @@ LLWorkerThread::LLWorkerThread(const std::string& name, bool threaded, bool shou if(!mLocalAPRFilePoolp) { - mLocalAPRFilePoolp = new LLVolatileAPRPool() ; + mLocalAPRFilePoolp = new LLVolatileAPRPool(name + " Pool"); } } diff --git a/indra/llfilesystem/lllfsthread.cpp b/indra/llfilesystem/lllfsthread.cpp index be8e83a56f0d39a9b44cbf320e573e528df80b67..b25de41d6c8e9ab64c9974e6821023e1c4c3b2a7 100644 --- a/indra/llfilesystem/lllfsthread.cpp +++ b/indra/llfilesystem/lllfsthread.cpp @@ -70,7 +70,7 @@ LLLFSThread::LLLFSThread(bool threaded) : { if(!mLocalAPRFilePoolp) { - mLocalAPRFilePoolp = new LLVolatileAPRPool() ; + mLocalAPRFilePoolp = new LLVolatileAPRPool("LFS Pool"); } } diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp index 51d4ac331b5a72696879c9bd4ff5201f78df0b09..7a66ff915676d2facca6d26fcf5320b7983e1e2c 100644 --- a/indra/llimage/llimage.cpp +++ b/indra/llimage/llimage.cpp @@ -2161,7 +2161,7 @@ bool LLImageFormatted::load(const std::string &filename, int load_size) { resetLastError(); - S32 file_size = 0; + apr_off_t file_size = 0; LLAPRFile infile ; infile.open(filename, LL_APR_RB, NULL, &file_size); apr_file_t* apr_file = infile.getFileHandle(); diff --git a/indra/llimage/llimagedimensionsinfo.cpp b/indra/llimage/llimagedimensionsinfo.cpp index 0c5e0dc5330fdd21a4a8c16f8b9e1af4916f5a64..ab190c18b3e6f63ce2bd807d4430de07d52e0cd7 100644 --- a/indra/llimage/llimagedimensionsinfo.cpp +++ b/indra/llimage/llimagedimensionsinfo.cpp @@ -41,7 +41,7 @@ bool LLImageDimensionsInfo::load(const std::string& src_filename,U32 codec) mSrcFilename = src_filename; - S32 file_size = 0; + apr_off_t file_size = 0; apr_status_t s = mInfile.open(src_filename, LL_APR_RB, NULL, &file_size); if (s != APR_SUCCESS) @@ -167,22 +167,26 @@ bool LLImageDimensionsInfo::getImageDimensionsWebP() } auto image_size = LLAPRFile::size(mSrcFilename); - auto image_buf = std::make_unique<U8[]>(image_size); - - mInfile.read(image_buf.get(), image_size); - - WebPBitstreamFeatures features; - // Decode the WebP data and extract sizing information - if (WebPGetFeatures(image_buf.get(), image_size, &features) != VP8_STATUS_OK) - { - LL_WARNS() << "Not a WebP" << LL_ENDL; - return false; - } - - mWidth = features.width; - mHeight = features.height; - - return true; + if(image_size > 0) + { + auto image_buf = std::make_unique<U8[]>(image_size); + + mInfile.read(image_buf.get(), image_size); + + WebPBitstreamFeatures features; + // Decode the WebP data and extract sizing information + if (WebPGetFeatures(image_buf.get(), image_size, &features) != VP8_STATUS_OK) + { + LL_WARNS() << "Not a WebP" << LL_ENDL; + return false; + } + + mWidth = features.width; + mHeight = features.height; + + return true; + } + return false; } // Called instead of exit() if Libjpeg encounters an error. diff --git a/indra/llimage/llimagej2c.cpp b/indra/llimage/llimagej2c.cpp index b79319b82b1e9071dbf7c876a5ef92978a8ef86f..30fbffe240bb6d88a2d6afec8f7de7946a83e81b 100644 --- a/indra/llimage/llimagej2c.cpp +++ b/indra/llimage/llimagej2c.cpp @@ -348,7 +348,7 @@ bool LLImageJ2C::loadAndValidate(const std::string &filename) resetLastError(); - S32 file_size = 0; + apr_off_t file_size = 0; LLAPRFile infile ; infile.open(filename, LL_APR_RB, NULL, &file_size); apr_file_t* apr_file = infile.getFileHandle() ; diff --git a/indra/newview/llfloaterbvhpreview.cpp b/indra/newview/llfloaterbvhpreview.cpp index ba975f93526dcae3b9d7f06e97179250e4606a45..be4bd2eeef4a65a79afda3644ea50a5da77e6f89 100644 --- a/indra/newview/llfloaterbvhpreview.cpp +++ b/indra/newview/llfloaterbvhpreview.cpp @@ -230,7 +230,7 @@ BOOL LLFloaterBvhPreview::postBuild() // loading a bvh file // now load bvh file - S32 file_size; + apr_off_t file_size; LLAPRFile infile ; infile.open(mFilenameAndPath, LL_APR_RB, NULL, &file_size); diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp index 9e71129cb0d7e6a9819728b3eec972fbe1917920..05b86d55961a1a1bab3fdb3e0603469838267109 100644 --- a/indra/newview/lltexturecache.cpp +++ b/indra/newview/lltexturecache.cpp @@ -845,7 +845,7 @@ LLTextureCache::LLTextureCache(bool threaded) mFastCachePoolp(NULL), mFastCachePadBuffer(NULL) { - mHeaderAPRFilePoolp = new LLVolatileAPRPool(); // is_local = true, because this pool is for headers, headers are under own mutex + mHeaderAPRFilePoolp = new LLVolatileAPRPool("Texture Cache Pool"); // is_local = true, because this pool is for headers, headers are under own mutex } LLTextureCache::~LLTextureCache() @@ -2175,7 +2175,7 @@ void LLTextureCache::openFastCache(bool first_time) { mFastCachePadBuffer = (U8*)ll_aligned_malloc_16(TEXTURE_FAST_CACHE_ENTRY_SIZE); } - mFastCachePoolp = new LLVolatileAPRPool(FALSE); // is_local=false, thread safe mode due to crashes + mFastCachePoolp = new LLVolatileAPRPool("Fast Cache Pool", FALSE); // is_local=false, thread safe mode due to crashes if (LLAPRFile::isExist(mFastCacheFileName, mFastCachePoolp)) { mFastCachep = new LLAPRFile(mFastCacheFileName, APR_READ|APR_WRITE|APR_BINARY, mFastCachePoolp) ; diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp index 27b6fdfc75d2c5c6d6fab761c8579ea5f221d472..6b6941e529375c1a617efb643105268eef30b4ee 100644 --- a/indra/newview/llviewerassetupload.cpp +++ b/indra/newview/llviewerassetupload.cpp @@ -468,7 +468,7 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile() setAssetType(assetType); // copy this file into the cache for upload - S32 file_size; + apr_off_t file_size; LLAPRFile infile; infile.open(filename, LL_APR_RB, NULL, &file_size); if (infile.getFileHandle()) diff --git a/indra/newview/llvocache.cpp b/indra/newview/llvocache.cpp index c716f51c0b92b75e9ae3312a8593bf58ff1314f6..d1bf50d26c246687a269621b0c1706b73cc48e2c 100644 --- a/indra/newview/llvocache.cpp +++ b/indra/newview/llvocache.cpp @@ -1028,7 +1028,7 @@ LLVOCache::LLVOCache(bool read_only) : mCacheSize(1) { mEnabled = gSavedSettings.getBOOL("ObjectCacheEnabled"); - mLocalAPRFilePoolp = new LLVolatileAPRPool() ; + mLocalAPRFilePoolp = new LLVolatileAPRPool("VOCache Pool") ; } LLVOCache::~LLVOCache()