servo / surfman

Accelerated offscreen graphics for WebGL
Apache License 2.0
173 stars 84 forks source link

Use cstr literals where possible #311

Closed jschwe closed 2 months ago

jschwe commented 2 months ago

Convert usage of byte str and normal str with a \0 to cstr literals where possible

mrobinson commented 2 months ago

This seems fine though it seems the build is failing on Windows.

jdm commented 2 months ago

I suspect c strings are i8 on windows? It's a common cross-platform error.

jschwe commented 2 months ago

I suspect c strings are i8 on windows? It's a common cross-platform error.

The nice thing about CStr is that the as_ptr() method documents that it [returns *const c_char](https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.as_ptr. This allows us to remove a lot of the casts in the window specific code.

While removing those needless casts, I stumbled a bit over CreateWindowExA accepting a u16 encoded in a pointer type and added a comment in the source code explaining it.