Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2007-04-17 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:50 +0300
commita145bfc7cf17f7bbcfae8f0064333c8ea75b455c (patch)
tree4ea458c9f35956fe080562989a702ea8c9af4b90 /CPP/Common
parentd9666cf046a8453b33b3e2fbf4d82295a9f87df3 (diff)
4.45 beta
Diffstat (limited to 'CPP/Common')
-rwxr-xr-xCPP/Common/Alloc.cpp133
-rwxr-xr-xCPP/Common/Alloc.h29
-rwxr-xr-xCPP/Common/CRC.cpp55
-rwxr-xr-xCPP/Common/CRC.h36
-rwxr-xr-xCPP/Common/MyCom.h2
-rwxr-xr-xCPP/Common/MyGuidDef.h8
-rwxr-xr-xCPP/Common/StdOutStream.h2
-rwxr-xr-xCPP/Common/String.h12
8 files changed, 16 insertions, 261 deletions
diff --git a/CPP/Common/Alloc.cpp b/CPP/Common/Alloc.cpp
deleted file mode 100755
index e4fc6a81..00000000
--- a/CPP/Common/Alloc.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-// Common/Alloc.cpp
-
-#include "StdAfx.h"
-
-#ifdef _WIN32
-#include "MyWindows.h"
-#else
-#include <stdlib.h>
-#endif
-
-#include "Alloc.h"
-
-/* #define _SZ_ALLOC_DEBUG */
-/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
-#ifdef _SZ_ALLOC_DEBUG
-#include <stdio.h>
-int g_allocCount = 0;
-int g_allocCountMid = 0;
-int g_allocCountBig = 0;
-#endif
-
-void *MyAlloc(size_t size) throw()
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount++);
- #endif
- return ::malloc(size);
-}
-
-void MyFree(void *address) throw()
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree; count = %10d", --g_allocCount);
- #endif
-
- ::free(address);
-}
-
-#ifdef _WIN32
-
-void *MidAlloc(size_t size) throw()
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++);
- #endif
- return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void MidFree(void *address) throw()
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
- #endif
- if (address == 0)
- return;
- ::VirtualFree(address, 0, MEM_RELEASE);
-}
-
-
-#ifndef MEM_LARGE_PAGES
-#define _7ZIP_NO_LARGE_PAGES
-#endif
-
-// define _7ZIP_NO_LARGE_PAGES if you don't need LARGE_PAGES support
-// #define _7ZIP_NO_LARGE_PAGES
-
-
-#ifndef _7ZIP_NO_LARGE_PAGES
-static SIZE_T g_LargePageSize =
- #ifdef _WIN64
- (1 << 21);
- #else
- (1 << 22);
- #endif
-
-typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
-#endif
-
-bool SetLargePageSize()
-{
- #ifndef _7ZIP_NO_LARGE_PAGES
- GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
- ::GetProcAddress(::GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
- if (largePageMinimum == 0)
- return false;
- SIZE_T size = largePageMinimum();
- if (size == 0 || (size & (size - 1)) != 0)
- return false;
- g_LargePageSize = size;
- #endif
- return true;
-}
-
-
-void *BigAlloc(size_t size) throw()
-{
- if (size == 0)
- return 0;
- #ifdef _SZ_ALLOC_DEBUG
- fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
- #endif
-
- #ifndef _7ZIP_NO_LARGE_PAGES
- if (size >= (1 << 18))
- {
- void *res = ::VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
- MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
- if (res != 0)
- return res;
- }
- #endif
- return ::VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
-}
-
-void BigFree(void *address) throw()
-{
- #ifdef _SZ_ALLOC_DEBUG
- if (address != 0)
- fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
- #endif
-
- if (address == 0)
- return;
- ::VirtualFree(address, 0, MEM_RELEASE);
-}
-
-#endif
diff --git a/CPP/Common/Alloc.h b/CPP/Common/Alloc.h
deleted file mode 100755
index d444f631..00000000
--- a/CPP/Common/Alloc.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Common/Alloc.h
-
-#ifndef __COMMON_ALLOC_H
-#define __COMMON_ALLOC_H
-
-#include <stddef.h>
-
-void *MyAlloc(size_t size) throw();
-void MyFree(void *address) throw();
-
-#ifdef _WIN32
-
-bool SetLargePageSize();
-
-void *MidAlloc(size_t size) throw();
-void MidFree(void *address) throw();
-void *BigAlloc(size_t size) throw();
-void BigFree(void *address) throw();
-
-#else
-
-#define MidAlloc(size) MyAlloc(size)
-#define MidFree(address) MyFree(address)
-#define BigAlloc(size) MyAlloc(size)
-#define BigFree(address) MyFree(address)
-
-#endif
-
-#endif
diff --git a/CPP/Common/CRC.cpp b/CPP/Common/CRC.cpp
index 35e1a187..b768128c 100755
--- a/CPP/Common/CRC.cpp
+++ b/CPP/Common/CRC.cpp
@@ -2,60 +2,13 @@
#include "StdAfx.h"
-#include "CRC.h"
-
-static const UInt32 kCRCPoly = 0xEDB88320;
-
-UInt32 CCRC::Table[256];
-
-void CCRC::InitTable()
-{
- for (UInt32 i = 0; i < 256; i++)
- {
- UInt32 r = i;
- for (int j = 0; j < 8; j++)
- if (r & 1)
- r = (r >> 1) ^ kCRCPoly;
- else
- r >>= 1;
- CCRC::Table[i] = r;
- }
+extern "C"
+{
+#include "../../C/7zCrc.h"
}
class CCRCTableInit
{
public:
- CCRCTableInit() { CCRC::InitTable(); }
+ CCRCTableInit() { CrcGenerateTable(); }
} g_CRCTableInit;
-
-void CCRC::UpdateByte(Byte b)
-{
- _value = Table[((Byte)(_value)) ^ b] ^ (_value >> 8);
-}
-
-void CCRC::UpdateUInt16(UInt16 v)
-{
- UpdateByte(Byte(v));
- UpdateByte(Byte(v >> 8));
-}
-
-void CCRC::UpdateUInt32(UInt32 v)
-{
- for (int i = 0; i < 4; i++)
- UpdateByte((Byte)(v >> (8 * i)));
-}
-
-void CCRC::UpdateUInt64(UInt64 v)
-{
- for (int i = 0; i < 8; i++)
- UpdateByte((Byte)(v >> (8 * i)));
-}
-
-void CCRC::Update(const void *data, size_t size)
-{
- UInt32 v = _value;
- const Byte *p = (const Byte *)data;
- for (; size > 0 ; size--, p++)
- v = Table[((Byte)(v)) ^ *p] ^ (v >> 8);
- _value = v;
-}
diff --git a/CPP/Common/CRC.h b/CPP/Common/CRC.h
deleted file mode 100755
index 277ae673..00000000
--- a/CPP/Common/CRC.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Common/CRC.h
-
-#ifndef __COMMON_CRC_H
-#define __COMMON_CRC_H
-
-#include <stddef.h>
-#include "Types.h"
-
-class CCRC
-{
- UInt32 _value;
-public:
- static UInt32 Table[256];
- static void InitTable();
-
- CCRC(): _value(0xFFFFFFFF){};
- void Init() { _value = 0xFFFFFFFF; }
- void UpdateByte(Byte v);
- void UpdateUInt16(UInt16 v);
- void UpdateUInt32(UInt32 v);
- void UpdateUInt64(UInt64 v);
- void Update(const void *data, size_t size);
- UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
- static UInt32 CalculateDigest(const void *data, size_t size)
- {
- CCRC crc;
- crc.Update(data, size);
- return crc.GetDigest();
- }
- static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
- {
- return (CalculateDigest(data, size) == digest);
- }
-};
-
-#endif
diff --git a/CPP/Common/MyCom.h b/CPP/Common/MyCom.h
index e9034930..07e8fb66 100755
--- a/CPP/Common/MyCom.h
+++ b/CPP/Common/MyCom.h
@@ -5,7 +5,9 @@
#include "MyWindows.h"
+#ifndef RINOK
#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }
+#endif
template <class T>
class CMyComPtr
diff --git a/CPP/Common/MyGuidDef.h b/CPP/Common/MyGuidDef.h
index 2c954f81..19562696 100755
--- a/CPP/Common/MyGuidDef.h
+++ b/CPP/Common/MyGuidDef.h
@@ -22,14 +22,14 @@ typedef struct {
#define REFIID REFGUID
#ifdef __cplusplus
-inline bool operator==(REFGUID g1, REFGUID g2)
+inline int operator==(REFGUID g1, REFGUID g2)
{
for (int i = 0; i < (int)sizeof(g1); i++)
if (((unsigned char *)&g1)[i] != ((unsigned char *)&g2)[i])
- return false;
- return true;
+ return 0;
+ return 1;
}
-inline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
+inline int operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
#endif
#ifdef __cplusplus
diff --git a/CPP/Common/StdOutStream.h b/CPP/Common/StdOutStream.h
index a3b11979..84907365 100755
--- a/CPP/Common/StdOutStream.h
+++ b/CPP/Common/StdOutStream.h
@@ -15,10 +15,10 @@ public:
CStdOutStream (): _streamIsOpen(false), _stream(0) {};
CStdOutStream (FILE *stream): _streamIsOpen(false), _stream(stream) {};
~CStdOutStream ();
+ operator FILE *() { return _stream; }
bool Open(const char *fileName);
bool Close();
bool Flush();
-
CStdOutStream & operator<<(CStdOutStream & (* aFunction)(CStdOutStream &));
CStdOutStream & operator<<(const char *string);
CStdOutStream & operator<<(const wchar_t *string);
diff --git a/CPP/Common/String.h b/CPP/Common/String.h
index cbc6ee26..6ec5b8f3 100755
--- a/CPP/Common/String.h
+++ b/CPP/Common/String.h
@@ -12,8 +12,6 @@
#include "MyWindows.h"
#endif
-static const char *kTrimDefaultCharSet = " \n\t";
-
template <class T>
inline int MyStringLen(const T *s)
{
@@ -55,7 +53,7 @@ inline char MyCharUpper(char c)
{ return (char)(unsigned int)(UINT_PTR)CharUpperA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }
#ifdef _UNICODE
inline wchar_t MyCharUpper(wchar_t c)
- { return (wchar_t)CharUpperW((LPWSTR)c); }
+ { return (wchar_t)(unsigned int)(UINT_PTR)CharUpperW((LPWSTR)(UINT_PTR)(unsigned int)c); }
#else
wchar_t MyCharUpper(wchar_t c);
#endif
@@ -64,7 +62,7 @@ inline char MyCharLower(char c)
{ return (char)(unsigned int)(UINT_PTR)CharLowerA((LPSTR)(UINT_PTR)(unsigned int)(unsigned char)c); }
#ifdef _UNICODE
inline wchar_t MyCharLower(wchar_t c)
- { return (wchar_t)CharLowerW((LPWSTR)c); }
+ { return (wchar_t)(unsigned int)(UINT_PTR)CharLowerW((LPWSTR)(UINT_PTR)(unsigned int)c); }
#else
wchar_t MyCharLower(wchar_t c);
#endif
@@ -431,9 +429,9 @@ public:
CStringBase GetTrimDefaultCharSet()
{
CStringBase<T> charSet;
- for(int i = 0; i < (int)(sizeof(kTrimDefaultCharSet) /
- sizeof(kTrimDefaultCharSet[0])); i++)
- charSet += (T)kTrimDefaultCharSet[i];
+ charSet += (T)' ';
+ charSet += (T)'\n';
+ charSet += (T)'\t';
return charSet;
}
public: