| OLD | NEW |
| 1 /* 7zAlloc.c -- Allocation functions | 1 /* 7zAlloc.c -- Allocation functions |
| 2 2010-10-29 : Igor Pavlov : Public domain */ | 2 2015-11-09 : Igor Pavlov : Public domain */ |
| 3 |
| 4 #include "Precomp.h" |
| 3 | 5 |
| 4 #include "7zAlloc.h" | 6 #include "7zAlloc.h" |
| 5 | 7 |
| 6 /* #define _SZ_ALLOC_DEBUG */ | 8 /* #define _SZ_ALLOC_DEBUG */ |
| 7 /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ | 9 /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ |
| 8 | 10 |
| 9 #ifdef _SZ_ALLOC_DEBUG | 11 #ifdef _SZ_ALLOC_DEBUG |
| 10 | 12 |
| 11 #ifdef _WIN32 | 13 #ifdef _WIN32 |
| 12 #include <windows.h> | 14 #include <windows.h> |
| 13 #endif | 15 #endif |
| 14 | 16 |
| 15 #include <stdio.h> | 17 #include <stdio.h> |
| 16 int g_allocCount = 0; | 18 int g_allocCount = 0; |
| 17 int g_allocCountTemp = 0; | 19 int g_allocCountTemp = 0; |
| 18 | 20 |
| 19 #endif | 21 #endif |
| 20 | 22 |
| 21 void *SzAlloc(void *p, size_t size) | 23 void *SzAlloc(void *p, size_t size) |
| 22 { | 24 { |
| 23 p = p; | 25 UNUSED_VAR(p); |
| 24 if (size == 0) | 26 if (size == 0) |
| 25 return 0; | 27 return 0; |
| 26 #ifdef _SZ_ALLOC_DEBUG | 28 #ifdef _SZ_ALLOC_DEBUG |
| 27 fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount); | 29 fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCou
nt); |
| 28 g_allocCount++; | 30 g_allocCount++; |
| 29 #endif | 31 #endif |
| 30 return malloc(size); | 32 return malloc(size); |
| 31 } | 33 } |
| 32 | 34 |
| 33 void SzFree(void *p, void *address) | 35 void SzFree(void *p, void *address) |
| 34 { | 36 { |
| 35 p = p; | 37 UNUSED_VAR(p); |
| 36 #ifdef _SZ_ALLOC_DEBUG | 38 #ifdef _SZ_ALLOC_DEBUG |
| 37 if (address != 0) | 39 if (address != 0) |
| 38 { | 40 { |
| 39 g_allocCount--; | 41 g_allocCount--; |
| 40 fprintf(stderr, "\nFree; count = %10d", g_allocCount); | 42 fprintf(stderr, "\nFree; count = %10d", g_allocCount); |
| 41 } | 43 } |
| 42 #endif | 44 #endif |
| 43 free(address); | 45 free(address); |
| 44 } | 46 } |
| 45 | 47 |
| 46 void *SzAllocTemp(void *p, size_t size) | 48 void *SzAllocTemp(void *p, size_t size) |
| 47 { | 49 { |
| 48 p = p; | 50 UNUSED_VAR(p); |
| 49 if (size == 0) | 51 if (size == 0) |
| 50 return 0; | 52 return 0; |
| 51 #ifdef _SZ_ALLOC_DEBUG | 53 #ifdef _SZ_ALLOC_DEBUG |
| 52 fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTe
mp); | 54 fprintf(stderr, "\nAlloc_temp %10u bytes; count = %10d", (unsigned)size, g_al
locCountTemp); |
| 53 g_allocCountTemp++; | 55 g_allocCountTemp++; |
| 54 #ifdef _WIN32 | 56 #ifdef _WIN32 |
| 55 return HeapAlloc(GetProcessHeap(), 0, size); | 57 return HeapAlloc(GetProcessHeap(), 0, size); |
| 56 #endif | 58 #endif |
| 57 #endif | 59 #endif |
| 58 return malloc(size); | 60 return malloc(size); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void SzFreeTemp(void *p, void *address) | 63 void SzFreeTemp(void *p, void *address) |
| 62 { | 64 { |
| 63 p = p; | 65 UNUSED_VAR(p); |
| 64 #ifdef _SZ_ALLOC_DEBUG | 66 #ifdef _SZ_ALLOC_DEBUG |
| 65 if (address != 0) | 67 if (address != 0) |
| 66 { | 68 { |
| 67 g_allocCountTemp--; | 69 g_allocCountTemp--; |
| 68 fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); | 70 fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); |
| 69 } | 71 } |
| 70 #ifdef _WIN32 | 72 #ifdef _WIN32 |
| 71 HeapFree(GetProcessHeap(), 0, address); | 73 HeapFree(GetProcessHeap(), 0, address); |
| 72 return; | 74 return; |
| 73 #endif | 75 #endif |
| 74 #endif | 76 #endif |
| 75 free(address); | 77 free(address); |
| 76 } | 78 } |
| OLD | NEW |