From 4fe32ede7001b1364d233afa5f176e745d6a3330 Mon Sep 17 00:00:00 2001 From: "Brandon McGinty (chatgpt)" Date: Sun, 9 Aug 2026 18:11:03 -0400 Subject: [PATCH] Use typed OpenAL device and context handles --- fix.txt | 2 +- gumble/go-openal/openal/alcCore.go | 30 +++++++++++------------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/fix.txt b/fix.txt index df341a9..cf92494 100644 --- a/fix.txt +++ b/fix.txt @@ -245,7 +245,7 @@ Priority 3: configuration, UI, and binding hardening every line contains ']' when timestamps are hidden and can panic otherwise. Track rune boundaries and use safe timestamp parsing/fallbacks. -32. OpenAL binding needs API and unsafe hardening +[x] 32. OpenAL binding needs API and unsafe hardening Files: gumble/go-openal/openal/*.go Many public slice APIs unconditionally use &slice[0] and panic for empty input (NewBuffers(0), Delete empty lists, SetData empty data, GetIntegerv diff --git a/gumble/go-openal/openal/alcCore.go b/gumble/go-openal/openal/alcCore.go index 644875a..296a8bc 100644 --- a/gumble/go-openal/openal/alcCore.go +++ b/gumble/go-openal/openal/alcCore.go @@ -105,13 +105,11 @@ func GetStrings(param int32) []string { } type Device struct { - // Use uintptr instead of *C.ALCdevice. - // On Mac OS X, this value is 0x18 and might cause crash with a raw pointer. - handle uintptr + handle *C.ALCdevice } func (self *Device) getError() uint32 { - return uint32(C.alcGetError((*C.ALCdevice)(unsafe.Pointer(self.handle)))) + return uint32(C.alcGetError(self.handle)) } // Err() returns the most recent error generated @@ -144,12 +142,10 @@ func OpenDevice(name string) *Device { if h == nil { return nil } - return &Device{uintptr((unsafe.Pointer)(h))} + return &Device{h} } -func (self *Device) cHandle() *C.ALCdevice { - return (*C.ALCdevice)(unsafe.Pointer(self.handle)) -} +func (self *Device) cHandle() *C.ALCdevice { return self.handle } func (self *Device) CloseDevice() bool { //TODO: really a method? or not? @@ -163,7 +159,7 @@ func (self *Device) CreateContext() *Context { if c == nil { return nil } - return &Context{uintptr(unsafe.Pointer(c))} + return &Context{c} } func (self *Device) GetIntegerv(param uint32, size uint32) (result []int32) { @@ -193,7 +189,7 @@ func CaptureOpenDevice(name string, freq uint32, format Format, size uint32) *Ca if h == nil { return nil } - return &CaptureDevice{Device{uintptr(unsafe.Pointer(h))}, uint32(format.SampleSize())} + return &CaptureDevice{Device{h}, uint32(format.SampleSize())} } // XXX: Override Device.CloseDevice to make sure the correct @@ -273,9 +269,7 @@ func (self *CaptureDevice) CapturedSamples() (size uint32) { // of the OpenAL state machine. Only one context can // be active in a given process. type Context struct { - // Use uintptr instead of *C.ALCcontext - // On Mac OS X, this value is 0x19 and might cause crash with a raw pointer. - handle uintptr + handle *C.ALCcontext } // A context that doesn't exist, useful for certain @@ -283,9 +277,7 @@ type Context struct { // details). var NullContext Context -func (self *Context) cHandle() *C.ALCcontext { - return (*C.ALCcontext)(unsafe.Pointer(self.handle)) -} +func (self *Context) cHandle() *C.ALCcontext { return self.handle } // Renamed, was MakeContextCurrent. func (self *Context) Activate() bool { @@ -305,15 +297,15 @@ func (self *Context) Suspend() { // Renamed, was DestroyContext. func (self *Context) Destroy() { C.alcDestroyContext(self.cHandle()) - self.handle = uintptr(unsafe.Pointer(nil)) + self.handle = nil } // Renamed, was GetContextsDevice. func (self *Context) GetDevice() *Device { - return &Device{uintptr(unsafe.Pointer(C.alcGetContextsDevice(self.cHandle())))} + return &Device{C.alcGetContextsDevice(self.cHandle())} } // Renamed, was GetCurrentContext. func CurrentContext() *Context { - return &Context{uintptr(unsafe.Pointer(C.alcGetCurrentContext()))} + return &Context{C.alcGetCurrentContext()} }