Skip to content

Match platform bindings to the C ABI - #7

Closed
elcritch wants to merge 1 commit into
fix/optional-platform-librariesfrom
fix/platform-c-abi
Closed

elcritch wants to merge 1 commit into
fix/optional-platform-librariesfrom
fix/platform-c-abi

Conversation

@elcritch

@elcritch elcritch commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Some platform declarations do not match their C signatures (i.e. 32bit platforms): Wayland and GLX pointers are declared as Nim structs, EGLBoolean results are declared as Nim bool, and Vulkan surface handles lose their upper 32 bits on 32-bit targets.

This PR changes them to match the native signatures and adapt Siwin's callers.

This is stacked on fix/optional-platform-libraries, the head branch of upstream dynamic-loading PR #56. Its diff contains only the ABI follow-up. The stacked review lives in this fork because the base branch is in this fork; after levovix0#56 merges, the ABI changes can be submitted upstream on their own.

  • Keep the original wl_display_* and wl_proxy_* names, bind native pointer signatures, and pass .raw from Siwin's callers. Keep meaningful Nim helpers such as dispatchPending and destroyCallbacks.
  • Keep original EGL names and bind EGLBoolean as cuint, including eglTerminate. Convert results at internal checks and omit bool compatibility adapters.
  • Use native pointers for GLX context calls and correct swap-interval signatures while preserving existing public GLX call patterns.
  • Keep Vulkan surfaces pointer-compatible on 64-bit targets and use uint64 on 32-bit targets, including the exported C header.
  • Explain the 32-bit struct-return problem and EGLBoolean width in comments beside the bindings.

Direct low-level callers now pass raw Wayland pointers and compare EGLBoolean results with zero or discard them. The dynamic-loading PR retains the previous signatures.

Validation

Checked with Nim 2.2.10 on FreeBSD:

  • tests/t_dynlib_loading.nim passed with the default memory manager and --mm:refc, including native EGL/Wayland signature checks and GLX/X11 source-compatibility checks.
  • Wayland display/proxy lifecycle smoke tests passed against a temporary libwayland server, including connection by name and file descriptor.
  • EGL context lifecycle and invalid-display failure-result checks passed under Xvfb; tests/t_opengl.nim also passed.
  • Startup, availability, error, and cleanup checks passed with optional libraries hidden by a dlopen shim.
  • nim check --os:linux --path:src src/siwin.nim passed for amd64 and i386.
  • git diff --check passed against both the stacked base and upstream master.

The i386 checks are compile-time checks only; no 32-bit runtime or live Wayland rendering was exercised.

@elcritch
elcritch marked this pull request as ready for review October 5, 2026 20:26
method `vsync=`*(window: Window, v: bool, silent = false) {.base.} = discard
## enable/disable vsync

when sizeof(pointer) == 8:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If VulkanSurface needs to be exactly 8 bytes, use uint64 on both architectures.
pointer is just a number anyway.

proc eglInitialize*(d: EglDisplay; major: ptr int32 = nil; minor: ptr int32 = nil): bool
proc eglTerminate*(d: EglDisplay)
proc eglInitialize*(d: EglDisplay; major: ptr int32 = nil; minor: ptr int32 = nil): cuint
proc eglTerminate*(d: EglDisplay): cuint

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about ABI, but this may not be necessary. bool is more convinient here, and most of the code here discard it anyway.
If you think this is necessary, ok.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I'll see. In theory the C layer should just cast it to a bool. I'm making a new PR on Siwin and I'll check it out.

@elcritch

elcritch commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

Replaced by levovix0#57 now that upstream levovix0#56 is merged. The replacement addresses both review comments: EGL keeps public bool results through explicit conversion from native cuint bindings, and Vulkan surfaces use uint64 on both architectures.

@elcritch elcritch closed this Oct 6, 2026
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

Successfully merging this pull request may close these issues.

2 participants