diff options
author | lloyd <[email protected]> | 2010-10-13 02:20:49 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-13 02:20:49 +0000 |
commit | c00da53d958ef8c266012ae9425337143f14f46e (patch) | |
tree | 144932858569f60d1fbfe2f079638819a123accb /src | |
parent | fe4119c74b5e81a354a5313e4d2efbf9a135aa81 (diff) |
s/u32bit/size_t/ in utils
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/bit_ops.h | 26 | ||||
-rw-r--r-- | src/utils/charset.cpp | 12 | ||||
-rw-r--r-- | src/utils/cpuid.cpp | 2 | ||||
-rw-r--r-- | src/utils/cpuid.h | 4 | ||||
-rw-r--r-- | src/utils/exceptn.h | 4 | ||||
-rw-r--r-- | src/utils/get_byte.h | 2 | ||||
-rw-r--r-- | src/utils/mlock.cpp | 4 | ||||
-rw-r--r-- | src/utils/mlock.h | 4 | ||||
-rw-r--r-- | src/utils/parsing.cpp | 38 | ||||
-rw-r--r-- | src/utils/parsing.h | 2 | ||||
-rw-r--r-- | src/utils/prefetch.h | 12 |
11 files changed, 55 insertions, 55 deletions
diff --git a/src/utils/bit_ops.h b/src/utils/bit_ops.h index 36bac9f73..af7f07a05 100644 --- a/src/utils/bit_ops.h +++ b/src/utils/bit_ops.h @@ -30,9 +30,9 @@ inline bool power_of_2(T arg) * @return index of the highest set bit in n */ template<typename T> -inline u32bit high_bit(T n) +inline size_t high_bit(T n) { - for(u32bit i = 8*sizeof(T); i > 0; --i) + for(size_t i = 8*sizeof(T); i > 0; --i) if((n >> (i - 1)) & 0x01) return i; return 0; @@ -45,9 +45,9 @@ inline u32bit high_bit(T n) * @return index of the lowest set bit in n */ template<typename T> -inline u32bit low_bit(T n) +inline size_t low_bit(T n) { - for(u32bit i = 0; i != 8*sizeof(T); ++i) + for(size_t i = 0; i != 8*sizeof(T); ++i) if((n >> i) & 0x01) return (i + 1); return 0; @@ -59,11 +59,11 @@ inline u32bit low_bit(T n) * @return number of significant bytes in n */ template<typename T> -inline u32bit significant_bytes(T n) +inline size_t significant_bytes(T n) { - for(u32bit j = 0; j != sizeof(T); ++j) - if(get_byte(j, n)) - return sizeof(T)-j; + for(size_t i = 0; i != sizeof(T); ++i) + if(get_byte(i, n)) + return sizeof(T)-i; return 0; } @@ -73,13 +73,13 @@ inline u32bit significant_bytes(T n) * @return number of bits in n set to 1 */ template<typename T> -inline u32bit hamming_weight(T n) +inline size_t hamming_weight(T n) { const byte NIBBLE_WEIGHTS[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; - u32bit weight = 0; - for(u32bit i = 0; i != 2*sizeof(T); ++i) + size_t weight = 0; + for(size_t i = 0; i != 2*sizeof(T); ++i) weight += NIBBLE_WEIGHTS[(n >> (4*i)) & 0x0F]; return weight; } @@ -90,9 +90,9 @@ inline u32bit hamming_weight(T n) * @return maximum x st 2^x divides n */ template<typename T> -inline u32bit ctz(T n) +inline size_t ctz(T n) { - for(u32bit i = 0; i != 8*sizeof(T); ++i) + for(size_t i = 0; i != 8*sizeof(T); ++i) if((n >> i) & 0x01) return i; return 8*sizeof(T); diff --git a/src/utils/charset.cpp b/src/utils/charset.cpp index 53125cad1..8e20e6492 100644 --- a/src/utils/charset.cpp +++ b/src/utils/charset.cpp @@ -26,10 +26,10 @@ std::string ucs2_to_latin1(const std::string& ucs2) std::string latin1; - for(u32bit j = 0; j != ucs2.size(); j += 2) + for(size_t i = 0; i != ucs2.size(); i += 2) { - const byte c1 = ucs2[j]; - const byte c2 = ucs2[j+1]; + const byte c1 = ucs2[i]; + const byte c2 = ucs2[i+1]; if(c1 != 0) throw Decoding_Error("UCS-2 has non-Latin1 characters"); @@ -47,7 +47,7 @@ std::string utf8_to_latin1(const std::string& utf8) { std::string iso8859; - u32bit position = 0; + size_t position = 0; while(position != utf8.size()) { const byte c1 = static_cast<byte>(utf8[position++]); @@ -80,9 +80,9 @@ std::string utf8_to_latin1(const std::string& utf8) std::string latin1_to_utf8(const std::string& iso8859) { std::string utf8; - for(u32bit j = 0; j != iso8859.size(); ++j) + for(size_t i = 0; i != iso8859.size(); ++i) { - const byte c = static_cast<byte>(iso8859[j]); + const byte c = static_cast<byte>(iso8859[i]); if(c <= 0x7F) utf8 += static_cast<char>(c); diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp index 40b27863e..c34a99942 100644 --- a/src/utils/cpuid.cpp +++ b/src/utils/cpuid.cpp @@ -48,7 +48,7 @@ namespace Botan { u64bit CPUID::x86_processor_flags = 0; -u32bit CPUID::cache_line = 32; +size_t CPUID::cache_line = 32; bool CPUID::altivec_capable = false; namespace { diff --git a/src/utils/cpuid.h b/src/utils/cpuid.h index 6cb4092bb..863ba5b63 100644 --- a/src/utils/cpuid.h +++ b/src/utils/cpuid.h @@ -26,7 +26,7 @@ class BOTAN_DLL CPUID /** * Return a best guess of the cache line size */ - static u32bit cache_line_size() { return cache_line; } + static size_t cache_line_size() { return cache_line; } /** * Check if the processor supports RDTSC @@ -105,7 +105,7 @@ class BOTAN_DLL CPUID } static u64bit x86_processor_flags; - static u32bit cache_line; + static size_t cache_line; static bool altivec_capable; }; diff --git a/src/utils/exceptn.h b/src/utils/exceptn.h index ef7b451bf..1177a4e7d 100644 --- a/src/utils/exceptn.h +++ b/src/utils/exceptn.h @@ -54,7 +54,7 @@ struct BOTAN_DLL Internal_Error : public Exception */ struct BOTAN_DLL Invalid_Key_Length : public Invalid_Argument { - Invalid_Key_Length(const std::string& name, u32bit length) : + Invalid_Key_Length(const std::string& name, size_t length) : Invalid_Argument(name + " cannot accept a key of length " + to_string(length)) {} @@ -77,7 +77,7 @@ struct BOTAN_DLL Invalid_Block_Size : public Invalid_Argument */ struct BOTAN_DLL Invalid_IV_Length : public Invalid_Argument { - Invalid_IV_Length(const std::string& mode, u32bit bad_len) : + Invalid_IV_Length(const std::string& mode, size_t bad_len) : Invalid_Argument("IV length " + to_string(bad_len) + " is invalid for " + mode) {} diff --git a/src/utils/get_byte.h b/src/utils/get_byte.h index 7eedbd783..6f8ef2632 100644 --- a/src/utils/get_byte.h +++ b/src/utils/get_byte.h @@ -18,7 +18,7 @@ namespace Botan { * @param input the value to extract from * @return byte byte_num of input */ -template<typename T> inline byte get_byte(u32bit byte_num, T input) +template<typename T> inline byte get_byte(size_t byte_num, T input) { return static_cast<byte>( input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3) diff --git a/src/utils/mlock.cpp b/src/utils/mlock.cpp index ce5ae8aed..cd92860df 100644 --- a/src/utils/mlock.cpp +++ b/src/utils/mlock.cpp @@ -28,7 +28,7 @@ bool has_mlock() /* * Lock an area of memory into RAM */ -bool lock_mem(void* ptr, u32bit bytes) +bool lock_mem(void* ptr, size_t bytes) { #if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK) return (::mlock((char*)ptr, bytes) == 0); @@ -42,7 +42,7 @@ bool lock_mem(void* ptr, u32bit bytes) /* * Unlock a previously locked region of memory */ -void unlock_mem(void* ptr, u32bit bytes) +void unlock_mem(void* ptr, size_t bytes) { #if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK) ::munlock((char*)ptr, bytes); diff --git a/src/utils/mlock.h b/src/utils/mlock.h index fea56d438..88788472d 100644 --- a/src/utils/mlock.h +++ b/src/utils/mlock.h @@ -23,14 +23,14 @@ bool has_mlock(); * @param length the length of the memory block in bytes * @returns true if successful, false otherwise */ -bool lock_mem(void* addr, u32bit length); +bool lock_mem(void* addr, size_t length); /** * Unlock memory locked with lock_mem() * @param addr the start of the memory block * @param length the length of the memory block in bytes */ -void unlock_mem(void* addr, u32bit length); +void unlock_mem(void* addr, size_t length); } diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp index e8259ac52..f46e2687d 100644 --- a/src/utils/parsing.cpp +++ b/src/utils/parsing.cpp @@ -19,14 +19,14 @@ u32bit to_u32bit(const std::string& number) { u32bit n = 0; - for(std::string::const_iterator j = number.begin(); j != number.end(); ++j) + for(std::string::const_iterator i = number.begin(); i != number.end(); ++i) { const u32bit OVERFLOW_MARK = 0xFFFFFFFF / 10; - if(*j == ' ') + if(*i == ' ') continue; - byte digit = Charset::char2digit(*j); + byte digit = Charset::char2digit(*i); if((n > OVERFLOW_MARK) || (n == OVERFLOW_MARK && digit > 5)) throw Decoding_Error("to_u32bit: Integer overflow"); @@ -39,7 +39,7 @@ u32bit to_u32bit(const std::string& number) /* * Convert an integer into a string */ -std::string to_string(u64bit n, u32bit min_len) +std::string to_string(u64bit n, size_t min_len) { std::string lenstr; if(n) @@ -101,20 +101,20 @@ std::vector<std::string> parse_algorithm_name(const std::string& namex) std::string name = namex, substring; std::vector<std::string> elems; - u32bit level = 0; + size_t level = 0; elems.push_back(name.substr(0, name.find('('))); name = name.substr(name.find('(')); - for(std::string::const_iterator j = name.begin(); j != name.end(); ++j) + for(std::string::const_iterator i = name.begin(); i != name.end(); ++i) { - char c = *j; + char c = *i; if(c == '(') ++level; if(c == ')') { - if(level == 1 && j == name.end() - 1) + if(level == 1 && i == name.end() - 1) { if(elems.size() == 1) elems.push_back(substring.substr(1)); @@ -123,7 +123,7 @@ std::vector<std::string> parse_algorithm_name(const std::string& namex) return elems; } - if(level == 0 || (level == 1 && j != name.end() - 1)) + if(level == 0 || (level == 1 && i != name.end() - 1)) throw Invalid_Algorithm_Name(namex); --level; } @@ -155,16 +155,16 @@ std::vector<std::string> split_on(const std::string& str, char delim) if(str == "") return elems; std::string substr; - for(std::string::const_iterator j = str.begin(); j != str.end(); ++j) + for(std::string::const_iterator i = str.begin(); i != str.end(); ++i) { - if(*j == delim) + if(*i == delim) { if(substr != "") elems.push_back(substr); substr.clear(); } else - substr += *j; + substr += *i; } if(substr == "") @@ -182,9 +182,9 @@ std::vector<u32bit> parse_asn1_oid(const std::string& oid) std::string substring; std::vector<u32bit> oid_elems; - for(std::string::const_iterator j = oid.begin(); j != oid.end(); ++j) + for(std::string::const_iterator i = oid.begin(); i != oid.end(); ++i) { - char c = *j; + char c = *i; if(c == '.') { @@ -258,9 +258,9 @@ u32bit string_to_ipv4(const std::string& str) u32bit ip = 0; - for(size_t j = 0; j != parts.size(); j++) + for(size_t i = 0; i != parts.size(); i++) { - u32bit octet = to_u32bit(parts[j]); + u32bit octet = to_u32bit(parts[i]); if(octet > 255) throw Decoding_Error("Invalid IP string " + str); @@ -278,11 +278,11 @@ std::string ipv4_to_string(u32bit ip) { std::string str; - for(size_t j = 0; j != sizeof(ip); j++) + for(size_t i = 0; i != sizeof(ip); i++) { - if(j) + if(i) str += "."; - str += to_string(get_byte(j, ip)); + str += to_string(get_byte(i, ip)); } return str; diff --git a/src/utils/parsing.h b/src/utils/parsing.h index cafdd146b..12370bf2b 100644 --- a/src/utils/parsing.h +++ b/src/utils/parsing.h @@ -53,7 +53,7 @@ BOTAN_DLL bool x500_name_cmp(const std::string& name1, * @param min_len the min length of the output string * @return n convert to a string */ -BOTAN_DLL std::string to_string(u64bit n, u32bit min_len= 0); +BOTAN_DLL std::string to_string(u64bit n, size_t min_len = 0); /** * Convert a string to a number diff --git a/src/utils/prefetch.h b/src/utils/prefetch.h index 4928c44a0..66024e5ce 100644 --- a/src/utils/prefetch.h +++ b/src/utils/prefetch.h @@ -13,23 +13,23 @@ namespace Botan { template<typename T> -inline void prefetch_readonly(const T* addr, u32bit length) +inline void prefetch_readonly(const T* addr, size_t length) { #if defined(__GNUG__) - const u32bit Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T); + const size_t Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T); - for(u32bit i = 0; i <= length; i += Ts_per_cache_line) + for(size_t i = 0; i <= length; i += Ts_per_cache_line) __builtin_prefetch(addr + i, 0); #endif } template<typename T> -inline void prefetch_readwrite(const T* addr, u32bit length) +inline void prefetch_readwrite(const T* addr, size_t length) { #if defined(__GNUG__) - const u32bit Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T); + const size_t Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T); - for(u32bit i = 0; i <= length; i += Ts_per_cache_line) + for(size_t i = 0; i <= length; i += Ts_per_cache_line) __builtin_prefetch(addr + i, 1); #endif } |