[Xcb] problem when getting replies

Ian Osgood iano at quirkster.com
Sat Nov 11 09:41:38 PST 2006


How about using the "checked" versions of the xcb calls and looking  
at the errors?

If you have problems with other init/finalize code, then maybe that  
is where the bugs are.

Is your work up in a public repository somewhere?

Ian

On Nov 11, 2006, at 9:23 AM, Vincent Torri wrote:

>
> Hey,
>
> it does not help :/
>
> Also, as I said, if I just use the _ecore_xcb_atom_init(_finalize)  
> functions and not the others, it does no segfault.
>
> Vincent
>
> PS: if someone wants, I can upload the whole ecore package somewhere
>
> On Sat, 11 Nov 2006, Ian Osgood wrote:
>
>> A difference between Xlib and the raw protocol is that Xlib hides  
>> the difference between predefined and custom atoms. The atoms  
>> "ATOM", "CARDINAL", "STRING", and "WINDOW" are predefined, so you  
>> must not intern them. That is probably why you get the segfault.
>>
>> If you want to keep the code identical, you can use the XCBAtom  
>> library, include <xcb/xcb_atom.h> and call intern_atom_fast() and  
>> intern_atom_fast_reply() instead of xcb_intern_atom() and  
>> xcb_intern_atom_reply().
>>
>> Ian
>>
>> On Nov 11, 2006, at 7:21 AM, Vincent Torri wrote:
>>
>>> 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