aboutsummaryrefslogtreecommitdiff
path: root/C/7zTypes.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--C/7zTypes.h262
1 files changed, 165 insertions, 97 deletions
diff --git a/C/7zTypes.h b/C/7zTypes.h
index f7d7071..1fcb247 100644
--- a/C/7zTypes.h
+++ b/C/7zTypes.h
@@ -1,8 +1,8 @@
1/* 7zTypes.h -- Basic types 1/* 7zTypes.h -- Basic types
22022-04-01 : Igor Pavlov : Public domain */ 22023-04-02 : Igor Pavlov : Public domain */
3 3
4#ifndef __7Z_TYPES_H 4#ifndef ZIP7_7Z_TYPES_H
5#define __7Z_TYPES_H 5#define ZIP7_7Z_TYPES_H
6 6
7#ifdef _WIN32 7#ifdef _WIN32
8/* #include <windows.h> */ 8/* #include <windows.h> */
@@ -52,6 +52,11 @@ typedef int SRes;
52 #define MY_ALIGN(n) 52 #define MY_ALIGN(n)
53 #endif 53 #endif
54#else 54#else
55 /*
56 // C11/C++11:
57 #include <stdalign.h>
58 #define MY_ALIGN(n) alignas(n)
59 */
55 #define MY_ALIGN(n) __attribute__ ((aligned(n))) 60 #define MY_ALIGN(n) __attribute__ ((aligned(n)))
56#endif 61#endif
57 62
@@ -62,7 +67,7 @@ typedef int SRes;
62typedef unsigned WRes; 67typedef unsigned WRes;
63#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x) 68#define MY_SRes_HRESULT_FROM_WRes(x) HRESULT_FROM_WIN32(x)
64 69
65// #define MY_HRES_ERROR__INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR) 70// #define MY_HRES_ERROR_INTERNAL_ERROR MY_SRes_HRESULT_FROM_WRes(ERROR_INTERNAL_ERROR)
66 71
67#else // _WIN32 72#else // _WIN32
68 73
@@ -70,13 +75,13 @@ typedef unsigned WRes;
70typedef int WRes; 75typedef int WRes;
71 76
72// (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT 77// (FACILITY_ERRNO = 0x800) is 7zip's FACILITY constant to represent (errno) errors in HRESULT
73#define MY__FACILITY_ERRNO 0x800 78#define MY_FACILITY_ERRNO 0x800
74#define MY__FACILITY_WIN32 7 79#define MY_FACILITY_WIN32 7
75#define MY__FACILITY__WRes MY__FACILITY_ERRNO 80#define MY_FACILITY_WRes MY_FACILITY_ERRNO
76 81
77#define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \ 82#define MY_HRESULT_FROM_errno_CONST_ERROR(x) ((HRESULT)( \
78 ( (HRESULT)(x) & 0x0000FFFF) \ 83 ( (HRESULT)(x) & 0x0000FFFF) \
79 | (MY__FACILITY__WRes << 16) \ 84 | (MY_FACILITY_WRes << 16) \
80 | (HRESULT)0x80000000 )) 85 | (HRESULT)0x80000000 ))
81 86
82#define MY_SRes_HRESULT_FROM_WRes(x) \ 87#define MY_SRes_HRESULT_FROM_WRes(x) \
@@ -120,17 +125,17 @@ typedef int WRes;
120#define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L) 125#define ERROR_INVALID_REPARSE_DATA ((HRESULT)0x80071128L)
121#define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L) 126#define ERROR_REPARSE_TAG_INVALID ((HRESULT)0x80071129L)
122 127
123// if (MY__FACILITY__WRes != FACILITY_WIN32), 128// if (MY_FACILITY_WRes != FACILITY_WIN32),
124// we use FACILITY_WIN32 for COM errors: 129// we use FACILITY_WIN32 for COM errors:
125#define E_OUTOFMEMORY ((HRESULT)0x8007000EL) 130#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
126#define E_INVALIDARG ((HRESULT)0x80070057L) 131#define E_INVALIDARG ((HRESULT)0x80070057L)
127#define MY__E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L) 132#define MY_E_ERROR_NEGATIVE_SEEK ((HRESULT)0x80070083L)
128 133
129/* 134/*
130// we can use FACILITY_ERRNO for some COM errors, that have errno equivalents: 135// we can use FACILITY_ERRNO for some COM errors, that have errno equivalents:
131#define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM) 136#define E_OUTOFMEMORY MY_HRESULT_FROM_errno_CONST_ERROR(ENOMEM)
132#define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL) 137#define E_INVALIDARG MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
133#define MY__E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL) 138#define MY_E_ERROR_NEGATIVE_SEEK MY_HRESULT_FROM_errno_CONST_ERROR(EINVAL)
134*/ 139*/
135 140
136#define TEXT(quote) quote 141#define TEXT(quote) quote
@@ -156,18 +161,18 @@ typedef int WRes;
156 161
157 162
158#ifndef RINOK 163#ifndef RINOK
159#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } 164#define RINOK(x) { const int _result_ = (x); if (_result_ != 0) return _result_; }
160#endif 165#endif
161 166
162#ifndef RINOK_WRes 167#ifndef RINOK_WRes
163#define RINOK_WRes(x) { WRes __result__ = (x); if (__result__ != 0) return __result__; } 168#define RINOK_WRes(x) { const WRes _result_ = (x); if (_result_ != 0) return _result_; }
164#endif 169#endif
165 170
166typedef unsigned char Byte; 171typedef unsigned char Byte;
167typedef short Int16; 172typedef short Int16;
168typedef unsigned short UInt16; 173typedef unsigned short UInt16;
169 174
170#ifdef _LZMA_UINT32_IS_ULONG 175#ifdef Z7_DECL_Int32_AS_long
171typedef long Int32; 176typedef long Int32;
172typedef unsigned long UInt32; 177typedef unsigned long UInt32;
173#else 178#else
@@ -206,37 +211,51 @@ typedef size_t SIZE_T;
206#endif // _WIN32 211#endif // _WIN32
207 212
208 213
209#define MY_HRES_ERROR__INTERNAL_ERROR ((HRESULT)0x8007054FL) 214#define MY_HRES_ERROR_INTERNAL_ERROR ((HRESULT)0x8007054FL)
210 215
211 216
212#ifdef _SZ_NO_INT_64 217#ifdef Z7_DECL_Int64_AS_long
213
214/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
215 NOTES: Some code will work incorrectly in that case! */
216 218
217typedef long Int64; 219typedef long Int64;
218typedef unsigned long UInt64; 220typedef unsigned long UInt64;
219 221
220#else 222#else
221 223
222#if defined(_MSC_VER) || defined(__BORLANDC__) 224#if (defined(_MSC_VER) || defined(__BORLANDC__)) && !defined(__clang__)
223typedef __int64 Int64; 225typedef __int64 Int64;
224typedef unsigned __int64 UInt64; 226typedef unsigned __int64 UInt64;
225#define UINT64_CONST(n) n 227#else
228#if defined(__clang__) || defined(__GNUC__)
229#include <stdint.h>
230typedef int64_t Int64;
231typedef uint64_t UInt64;
226#else 232#else
227typedef long long int Int64; 233typedef long long int Int64;
228typedef unsigned long long int UInt64; 234typedef unsigned long long int UInt64;
229#define UINT64_CONST(n) n ## ULL 235// #define UINT64_CONST(n) n ## ULL
236#endif
230#endif 237#endif
231 238
232#endif 239#endif
233 240
234#ifdef _LZMA_NO_SYSTEM_SIZE_T 241#define UINT64_CONST(n) n
235typedef UInt32 SizeT; 242
243
244#ifdef Z7_DECL_SizeT_AS_unsigned_int
245typedef unsigned int SizeT;
236#else 246#else
237typedef size_t SizeT; 247typedef size_t SizeT;
238#endif 248#endif
239 249
250/*
251#if (defined(_MSC_VER) && _MSC_VER <= 1200)
252typedef size_t MY_uintptr_t;
253#else
254#include <stdint.h>
255typedef uintptr_t MY_uintptr_t;
256#endif
257*/
258
240typedef int BoolInt; 259typedef int BoolInt;
241/* typedef BoolInt Bool; */ 260/* typedef BoolInt Bool; */
242#define True 1 261#define True 1
@@ -244,23 +263,23 @@ typedef int BoolInt;
244 263
245 264
246#ifdef _WIN32 265#ifdef _WIN32
247#define MY_STD_CALL __stdcall 266#define Z7_STDCALL __stdcall
248#else 267#else
249#define MY_STD_CALL 268#define Z7_STDCALL
250#endif 269#endif
251 270
252#ifdef _MSC_VER 271#ifdef _MSC_VER
253 272
254#if _MSC_VER >= 1300 273#if _MSC_VER >= 1300
255#define MY_NO_INLINE __declspec(noinline) 274#define Z7_NO_INLINE __declspec(noinline)
256#else 275#else
257#define MY_NO_INLINE 276#define Z7_NO_INLINE
258#endif 277#endif
259 278
260#define MY_FORCE_INLINE __forceinline 279#define Z7_FORCE_INLINE __forceinline
261 280
262#define MY_CDECL __cdecl 281#define Z7_CDECL __cdecl
263#define MY_FAST_CALL __fastcall 282#define Z7_FASTCALL __fastcall
264 283
265#else // _MSC_VER 284#else // _MSC_VER
266 285
@@ -268,27 +287,25 @@ typedef int BoolInt;
268 || (defined(__clang__) && (__clang_major__ >= 4)) \ 287 || (defined(__clang__) && (__clang_major__ >= 4)) \
269 || defined(__INTEL_COMPILER) \ 288 || defined(__INTEL_COMPILER) \
270 || defined(__xlC__) 289 || defined(__xlC__)
271#define MY_NO_INLINE __attribute__((noinline)) 290#define Z7_NO_INLINE __attribute__((noinline))
272// #define MY_FORCE_INLINE __attribute__((always_inline)) inline 291#define Z7_FORCE_INLINE __attribute__((always_inline)) inline
273#else 292#else
274#define MY_NO_INLINE 293#define Z7_NO_INLINE
294#define Z7_FORCE_INLINE
275#endif 295#endif
276 296
277#define MY_FORCE_INLINE 297#define Z7_CDECL
278
279
280#define MY_CDECL
281 298
282#if defined(_M_IX86) \ 299#if defined(_M_IX86) \
283 || defined(__i386__) 300 || defined(__i386__)
284// #define MY_FAST_CALL __attribute__((fastcall)) 301// #define Z7_FASTCALL __attribute__((fastcall))
285// #define MY_FAST_CALL __attribute__((cdecl)) 302// #define Z7_FASTCALL __attribute__((cdecl))
286#define MY_FAST_CALL 303#define Z7_FASTCALL
287#elif defined(MY_CPU_AMD64) 304#elif defined(MY_CPU_AMD64)
288// #define MY_FAST_CALL __attribute__((ms_abi)) 305// #define Z7_FASTCALL __attribute__((ms_abi))
289#define MY_FAST_CALL 306#define Z7_FASTCALL
290#else 307#else
291#define MY_FAST_CALL 308#define Z7_FASTCALL
292#endif 309#endif
293 310
294#endif // _MSC_VER 311#endif // _MSC_VER
@@ -296,41 +313,49 @@ typedef int BoolInt;
296 313
297/* The following interfaces use first parameter as pointer to structure */ 314/* The following interfaces use first parameter as pointer to structure */
298 315
299typedef struct IByteIn IByteIn; 316// #define Z7_C_IFACE_CONST_QUAL
300struct IByteIn 317#define Z7_C_IFACE_CONST_QUAL const
318
319#define Z7_C_IFACE_DECL(a) \
320 struct a ## _; \
321 typedef Z7_C_IFACE_CONST_QUAL struct a ## _ * a ## Ptr; \
322 typedef struct a ## _ a; \
323 struct a ## _
324
325
326Z7_C_IFACE_DECL (IByteIn)
301{ 327{
302 Byte (*Read)(const IByteIn *p); /* reads one byte, returns 0 in case of EOF or error */ 328 Byte (*Read)(IByteInPtr p); /* reads one byte, returns 0 in case of EOF or error */
303}; 329};
304#define IByteIn_Read(p) (p)->Read(p) 330#define IByteIn_Read(p) (p)->Read(p)
305 331
306 332
307typedef struct IByteOut IByteOut; 333Z7_C_IFACE_DECL (IByteOut)
308struct IByteOut
309{ 334{
310 void (*Write)(const IByteOut *p, Byte b); 335 void (*Write)(IByteOutPtr p, Byte b);
311}; 336};
312#define IByteOut_Write(p, b) (p)->Write(p, b) 337#define IByteOut_Write(p, b) (p)->Write(p, b)
313 338
314 339
315typedef struct ISeqInStream ISeqInStream; 340Z7_C_IFACE_DECL (ISeqInStream)
316struct ISeqInStream
317{ 341{
318 SRes (*Read)(const ISeqInStream *p, void *buf, size_t *size); 342 SRes (*Read)(ISeqInStreamPtr p, void *buf, size_t *size);
319 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. 343 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
320 (output(*size) < input(*size)) is allowed */ 344 (output(*size) < input(*size)) is allowed */
321}; 345};
322#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size) 346#define ISeqInStream_Read(p, buf, size) (p)->Read(p, buf, size)
323 347
348/* try to read as much as avail in stream and limited by (*processedSize) */
349SRes SeqInStream_ReadMax(ISeqInStreamPtr stream, void *buf, size_t *processedSize);
324/* it can return SZ_ERROR_INPUT_EOF */ 350/* it can return SZ_ERROR_INPUT_EOF */
325SRes SeqInStream_Read(const ISeqInStream *stream, void *buf, size_t size); 351// SRes SeqInStream_Read(ISeqInStreamPtr stream, void *buf, size_t size);
326SRes SeqInStream_Read2(const ISeqInStream *stream, void *buf, size_t size, SRes errorType); 352// SRes SeqInStream_Read2(ISeqInStreamPtr stream, void *buf, size_t size, SRes errorType);
327SRes SeqInStream_ReadByte(const ISeqInStream *stream, Byte *buf); 353SRes SeqInStream_ReadByte(ISeqInStreamPtr stream, Byte *buf);
328 354
329 355
330typedef struct ISeqOutStream ISeqOutStream; 356Z7_C_IFACE_DECL (ISeqOutStream)
331struct ISeqOutStream
332{ 357{
333 size_t (*Write)(const ISeqOutStream *p, const void *buf, size_t size); 358 size_t (*Write)(ISeqOutStreamPtr p, const void *buf, size_t size);
334 /* Returns: result - the number of actually written bytes. 359 /* Returns: result - the number of actually written bytes.
335 (result < size) means error */ 360 (result < size) means error */
336}; 361};
@@ -344,29 +369,26 @@ typedef enum
344} ESzSeek; 369} ESzSeek;
345 370
346 371
347typedef struct ISeekInStream ISeekInStream; 372Z7_C_IFACE_DECL (ISeekInStream)
348struct ISeekInStream
349{ 373{
350 SRes (*Read)(const ISeekInStream *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ 374 SRes (*Read)(ISeekInStreamPtr p, void *buf, size_t *size); /* same as ISeqInStream::Read */
351 SRes (*Seek)(const ISeekInStream *p, Int64 *pos, ESzSeek origin); 375 SRes (*Seek)(ISeekInStreamPtr p, Int64 *pos, ESzSeek origin);
352}; 376};
353#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size) 377#define ISeekInStream_Read(p, buf, size) (p)->Read(p, buf, size)
354#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin) 378#define ISeekInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
355 379
356 380
357typedef struct ILookInStream ILookInStream; 381Z7_C_IFACE_DECL (ILookInStream)
358struct ILookInStream
359{ 382{
360 SRes (*Look)(const ILookInStream *p, const void **buf, size_t *size); 383 SRes (*Look)(ILookInStreamPtr p, const void **buf, size_t *size);
361 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. 384 /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
362 (output(*size) > input(*size)) is not allowed 385 (output(*size) > input(*size)) is not allowed
363 (output(*size) < input(*size)) is allowed */ 386 (output(*size) < input(*size)) is allowed */
364 SRes (*Skip)(const ILookInStream *p, size_t offset); 387 SRes (*Skip)(ILookInStreamPtr p, size_t offset);
365 /* offset must be <= output(*size) of Look */ 388 /* offset must be <= output(*size) of Look */
366 389 SRes (*Read)(ILookInStreamPtr p, void *buf, size_t *size);
367 SRes (*Read)(const ILookInStream *p, void *buf, size_t *size);
368 /* reads directly (without buffer). It's same as ISeqInStream::Read */ 390 /* reads directly (without buffer). It's same as ISeqInStream::Read */
369 SRes (*Seek)(const ILookInStream *p, Int64 *pos, ESzSeek origin); 391 SRes (*Seek)(ILookInStreamPtr p, Int64 *pos, ESzSeek origin);
370}; 392};
371 393
372#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size) 394#define ILookInStream_Look(p, buf, size) (p)->Look(p, buf, size)
@@ -375,19 +397,18 @@ struct ILookInStream
375#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin) 397#define ILookInStream_Seek(p, pos, origin) (p)->Seek(p, pos, origin)
376 398
377 399
378SRes LookInStream_LookRead(const ILookInStream *stream, void *buf, size_t *size); 400SRes LookInStream_LookRead(ILookInStreamPtr stream, void *buf, size_t *size);
379SRes LookInStream_SeekTo(const ILookInStream *stream, UInt64 offset); 401SRes LookInStream_SeekTo(ILookInStreamPtr stream, UInt64 offset);
380 402
381/* reads via ILookInStream::Read */ 403/* reads via ILookInStream::Read */
382SRes LookInStream_Read2(const ILookInStream *stream, void *buf, size_t size, SRes errorType); 404SRes LookInStream_Read2(ILookInStreamPtr stream, void *buf, size_t size, SRes errorType);
383SRes LookInStream_Read(const ILookInStream *stream, void *buf, size_t size); 405SRes LookInStream_Read(ILookInStreamPtr stream, void *buf, size_t size);
384
385 406
386 407
387typedef struct 408typedef struct
388{ 409{
389 ILookInStream vt; 410 ILookInStream vt;
390 const ISeekInStream *realStream; 411 ISeekInStreamPtr realStream;
391 412
392 size_t pos; 413 size_t pos;
393 size_t size; /* it's data size */ 414 size_t size; /* it's data size */
@@ -399,13 +420,13 @@ typedef struct
399 420
400void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead); 421void LookToRead2_CreateVTable(CLookToRead2 *p, int lookahead);
401 422
402#define LookToRead2_Init(p) { (p)->pos = (p)->size = 0; } 423#define LookToRead2_INIT(p) { (p)->pos = (p)->size = 0; }
403 424
404 425
405typedef struct 426typedef struct
406{ 427{
407 ISeqInStream vt; 428 ISeqInStream vt;
408 const ILookInStream *realStream; 429 ILookInStreamPtr realStream;
409} CSecToLook; 430} CSecToLook;
410 431
411void SecToLook_CreateVTable(CSecToLook *p); 432void SecToLook_CreateVTable(CSecToLook *p);
@@ -415,20 +436,19 @@ void SecToLook_CreateVTable(CSecToLook *p);
415typedef struct 436typedef struct
416{ 437{
417 ISeqInStream vt; 438 ISeqInStream vt;
418 const ILookInStream *realStream; 439 ILookInStreamPtr realStream;
419} CSecToRead; 440} CSecToRead;
420 441
421void SecToRead_CreateVTable(CSecToRead *p); 442void SecToRead_CreateVTable(CSecToRead *p);
422 443
423 444
424typedef struct ICompressProgress ICompressProgress; 445Z7_C_IFACE_DECL (ICompressProgress)
425
426struct ICompressProgress
427{ 446{
428 SRes (*Progress)(const ICompressProgress *p, UInt64 inSize, UInt64 outSize); 447 SRes (*Progress)(ICompressProgressPtr p, UInt64 inSize, UInt64 outSize);
429 /* Returns: result. (result != SZ_OK) means break. 448 /* Returns: result. (result != SZ_OK) means break.
430 Value (UInt64)(Int64)-1 for size means unknown value. */ 449 Value (UInt64)(Int64)-1 for size means unknown value. */
431}; 450};
451
432#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize) 452#define ICompressProgress_Progress(p, inSize, outSize) (p)->Progress(p, inSize, outSize)
433 453
434 454
@@ -466,13 +486,13 @@ struct ISzAlloc
466 486
467 487
468 488
469#ifndef MY_container_of 489#ifndef Z7_container_of
470 490
471/* 491/*
472#define MY_container_of(ptr, type, m) container_of(ptr, type, m) 492#define Z7_container_of(ptr, type, m) container_of(ptr, type, m)
473#define MY_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m) 493#define Z7_container_of(ptr, type, m) CONTAINING_RECORD(ptr, type, m)
474#define MY_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m))) 494#define Z7_container_of(ptr, type, m) ((type *)((char *)(ptr) - offsetof(type, m)))
475#define MY_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m)))) 495#define Z7_container_of(ptr, type, m) (&((type *)0)->m == (ptr), ((type *)(((char *)(ptr)) - MY_offsetof(type, m))))
476*/ 496*/
477 497
478/* 498/*
@@ -481,24 +501,64 @@ struct ISzAlloc
481 GCC 4.8.1 : classes with non-public variable members" 501 GCC 4.8.1 : classes with non-public variable members"
482*/ 502*/
483 503
484#define MY_container_of(ptr, type, m) ((type *)(void *)((char *)(void *)(1 ? (ptr) : &((type *)0)->m) - MY_offsetof(type, m))) 504#define Z7_container_of(ptr, type, m) \
505 ((type *)(void *)((char *)(void *) \
506 (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
485 507
486#endif 508#define Z7_container_of_CONST(ptr, type, m) \
487 509 ((const type *)(const void *)((const char *)(const void *) \
488#define CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr)) 510 (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
489 511
490/* 512/*
491#define CONTAINER_FROM_VTBL(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) 513#define Z7_container_of_NON_CONST_FROM_CONST(ptr, type, m) \
514 ((type *)(void *)(const void *)((const char *)(const void *) \
515 (1 ? (ptr) : &((type *)NULL)->m) - MY_offsetof(type, m)))
492*/ 516*/
493#define CONTAINER_FROM_VTBL(ptr, type, m) MY_container_of(ptr, type, m)
494 517
495#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) 518#endif
519
520#define Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m) ((type *)(void *)(ptr))
521
522// #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
523#define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_container_of(ptr, type, m)
524// #define Z7_CONTAINER_FROM_VTBL(ptr, type, m) Z7_container_of_NON_CONST_FROM_CONST(ptr, type, m)
525
526#define Z7_CONTAINER_FROM_VTBL_CONST(ptr, type, m) Z7_container_of_CONST(ptr, type, m)
527
528#define Z7_CONTAINER_FROM_VTBL_CLS(ptr, type, m) Z7_CONTAINER_FROM_VTBL_SIMPLE(ptr, type, m)
496/* 529/*
497#define CONTAINER_FROM_VTBL_CLS(ptr, type, m) CONTAINER_FROM_VTBL(ptr, type, m) 530#define Z7_CONTAINER_FROM_VTBL_CLS(ptr, type, m) Z7_CONTAINER_FROM_VTBL(ptr, type, m)
498*/ 531*/
532#if defined (__clang__) || defined(__GNUC__)
533#define Z7_DIAGNOSCTIC_IGNORE_BEGIN_CAST_QUAL \
534 _Pragma("GCC diagnostic push") \
535 _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
536#define Z7_DIAGNOSCTIC_IGNORE_END_CAST_QUAL \
537 _Pragma("GCC diagnostic pop")
538#else
539#define Z7_DIAGNOSCTIC_IGNORE_BEGIN_CAST_QUAL
540#define Z7_DIAGNOSCTIC_IGNORE_END_CAST_QUAL
541#endif
542
543#define Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR(ptr, type, m, p) \
544 Z7_DIAGNOSCTIC_IGNORE_BEGIN_CAST_QUAL \
545 type *p = Z7_CONTAINER_FROM_VTBL(ptr, type, m); \
546 Z7_DIAGNOSCTIC_IGNORE_END_CAST_QUAL
547
548#define Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR_pp_vt_p(type) \
549 Z7_CONTAINER_FROM_VTBL_TO_DECL_VAR(pp, type, vt, p)
499 550
500 551
501#define MY_memset_0_ARRAY(a) memset((a), 0, sizeof(a)) 552// #define ZIP7_DECLARE_HANDLE(name) typedef void *name;
553#define Z7_DECLARE_HANDLE(name) struct name##_dummy{int unused;}; typedef struct name##_dummy *name;
554
555
556#define Z7_memset_0_ARRAY(a) memset((a), 0, sizeof(a))
557
558#ifndef Z7_ARRAY_SIZE
559#define Z7_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
560#endif
561
502 562
503#ifdef _WIN32 563#ifdef _WIN32
504 564
@@ -527,3 +587,11 @@ struct ISzAlloc
527EXTERN_C_END 587EXTERN_C_END
528 588
529#endif 589#endif
590
591/*
592#ifndef Z7_ST
593#ifdef _7ZIP_ST
594#define Z7_ST
595#endif
596#endif
597*/