Created
December 1, 2013 06:55
-
-
Save o11c/7729355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// amd64 | |
typedef unsigned long size_t; | |
void *tor_realloc(void *, size_t); | |
typedef struct smartlist_t { | |
/** @{ */ | |
/** <b>list</b> has enough capacity to store exactly <b>capacity</b> elements | |
* before it needs to be resized. Only the first <b>num_used</b> (\<= | |
* capacity) elements point to valid data. | |
*/ | |
void **list; | |
int num_used; | |
int capacity; | |
/** @} */ | |
} smartlist_t; | |
void | |
smartlist_ensure_capacity(smartlist_t *sl, int size) | |
{ | |
#define MAX_CAPACITY (0x7fffffff) | |
if (size > sl->capacity) { | |
int higher = sl->capacity; | |
if ((size > MAX_CAPACITY/2)) { | |
higher = MAX_CAPACITY; | |
} else { | |
while (size > higher) | |
higher *= 2; | |
} | |
sl->capacity = higher; | |
sl->list = tor_realloc(sl->list, sizeof(void*)*((size_t)sl->capacity)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment