Skip to content

Type errors in unix::WindowExt for X11 #256

Closed

Description

@elinorbgr

The get_xlib_window returns a value that is defined by the X11 API to be Wffi::indow (which is a typedef to c_ulong), but casts it to *mut c_void.

Likewise, get_xlib_screen_id returns a value defined by the X11 API to be a c_int, but casts it to *mut c_void.

My understanding of the X11 API is very light, but this seems wrong to do so, especially given depending on the architecture, these types are not guaranteed to even be the same size.

Do you have some insight regarding this @Ralith ? (pinging you as you seem to have a fair amount of knowledge of X11)

Activity

  1. added
    DS - x11
    on Aug 8, 2017
  2. francesca64 commented on Dec 15, 2017

    @francesca64
    Member

    When get_xlib_window is used by glutin, it's either cast right back to ffi::Window (here) or used as ffi::EGLNativeWindowType to later be passed to eglCreateWindowSurface (here). Looking at the official example, that function does expect the window ID, so casting the value itself into a pointer does seem to be correct, albeit unintuitive, since it's being used for type erasure.

    While ffi::Window isn't guaranteed to be pointer-sized, I can't imagine it will ever be larger, and as far as I can tell Rust treats these pointer conversions just like it would any ordinary integer cast. In other words, this should always work.

  3. Ralith commented on Dec 15, 2017

    @Ralith
    Contributor

    Sorry, this must have slipped through the cracks. I don't know of any reason why we shouldn't be using the proper C types here; it seems we're only getting away with it by coincidence.

  4. added 2 commits that reference this issue on Dec 15, 2017
    9e8af57
    32d76ef
  5. added a commit that references this issue on Dec 17, 2017
    23e4293
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DS - x11

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions