Skip to content

Commit

Permalink
allow non null-terminated strings in gl.Strs
Browse files Browse the repository at this point in the history
Fixes #46
  • Loading branch information
emidoots committed Mar 6, 2016
1 parent a18221b commit 2d8a6d5
Show file tree
Hide file tree
Showing 20 changed files with 2,196 additions and 21,428 deletions.
13 changes: 5 additions & 8 deletions all-core/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ 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 (with or without null-termination) and
// returns their C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
// 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 @@ -79,9 +79,6 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
// Allocate a contiguous array large enough to hold all the strings' contents.
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
}
n += len(strs[i])
}
data := C.malloc(C.size_t(n))
Expand Down
2,178 changes: 1 addition & 2,177 deletions all-core/gl/package.go

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions v2.1/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ 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 (with or without null-termination) and
// returns their C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
// 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 @@ -79,9 +79,6 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
// Allocate a contiguous array large enough to hold all the strings' contents.
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
}
n += len(strs[i])
}
data := C.malloc(C.size_t(n))
Expand Down
13 changes: 5 additions & 8 deletions v3.1/gles2/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ 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 (with or without null-termination) and
// returns their C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
// 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 @@ -79,9 +79,6 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
// Allocate a contiguous array large enough to hold all the strings' contents.
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
}
n += len(strs[i])
}
data := C.malloc(C.size_t(n))
Expand Down
10,367 changes: 2,115 additions & 8,252 deletions v3.1/gles2/package.go

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions v3.2-compatibility/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ 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 (with or without null-termination) and
// returns their C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
// 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 @@ -79,9 +79,6 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
// Allocate a contiguous array large enough to hold all the strings' contents.
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
}
n += len(strs[i])
}
data := C.malloc(C.size_t(n))
Expand Down
13 changes: 5 additions & 8 deletions v3.2-core/gl/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ 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 (with or without null-termination) and
// returns their C counterpart.
//
// The returned free function must be called once you are done using the strings in
// order to free the memory.
// 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 @@ -79,9 +79,6 @@ func Strs(strs ...string) (cstrs **uint8, free func()) {
// Allocate a contiguous array large enough to hold all the strings' contents.
n := 0
for i := range strs {
if !strings.HasSuffix(strs[i], "\x00") {
panic("Strs: str argument missing null terminator: " + strs[i])
}
n += len(strs[i])
}
data := C.malloc(C.size_t(n))
Expand Down
Loading

0 comments on commit 2d8a6d5

Please sign in to comment.