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

Allow non-whitespace terminated strings in Strs #47

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions all-core/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v2.1/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v3.1/gles2/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v3.2-compatibility/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v3.2-core/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v3.3-compatibility/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v3.3-core/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v4.1-compatibility/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v4.1-core/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v4.4-compatibility/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
10 changes: 6 additions & 4 deletions v4.4-core/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ func GoStr(cstr *uint8) string {
return C.GoString((*C.char)(unsafe.Pointer(cstr)))
}

// Strs takes a list of null-terminated Go strings and return's their C counterpart.
// Strs takes a list of Go strings and returns their nul-terminated C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
//
// If no strings are provided as a parameter, or if any string is not null-terminated,
// this function will panic.
// If no strings are provided as a parameter, this function will panic.
func Strs(strs ...string) (cstrs **uint8, free func()) {
if len(strs) == 0 {
panic("Strs: expected at least 1 string")
Expand All @@ -80,7 +79,7 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
n++
}
n += len(strs[i])
}
Expand All @@ -98,6 +97,9 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
copy(dataSlice[offset:offset+len(strs[i])], strs[i][:]) // Copy strs[i] into proper data location.
css[i] = (*uint8)(unsafe.Pointer(&dataSlice[offset])) // Set a pointer to it.
offset += len(strs[i])
if !strings.HasSuffix(strs[i], "\x00") {
offset++
}
}

return (**uint8)(&css[0]), func() { C.free(data) }
Expand Down
Loading