[Xcb] problem when getting replies
Vincent Torri
vtorri at univ-evry.fr
Sat Nov 11 07:21:36 PST 2006
Hey,
I've finished to write ecore_xcb. But (always a but) it seg fault, and I
don't understand the reason. The code is the following:
In a file, I define these variables and functions:
#define ECORE_XCB_ATOMS_COUNT 8
static xcb_intern_atom_cookie_t
ecore_xcb_atom_init_cookies[ECORE_XCB_ATOMS_COUNT];
/* Atoms */
EAPI Ecore_Xcb_Atom ECORE_XCB_ATOM_ATOM = 0;
EAPI Ecore_Xcb_Atom ECORE_XCB_ATOM_CARDINAL = 0;
EAPI Ecore_Xcb_Atom ECORE_XCB_ATOM_COMPOUND_TEXT = 0;
EAPI Ecore_Xcb_Atom ECORE_XCB_ATOM_FILE_NAME = 0;
EAPI Ecore_Xcb_Atom ECORE_XCB_ATOM_STRING = 0;
EAPI Ecore_Xcb_Atom ECORE_XCB_ATOM_TEXT = 0;
EAPI Ecore_Xcb_Atom ECORE_XCB_ATOM_UTF8_STRING = 0;
EAPI Ecore_Xcb_Atom ECORE_XCB_ATOM_WINDOW = 0;
/* To avoid round trips, the initialization is separated in 2
functions: _ecore_xcb_atom_init and
_ecore_xcb_atom_init_finalize. The first one gets the cookies and
the second one gets the replies and set the atoms. */
void
_ecore_xcb_atom_init(void)
{
const char *atom_names[ECORE_XCB_ATOMS_COUNT] = {
"ATOM",
"CARDINAL",
"COMPOUND_TEXT",
"FILE_NAME",
"STRING",
"TEXT",
"UTF8_STRING",
"WINDOW"
};
int i;
for (i = 0; i < ECORE_XCB_ATOMS_COUNT; i++)
ecore_xcb_atom_init_cookies[i] =
xcb_intern_atom_unchecked(_ecore_xcb_conn, 0,
strlen(atom_names[i]),
atom_names[i]);
}
void
_ecore_xcb_atom_init_finalize(void)
{
xcb_intern_atom_reply_t *replies[ECORE_XCB_ATOMS_COUNT];
int i;
for (i = 0; i < ECORE_XCB_ATOMS_COUNT; i++)
replies[i] = xcb_intern_atom_reply(_ecore_xcb_conn,
ecore_xcb_atom_init_cookies[i],
NULL);
ECORE_XCB_ATOM_ATOM = replies[0]->atom;
ECORE_XCB_ATOM_CARDINAL = replies[1]->atom;
ECORE_XCB_ATOM_COMPOUND_TEXT = replies[2]->atom;
ECORE_XCB_ATOM_FILE_NAME = replies[3]->atom;
ECORE_XCB_ATOM_STRING = replies[4]->atom;
ECORE_XCB_ATOM_TEXT = replies[5]->atom;
ECORE_XCB_ATOM_UTF8_STRING = replies[6]->atom;
ECORE_XCB_ATOM_WINDOW = replies[7]->atom;
for (i = 0; i < ECORE_XCB_ATOMS_COUNT; i++)
free(replies[i]);
}
So it's not that complicated. I save the cookies in a global variable and
I set them in _ecore_xcb_atom_init. Later, I call
_ecore_xcb_atom_init_finalize to get the replies and to set the atoms.
In another function (ecore_xcb_init, to name it), I use these functions:
{
/* I prefetch the extension data */
...
...
/* I 'initialize' the atoms */
_ecore_xcb_atom_init ();
/* other similar init functions */
/* I get the extension data */
...
...
/* I 'finalize' the init */
_ecore_xcb_atom_init_finalize();
/* other similar finalization functions, in the same order */
}
If I only keep the ecore_xcb_atom_init(_finalize) functions, and not the
others *init(_finalize) functions, no seg fault. If I add the others, all
the replies in ecore_xcb_atom_init_finalize are NULL.
I'm certainly doing something wrong, but I don't know what.
Does someone have an idea, please ?
Vincent
More information about the Xcb
mailing list