Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X11 bindings broken/annoying #3944

Closed
Lord-Hellgrim opened this issue Jul 20, 2024 · 3 comments
Closed

X11 bindings broken/annoying #3944

Lord-Hellgrim opened this issue Jul 20, 2024 · 3 comments

Comments

@Lord-Hellgrim
Copy link

Context

While playing with the X11 bindings I encountered a fatal bug and a couple annoyances.

  • Operating System & Odin Version:

Odin: dev-2024-07:7237f9c9f
OS: Linux Mint 21.3, Linux 5.15.0-113-generic
CPU: Intel(R) Core(TM) i5-3427U CPU @ 1.80GHz
RAM: 7637 MiB
Backend: LLVM 14.0.0

Expected Behavior

I am expecting the X11.DefaultDepth() function to return an i32

Current Behavior

It immediately segfaults my program.

Failure Information (for bugs)

The bindings to the C function are wrong. DefaultDepth is a macro that takes two arguments in C (*Display, int).

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

Just call the function. It reliably segfaults my process.

Failure Logs

Please include any relevant log snippets or files here.
Segmentation fault (core dumped)

Additionally, some odin xlib functions return the wrong type of integer. This is annoying since you have to cast them to feed them into their respective function. The one example I encountered:

black: uint = X11.BlackPixel(display, screen)
white: uint = X11.WhitePixel(display, screen)
but the function X11.CreateSimpleWindow() takes two "colors" as the final arguments and those colors are int, not uint. I think they should match.

@nobodyspecial1553
Copy link

Just to add some further context to future readers about the segment at the bottom:
It's not so much that it would be preferable for them to match, but that the X11.CreateSimpleWindow binding is wrong.

extern Window XCreateSimpleWindow(
    Display*		/* display */,
    Window		/* parent */,
    int			/* x */,
    int			/* y */,
    unsigned int	/* width */,
    unsigned int	/* height */,
    unsigned int	/* border_width */,
    unsigned long	/* border */,
    unsigned long	/* background */
);

It takes unsigned long for border and background, but the vendor api defines the procedure as

CreateSimpleWindow :: proc(
  display:   ^Display,
  parent:    Window,
  x:         i32,
  y:         i32,
  width:     u32,
  height:    u32,
  bordersz:  u32,
  border:    int,
  bg:        int,
) -> Window ---

@flysand7
Copy link
Contributor

int in Odin is the same thing as long on linux.
Similarly uint is the same as unsigned long.

So the issue is that the signedness is wrong?

@nobodyspecial1553
Copy link

nobodyspecial1553 commented Jul 20, 2024

Yes, it should be uint. It's not the width that's wrong, but its "signedness."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants