Change memory allocation API to require size for free and realloc.

This commit is contained in:
Damien
2013-12-29 19:33:23 +00:00
parent a1c8e5737c
commit 732407f1bf
22 changed files with 57 additions and 52 deletions

View File

@@ -16,8 +16,8 @@ void qstr_init(void) {
static qstr qstr_add(const char *str) {
if (qstrs_len >= qstrs_alloc) {
qstrs = m_renew(const char*, qstrs, qstrs_alloc, qstrs_alloc * 2);
qstrs_alloc *= 2;
qstrs = m_renew(const char*, qstrs, qstrs_alloc);
}
qstrs[qstrs_len++] = str;
return qstrs_len - 1;
@@ -32,10 +32,10 @@ qstr qstr_from_str_static(const char *str) {
return qstr_add(str);
}
qstr qstr_from_str_take(char *str) {
qstr qstr_from_str_take(char *str, int alloc_len) {
for (int i = 0; i < qstrs_len; i++) {
if (strcmp(qstrs[i], str) == 0) {
m_free(str);
m_del(char, str, alloc_len);
return i;
}
}