[Xcb] Are there any naming conventions for XCB?

Lucas Augusto Valentim Dantas lucasvalentim at outlook.com.br
Mon Mar 8 11:11:27 UTC 2021


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/xcb/attachments/20210308/4e51d5b9/attachment.htm>


More information about the Xcb mailing list