Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* 7zAlloc.c -- Allocation functions | 1 /* 7zAlloc.c -- Allocation functions |
| 2 2010-10-29 : Igor Pavlov : Public domain */ | 2 2010-10-29 : Igor Pavlov : Public domain */ |
| 3 | 3 |
| 4 #include "7zAlloc.h" | 4 #include "7zAlloc.h" |
| 5 | 5 |
| 6 /* #define _SZ_ALLOC_DEBUG */ | 6 /* #define _SZ_ALLOC_DEBUG */ |
| 7 /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ | 7 /* use _SZ_ALLOC_DEBUG to debug alloc/free operations */ |
| 8 | 8 |
| 9 #ifdef _SZ_ALLOC_DEBUG | 9 #ifdef _SZ_ALLOC_DEBUG |
| 10 | 10 |
| 11 #ifdef _WIN32 | 11 #ifdef _WIN32 |
| 12 #include <windows.h> | 12 #include <windows.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include <stdio.h> | 15 #include <stdio.h> |
| 16 int g_allocCount = 0; | 16 int g_allocCount = 0; |
| 17 int g_allocCountTemp = 0; | 17 int g_allocCountTemp = 0; |
| 18 | 18 |
| 19 #endif | 19 #endif |
| 20 | 20 |
| 21 void *SzAlloc(void *p, size_t size) | 21 void *SzAlloc(void *p, size_t size) |
| 22 { | 22 { |
| 23 p = p; | |
|
Nico
2015/06/29 23:51:02
I bet these are here to fix -Wunused-parameter war
scottmg
2015/06/30 00:32:55
I don't think you can remove the argument names in
| |
| 24 if (size == 0) | 23 if (size == 0) |
| 25 return 0; | 24 return 0; |
| 26 #ifdef _SZ_ALLOC_DEBUG | 25 #ifdef _SZ_ALLOC_DEBUG |
| 27 fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount); | 26 fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, g_allocCount); |
| 28 g_allocCount++; | 27 g_allocCount++; |
| 29 #endif | 28 #endif |
| 30 return malloc(size); | 29 return malloc(size); |
| 31 } | 30 } |
| 32 | 31 |
| 33 void SzFree(void *p, void *address) | 32 void SzFree(void *p, void *address) |
| 34 { | 33 { |
| 35 p = p; | |
| 36 #ifdef _SZ_ALLOC_DEBUG | 34 #ifdef _SZ_ALLOC_DEBUG |
| 37 if (address != 0) | 35 if (address != 0) |
| 38 { | 36 { |
| 39 g_allocCount--; | 37 g_allocCount--; |
| 40 fprintf(stderr, "\nFree; count = %10d", g_allocCount); | 38 fprintf(stderr, "\nFree; count = %10d", g_allocCount); |
| 41 } | 39 } |
| 42 #endif | 40 #endif |
| 43 free(address); | 41 free(address); |
| 44 } | 42 } |
| 45 | 43 |
| 46 void *SzAllocTemp(void *p, size_t size) | 44 void *SzAllocTemp(void *p, size_t size) |
| 47 { | 45 { |
| 48 p = p; | |
| 49 if (size == 0) | 46 if (size == 0) |
| 50 return 0; | 47 return 0; |
| 51 #ifdef _SZ_ALLOC_DEBUG | 48 #ifdef _SZ_ALLOC_DEBUG |
| 52 fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTe mp); | 49 fprintf(stderr, "\nAlloc_temp %10d bytes; count = %10d", size, g_allocCountTe mp); |
| 53 g_allocCountTemp++; | 50 g_allocCountTemp++; |
| 54 #ifdef _WIN32 | 51 #ifdef _WIN32 |
| 55 return HeapAlloc(GetProcessHeap(), 0, size); | 52 return HeapAlloc(GetProcessHeap(), 0, size); |
| 56 #endif | 53 #endif |
| 57 #endif | 54 #endif |
| 58 return malloc(size); | 55 return malloc(size); |
| 59 } | 56 } |
| 60 | 57 |
| 61 void SzFreeTemp(void *p, void *address) | 58 void SzFreeTemp(void *p, void *address) |
| 62 { | 59 { |
| 63 p = p; | |
| 64 #ifdef _SZ_ALLOC_DEBUG | 60 #ifdef _SZ_ALLOC_DEBUG |
| 65 if (address != 0) | 61 if (address != 0) |
| 66 { | 62 { |
| 67 g_allocCountTemp--; | 63 g_allocCountTemp--; |
| 68 fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); | 64 fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); |
| 69 } | 65 } |
| 70 #ifdef _WIN32 | 66 #ifdef _WIN32 |
| 71 HeapFree(GetProcessHeap(), 0, address); | 67 HeapFree(GetProcessHeap(), 0, address); |
| 72 return; | 68 return; |
| 73 #endif | 69 #endif |
| 74 #endif | 70 #endif |
| 75 free(address); | 71 free(address); |
| 76 } | 72 } |
| OLD | NEW |