Update to 7-Zip Version 22.00

See: https://sourceforge.net/p/sevenzip/discussion/45797/thread/9c2d9061ce/
This commit is contained in:
Tino Reichardt
2022-08-07 09:59:33 +02:00
parent 6a4fe97fc3
commit 57558682a8
211 changed files with 15251 additions and 2482 deletions

View File

@@ -35,7 +35,7 @@ you can change this h file or h files included in this file.
So we can use MY_ARRAY_NEW macro instead of new[] operator. */
#if defined(_MSC_VER) && (_MSC_VER == 1200) && !defined(_WIN64)
#define MY_ARRAY_NEW(p, T, size) p = new T[(size > (unsigned)0xFFFFFFFF / sizeof(T)) ? (unsigned)0xFFFFFFFF / sizeof(T) : size];
#define MY_ARRAY_NEW(p, T, size) p = new T[((size) > (unsigned)0xFFFFFFFF / sizeof(T)) ? (unsigned)0xFFFFFFFF / sizeof(T) : (size)];
#else
#define MY_ARRAY_NEW(p, T, size) p = new T[size];
#endif

View File

@@ -67,6 +67,7 @@ public:
template <class Q>
HRESULT QueryInterface(REFGUID iid, Q** pp) const throw()
{
// if (*pp) throw 20220216; // for debug
return _p->QueryInterface(iid, (void**)pp);
}
};

View File

@@ -3,6 +3,18 @@
#ifndef __MY_LIN_LINUX_H
#define __MY_LIN_LINUX_H
// #include "../../C/7zTypes.h"
#define MY_LIN_DT_UNKNOWN 0
#define MY_LIN_DT_FIFO 1
#define MY_LIN_DT_CHR 2
#define MY_LIN_DT_DIR 4
#define MY_LIN_DT_BLK 6
#define MY_LIN_DT_REG 8
#define MY_LIN_DT_LNK 10
#define MY_LIN_DT_SOCK 12
#define MY_LIN_DT_WHT 14
#define MY_LIN_S_IFMT 00170000
#define MY_LIN_S_IFSOCK 0140000
#define MY_LIN_S_IFLNK 0120000
@@ -39,4 +51,25 @@
#define MY_LIN_S_IWOTH 00002
#define MY_LIN_S_IXOTH 00001
/*
// major/minor encoding for makedev(): MMMMMmmmmmmMMMmm:
inline UInt32 MY_dev_major(UInt64 dev)
{
return ((UInt32)(dev >> 8) & (UInt32)0xfff) | ((UInt32)(dev >> 32) & ~(UInt32)0xfff);
}
inline UInt32 MY_dev_minor(UInt64 dev)
{
return ((UInt32)(dev) & 0xff) | ((UInt32)(dev >> 12) & ~0xff);
}
inline UInt64 MY_dev_makedev(UInt32 __major, UInt32 __minor)
{
return (__minor & 0xff) | ((__major & 0xfff) << 8)
| ((UInt64) (__minor & ~0xff) << 12)
| ((UInt64) (__major & ~0xfff) << 32);
}
*/
#endif

View File

@@ -30,8 +30,8 @@ inline const char* MyStringGetNextCharPointer(const char *p) throw()
}
*/
#define MY_STRING_NEW_char(_size_) MY_STRING_NEW(char, _size_)
#define MY_STRING_NEW_wchar_t(_size_) MY_STRING_NEW(wchar_t, _size_)
#define MY_STRING_NEW_char(_size_) MY_STRING_NEW(char, (_size_))
#define MY_STRING_NEW_wchar_t(_size_) MY_STRING_NEW(wchar_t, (_size_))
int FindCharPosInString(const char *s, char c) throw()
@@ -190,8 +190,8 @@ bool IsString1PrefixedByString2(const char *s1, const char *s2) throw()
{
for (;;)
{
unsigned char c2 = (unsigned char)*s2++; if (c2 == 0) return true;
unsigned char c1 = (unsigned char)*s1++; if (c1 != c2) return false;
const unsigned char c2 = (unsigned char)*s2++; if (c2 == 0) return true;
const unsigned char c1 = (unsigned char)*s1++; if (c1 != c2) return false;
}
}
@@ -199,8 +199,8 @@ bool StringsAreEqualNoCase(const wchar_t *s1, const wchar_t *s2) throw()
{
for (;;)
{
wchar_t c1 = *s1++;
wchar_t c2 = *s2++;
const wchar_t c1 = *s1++;
const wchar_t c2 = *s2++;
if (c1 != c2 && MyCharUpper(c1) != MyCharUpper(c2)) return false;
if (c1 == 0) return true;
}
@@ -213,10 +213,10 @@ bool AString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw()
const char *s1 = _chars;
for (;;)
{
char c2 = *s++;
const char c2 = *s++;
if (c2 == 0)
return true;
char c1 = *s1++;
const char c1 = *s1++;
if (MyCharLower_Ascii(c1) !=
MyCharLower_Ascii(c2))
return false;
@@ -228,10 +228,10 @@ bool UString::IsPrefixedBy_Ascii_NoCase(const char *s) const throw()
const wchar_t *s1 = _chars;
for (;;)
{
char c2 = *s++;
const char c2 = *s++;
if (c2 == 0)
return true;
wchar_t c1 = *s1++;
const wchar_t c1 = *s1++;
if (MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2))
return false;
}
@@ -241,7 +241,7 @@ bool StringsAreEqual_Ascii(const char *u, const char *a) throw()
{
for (;;)
{
char c = *a;
const char c = *a;
if (c != *u)
return false;
if (c == 0)
@@ -255,7 +255,7 @@ bool StringsAreEqual_Ascii(const wchar_t *u, const char *a) throw()
{
for (;;)
{
unsigned char c = (unsigned char)*a;
const unsigned char c = (unsigned char)*a;
if (c != *u)
return false;
if (c == 0)
@@ -269,8 +269,8 @@ bool StringsAreEqualNoCase_Ascii(const char *s1, const char *s2) throw()
{
for (;;)
{
char c1 = *s1++;
char c2 = *s2++;
const char c1 = *s1++;
const char c2 = *s2++;
if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2))
return false;
if (c1 == 0)
@@ -282,8 +282,8 @@ bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const wchar_t *s2) throw()
{
for (;;)
{
wchar_t c1 = *s1++;
wchar_t c2 = *s2++;
const wchar_t c1 = *s1++;
const wchar_t c2 = *s2++;
if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2))
return false;
if (c1 == 0)
@@ -295,8 +295,8 @@ bool StringsAreEqualNoCase_Ascii(const wchar_t *s1, const char *s2) throw()
{
for (;;)
{
wchar_t c1 = *s1++;
char c2 = *s2++;
const wchar_t c1 = *s1++;
const char c2 = *s2++;
if (c1 != (unsigned char)c2 && (c1 > 0x7F || MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2)))
return false;
if (c1 == 0)
@@ -308,8 +308,8 @@ bool IsString1PrefixedByString2(const wchar_t *s1, const wchar_t *s2) throw()
{
for (;;)
{
wchar_t c2 = *s2++; if (c2 == 0) return true;
wchar_t c1 = *s1++; if (c1 != c2) return false;
const wchar_t c2 = *s2++; if (c2 == 0) return true;
const wchar_t c1 = *s1++; if (c1 != c2) return false;
}
}
@@ -317,8 +317,8 @@ bool IsString1PrefixedByString2(const wchar_t *s1, const char *s2) throw()
{
for (;;)
{
unsigned char c2 = (unsigned char)(*s2++); if (c2 == 0) return true;
wchar_t c1 = *s1++; if (c1 != c2) return false;
const unsigned char c2 = (unsigned char)(*s2++); if (c2 == 0) return true;
const wchar_t c1 = *s1++; if (c1 != c2) return false;
}
}
@@ -326,8 +326,8 @@ bool IsString1PrefixedByString2_NoCase_Ascii(const char *s1, const char *s2) thr
{
for (;;)
{
char c2 = *s2++; if (c2 == 0) return true;
char c1 = *s1++;
const char c2 = *s2++; if (c2 == 0) return true;
const char c1 = *s1++;
if (c1 != c2 && MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2))
return false;
}
@@ -337,8 +337,8 @@ bool IsString1PrefixedByString2_NoCase_Ascii(const wchar_t *s1, const char *s2)
{
for (;;)
{
char c2 = *s2++; if (c2 == 0) return true;
wchar_t c1 = *s1++;
const char c2 = *s2++; if (c2 == 0) return true;
const wchar_t c1 = *s1++;
if (c1 != (unsigned char)c2 && MyCharLower_Ascii(c1) != (unsigned char)MyCharLower_Ascii(c2))
return false;
}
@@ -348,8 +348,8 @@ bool IsString1PrefixedByString2_NoCase(const wchar_t *s1, const wchar_t *s2) thr
{
for (;;)
{
wchar_t c2 = *s2++; if (c2 == 0) return true;
wchar_t c1 = *s1++;
const wchar_t c2 = *s2++; if (c2 == 0) return true;
const wchar_t c1 = *s1++;
if (c1 != c2 && MyCharUpper(c1) != MyCharUpper(c2))
return false;
}
@@ -360,12 +360,12 @@ int MyStringCompareNoCase(const wchar_t *s1, const wchar_t *s2) throw()
{
for (;;)
{
wchar_t c1 = *s1++;
wchar_t c2 = *s2++;
const wchar_t c1 = *s1++;
const wchar_t c2 = *s2++;
if (c1 != c2)
{
wchar_t u1 = MyCharUpper(c1);
wchar_t u2 = MyCharUpper(c2);
const wchar_t u1 = MyCharUpper(c1);
const wchar_t u2 = MyCharUpper(c2);
if (u1 < u2) return -1;
if (u1 > u2) return 1;
}
@@ -401,14 +401,13 @@ void AString::InsertSpace(unsigned &index, unsigned size)
MoveItems(index + size, index);
}
#define k_Alloc_Len_Limit 0x40000000
#define k_Alloc_Len_Limit (0x40000000 - 2)
void AString::ReAlloc(unsigned newLimit)
{
if (newLimit < _len || newLimit >= k_Alloc_Len_Limit) throw 20130220;
// MY_STRING_REALLOC(_chars, char, newLimit + 1, _len + 1);
char *newBuf = MY_STRING_NEW_char(newLimit + 1);
memcpy(newBuf, _chars, (size_t)(_len + 1));
// MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, (size_t)_len + 1);
char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1);
memcpy(newBuf, _chars, (size_t)_len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = newLimit;
@@ -416,9 +415,9 @@ void AString::ReAlloc(unsigned newLimit)
void AString::ReAlloc2(unsigned newLimit)
{
if (newLimit >= k_Alloc_Len_Limit) throw 20130220;
// MY_STRING_REALLOC(_chars, char, newLimit + 1, 0);
char *newBuf = MY_STRING_NEW_char(newLimit + 1);
if (newLimit > k_Alloc_Len_Limit) throw 20130220;
// MY_STRING_REALLOC(_chars, char, (size_t)newLimit + 1, 0);
char *newBuf = MY_STRING_NEW_char((size_t)newLimit + 1);
newBuf[0] = 0;
MY_STRING_DELETE(_chars);
_chars = newBuf;
@@ -427,8 +426,8 @@ void AString::ReAlloc2(unsigned newLimit)
void AString::SetStartLen(unsigned len)
{
_chars = 0;
_chars = MY_STRING_NEW_char(len + 1);
_chars = NULL;
_chars = MY_STRING_NEW_char((size_t)len + 1);
_len = len;
_limit = len;
}
@@ -439,20 +438,30 @@ void AString::Grow_1()
next += next / 2;
next += 16;
next &= ~(unsigned)15;
ReAlloc(next - 1);
next--;
if (next < _len || next > k_Alloc_Len_Limit)
next = k_Alloc_Len_Limit;
if (next <= _len)
throw 20130220;
ReAlloc(next);
// Grow(1);
}
void AString::Grow(unsigned n)
{
unsigned freeSize = _limit - _len;
const unsigned freeSize = _limit - _len;
if (n <= freeSize)
return;
unsigned next = _len + n;
next += next / 2;
next += 16;
next &= ~(unsigned)15;
ReAlloc(next - 1);
next--;
if (next < _len || next > k_Alloc_Len_Limit)
next = k_Alloc_Len_Limit;
if (next <= _len || next - _len < n)
throw 20130220;
ReAlloc(next);
}
AString::AString(unsigned num, const char *s)
@@ -500,7 +509,7 @@ static const unsigned kStartStringCapacity = 4;
AString::AString()
{
_chars = 0;
_chars = NULL;
_chars = MY_STRING_NEW_char(kStartStringCapacity);
_len = 0;
_limit = kStartStringCapacity - 1;
@@ -548,7 +557,7 @@ AString &AString::operator=(const char *s)
unsigned len = MyStringLen(s);
if (len > _limit)
{
char *newBuf = MY_STRING_NEW_char(len + 1);
char *newBuf = MY_STRING_NEW_char((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -565,7 +574,7 @@ AString &AString::operator=(const AString &s)
unsigned len = s._len;
if (len > _limit)
{
char *newBuf = MY_STRING_NEW_char(len + 1);
char *newBuf = MY_STRING_NEW_char((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -590,7 +599,7 @@ void AString::SetFromWStr_if_Ascii(const wchar_t *s)
}
if (len > _limit)
{
char *newBuf = MY_STRING_NEW_char(len + 1);
char *newBuf = MY_STRING_NEW_char((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -614,7 +623,7 @@ void AString::SetFromBstr_if_Ascii(BSTR s)
}
if (len > _limit)
{
char *newBuf = MY_STRING_NEW_char(len + 1);
char *newBuf = MY_STRING_NEW_char((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -631,6 +640,7 @@ void AString::SetFromBstr_if_Ascii(BSTR s)
void AString::Add_Space() { operator+=(' '); }
void AString::Add_Space_if_NotEmpty() { if (!IsEmpty()) Add_Space(); }
void AString::Add_LF() { operator+=('\n'); }
void AString::Add_Slash() { operator+=('/'); }
AString &AString::operator+=(const char *s)
{
@@ -667,11 +677,23 @@ void UString::Add_UInt64(UInt64 v)
_len = (unsigned)(ConvertUInt64ToString(v, _chars + _len) - _chars);
}
void AString::AddFrom(const char *s, unsigned len) // no check
{
if (len != 0)
{
Grow(len);
memcpy(_chars + _len, s, len);
len += _len;
_chars[len] = 0;
_len = len;
}
}
void AString::SetFrom(const char *s, unsigned len) // no check
{
if (len > _limit)
{
char *newBuf = MY_STRING_NEW_char(len + 1);
char *newBuf = MY_STRING_NEW_char((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -976,9 +998,8 @@ void UString::InsertSpace(unsigned index, unsigned size)
void UString::ReAlloc(unsigned newLimit)
{
if (newLimit < _len || newLimit >= k_Alloc_Len_Limit) throw 20130221;
// MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, _len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t(newLimit + 1);
// MY_STRING_REALLOC(_chars, wchar_t, (size_t)newLimit + 1, (size_t)_len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1);
wmemcpy(newBuf, _chars, _len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
@@ -987,9 +1008,9 @@ void UString::ReAlloc(unsigned newLimit)
void UString::ReAlloc2(unsigned newLimit)
{
if (newLimit >= k_Alloc_Len_Limit) throw 20130221;
if (newLimit > k_Alloc_Len_Limit) throw 20130221;
// MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0);
wchar_t *newBuf = MY_STRING_NEW_wchar_t(newLimit + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)newLimit + 1);
newBuf[0] = 0;
MY_STRING_DELETE(_chars);
_chars = newBuf;
@@ -999,7 +1020,7 @@ void UString::ReAlloc2(unsigned newLimit)
void UString::SetStartLen(unsigned len)
{
_chars = 0;
_chars = MY_STRING_NEW_wchar_t(len + 1);
_chars = MY_STRING_NEW_wchar_t((size_t)len + 1);
_len = len;
_limit = len;
}
@@ -1010,19 +1031,28 @@ void UString::Grow_1()
next += next / 2;
next += 16;
next &= ~(unsigned)15;
ReAlloc(next - 1);
next--;
if (next < _len || next > k_Alloc_Len_Limit)
next = k_Alloc_Len_Limit;
if (next <= _len)
throw 20130220;
ReAlloc(next);
}
void UString::Grow(unsigned n)
{
unsigned freeSize = _limit - _len;
const unsigned freeSize = _limit - _len;
if (n <= freeSize)
return;
unsigned next = _len + n;
next += next / 2;
next += 16;
next &= ~(unsigned)15;
next--;
if (next < _len || next > k_Alloc_Len_Limit)
next = k_Alloc_Len_Limit;
if (next <= _len || next - _len < n)
throw 20130220;
ReAlloc(next - 1);
}
@@ -1149,7 +1179,7 @@ UString &UString::operator=(const wchar_t *s)
unsigned len = MyStringLen(s);
if (len > _limit)
{
wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -1166,7 +1196,7 @@ UString &UString::operator=(const UString &s)
unsigned len = s._len;
if (len > _limit)
{
wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -1180,7 +1210,7 @@ void UString::SetFrom(const wchar_t *s, unsigned len) // no check
{
if (len > _limit)
{
wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -1218,7 +1248,7 @@ void UString::SetFromBstr(LPCOLESTR s)
if (len > _limit)
{
wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -1258,7 +1288,7 @@ UString &UString::operator=(const char *s)
unsigned len = MyStringLen(s);
if (len > _limit)
{
wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1);
MY_STRING_DELETE(_chars);
_chars = newBuf;
_limit = len;
@@ -1566,15 +1596,24 @@ void UString::DeleteFrontal(unsigned num) throw()
void UString2::ReAlloc2(unsigned newLimit)
{
if (newLimit >= k_Alloc_Len_Limit) throw 20130221;
// wrong (_len) is allowed after this function
if (newLimit > k_Alloc_Len_Limit) throw 20130221;
// MY_STRING_REALLOC(_chars, wchar_t, newLimit + 1, 0);
_chars = MY_STRING_NEW_wchar_t(newLimit + 1);
if (_chars)
{
MY_STRING_DELETE(_chars);
_chars = NULL;
// _len = 0;
}
_chars = MY_STRING_NEW_wchar_t((size_t)newLimit + 1);
_chars[0] = 0;
// _len = newLimit;
}
void UString2::SetStartLen(unsigned len)
{
_chars = 0;
_chars = MY_STRING_NEW_wchar_t(len + 1);
_chars = NULL;
_chars = MY_STRING_NEW_wchar_t((size_t)len + 1);
_len = len;
}
@@ -1591,7 +1630,7 @@ UString2::UString2(wchar_t c)
UString2::UString2(const wchar_t *s)
{
unsigned len = MyStringLen(s);
const unsigned len = MyStringLen(s);
SetStartLen(len);
wmemcpy(_chars, s, len + 1);
}
@@ -1628,7 +1667,7 @@ UString2 &UString2::operator=(const wchar_t *s)
unsigned len = MyStringLen(s);
if (len > _len)
{
wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1);
if (_chars)
MY_STRING_DELETE(_chars);
_chars = newBuf;
@@ -1643,7 +1682,7 @@ void UString2::SetFromAscii(const char *s)
unsigned len = MyStringLen(s);
if (len > _len)
{
wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1);
if (_chars)
MY_STRING_DELETE(_chars);
_chars = newBuf;
@@ -1662,7 +1701,7 @@ UString2 &UString2::operator=(const UString2 &s)
unsigned len = s._len;
if (len > _len)
{
wchar_t *newBuf = MY_STRING_NEW_wchar_t(len + 1);
wchar_t *newBuf = MY_STRING_NEW_wchar_t((size_t)len + 1);
if (_chars)
MY_STRING_DELETE(_chars);
_chars = newBuf;

View File

@@ -378,6 +378,7 @@ public:
void Add_Space_if_NotEmpty();
void Add_OptSpaced(const char *s);
void Add_LF();
void Add_Slash();
void Add_PathSepar() { operator+=(CHAR_PATH_SEPARATOR); }
AString &operator+=(const char *s);
@@ -386,12 +387,12 @@ public:
void Add_UInt32(UInt32 v);
void Add_UInt64(UInt64 v);
void AddFrom(const char *s, unsigned len); // no check
void SetFrom(const char *s, unsigned len); // no check
void SetFrom_CalcLen(const char *s, unsigned len);
AString Mid(unsigned startIndex, unsigned count) const { return AString(count, _chars + startIndex); }
AString Left(unsigned count) const { return AString(count, *this); }
// void MakeUpper() { MyStringUpper(_chars); }
// void MakeLower() { MyStringLower(_chars); }
void MakeLower_Ascii() { MyStringLower_Ascii(_chars); }

View File

@@ -5,6 +5,8 @@
#include <string.h>
const unsigned k_VectorSizeMax = ((unsigned)1 << 31) - 1;
template <class T>
class CRecordVector
{
@@ -17,31 +19,41 @@ class CRecordVector
memmove(_items + destIndex, _items + srcIndex, (size_t)(_size - srcIndex) * sizeof(T));
}
void ReserveOnePosition()
void ReAllocForNewCapacity(const unsigned newCapacity)
{
if (_size == _capacity)
{
unsigned newCapacity = _capacity + (_capacity >> 2) + 1;
T *p;
MY_ARRAY_NEW(p, T, newCapacity);
// p = new T[newCapacity];
if (_size != 0)
memcpy(p, _items, (size_t)_size * sizeof(T));
delete []_items;
_items = p;
_capacity = newCapacity;
}
T *p;
MY_ARRAY_NEW(p, T, newCapacity);
// p = new T[newCapacity];
if (_size != 0)
memcpy(p, _items, (size_t)_size * sizeof(T));
delete []_items;
_items = p;
_capacity = newCapacity;
}
public:
void ReserveOnePosition()
{
if (_size != _capacity)
return;
if (_capacity >= k_VectorSizeMax)
throw 2021;
const unsigned rem = k_VectorSizeMax - _capacity;
unsigned add = (_capacity >> 2) + 1;
if (add > rem)
add = rem;
ReAllocForNewCapacity(_capacity + add);
}
CRecordVector(): _items(NULL), _size(0), _capacity(0) {}
CRecordVector(const CRecordVector &v): _items(0), _size(0), _capacity(0)
CRecordVector(const CRecordVector &v): _items(NULL), _size(0), _capacity(0)
{
unsigned size = v.Size();
const unsigned size = v.Size();
if (size != 0)
{
// MY_ARRAY_NEW(_items, T, size)
_items = new T[size];
_size = size;
_capacity = size;
@@ -66,22 +78,25 @@ public:
{
if (newCapacity > _capacity)
{
T *p;
MY_ARRAY_NEW(p, T, newCapacity);
// p = new T[newCapacity];
if (_size != 0)
memcpy(p, _items, (size_t)_size * sizeof(T));
delete []_items;
_items = p;
_capacity = newCapacity;
if (newCapacity > k_VectorSizeMax)
throw 2021;
ReAllocForNewCapacity(newCapacity);
}
}
void ChangeSize_KeepData(unsigned newSize)
{
Reserve(newSize);
_size = newSize;
}
void ClearAndReserve(unsigned newCapacity)
{
Clear();
if (newCapacity > _capacity)
{
if (newCapacity > k_VectorSizeMax)
throw 2021;
delete []_items;
_items = NULL;
_capacity = 0;
@@ -97,22 +112,6 @@ public:
_size = newSize;
}
void ChangeSize_KeepData(unsigned newSize)
{
if (newSize > _capacity)
{
T *p;
MY_ARRAY_NEW(p, T, newSize)
// p = new T[newSize];
if (_size != 0)
memcpy(p, _items, (size_t)_size * sizeof(T));
delete []_items;
_items = p;
_capacity = newSize;
}
_size = newSize;
}
void ReserveDown()
{
if (_size == _capacity)
@@ -120,6 +119,7 @@ public:
T *p = NULL;
if (_size != 0)
{
// MY_ARRAY_NEW(p, T, _size)
p = new T[_size];
memcpy(p, _items, (size_t)_size * sizeof(T));
}
@@ -178,7 +178,7 @@ public:
{
if (&v == this)
return *this;
unsigned size = v.Size();
const unsigned size = v.Size();
if (size > _capacity)
{
delete []_items;
@@ -196,24 +196,45 @@ public:
CRecordVector& operator+=(const CRecordVector &v)
{
unsigned size = v.Size();
Reserve(_size + size);
const unsigned size = v.Size();
if (size != 0)
{
if (_size >= k_VectorSizeMax || size > k_VectorSizeMax - _size)
throw 2021;
const unsigned newSize = _size + size;
Reserve(newSize);
memcpy(_items + _size, v._items, (size_t)size * sizeof(T));
_size += size;
_size = newSize;
}
return *this;
}
unsigned Add(const T item)
{
ReserveOnePosition();
_items[_size] = item;
return _size++;
const unsigned size = _size;
_size = size + 1;
_items[size] = item;
return size;
}
void AddInReserved(const T item)
/*
unsigned Add2(const T &item)
{
_items[_size++] = item;
ReserveOnePosition();
const unsigned size = _size;
_size = size + 1;
_items[size] = item;
return size;
}
*/
unsigned AddInReserved(const T item)
{
const unsigned size = _size;
_size = size + 1;
_items[size] = item;
return size;
}
void Insert(unsigned index, const T item)
@@ -224,6 +245,13 @@ public:
_size++;
}
void InsertInReserved(unsigned index, const T item)
{
MoveItems(index + 1, index);
_items[index] = item;
_size++;
}
void MoveToFront(unsigned index)
{
if (index != 0)
@@ -254,7 +282,8 @@ public:
{
while (left != right)
{
unsigned mid = (left + right) / 2;
// const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
const unsigned mid = (left + right) / 2;
const T midVal = (*this)[mid];
if (item == midVal)
return (int)mid;
@@ -270,9 +299,10 @@ public:
{
while (left != right)
{
unsigned mid = (left + right) / 2;
// const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
const unsigned mid = (left + right) / 2;
const T& midVal = (*this)[mid];
int comp = item.Compare(midVal);
const int comp = item.Compare(midVal);
if (comp == 0)
return (int)mid;
if (comp < 0)
@@ -298,7 +328,8 @@ public:
unsigned left = 0, right = _size;
while (left != right)
{
unsigned mid = (left + right) / 2;
// const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
const unsigned mid = (left + right) / 2;
const T midVal = (*this)[mid];
if (item == midVal)
return mid;
@@ -316,9 +347,10 @@ public:
unsigned left = 0, right = _size;
while (left != right)
{
unsigned mid = (left + right) / 2;
// const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
const unsigned mid = (left + right) / 2;
const T& midVal = (*this)[mid];
int comp = item.Compare(midVal);
const int comp = item.Compare(midVal);
if (comp == 0)
return mid;
if (comp < 0)
@@ -431,29 +463,35 @@ public:
CObjectVector() {}
CObjectVector(const CObjectVector &v)
{
unsigned size = v.Size();
const unsigned size = v.Size();
_v.ConstructReserve(size);
for (unsigned i = 0; i < size; i++)
_v.AddInReserved(new T(v[i]));
AddInReserved(v[i]);
}
CObjectVector& operator=(const CObjectVector &v)
{
if (&v == this)
return *this;
Clear();
unsigned size = v.Size();
const unsigned size = v.Size();
_v.Reserve(size);
for (unsigned i = 0; i < size; i++)
_v.AddInReserved(new T(v[i]));
AddInReserved(v[i]);
return *this;
}
CObjectVector& operator+=(const CObjectVector &v)
{
unsigned size = v.Size();
_v.Reserve(Size() + size);
for (unsigned i = 0; i < size; i++)
_v.AddInReserved(new T(v[i]));
const unsigned addSize = v.Size();
if (addSize != 0)
{
const unsigned size = Size();
if (size >= k_VectorSizeMax || addSize > k_VectorSizeMax - size)
throw 2021;
_v.Reserve(size + addSize);
for (unsigned i = 0; i < addSize; i++)
AddInReserved(v[i]);
}
return *this;
}
@@ -466,14 +504,37 @@ public:
void MoveToFront(unsigned index) { _v.MoveToFront(index); }
unsigned Add(const T& item) { return _v.Add(new T(item)); }
unsigned Add(const T& item)
{
_v.ReserveOnePosition();
return AddInReserved(item);
}
unsigned AddInReserved(const T& item)
{
return _v.AddInReserved(new T(item));
}
void ReserveOnePosition()
{
_v.ReserveOnePosition();
}
unsigned AddInReserved_Ptr_of_new(T *ptr)
{
return _v.AddInReserved(ptr);
}
#define VECTOR_ADD_NEW_OBJECT(v, a) \
(v).ReserveOnePosition(); \
(v).AddInReserved_Ptr_of_new(new a);
void AddInReserved(const T& item) { _v.AddInReserved(new T(item)); }
T& AddNew()
{
_v.ReserveOnePosition();
T *p = new T;
_v.Add(p);
_v.AddInReserved(p);
return *p;
}
@@ -484,12 +545,17 @@ public:
return *p;
}
void Insert(unsigned index, const T& item) { _v.Insert(index, new T(item)); }
void Insert(unsigned index, const T& item)
{
_v.ReserveOnePosition();
_v.InsertInReserved(index, new T(item));
}
T& InsertNew(unsigned index)
{
_v.ReserveOnePosition();
T *p = new T;
_v.Insert(index, p);
_v.InsertInReserved(index, p);
return *p;
}
@@ -514,7 +580,7 @@ public:
void DeleteFrom(unsigned index)
{
unsigned size = _v.Size();
const unsigned size = _v.Size();
for (unsigned i = index; i < size; i++)
delete (T *)_v[i];
_v.DeleteFrom(index);
@@ -564,9 +630,10 @@ public:
unsigned left = 0, right = Size();
while (left != right)
{
unsigned mid = (left + right) / 2;
// const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
const unsigned mid = (left + right) / 2;
const T& midVal = (*this)[mid];
int comp = item.Compare(midVal);
const int comp = item.Compare(midVal);
if (comp == 0)
return (int)mid;
if (comp < 0)
@@ -582,9 +649,10 @@ public:
unsigned left = 0, right = Size();
while (left != right)
{
unsigned mid = (left + right) / 2;
// const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
const unsigned mid = (left + right) / 2;
const T& midVal = (*this)[mid];
int comp = item.Compare(midVal);
const int comp = item.Compare(midVal);
if (comp == 0)
return mid;
if (comp < 0)
@@ -602,9 +670,10 @@ public:
unsigned left = 0, right = Size();
while (left != right)
{
unsigned mid = (left + right) / 2;
// const unsigned mid = (unsigned)(((size_t)left + (size_t)right) / 2);
const unsigned mid = (left + right) / 2;
const T& midVal = (*this)[mid];
int comp = item.Compare(midVal);
const int comp = item.Compare(midVal);
if (comp == 0)
{
right = mid + 1;

View File

@@ -76,7 +76,6 @@ typedef struct _FILETIME
DWORD dwHighDateTime;
} FILETIME;
#define HRESULT LONG
#define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
#define FAILED(hr) ((HRESULT)(hr) < 0)
typedef ULONG PROPID;
@@ -150,6 +149,7 @@ enum VARENUM
VT_VARIANT = 12,
VT_UNKNOWN = 13,
VT_DECIMAL = 14,
VT_I1 = 16,
VT_UI1 = 17,
VT_UI2 = 18,

View File

@@ -97,19 +97,33 @@ const int kDebugSize = 1000000;
static void *a[kDebugSize];
static int index = 0;
static bool wasInit = false;
static CRITICAL_SECTION cs;
static int numAllocs = 0;
void * __cdecl operator new(size_t size)
{
if (!wasInit)
{
InitializeCriticalSection(&cs);
wasInit = true;
}
EnterCriticalSection(&cs);
numAllocs++;
int loc = numAllocs;
void *p = HeapAlloc(GetProcessHeap(), 0, size);
/*
if (index < kDebugSize)
{
a[index] = p;
index++;
}
*/
printf("Alloc %6d, size = %8u\n", loc, (unsigned)size);
LeaveCriticalSection(&cs);
if (p == 0)
throw CNewException();
printf("Alloc %6d, size = %8u\n", numAllocs, (unsigned)size);
return p;
}
@@ -123,6 +137,7 @@ public:
}
~CC()
{
printf("\nDestructor: %d\n", numAllocs);
for (int i = 0; i < kDebugSize; i++)
if (a[i] != 0)
return;
@@ -134,6 +149,7 @@ void __cdecl operator delete(void *p)
{
if (p == 0)
return;
EnterCriticalSection(&cs);
/*
for (int i = 0; i < index; i++)
if (a[i] == p)
@@ -142,6 +158,7 @@ void __cdecl operator delete(void *p)
HeapFree(GetProcessHeap(), 0, p);
numAllocs--;
printf("Free %d\n", numAllocs);
LeaveCriticalSection(&cs);
}
#endif

View File

@@ -26,6 +26,33 @@ CONVERT_STRING_TO_UINT_FUNC(UInt32, wchar_t, wchar_t)
CONVERT_STRING_TO_UINT_FUNC(UInt64, char, Byte)
CONVERT_STRING_TO_UINT_FUNC(UInt64, wchar_t, wchar_t)
/*
Int32 ConvertStringToInt32(const char *s, const char **end) throw()
{
if (end)
*end = s;
const char *s2 = s;
if (*s == '-')
s2++;
if (*s2 == 0)
return 0;
const char *end2;
UInt32 res = ConvertStringToUInt32(s2, &end2);
if (*s == '-')
{
if (res > ((UInt32)1 << (32 - 1)))
return 0;
}
else if ((res & ((UInt32)1 << (32 - 1))) != 0)
return 0;
if (end)
*end = end2;
if (*s == '-')
return -(Int32)res;
return (Int32)res;
}
*/
Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw()
{
if (end)

View File

@@ -10,6 +10,7 @@ UInt64 ConvertStringToUInt64(const char *s, const char **end) throw();
UInt32 ConvertStringToUInt32(const wchar_t *s, const wchar_t **end) throw();
UInt64 ConvertStringToUInt64(const wchar_t *s, const wchar_t **end) throw();
// Int32 ConvertStringToInt32(const char *s, const char **end) throw();
Int32 ConvertStringToInt32(const wchar_t *s, const wchar_t **end) throw();
UInt32 ConvertOctStringToUInt32(const char *s, const char **end) throw();