<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jul 18, 2015 at 9:42 AM, Alan Coopersmith <span dir="ltr"><<a href="mailto:alan.coopersmith@oracle.com" target="_blank">alan.coopersmith@oracle.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 07/17/15 05:45 PM, Ben Hildred wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
So I wanted to really understand how the xcb layer works, so I thought I would<br>
port a couple c language XCB examples to perl. I assure you this is a great way<br>
to learn especially as X11::XCB is a work in progress. Anyway I hit a line that<br>
I really don't understand, that I was hoping that someone could explain to me,<br>
or point me to the relevant doc.<br>
<br>
xcb_connection_t *c;<br>
xcb_screen_t *screen;<br>
c = xcb_connect (NULL, NULL);<br>
screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;<br>
<br>
so we declare some variables, and connect. ok all good so far, and screen is a<br>
pointer to a useful struct that contains a lot of useful information, that I'm<br>
learning to use, but why are we doing a double function call? this does seem to<br>
be a common idiom as I have seen it from at least three different programmers.<br>
What are these two functions documented and why does noone keep the results from<br>
xcb_get_setup around so that you don't have to keep calling it especially when<br>
calling xcb_setup_toots_iterator which always seems to also call xcb_get_setup?<br>
At the moment this is not a critical problem as I am writing code that works, I<br>
just don't understand what is going on with that line.<br>
</blockquote>
<br></span>
xcb_get_setup() is just an accessor function that returns a pointer to data<br>
stored in the opaque xcb_connection_t - you don't need to save the pointer<br>
since the data is already saved and it's cheap to get the pointer again from<br>
the xcb_connection_t - if you look at the function, it's literally just a<br>
check for whether the connection is real or a fake error-handling placeholder,<br>
and then returning a pointer from a member of the opaque struct.</blockquote><div> </div><div>Ok, that makes sense.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
xcb_setup_roots_iterator just sets up a small structure with pointers to the<br>
list of roots in the xcb_setup_t and the mechanism to walk it without exposing<br>
the structure details to callers.</blockquote><div><br></div><div>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?</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><font color="#888888"><br>
<br>
-- <br>
-Alan Coopersmith- <a href="mailto:alan.coopersmith@oracle.com" target="_blank">alan.coopersmith@oracle.com</a><br>
Oracle Solaris Engineering - <a href="http://blogs.oracle.com/alanc" rel="noreferrer" target="_blank">http://blogs.or</a></font></span><font color="#1155cc"><u>forth</u></font><a href="http://blogs.oracle.com/alanc" rel="noreferrer" target="_blank">acle.com/alanc</a></blockquote></div>Thanks for your help.<br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div>--</div><div><div>Ben Hildred</div><div>Automation Support Services</div></div><div>303 815 6721</div></div>
</div></div>