From 62d7f3d59f5c4b00402282de450e0a86eadbf37e Mon Sep 17 00:00:00 2001 From: Shyotl Date: Tue, 15 Mar 2011 02:28:22 -0500 Subject: [PATCH] Misc llcommon tidbits from v2. --- indra/llcharacter/llcharacter.h | 4 ++-- indra/llcommon/lldarray.h | 2 +- indra/llcommon/llerrorlegacy.h | 17 +++++++++-------- indra/llcommon/llfile.cpp | 11 +++++++++++ indra/llcommon/llfile.h | 2 ++ indra/llcommon/llmd5.cpp | 29 +++++++++++++++++++++-------- indra/llcommon/llmd5.h | 8 ++++++-- indra/llcommon/llsdserialize.cpp | 2 +- indra/llcommon/lluri.cpp | 18 +++++++++++++++--- 9 files changed, 68 insertions(+), 25 deletions(-) diff --git a/indra/llcharacter/llcharacter.h b/indra/llcharacter/llcharacter.h index 06c4e5ff4..4de59e9ee 100644 --- a/indra/llcharacter/llcharacter.h +++ b/indra/llcharacter/llcharacter.h @@ -246,9 +246,9 @@ public: return rtn; } - LLVisualParam* getVisualParam(S32 id) + LLVisualParam* getVisualParam(S32 id) const { - visual_param_index_map_t::iterator iter = mVisualParamIndexMap.find(id); + visual_param_index_map_t::const_iterator iter = mVisualParamIndexMap.find(id); return (iter == mVisualParamIndexMap.end()) ? 0 : iter->second; } S32 getVisualParamID(LLVisualParam *id) diff --git a/indra/llcommon/lldarray.h b/indra/llcommon/lldarray.h index aee136363..5433e8d72 100644 --- a/indra/llcommon/lldarray.h +++ b/indra/llcommon/lldarray.h @@ -202,7 +202,7 @@ public: { U32 n = mVector.size(); mIndexMap[k] = n; - mVector.resize(n+1); + mVector.push_back(Type()); llassert(mVector.size() == mIndexMap.size()); return mVector[n]; } diff --git a/indra/llcommon/llerrorlegacy.h b/indra/llcommon/llerrorlegacy.h index 143fe2018..fc563dc09 100644 --- a/indra/llcommon/llerrorlegacy.h +++ b/indra/llcommon/llerrorlegacy.h @@ -75,6 +75,10 @@ const int LL_ERR_PRICE_MISMATCH = -23018; #define SHOW_ASSERT #else // _DEBUG +#ifdef LL_RELEASE_WITH_DEBUG_INFO +#define SHOW_ASSERT +#endif // LL_RELEASE_WITH_DEBUG_INFO + #ifdef RELEASE_SHOW_DEBUG #define SHOW_DEBUG #endif @@ -103,17 +107,14 @@ const int LL_ERR_PRICE_MISMATCH = -23018; #define llwarning(msg, num) llwarns << "Warning # " << num << ": " << msg << llendl; -#ifdef SHOW_ASSERT -#define llassert(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl; -#else -#define llassert(func) -#endif -#define llassert_always(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl; +#define llassert_always(func) if (LL_UNLIKELY(!(func))) llerrs << "ASSERT (" << #func << ")" << llendl; #ifdef SHOW_ASSERT -#define llverify(func) if (!(func)) llerrs << "ASSERT (" << #func << ")" << llendl; +#define llassert(func) llassert_always(func) +#define llverify(func) llassert_always(func) #else -#define llverify(func) (func); // get rid of warning C4189 +#define llassert(func) +#define llverify(func) do {if (func) {}} while(0) #endif // handy compile-time assert - enforce those template parameters! diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index 71a2df48f..d3e97f5c1 100644 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -98,6 +98,17 @@ LLFILE* LLFile::_fsopen(const std::string& filename, const char* mode, int shari #endif } +int LLFile::close(LLFILE * file) +{ + int ret_value = 0; + if (file) + { + ret_value = fclose(file); + } + return ret_value; +} + + int LLFile::remove(const std::string& filename) { #if LL_WINDOWS diff --git a/indra/llcommon/llfile.h b/indra/llcommon/llfile.h index ee376054b..8b28d77bd 100644 --- a/indra/llcommon/llfile.h +++ b/indra/llcommon/llfile.h @@ -77,6 +77,8 @@ public: static LLFILE* fopen(const std::string& filename,const char* accessmode); /* Flawfinder: ignore */ static LLFILE* _fsopen(const std::string& filename,const char* accessmode,int sharingFlag); + static int close(LLFILE * file); + // perms is a permissions mask like 0777 or 0700. In most cases it will // be overridden by the user's umask. It is ignored on Windows. static int mkdir(const std::string& filename, int perms = 0700); diff --git a/indra/llcommon/llmd5.cpp b/indra/llcommon/llmd5.cpp index 887979bbf..35067b3b3 100644 --- a/indra/llcommon/llmd5.cpp +++ b/indra/llcommon/llmd5.cpp @@ -192,9 +192,10 @@ void LLMD5::update(std::istream& stream){ } - - - +void LLMD5::update(const std::string& s) +{ + update((unsigned char *)s.c_str(),s.length()); +} // MD5 finalization. Ends an MD5 message-digest operation, writing the // the message digest and zeroizing the context. @@ -277,7 +278,7 @@ LLMD5::LLMD5(const unsigned char *s) finalize(); } -void LLMD5::raw_digest(unsigned char *s) +void LLMD5::raw_digest(unsigned char *s) const { if (!finalized) { @@ -293,7 +294,7 @@ void LLMD5::raw_digest(unsigned char *s) -void LLMD5::hex_digest(char *s) +void LLMD5::hex_digest(char *s) const { int i; @@ -327,13 +328,25 @@ std::ostream& operator<<(std::ostream &stream, LLMD5 context) return stream; } +bool operator==(const LLMD5& a, const LLMD5& b) +{ + unsigned char a_guts[16]; + unsigned char b_guts[16]; + a.raw_digest(a_guts); + b.raw_digest(b_guts); + if (memcmp(a_guts,b_guts,16)==0) + return true; + else + return false; +} - +bool operator!=(const LLMD5& a, const LLMD5& b) +{ + return !(a==b); +} // PRIVATE METHODS: - - void LLMD5::init(){ finalized=0; // we just started! diff --git a/indra/llcommon/llmd5.h b/indra/llcommon/llmd5.h index df9d7324a..837dd3e5a 100644 --- a/indra/llcommon/llmd5.h +++ b/indra/llcommon/llmd5.h @@ -95,6 +95,7 @@ public: void update (const uint1 *input, const uint4 input_length); void update (std::istream& stream); void update (FILE *file); + void update (const std::string& str); void finalize (); // constructors for special circumstances. All these constructors finalize @@ -105,8 +106,8 @@ public: LLMD5 (const unsigned char *string, const unsigned int number); // methods to acquire finalized result - void raw_digest(unsigned char *array); // provide 16-byte array for binary data - void hex_digest(char *string); // provide 33-byte array for ascii-hex string + void raw_digest(unsigned char *array) const; // provide 16-byte array for binary data + void hex_digest(char *string) const; // provide 33-byte array for ascii-hex string friend std::ostream& operator<< (std::ostream&, LLMD5 context); @@ -131,4 +132,7 @@ private: }; +LL_COMMON_API bool operator==(const LLMD5& a, const LLMD5& b); +LL_COMMON_API bool operator!=(const LLMD5& a, const LLMD5& b); + #endif // LL_LLMD5_H diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp index 9f4ce64d2..48423934c 100644 --- a/indra/llcommon/llsdserialize.cpp +++ b/indra/llcommon/llsdserialize.cpp @@ -77,7 +77,7 @@ void LLSDSerialize::serialize(const LLSD& sd, std::ostream& str, ELLSD_Serialize break; default: - llwarns << "serialize request for unkown ELLSD_Serialize" << llendl; + llwarns << "serialize request for unknown ELLSD_Serialize" << llendl; } if (f.notNull()) diff --git a/indra/llcommon/lluri.cpp b/indra/llcommon/lluri.cpp index 3dbc83787..673afd460 100644 --- a/indra/llcommon/lluri.cpp +++ b/indra/llcommon/lluri.cpp @@ -46,10 +46,21 @@ void encode_character(std::ostream& ostr, std::string::value_type val) { - ostr << "%" << std::uppercase << std::hex << std::setw(2) << std::setfill('0') + ostr << "%" + + << std::uppercase + << std::hex + << std::setw(2) + << std::setfill('0') + // VWR-4010 Cannot cast to U32 because sign-extension on // chars > 128 will result in FFFFFFC3 instead of F3. - << static_cast(static_cast(val)); + << static_cast(static_cast(val)) + + // reset stream state + << std::nouppercase + << std::dec + << std::setfill(' '); } // static @@ -221,7 +232,8 @@ static BOOL isDefault(const std::string& scheme, U16 port) void LLURI::parseAuthorityAndPathUsingOpaque() { if (mScheme == "http" || mScheme == "https" || - mScheme == "ftp" || mScheme == "secondlife" ) + mScheme == "ftp" || mScheme == "secondlife" || + mScheme == "x-grid-location-info") { if (mEscapedOpaque.substr(0,2) != "//") {