[Xcb] xcb_setup_roots_iterator

Ben Hildred 42656e at gmail.com
Sat Jul 18 10:19:10 PDT 2015


On Sat, Jul 18, 2015 at 9:42 AM, Alan Coopersmith <
alan.coopersmith at oracle.com> wrote:

> On 07/17/15 05:45 PM, Ben Hildred wrote:
>
>>
>> So I wanted to really understand how the xcb layer works, so I thought I
>> would
>> port a couple c language XCB examples to perl. I assure you this is a
>> great way
>> to learn especially as X11::XCB is a work in progress. Anyway I hit a
>> line that
>> I really don't understand, that I was hoping that someone could explain
>> to me,
>> or point me to the relevant doc.
>>
>> xcb_connection_t    *c;
>> xcb_screen_t        *screen;
>> c = xcb_connect (NULL, NULL);
>> screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
>>
>> so we declare some variables, and connect. ok all good so far, and screen
>> is a
>> pointer to a useful struct that contains a lot of useful information,
>> that I'm
>> learning to use, but why are we doing a double function call? this does
>> seem to
>> be a common idiom as I have seen it from at least three different
>> programmers.
>> What are these two functions documented and why does noone keep the
>> results from
>> xcb_get_setup around so that you don't have to keep calling it especially
>> when
>> calling xcb_setup_toots_iterator which always seems to also call
>> xcb_get_setup?
>> At the moment this is not a critical problem as I am writing code that
>> works, I
>> just don't understand what is going on with that line.
>>
>
> xcb_get_setup() is just an accessor function that returns a pointer to data
> stored in the opaque xcb_connection_t - you don't need to save the pointer
> since the data is already saved and it's cheap to get the pointer again
> from
> the xcb_connection_t - if you look at the function, it's literally just a
> check for whether the connection is real or a fake error-handling
> placeholder,
> and then returning a pointer from a member of the opaque struct.


Ok, that makes sense.


> xcb_setup_roots_iterator just sets up a small structure with pointers to
> the
> list of roots in the xcb_setup_t and the mechanism to walk it without
> exposing
> the structure details to callers.


and that explains a lot of the examples, I have seen the walker function
too, but I have not seen a corresponding free function. Does it set up the
indexes in the connection structure or is that fourth line just a small
memory leak as only the data member is used or saved and the structure
returned never freed?

>
>
> --
>         -Alan Coopersmith-              alan.coopersmith at oracle.com
>          Oracle Solaris Engineering - http://blogs.or
> <http://blogs.oracle.com/alanc>*forth*acle.com/alanc
> <http://blogs.oracle.com/alanc>

Thanks for your help.


-- 
--
Ben Hildred
Automation Support Services
303 815 6721
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20150718/9a6c56a2/attachment.html>


More information about the Xcb mailing list