Problème récupération pointeur
:salut:
Je suis devant un problème que je ne m'explique pas, je vous donne de quoi vérifier le code puis ensuite vous montre le problème...
J'ai un objet de base:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| typedef struct _BObject BObject;
...
struct _BObject
{
/* Private object informations. */
BType * type;
/* Callback function for auto-destroy. */
BDestroyCallback destroy_func;
/* Object is pointed ? */
BLib_bool pointed;
/* Reserved pointers for futur. */
void * p_reserved_1;
void * p_reserved_2;
void * p_reserved_3;
/* Chaining for all objects. */
struct _BObject * p_prev;
struct _BObject * p_next;
}; |
et un objet String que voici:
Code:
1 2 3 4 5 6 7 8
| typedef struct
{
BObject;
char * sz_string; /* Always null terminated string. */
size_t len;
}BString; |
j'ai un semblant de garbage collector qui n'est autre qu'une liste d'objets:
Code:
1 2 3 4 5 6 7 8 9 10
| typedef struct
{
BObject * p_head;
BObject * p_tail;
BObject * p_cur;
size_t ref_cnt;
}BGarbageCollector;
...
BGarbageCollector BGC; |
J'ai une fonction qui permet de récupérer le pointeur d'un objet mis de côté pour être réutilisé:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| DECLSPEC BObject * b_gc_find_saved_object (const char * s_object_type)
{
BObject * p_obj = NULL;
if (s_object_type)
{
size_t i = 0;
BGC.p_cur = BGC.p_head;
for (i = 0; i < BGC.ref_cnt; i++)
{
if (BGC.p_cur->pointed)
break;
else
if (IS_TYPE (BGC.p_cur, s_object_type))
{
p_obj = BGC.p_cur;
break;
}
BGC.p_cur = BGC.p_cur->p_next;
}
}
return p_obj;
} |
Dans mon module qui permet de parser des fichiers de type ini/conf j'ai la fonction suivante:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| static BString * b_prefs_get_value (const char * s_filename,
const char * s_section_name,
const char * s_key_name)
{
BString * p_value = NULL;
if (s_filename && s_section_name && s_key_name)
{
BString * p_str = NULL;
if (b_string_cat_with_str (p_str, "[", s_section_name, "]", NULL))
{
FILE * p_file = fopen (s_filename, "r");
if (p_file)
{
char line[BUF_SIZE] = {0};
BLib_bool section_found = BLIB_FALSE;
while (fgets (line, BUF_SIZE, p_file))
{
if (!section_found)
if (strstr (line, b_string_get (p_str)))
section_found = BLIB_TRUE;
else
if (strstr (line, s_key_name))
{
char * p = strchr (line, SEP);
if (p)
{
p_value = B_STRING_PTR (b_gc_find_saved_object (
B_STRING_TYPE));
if (p_value)
{
b_object_set_pointed (
B_OBJECT_ADDR (p_value),
BLIB_TRUE);
b_string_set_text (p_value, p+1);
}
else
p_value = b_string_new_with_text (p+1);
}
}
}
fclose (p_file);
}
b_string_free (B_OBJECT_ADDR (p_str));
}
}
return p_value;
} |
C'est la ligne en rouge qui pose problème (warning):
Citation:
/media/hecht/CORSAIR/Projects/BEngine/BLib/parsers/BLib_prefs.c|87|attention : transtypage vers un pointeur depuis un entier de taille différente [-Wint-to-pointer-cast]|
Pour infos, B_STRING_PTR est la macro suivante:
Code:
1 2
| #define B_STRING_PTR(obj) \
(BString *)(obj) |
J'ai essayé en récupérant directement le retour de la fonction avec un objet du même type comme ceci:
Code:
BObject * p2 = b_gc_find_saved_object (B_STRING_TYPE);
mais j'ai ceci comme warning:
Citation:
/media/hecht/CORSAIR/Projects/BEngine/BLib/parsers/BLib_prefs.c|87|attention : initialization makes pointer from integer without a cast [enabled by default]|
Si quelqu'un vois le problème... :aie: re-:aie:
:merci: