[Xcb] Interning multiple atoms w/ one function call (alla XInternAtoms)

Travis Spencer travislspencer at gmail.com
Wed Aug 10 15:43:13 EST 2005


On 8/9/05, Vincent Torri <Vincent.Torri at iecn.u-nancy.fr> wrote:
> in this xcl function, why allocating memory (for cs) and doing 2 loops ?
> That is, why not always doing something like in the case when the
> allocation of cs fails ?

In case the reply fails.

    for (i = 0; i < count; ++i) {
        XCBInternAtomRep *r;
        r = XCBInternAtomReply(c, cs[i], 0);
        if (!r) {
            ret = 0; /* something failed... */
            continue; /* ...but finish working anyway. */
        }
        atoms_return[i] = r->atom.xid;
        free(r);
    }

If the ith reply fails, the ith Atom passed in will be unmodified. 
When the caller checks the return Status, it will see that it is 0 and
be able to determine which atoms failed.  Something like this maybe:

Atoms atoms[ATOMS_CNT] = {0};

if (XInternAtoms(dpy, names, ATOMS_CNT, false, atoms) == 0)
    for (int i = 0; i < ATOMS_CNT; i++)
        if (atoms[i] == 0)
            fprintf(stderr, "Failed to set atom `%s'\n", names[i]);

I just looked at the code for the first time, so I might be off.  But,
that is my best, untested guess.

-- 

Regards,

Travis Spencer


More information about the xcb mailing list