~sircmpwn/hare-users

Hare does not allow pointer to non-zero types anymore v1 PROPOSED

francorbacho: 1
 Hare does not allow pointer to non-zero types anymore

 8 files changed, 27 insertions(+), 27 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/hare-users/patches/43993/mbox | git am -3
Learn more about email & git

[PATCH] Hare does not allow pointer to non-zero types anymore Export this patch

---
This patch makes hare-sdl2 compile, but the demo seems broken due to
compiler errors (reaches unreachable code) — possibly because of
`opaque`'s implementation.

 sdl2/errors.ha         |  4 ++--
 sdl2/events.ha         |  6 +++---
 sdl2/gamecontroller.ha |  2 +-
 sdl2/gl.ha             |  6 +++---
 sdl2/render.ha         | 12 ++++++------
 sdl2/rwops.ha          | 14 +++++++-------
 sdl2/surface.ha        |  8 ++++----
 sdl2/video.ha          |  2 +-
 8 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/sdl2/errors.ha b/sdl2/errors.ha
index b386ebe..a848667 100644
--- a/sdl2/errors.ha
+++ b/sdl2/errors.ha
@@ -21,9 +21,9 @@ export fn wrapint(ret: int) (int | error) = {
	return ret;
};

export fn wrapptr(ret: nullable *void) (*void | error) = {
export fn wrapptr(ret: nullable *opaque) (*opaque | error) = {
	match (ret) {
	case let v: *void =>
	case let v: *opaque =>
		return v;
	case null =>
		return c::tostr(SDL_GetError()): error;
diff --git a/sdl2/events.ha b/sdl2/events.ha
index beb1343..55a0a63 100644
--- a/sdl2/events.ha
+++ b/sdl2/events.ha
@@ -322,15 +322,15 @@ export type SDL_UserEvent = struct {
	SDL_CommonEvent,
	window_id: u32,
	code: i32,
	data1: *void,
	data2: *void,
	data1: *opaque,
	data2: *opaque,
};

// A video driver dependent system event (event.syswm.*)
// This event is disabled by default, you can enable it with [[eventstate]].
export type SDL_SysWMEvent = struct {
	SDL_CommonEvent,
	msg: *void, // TODO
	msg: *opaque, // TODO
};

// General event structure
diff --git a/sdl2/gamecontroller.ha b/sdl2/gamecontroller.ha
index 1ce9384..4cab9ce 100644
--- a/sdl2/gamecontroller.ha
+++ b/sdl2/gamecontroller.ha
@@ -2,7 +2,7 @@

// The SDL_GameController structure used to identify an SDL game controller.
// (Opaque)
export type SDL_GameController = void;
export type SDL_GameController = opaque;

// The list of axes available from a controller
//
diff --git a/sdl2/gl.ha b/sdl2/gl.ha
index 6599da8..9e3c163 100644
--- a/sdl2/gl.ha
+++ b/sdl2/gl.ha
@@ -1,6 +1,6 @@
use types::c;

export type SDL_GLContext = void;
export type SDL_GLContext = opaque;

export type SDL_GLprofile = enum int {
	GL_CONTEXT_PROFILE_CORE = 0x0001,
@@ -41,7 +41,7 @@ export type SDL_GLattr = enum {
export @symbol("SDL_GL_CreateContext") fn SDL_GL_CreateContext(
	window: *SDL_Window) *SDL_GLContext;
export @symbol("SDL_GL_GetProcAddress") fn SDL_GL_GetProcAddress(
	proc: *const c::char) *void;
	proc: *const c::char) *opaque;
export @symbol("SDL_GL_SetAttribute") fn SDL_GL_SetAttribute(
	attr: SDL_GLattr, value: int) *void;
	attr: SDL_GLattr, value: int) *opaque;
export @symbol("SDL_GL_SwapWindow") fn SDL_GL_SwapWindow(window: *SDL_Window) void;
diff --git a/sdl2/render.ha b/sdl2/render.ha
index 66571b1..d05b33c 100644
--- a/sdl2/render.ha
+++ b/sdl2/render.ha
@@ -1,10 +1,10 @@
// TODO: Flesh me out

// A structure representing rendering state. (Opaque)
export type SDL_Renderer = void;
export type SDL_Renderer = opaque;

// An efficient driver-specific representation of pixel data. (Opaque)
export type SDL_Texture = void;
export type SDL_Texture = opaque;

export type SDLPixelFormatValues = enum u32 {
    SDL_PIXELFORMAT_UNKNOWN,
@@ -327,21 +327,21 @@ export fn SDL_CreateTextureFromSurface(
};

@symbol("SDL_UpdateTexture") fn _SDL_UpdateTexture(texture: *SDL_Texture,
	rect: const nullable *SDL_Rect, pixels: const nullable *void, pitch: int) int;
	rect: const nullable *SDL_Rect, pixels: const nullable *opaque, pitch: int) int;

// Update the given texture rectangle with new pixel data.
export fn SDL_UpdateTexture(texture: *SDL_Texture,
	rect: const nullable *SDL_Rect, pixels: const nullable *void, pitch: int)
	rect: const nullable *SDL_Rect, pixels: const nullable *opaque, pitch: int)
	(int | error) = {
	return wrapint(_SDL_UpdateTexture(texture, rect, pixels, pitch))?: int;
};

@symbol("SDL_LockTexture") fn _SDL_LockTexture(texture: *SDL_Texture,
	rect: const nullable *SDL_Rect, pixels: nullable * nullable *void, pitch: *int) int;
	rect: const nullable *SDL_Rect, pixels: nullable * nullable *opaque, pitch: *int) int;

// Lock a portion of the texture for write-only pixel access.
export fn SDL_LockTexture(texture: *SDL_Texture,
	rect: const nullable *SDL_Rect, pixels: nullable * nullable *void, pitch: *int)
	rect: const nullable *SDL_Rect, pixels: nullable * nullable *opaque, pitch: *int)
	(int | error) = {
	return wrapint(_SDL_LockTexture(texture, rect, pixels, pitch))?: int;
};
diff --git a/sdl2/rwops.ha b/sdl2/rwops.ha
index 4c9077b..4605a3a 100644
--- a/sdl2/rwops.ha
+++ b/sdl2/rwops.ha
@@ -15,8 +15,8 @@ export type rwops_type = enum u32 {
export type SDL_RWops = struct {
	sz: *fn(ctx: *SDL_RWops) i64,
	seek: *fn(ctx: *SDL_RWops, offs: i64, whence: int) i64,
	read: *fn(ctx: *SDL_RWops, ptr: *void, sz: size, maxnum: size) size,
	write: *fn(ctx: *SDL_RWops, ptr: *const void, sz: size, num: size) size,
	read: *fn(ctx: *SDL_RWops, ptr: *opaque, sz: size, maxnum: size) size,
	write: *fn(ctx: *SDL_RWops, ptr: *const opaque, sz: size, num: size) size,
	close: *fn(ctx: *SDL_RWops) int,

	type_: rwops_type,
@@ -24,7 +24,7 @@ export type SDL_RWops = struct {
	hidden: union {
		stdio: struct {
			autoclose: bool,
			fp: nullable *void, // FILE *
			fp: nullable *opaque, // FILE *
		},
		mem: struct {
			base: nullable *u8,
@@ -32,8 +32,8 @@ export type SDL_RWops = struct {
			stop: nullable *u8,
		},
		unknown: struct {
			data1: nullable *void,
			data2: nullable *void,
			data1: nullable *opaque,
			data2: nullable *opaque,
		},
	},
};
@@ -100,7 +100,7 @@ fn stream_seek(ctx: *SDL_RWops, offs: i64, whence: int) i64 = {
	};
};

fn stream_read(ctx: *SDL_RWops, ptr: *void, sz: size, maxnum: size) size = {
fn stream_read(ctx: *SDL_RWops, ptr: *opaque, sz: size, maxnum: size) size = {
	const handle = *(&ctx.hidden.unknown.data1: *io::handle);
	let buf = ptr: *[*]u8;
	match (io::readall(handle, buf[..sz * maxnum])) {
@@ -113,7 +113,7 @@ fn stream_read(ctx: *SDL_RWops, ptr: *void, sz: size, maxnum: size) size = {
	};
};

fn stream_write(ctx: *SDL_RWops, ptr: *const void, sz: size, num: size) size = {
fn stream_write(ctx: *SDL_RWops, ptr: *const opaque, sz: size, num: size) size = {
	const handle = *(&ctx.hidden.unknown.data1: *io::handle);
	let buf = ptr: *[*]const u8;
	match (io::writeall(handle, buf[..sz * num])) {
diff --git a/sdl2/surface.ha b/sdl2/surface.ha
index 572bdcc..24153c3 100644
--- a/sdl2/surface.ha
+++ b/sdl2/surface.ha
@@ -8,12 +8,12 @@ export type SDL_Surface = struct {
	w: int,
	h: int,
	pitch: int,
	pixels: nullable *void,
	pixels: nullable *opaque,

	userdata: *void,
	userdata: *opaque,

	locked: int,
	lock_data: *void,
	lock_data: *opaque,

	clip_rect: SDL_Rect,

@@ -22,7 +22,7 @@ export type SDL_Surface = struct {
	refcount: int,
};

export type SDL_BlitMap = void;
export type SDL_BlitMap = opaque;

@symbol("SDL_CreateRGBSurface") fn _SDL_CreateRGBSurface(flags: u32,
	width: int, height: int, depth: int, Rmask: u32, Gmask: u32, Bmask: u32,
diff --git a/sdl2/video.ha b/sdl2/video.ha
index f60d915..466052e 100644
--- a/sdl2/video.ha
+++ b/sdl2/video.ha
@@ -2,7 +2,7 @@
use types::c;

// The type used to identify a window. (Opaque)
export type SDL_Window = void;
export type SDL_Window = opaque;

// The flags on a window
export type SDL_WindowFlags = enum u32 {
-- 
2.41.0
Looks like it builds and runs correctly with master as of 2023-08-29.

```bash
$ harec -v
harec dev+c09514a
$ hare version
Hare dev+7f432b06-arch
```