ui/app: merge goString implementations and add test

Fixes gio#30

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-08-26 21:19:58 +01:00
parent 7d47fe0fc9
commit 069bb0e7cd
4 changed files with 45 additions and 48 deletions
+1 -24
View File
@@ -4,7 +4,6 @@ package gl
import (
"math"
"reflect"
"syscall"
"unsafe"
@@ -284,7 +283,7 @@ func (c *Functions) GetShaderInfoLog(s Shader) string {
}
func (c *Functions) GetString(pname Enum) string {
s, _, _ := syscall.Syscall(_glGetString.Addr(), 1, uintptr(pname), 0, 0)
return goString(s)
return GoString(SliceOf(s))
}
func (c *Functions) GetUniformLocation(p Program, name string) Uniform {
cname := cString(name)
@@ -365,25 +364,3 @@ func cString(s string) []byte {
copy(b, s)
return b
}
func goString(s uintptr) string {
if s == 0 {
return ""
}
sh := reflect.SliceHeader{
Data: s,
Len: 1 << 30,
Cap: 1 << 30,
}
sl := *(*[]byte)(unsafe.Pointer(&sh))
var v string
for i, c := range sl {
if c == 0 {
if i > 0 {
v = string(sl[:i-1])
}
break
}
}
return v
}