rust-x-bindings / rust-xcb

Rust bindings and wrapper for XCB.
MIT License
165 stars 64 forks source link

Are all the atoms interned automatically? #203

Closed vikigenius closed 2 years ago

vikigenius commented 2 years ago

I am trying to get a better understanding of this amazing crate, and I am very interested in how you are doing code gen.

So I hope you don't mind answering my questions.

Looking at https://github.com/rust-x-bindings/rust-xcb/blob/777edbdbb36d113ca4f3cb5611a40975f272a433/xml/xproto.xml#L889

It seems like you have an xml file that specifies a bunch of atoms. And they are generated as Rust constants during build?

My question is are these atoms being automatically interned somewhere when a new connection is created?

Also just to get more clarity, is there any advantage to using this setup? Was the XML handwritten? If so won't it be the same effort to write the equivalent Rust code for this instance?

rtbo commented 2 years ago

The XML files are from the upstream C XCB project which generate the C code from XML. What I do is that I use them to generate the rust code with my own build code. The atoms defined in the XML files are translated as rust constants. See https://rust-x-bindings.github.io/rust-xcb/xcb/x/index.html#constants. As far as I know these are pre-defined atoms recognized by the X server, there is no need to intern them.

I think the XCB folks handwritten the XML by hand to describe the X protocol. There is a big advantage to the XML description: it allows to generate the other languages bindings as well. Wayland works in exactly the same way.