[Xcb] Are there any naming conventions for XCB?
Uli Schlachter
psychon at znc.in
Mon Mar 8 15:53:42 UTC 2021
By fixing the compiler warnings, I got the following working version
(sorry for line wrapping, but you'll manage):
#include <stdio.h>
#include <stdlib.h>
#include <xcb/xcb.h>
int main(void)
{
xcb_connection_t *connection = xcb_connect(NULL, NULL);
xcb_list_extensions_cookie_t cookie = xcb_list_extensions(connection);
const xcb_list_extensions_reply_t *reply =
xcb_list_extensions_reply(connection, cookie, 0);
/*const*/ xcb_str_iterator_t str_iterator =
xcb_list_extensions_names_iterator(reply);
while(str_iterator.rem) {
int length = xcb_str_name_length(str_iterator.data);
char *name = xcb_str_name(str_iterator.data);
fwrite(name, sizeof(*name), length, stdout);
putchar('\n');
xcb_str_next(&str_iterator);
}
xcb_disconnect(connection);
exit(EXIT_SUCCESS);
}
Cheers,
Uli
Am 08.03.21 um 16:50 schrieb Lucas Augusto Valentim Dantas:
> #include <stdio.h>
> #include <stdlib.h>
>
> #include <xcb/xcb.h>
> Yeah the program doesn't work like I thought it would.
>
> int main(void)
> {
> xcb_connection_t *connection = xcb_connect(NULL, NULL);
> xcb_list_extensions_cookie_t cookie = xcb_list_extensions(connection);
> const xcb_list_extensions_reply_t *reply = xcb_list_extensions_reply(connection, cookie, 0);
> const xcb_str_iterator_t str_iterator = xcb_list_extensions_names_iterator(reply);
> while(str_iterator.rem) {
> int length = xcb_str_name_length(&str_iterator); // doesn't work
> char *name = xcb_str_name(&str_iterator); // doesn't work
> fwrite(name, sizeof(*name), length, stdout);
> putchar('\n');
> xcb_str_next(&str_iterator);
> }
> xcb_disconnect(connection);
> exit(EXIT_SUCCESS);
> }
>
>
> ________________________________
> De: Xcb <xcb-bounces at lists.freedesktop.org> em nome de Lucas Augusto Valentim Dantas <lucasvalentim at outlook.com.br>
> Enviado: segunda-feira, 8 de março de 2021 11:20
> Para: xcb at lists.freedesktop.org <xcb at lists.freedesktop.org>
> Assunto: Re: [Xcb] Are there any naming conventions for XCB?
>
>
> I wasn't aware that the pointer value of the first member of a struct equals to the pointer value of the struct itself.
>
> From the C89 draft: "A pointer to a structure object, suitably
> cast, points to its initial member (or if that member is a bit-field,
> then to the unit in which it resides), and vice versa. There may
> therefore be unnamed holes within a structure object, but not at its
> beginning, as necessary to achieve the appropriate alignment."
>
> xcb_str_name() covers that necessity then.
>
> ________________________________
> De: Xcb <xcb-bounces at lists.freedesktop.org> em nome de Lucas Augusto Valentim Dantas <lucasvalentim at outlook.com.br>
> Enviado: segunda-feira, 8 de março de 2021 08:11
> Para: xcb at lists.freedesktop.org <xcb at lists.freedesktop.org>
> Assunto: Re: [Xcb] Are there any naming conventions for XCB?
>
> I am resending this e-mail to the list, I didn't notice I was replying to Uli directly, apologies.
>
> ===========================================================
>
> The function is supposed to return the pointer to the current element in that iterator, I have found no function that does that in libxcb. Consider the program below:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> #include <xcb/xcb.h>
>
> int main(void)
> {
> xcb_connection_t *connection = xcb_connect(NULL, NULL);
> xcb_list_extensions_cookie_t cookie = xcb_list_extensions(connection);
> const xcb_list_extensions_reply_t *reply = xcb_list_extensions_reply(connection, cookie, 0);
> xcb_str_iterator_t str_iterator = xcb_list_extensions_names_iterator(reply);
>
> while(str_iterator.rem) { // verify if there are any elements left
> xcb_str_t *name = str_iterator.data; // gather the current element in the iterator
> int length = xcb_str_name_length(name);
> char *str = xcb_str_name(name);
> fwrite(str, sizeof(*str), length, stdout);
> putchar('\n');
> xcb_str_next(&str_iterator);
> }
> xcb_disconnect(connection);
> exit(EXIT_SUCCESS);
> }
>
> I don't know how useful this program is outside of an educational purpose, but notice that the members rem and data from the iterator has to be accessed by the user in order to finally convert it to a stringm then send that to stdout. If the members rem and data aren't supposed to be accessed by the user, I suggest creating a function to access them, or modify xcb_str_next to return a pointer to xcb_str_t for the current element, then have it iterate to the next element.
> If the members of the struct xcb_str_iterator_t are supposed to be accessed by the user, then there is no reason to add said function.
> ________________________________
> De: Xcb <xcb-bounces at lists.freedesktop.org> em nome de Uli Schlachter <psychon at znc.in>
> Enviado: domingo, 7 de março de 2021 05:35
> Para: Lucas <lucasvalentim at outlook.com.br>; xcb at lists.freedesktop.org <xcb at lists.freedesktop.org>
> Assunto: Re: [Xcb] Are there any naming conventions for XCB?
>
> Hi,
>
> Am 14.02.21 um 23:37 schrieb Lucas:
>> I want to introduce one function (another one might be needed) to return
>> a xcb_str_t pointer from an iterator because I could not find a function
>> to do just that, but I have noticed a pattern in the names of the
>> function, hence the question. Here is the function:
>>
>> xcb_str_t *xcb_str_iterator_name(xcb_str_iterator_t *iterator)
>> {
>> return iterator->data;
>> }
>
> Uhm, sorry, but *why*? Can't you just put this function into your own
> code with a name of your liking? Why do you think this needs to be in
> libxcb?
>
> Also, are you sure the function above really does what you want it to
> do? Aren't you instead looking for the already existing xcb_str_name()?
>
> And for the question about naming conventions: Well... kind of. Since
> most of the code is automatically generated from an XML description, I
> guess "what the code generator does" is the naming convention. It all
> maps pretty mechanical to the XML, I think.
>
> Cheers,
> Uli
> --
> This can be a, a little complicated. Listen, my advice is... ask
> somebody else for advice, at least someone who's... got more experience
> at... giving advice.
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/xcb
>
>
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/xcb
>
--
This can be a, a little complicated. Listen, my advice is... ask
somebody else for advice, at least someone who's... got more experience
at... giving advice.
More information about the Xcb
mailing list