[Xcb] Interning multiple atoms w/ one function call (alla
XInternAtoms)
Jamey Sharp
jamey at minilop.net
Thu Aug 11 03:31:43 EST 2005
On Tue, 2005-08-09 at 22:24 -0700, Travis Spencer wrote:
> On 8/9/05, Jamey Sharp <jamey at minilop.net> wrote:
> > Yup, all that is exactly right. Actually given the simplicity of writing
> > one for-loop to issue all the InternAtom requests, and then another to
> > get all the replies, it's not obvious to me that a new function is a win
> > here, even for porters.
>
> Its 30 lines of code that I wouldn't want to repeat in more than one
> or two places.
I had forgotten that I made sure the function would work even if memory
allocation failed. This is kind of silly, of course, since XCB is about
to do more memory allocation that will likely also fail...
Anyway, if you weren't constrained by Xlib's interface, you might be
able to just stack-allocate the intermediate array, or even
globally-allocate it. In either case you get rid of one-third of the
code in that function. And personally, I think this is really natural
code given the requirements:
for(i = 0; i < count; ++i)
cs[i] = XCBInternAtom(c, onlyIfExists, strlen(names[i]), names[i]);
for(i = 0; i < count; ++i)
{
XCBInternAtomRep *r = XCBInternAtomReply(c, cs[i], 0);
if(r)
atoms[i] = r->atom.xid;
free(r);
}
I wrote code in a similar style in xcb-util/wm/manage.c, when I needed
to make a GetWindowAttributes request for every child window reported by
QueryTree. I think this is going to become idiomatic for XCB.
> > That said, I implemented exactly the function being asked for in the old
> > XCL source; somebody could check it out of the xcl module in CVS if they
> > wanted to.
>
> That's a helpful resource. It might not be the best one since some
> things have changed,
I don't think any API used by this particular file has changed, FWIW.
> but it one more example to look at while learning
> this stuff. In case it helps someone or saves a couple minutes of Web
> surfing:
>
> cvs -d :pserver:anoncvs at keithp.com:/local/src/CVS login
> cvs -d :pserver:anoncvs at keithp.com:/local/src/CVS co xcb
No, don't use the keithp.com repository. I meant the 'xcl' module in
current XCB CVS. Here's the file in question via ViewCVS.
http://cvs.freedesktop.org/xcb/xcl/src/IntAtom.c?rev=HEAD&view=markup
--Jamey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/xcb/attachments/20050810/1ead908d/attachment-0001.pgp
More information about the xcb
mailing list