diff options
| author | 2024-10-08 02:41:52 +0200 | |
|---|---|---|
| committer | 2024-10-08 02:41:52 +0200 | |
| commit | 881102944edf36abc98539b10d13e2375fda88cf (patch) | |
| tree | aaf421f57561c795de3d3f60960ebbe007d2c1f5 /3rd_party/libsrp6a-sha512 | |
| parent | ed9703db1ee6d54e3801b618cee9524563d709e1 (diff) | |
| download | libimobiledevice-881102944edf36abc98539b10d13e2375fda88cf.tar.gz libimobiledevice-881102944edf36abc98539b10d13e2375fda88cf.tar.bz2 | |
3rd_party/libsrp6a: Remove unnecessary allocator code and just use malloc/free
Diffstat (limited to '3rd_party/libsrp6a-sha512')
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/cstr.c | 62 | ||||
| -rw-r--r-- | 3rd_party/libsrp6a-sha512/cstr.h | 12 |
2 files changed, 10 insertions, 64 deletions
diff --git a/3rd_party/libsrp6a-sha512/cstr.c b/3rd_party/libsrp6a-sha512/cstr.c index 9856f46..58a5638 100644 --- a/3rd_party/libsrp6a-sha512/cstr.c +++ b/3rd_party/libsrp6a-sha512/cstr.c | |||
| @@ -8,72 +8,31 @@ | |||
| 8 | #define MINSIZE 4 /* Absolute minimum - one word */ | 8 | #define MINSIZE 4 /* Absolute minimum - one word */ |
| 9 | 9 | ||
| 10 | static char cstr_empty_string[] = { '\0' }; | 10 | static char cstr_empty_string[] = { '\0' }; |
| 11 | static cstr_allocator * default_alloc = NULL; | ||
| 12 | |||
| 13 | /* | ||
| 14 | * It is assumed, for efficiency, that it is okay to pass more arguments | ||
| 15 | * to a function than are called for, as long as the required arguments | ||
| 16 | * are in proper form. If extra arguments to malloc() and free() cause | ||
| 17 | * problems, define PEDANTIC_ARGS below. | ||
| 18 | */ | ||
| 19 | #ifdef PEDANTIC_ARGS | ||
| 20 | static void * Cmalloc(int n, void * heap) { return malloc(n); } | ||
| 21 | static void Cfree(void * p, void * heap) { free(p); } | ||
| 22 | static cstr_allocator malloc_allocator = { Cmalloc, Cfree, NULL }; | ||
| 23 | #else | ||
| 24 | static cstr_allocator malloc_allocator = { malloc, free, NULL }; | ||
| 25 | #endif | ||
| 26 | |||
| 27 | _TYPE( void ) | ||
| 28 | cstr_set_allocator(cstr_allocator * alloc) | ||
| 29 | { | ||
| 30 | default_alloc = alloc; | ||
| 31 | } | ||
| 32 | 11 | ||
| 33 | _TYPE( cstr * ) | 12 | _TYPE( cstr * ) |
| 34 | cstr_new_alloc(cstr_allocator * alloc) | 13 | cstr_new() |
| 35 | { | 14 | { |
| 36 | cstr * str; | 15 | cstr * str; |
| 37 | 16 | ||
| 38 | if(alloc == NULL) { | 17 | str = (cstr *) malloc(sizeof(cstr)); |
| 39 | if(default_alloc == NULL) { | ||
| 40 | default_alloc = &malloc_allocator; | ||
| 41 | } | ||
| 42 | alloc = default_alloc; | ||
| 43 | } | ||
| 44 | |||
| 45 | str = (cstr *) (*alloc->alloc)(sizeof(cstr), alloc->heap); | ||
| 46 | if(str) { | 18 | if(str) { |
| 47 | str->data = cstr_empty_string; | 19 | str->data = cstr_empty_string; |
| 48 | str->length = str->cap = 0; | 20 | str->length = str->cap = 0; |
| 49 | str->ref = 1; | 21 | str->ref = 1; |
| 50 | str->allocator = alloc; | ||
| 51 | } | 22 | } |
| 52 | return str; | 23 | return str; |
| 53 | } | 24 | } |
| 54 | 25 | ||
| 55 | _TYPE( cstr * ) | 26 | _TYPE( cstr * ) |
| 56 | cstr_new() | 27 | cstr_dup(const cstr * str) |
| 57 | { | ||
| 58 | return cstr_new_alloc(NULL); | ||
| 59 | } | ||
| 60 | |||
| 61 | _TYPE( cstr * ) | ||
| 62 | cstr_dup_alloc(const cstr * str, cstr_allocator * alloc) | ||
| 63 | { | 28 | { |
| 64 | cstr * nstr = cstr_new_alloc(alloc); | 29 | cstr * nstr = cstr_new(); |
| 65 | if(nstr) | 30 | if(nstr) |
| 66 | cstr_setn(nstr, str->data, str->length); | 31 | cstr_setn(nstr, str->data, str->length); |
| 67 | return nstr; | 32 | return nstr; |
| 68 | } | 33 | } |
| 69 | 34 | ||
| 70 | _TYPE( cstr * ) | 35 | _TYPE( cstr * ) |
| 71 | cstr_dup(const cstr * str) | ||
| 72 | { | ||
| 73 | return cstr_dup_alloc(str, NULL); | ||
| 74 | } | ||
| 75 | |||
| 76 | _TYPE( cstr * ) | ||
| 77 | cstr_create(const char * s) | 36 | cstr_create(const char * s) |
| 78 | { | 37 | { |
| 79 | return cstr_createn(s, strlen(s)); | 38 | return cstr_createn(s, strlen(s)); |
| @@ -101,9 +60,9 @@ cstr_clear_free(cstr * str) | |||
| 101 | if(--str->ref == 0) { | 60 | if(--str->ref == 0) { |
| 102 | if(str->cap > 0) { | 61 | if(str->cap > 0) { |
| 103 | memset(str->data, 0, str->cap); | 62 | memset(str->data, 0, str->cap); |
| 104 | (*str->allocator->free)(str->data, str->allocator->heap); | 63 | free(str->data); |
| 105 | } | 64 | } |
| 106 | (*str->allocator->free)(str, str->allocator->heap); | 65 | free(str); |
| 107 | } | 66 | } |
| 108 | } | 67 | } |
| 109 | 68 | ||
| @@ -112,8 +71,8 @@ cstr_free(cstr * str) | |||
| 112 | { | 71 | { |
| 113 | if(--str->ref == 0) { | 72 | if(--str->ref == 0) { |
| 114 | if(str->cap > 0) | 73 | if(str->cap > 0) |
| 115 | (*str->allocator->free)(str->data, str->allocator->heap); | 74 | free(str->data); |
| 116 | (*str->allocator->free)(str, str->allocator->heap); | 75 | free(str); |
| 117 | } | 76 | } |
| 118 | } | 77 | } |
| 119 | 78 | ||
| @@ -121,7 +80,7 @@ _TYPE( void ) | |||
| 121 | cstr_empty(cstr * str) | 80 | cstr_empty(cstr * str) |
| 122 | { | 81 | { |
| 123 | if(str->cap > 0) | 82 | if(str->cap > 0) |
| 124 | (*str->allocator->free)(str->data, str->allocator->heap); | 83 | free(str->data); |
| 125 | str->data = cstr_empty_string; | 84 | str->data = cstr_empty_string; |
| 126 | str->length = str->cap = 0; | 85 | str->length = str->cap = 0; |
| 127 | } | 86 | } |
| @@ -137,8 +96,7 @@ cstr_alloc(cstr * str, int len) | |||
| 137 | if(len < MINSIZE) | 96 | if(len < MINSIZE) |
| 138 | len = MINSIZE; | 97 | len = MINSIZE; |
| 139 | 98 | ||
| 140 | t = (char *) (*str->allocator->alloc)(len * sizeof(char), | 99 | t = (char *) malloc(len * sizeof(char)); |
| 141 | str->allocator->heap); | ||
| 142 | if(t) { | 100 | if(t) { |
| 143 | if(str->data) { | 101 | if(str->data) { |
| 144 | t[str->length] = 0; | 102 | t[str->length] = 0; |
diff --git a/3rd_party/libsrp6a-sha512/cstr.h b/3rd_party/libsrp6a-sha512/cstr.h index 7cc019a..ae7d71a 100644 --- a/3rd_party/libsrp6a-sha512/cstr.h +++ b/3rd_party/libsrp6a-sha512/cstr.h | |||
| @@ -51,27 +51,15 @@ | |||
| 51 | extern "C" { | 51 | extern "C" { |
| 52 | #endif /* __cplusplus */ | 52 | #endif /* __cplusplus */ |
| 53 | 53 | ||
| 54 | /* Arguments to allocator methods ordered this way for compatibility */ | ||
| 55 | typedef struct cstr_alloc_st { | ||
| 56 | void * (_CDECL * alloc)(size_t n, void * heap); | ||
| 57 | void (_CDECL * free)(void * p, void * heap); | ||
| 58 | void * heap; | ||
| 59 | } cstr_allocator; | ||
| 60 | |||
| 61 | typedef struct cstr_st { | 54 | typedef struct cstr_st { |
| 62 | char * data; /* Okay to access data and length fields directly */ | 55 | char * data; /* Okay to access data and length fields directly */ |
| 63 | int length; | 56 | int length; |
| 64 | int cap; | 57 | int cap; |
| 65 | int ref; /* Simple reference counter */ | 58 | int ref; /* Simple reference counter */ |
| 66 | cstr_allocator * allocator; | ||
| 67 | } cstr; | 59 | } cstr; |
| 68 | 60 | ||
| 69 | _TYPE( void ) cstr_set_allocator P((cstr_allocator * alloc)); | ||
| 70 | |||
| 71 | _TYPE( cstr * ) cstr_new P((void)); | 61 | _TYPE( cstr * ) cstr_new P((void)); |
| 72 | _TYPE( cstr * ) cstr_new_alloc P((cstr_allocator * alloc)); | ||
| 73 | _TYPE( cstr * ) cstr_dup P((const cstr * str)); | 62 | _TYPE( cstr * ) cstr_dup P((const cstr * str)); |
| 74 | _TYPE( cstr * ) cstr_dup_alloc P((const cstr * str, cstr_allocator * alloc)); | ||
| 75 | _TYPE( cstr * ) cstr_create P((const char * s)); | 63 | _TYPE( cstr * ) cstr_create P((const char * s)); |
| 76 | _TYPE( cstr * ) cstr_createn P((const char * s, int len)); | 64 | _TYPE( cstr * ) cstr_createn P((const char * s, int len)); |
| 77 | 65 | ||
