Commit 3e59d344 authored by Cedric BAIL's avatar Cedric BAIL

* eet: Fix override of global symbols.

	Patch from Albin "Lutin" Tonnerre <albin.tonnerre@gmail.com>


SVN revision: 46682
parent d7aa7829
......@@ -8,3 +8,4 @@ Vincent Torri <vtorri@univ-evry.fr>
Gustavo Sverzut Barbieri <barbieri@gmail.com>
Raphael Kubo da Costa <kubo@profusion.mobi>
Mathieu Taillefumier <mathieu.taillefumier@free.fr>
Albin "Lutin" Tonnerre <albin.tonnerre@gmail.com>
......@@ -299,7 +299,7 @@
2010-01-04 Carsten Haitzler (The Rasterman)
* Fix another thread deadlock in mutex handling even in a single-threaded app.
2010-01-12 Cedric BAIL
* Rewrite Eet_Data. Now you can do list/hash/array of strings and all
......@@ -334,3 +334,6 @@
* Improve security by zeroying cipher material as soon as possible.
2010-03-01 Albin Tonnerre
* Fix override of global symbols.
......@@ -448,11 +448,11 @@ eet_data_get_string_hash(const Eet_Dictionary *ed, const void *src, const void *
{
if (ed)
{
int index;
int idx;
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
if (eet_data_get_int(ed, src, src_end, &idx) < 0) return -1;
return eet_dictionary_string_get_hash(ed, index);
return eet_dictionary_string_get_hash(ed, idx);
}
return -1;
......@@ -468,16 +468,16 @@ eet_data_get_string(const Eet_Dictionary *ed, const void *src, const void *src_e
if (ed)
{
const char *str;
int index;
int idx;
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
if (eet_data_get_int(ed, src, src_end, &idx) < 0) return -1;
str = eet_dictionary_string_get_char(ed, index);
str = eet_dictionary_string_get_char(ed, idx);
if (str == NULL)
return -1;
*d = (char *) str;
return eet_dictionary_string_get_size(ed, index);
return eet_dictionary_string_get_size(ed, idx);
}
s = (char *)src;
......@@ -500,15 +500,15 @@ eet_data_put_string(Eet_Dictionary *ed, const void *src, int *size_ret)
if (ed)
{
const char *str;
int index;
int idx;
str = *((const char **) src);
if (!str) return NULL;
index = eet_dictionary_string_add(ed, str);
if (index == -1) return NULL;
idx = eet_dictionary_string_add(ed, str);
if (idx == -1) return NULL;
return eet_data_put_int(ed, &index, size_ret);
return eet_data_put_int(ed, &idx, size_ret);
}
s = (char *)(*((char **)src));
......@@ -598,7 +598,7 @@ static int
eet_data_get_float(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
float *d;
int index;
int idx;
d = (float *) dst;
if (!ed)
......@@ -621,9 +621,9 @@ eet_data_get_float(const Eet_Dictionary *ed, const void *src, const void *src_en
return len + 1;
}
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
if (eet_data_get_int(ed, src, src_end, &idx) < 0) return -1;
if (!eet_dictionary_string_get_float(ed, index, d))
if (!eet_dictionary_string_get_float(ed, idx, d))
return -1;
return 1;
}
......@@ -632,7 +632,7 @@ static void *
eet_data_put_float(Eet_Dictionary *ed, const void *src, int *size_ret)
{
char buf[128];
int index;
int idx;
eina_convert_dtoa((double)(*(float *)src), buf);
......@@ -649,10 +649,10 @@ eet_data_put_float(Eet_Dictionary *ed, const void *src, int *size_ret)
return d;
}
index = eet_dictionary_string_add(ed, buf);
if (index == -1) return NULL;
idx = eet_dictionary_string_add(ed, buf);
if (idx == -1) return NULL;
return eet_data_put_int(ed, &index, size_ret);
return eet_data_put_int(ed, &idx, size_ret);
}
/* DOUBLE TYPE */
......@@ -660,7 +660,7 @@ static int
eet_data_get_double(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
double *d;
int index;
int idx;
d = (double *) dst;
......@@ -684,9 +684,9 @@ eet_data_get_double(const Eet_Dictionary *ed, const void *src, const void *src_e
return len + 1;
}
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
if (eet_data_get_int(ed, src, src_end, &idx) < 0) return -1;
if (!eet_dictionary_string_get_double(ed, index, d))
if (!eet_dictionary_string_get_double(ed, idx, d))
return -1;
return 1;
}
......@@ -695,7 +695,7 @@ static void *
eet_data_put_double(Eet_Dictionary *ed, const void *src, int *size_ret)
{
char buf[128];
int index;
int idx;
eina_convert_dtoa((double)(*(double *)src), buf);
......@@ -713,25 +713,25 @@ eet_data_put_double(Eet_Dictionary *ed, const void *src, int *size_ret)
return d;
}
index = eet_dictionary_string_add(ed, buf);
if (index == -1) return NULL;
idx = eet_dictionary_string_add(ed, buf);
if (idx == -1) return NULL;
return eet_data_put_int(ed, &index, size_ret);
return eet_data_put_int(ed, &idx, size_ret);
}
static int
eet_data_get_f32p32(const Eet_Dictionary *ed, const void *src, const void *src_end, void *dst)
{
Eina_F32p32 *fp;
int index;
int idx;
fp = (Eina_F32p32*) dst;
if (!ed) return -1;
if (eet_data_get_int(ed, src, src_end, &index) < 0) return -1;
if (eet_data_get_int(ed, src, src_end, &idx) < 0) return -1;
if (!eet_dictionary_string_get_fp(ed, index, fp))
if (!eet_dictionary_string_get_fp(ed, idx, fp))
return -1;
return 1;
}
......@@ -740,16 +740,16 @@ static void *
eet_data_put_f32p32(Eet_Dictionary *ed, const void *src, int *size_ret)
{
char buf[128];
int index;
int idx;
if (!ed) return NULL;
eina_convert_fptoa((Eina_F32p32)(*(Eina_F32p32 *)src), buf);
index = eet_dictionary_string_add(ed, buf);
if (index == -1) return NULL;
idx = eet_dictionary_string_add(ed, buf);
if (idx == -1) return NULL;
return eet_data_put_int(ed, &index, size_ret);
return eet_data_put_int(ed, &idx, size_ret);
}
static int
......@@ -2744,8 +2744,6 @@ eet_data_get_array(Eet_Free_Context *context, const Eet_Dictionary *ed, Eet_Data
if (IS_POINTER_TYPE(echnk->type))
{
int ret;
ret = eet_data_get_unknown(context, ed, edd, ede, echnk, echnk->type, EET_G_UNKNOWN,
&data_ret, p, size);
if (!ret) goto on_error;
......
......@@ -81,7 +81,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
Eet_String *current;
char *str;
int hash;
int index;
int idx;
int len;
if (!ed)
......@@ -89,19 +89,19 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
hash = _eet_hash_gen(string, 8);
index = _eet_dictionary_lookup(ed, string, hash);
idx = _eet_dictionary_lookup(ed, string, hash);
if (index != -1)
if (idx != -1)
{
if (ed->all[index].str)
if (ed->all[idx].str)
{
if (strcmp(ed->all[index].str, string) == 0)
return index;
if (strcmp(ed->all[idx].str, string) == 0)
return idx;
}
if (ed->all[index].mmap)
if (ed->all[idx].mmap)
{
if (strcmp(ed->all[index].mmap, string) == 0)
return index;
if (strcmp(ed->all[idx].mmap, string) == 0)
return idx;
}
}
......@@ -135,7 +135,7 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
current->len = len;
current->mmap = NULL;
if (index == -1)
if (idx == -1)
{
current->next = ed->hash[hash];
current->prev = -1;
......@@ -143,8 +143,8 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
}
else
{
current->next = index;
current->prev = ed->all[index].prev;
current->next = idx;
current->prev = ed->all[idx].prev;
if (current->next != -1)
ed->all[current->next].prev = ed->count;
......@@ -158,44 +158,44 @@ eet_dictionary_string_add(Eet_Dictionary *ed, const char *string)
}
int
eet_dictionary_string_get_size(const Eet_Dictionary *ed, int index)
eet_dictionary_string_get_size(const Eet_Dictionary *ed, int idx)
{
if (!ed) return 0;
if (index < 0) return 0;
if (index < ed->count)
return ed->all[index].len;
if (idx < 0) return 0;
if (idx < ed->count)
return ed->all[idx].len;
return 0;
}
int
eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int index)
eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int idx)
{
if (!ed) return -1;
if (index < 0) return -1;
if (index < ed->count)
return ed->all[index].hash;
if (idx < 0) return -1;
if (idx < ed->count)
return ed->all[idx].hash;
return -1;
}
const char *
eet_dictionary_string_get_char(const Eet_Dictionary *ed, int index)
eet_dictionary_string_get_char(const Eet_Dictionary *ed, int idx)
{
if (!ed) return NULL;
if (index < 0) return NULL;
if (index < ed->count)
if (idx < 0) return NULL;
if (idx < ed->count)
{
#ifdef _WIN32
/* Windows file system could change the mmaped file when replacing a file. So we need to copy all string in memory to avoid bugs. */
if (ed->all[index].str == NULL)
if (ed->all[idx].str == NULL)
{
ed->all[index].str = strdup(ed->all[index].mmap);
ed->all[index].mmap = NULL;
ed->all[idx].str = strdup(ed->all[idx].mmap);
ed->all[idx].mmap = NULL;
}
#else
if (ed->all[index].mmap)
return ed->all[index].mmap;
if (ed->all[idx].mmap)
return ed->all[idx].mmap;
#endif
return ed->all[index].str;
return ed->all[idx].str;
}
return NULL;
}
......@@ -246,93 +246,93 @@ _eet_dictionary_string_get_double_cache(const char *s, int len, double *result)
}
static inline Eina_Bool
_eet_dictionary_test(const Eet_Dictionary *ed, int index, void *result)
_eet_dictionary_test(const Eet_Dictionary *ed, int idx, void *result)
{
if (!result) return EINA_FALSE;
if (!ed) return EINA_FALSE;
if (index < 0) return EINA_FALSE;
if (!(index < ed->count)) return EINA_FALSE;
if (idx < 0) return EINA_FALSE;
if (!(idx < ed->count)) return EINA_FALSE;
return EINA_TRUE;
}
Eina_Bool
eet_dictionary_string_get_float(const Eet_Dictionary *ed, int index, float *result)
eet_dictionary_string_get_float(const Eet_Dictionary *ed, int idx, float *result)
{
if (!_eet_dictionary_test(ed, index, result)) return EINA_FALSE;
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
if (!(ed->all[index].type & EET_D_FLOAT))
if (!(ed->all[idx].type & EET_D_FLOAT))
{
const char *str;
str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap;
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
if (!_eet_dictionary_string_get_float_cache(str, ed->all[index].len, &ed->all[index].f))
if (!_eet_dictionary_string_get_float_cache(str, ed->all[idx].len, &ed->all[idx].f))
{
long long mantisse = 0;
long exponent = 0;
if (eina_convert_atod(str, ed->all[index].len, &mantisse, &exponent) == EINA_FALSE)
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE)
return EINA_FALSE;
ed->all[index].f = ldexpf((float) mantisse, exponent);
ed->all[idx].f = ldexpf((float) mantisse, exponent);
}
ed->all[index].type |= EET_D_FLOAT;
ed->all[idx].type |= EET_D_FLOAT;
}
*result = ed->all[index].f;
*result = ed->all[idx].f;
return EINA_TRUE;
}
Eina_Bool
eet_dictionary_string_get_double(const Eet_Dictionary *ed, int index, double *result)
eet_dictionary_string_get_double(const Eet_Dictionary *ed, int idx, double *result)
{
if (!_eet_dictionary_test(ed, index, result)) return EINA_FALSE;
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
if (!(ed->all[index].type & EET_D_DOUBLE))
if (!(ed->all[idx].type & EET_D_DOUBLE))
{
const char *str;
str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap;
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
if (!_eet_dictionary_string_get_double_cache(str, ed->all[index].len, &ed->all[index].d))
if (!_eet_dictionary_string_get_double_cache(str, ed->all[idx].len, &ed->all[idx].d))
{
long long mantisse = 0;
long exponent = 0;
if (eina_convert_atod(str, ed->all[index].len, &mantisse, &exponent) == EINA_FALSE)
if (eina_convert_atod(str, ed->all[idx].len, &mantisse, &exponent) == EINA_FALSE)
return EINA_FALSE;
ed->all[index].d = ldexp((double) mantisse, exponent);
ed->all[idx].d = ldexp((double) mantisse, exponent);
}
ed->all[index].type |= EET_D_DOUBLE;
ed->all[idx].type |= EET_D_DOUBLE;
}
*result = ed->all[index].d;
*result = ed->all[idx].d;
return EINA_TRUE;
}
Eina_Bool
eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int index, Eina_F32p32 *result)
eet_dictionary_string_get_fp(const Eet_Dictionary *ed, int idx, Eina_F32p32 *result)
{
if (!_eet_dictionary_test(ed, index, result)) return EINA_FALSE;
if (!_eet_dictionary_test(ed, idx, result)) return EINA_FALSE;
if (!(ed->all[index].type & EET_D_FIXED_POINT))
if (!(ed->all[idx].type & EET_D_FIXED_POINT))
{
const char *str;
Eina_F32p32 fp;
str = ed->all[index].str ? ed->all[index].str : ed->all[index].mmap;
str = ed->all[idx].str ? ed->all[idx].str : ed->all[idx].mmap;
if (!eina_convert_atofp(str, ed->all[index].len, &fp))
if (!eina_convert_atofp(str, ed->all[idx].len, &fp))
return EINA_FALSE;
ed->all[index].fp = fp;
ed->all[index].type |= EET_D_FIXED_POINT;
ed->all[idx].fp = fp;
ed->all[idx].type |= EET_D_FIXED_POINT;
}
*result = ed->all[index].fp;
*result = ed->all[idx].fp;
return EINA_TRUE;
}
......
This diff is collapsed.
......@@ -898,7 +898,7 @@ eet_internal_read2(Eet_File *ef)
{
const int *data = (const int*) ef->data;
const char *start = (const char*) ef->data;
int index = 0;
int idx = 0;
int num_directory_entries;
int bytes_directory_entries;
int num_dictionary_entries;
......@@ -906,7 +906,7 @@ eet_internal_read2(Eet_File *ef)
int signature_base_offset;
int i;
index += sizeof(int);
idx += sizeof(int);
if (eet_test_close((int) ntohl(*data) != EET_MAGIC_FILE2, ef))
return NULL;
data++;
......@@ -919,9 +919,9 @@ eet_internal_read2(Eet_File *ef)
}
/* get entries count and byte count */
GET_INT(num_directory_entries, data, index);
GET_INT(num_directory_entries, data, idx);
/* get dictionary count and byte count */
GET_INT(num_dictionary_entries, data, index);
GET_INT(num_dictionary_entries, data, idx);
bytes_directory_entries = EET_FILE2_DIRECTORY_ENTRY_SIZE * num_directory_entries + EET_FILE2_HEADER_SIZE;
bytes_dictionary_entries = EET_FILE2_DICTIONARY_ENTRY_SIZE * num_dictionary_entries;
......@@ -972,12 +972,12 @@ eet_internal_read2(Eet_File *ef)
return NULL;
/* get entrie header */
GET_INT(efn->offset, data, index);
GET_INT(efn->size, data, index);
GET_INT(efn->data_size, data, index);
GET_INT(name_offset, data, index);
GET_INT(name_size, data, index);
GET_INT(flag, data, index);
GET_INT(efn->offset, data, idx);
GET_INT(efn->size, data, idx);
GET_INT(efn->data_size, data, idx);
GET_INT(name_offset, data, idx);
GET_INT(name_size, data, idx);
GET_INT(flag, data, idx);
efn->compression = flag & 0x1 ? 1 : 0;
efn->ciphered = flag & 0x2 ? 1 : 0;
......@@ -1035,7 +1035,7 @@ eet_internal_read2(Eet_File *ef)
const int *dico = (const int*) ef->data + EET_FILE2_DIRECTORY_ENTRY_COUNT * num_directory_entries + EET_FILE2_HEADER_COUNT;
int j;
if (eet_test_close((num_dictionary_entries * (int) EET_FILE2_DICTIONARY_ENTRY_SIZE + index) > (bytes_dictionary_entries + bytes_directory_entries), ef))
if (eet_test_close((num_dictionary_entries * (int) EET_FILE2_DICTIONARY_ENTRY_SIZE + idx) > (bytes_dictionary_entries + bytes_directory_entries), ef))
return NULL;
ef->ed = calloc(1, sizeof (Eet_Dictionary));
......@@ -1054,11 +1054,11 @@ eet_internal_read2(Eet_File *ef)
int hash;
int offset;
GET_INT(hash, dico, index);
GET_INT(offset, dico, index);
GET_INT(ef->ed->all[j].len, dico, index);
GET_INT(ef->ed->all[j].prev, dico, index);
GET_INT(ef->ed->all[j].next, dico, index);
GET_INT(hash, dico, idx);
GET_INT(offset, dico, idx);
GET_INT(ef->ed->all[j].len, dico, idx);
GET_INT(ef->ed->all[j].prev, dico, idx);
GET_INT(ef->ed->all[j].next, dico, idx);
/* Hash value could be stored on 8bits data, but this will break alignment of all the others data.
So stick to int and check the value. */
......@@ -1120,7 +1120,7 @@ eet_internal_read1(Eet_File *ef)
{
const unsigned char *dyn_buf = NULL;
const unsigned char *p = NULL;
int index = 0;
int idx = 0;
int num_entries;
int byte_entries;
int i;
......@@ -1129,7 +1129,7 @@ eet_internal_read1(Eet_File *ef)
/* build header table if read mode */
/* geat header */
index += sizeof(int);
idx += sizeof(int);
if (eet_test_close((int)ntohl(*((int *)ef->data)) != EET_MAGIC_FILE, ef))
return NULL;
......@@ -1142,8 +1142,8 @@ eet_internal_read1(Eet_File *ef)
}
/* get entries count and byte count */
EXTRACT_INT(num_entries, ef->data, index);
EXTRACT_INT(byte_entries, ef->data, index);
EXTRACT_INT(num_entries, ef->data, idx);
EXTRACT_INT(byte_entries, ef->data, idx);
/* we cant have <= 0 values here - invalid */
if (eet_test_close((num_entries <= 0) || (byte_entries <= 0), ef))
......@@ -1177,7 +1177,7 @@ eet_internal_read1(Eet_File *ef)
return NULL;
/* actually read the directory block - all of it, into ram */
dyn_buf = ef->data + index;
dyn_buf = ef->data + idx;
/* parse directory block */
p = dyn_buf;
......@@ -1844,7 +1844,7 @@ eet_read_direct(Eet_File *ef, const char *name, int *size_ret)
}
EAPI int
eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int compress, const char *cipher_key)
eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int comp, const char *cipher_key)
{
Eet_File_Node *efn;
void *data2 = NULL;
......@@ -1895,16 +1895,16 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
/* figure hash bucket */
hash = _eet_hash_gen(name, ef->header->directory->size);
data_size = compress ? 12 + ((size * 101) / 100) : size;
data_size = comp ? 12 + ((size * 101) / 100) : size;
if (compress || !cipher_key)
if (comp || !cipher_key)
{
data2 = malloc(data_size);
if (!data2) goto on_error;
}
/* if we want to compress */
if (compress)
if (comp)
{
uLongf buflen;
......@@ -1920,7 +1920,7 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
data_size = (int)buflen;
if (data_size < 0 || data_size >= size)
{
compress = 0;
comp = 0;
data_size = size;
}
else
......@@ -1954,7 +1954,7 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
}
}
else
if (!compress)
if (!comp)
memcpy(data2, data, size);
/* Does this node already exist? */
......@@ -1965,7 +1965,7 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
{
free(efn->data);
efn->ciphered = cipher_key ? 1 : 0;
efn->compression = !!compress;
efn->compression = !!comp;
efn->size = data_size;
efn->data_size = size;
efn->data = data2;
......@@ -1990,7 +1990,7 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
ef->header->directory->nodes[hash] = efn;
efn->offset = -1;
efn->ciphered = cipher_key ? 1 : 0;
efn->compression = !!compress;
efn->compression = !!comp;
efn->size = data_size;
efn->data_size = size;
efn->data = data2;
......@@ -2007,9 +2007,9 @@ eet_write_cipher(Eet_File *ef, const char *name, const void *data, int size, int
}
EAPI int
eet_write(Eet_File *ef, const char *name, const void *data, int size, int compress)
eet_write(Eet_File *ef, const char *name, const void *data, int size, int comp)
{
return eet_write_cipher(ef, name, data, size, compress, NULL);
return eet_write_cipher(ef, name, data, size, comp, NULL);
}
EAPI int
......
......@@ -626,8 +626,8 @@ eet_node_walk(void *parent, const char *name, Eet_Node *root, Eet_Node_Walk *cb,
int
eet_node_init(void)
{
char *choice;
char *tmp;
const char *choice;
const char *tmp;
choice = "chained_mempool";
tmp = getenv("EET_MEMPOOL");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment