Skip to content

Commit

Permalink
Fix issues for Python and NodeJS bindings on 32-bit systems, see #707
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 25, 2024
1 parent 06a486e commit d4342bd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: NodeJS
on:
push:
branches:
- master
tags:
- 'v*'
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Python
on:
push:
branches:
- master
tags:
- 'v*'
pull_request:
Expand Down
10 changes: 3 additions & 7 deletions bindings/js/minify.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ func init() {
minifyConfig(nil, nil, 0)
}

func goBytes(str *C.char, length C.longlong) []byte {
return (*[1 << 30]byte)(unsafe.Pointer(str))[:length:length]
}

func goStringArray(carr **C.char, length C.longlong) []string {
if length == 0 {
return []string{}
}

strs := make([]string, length)
arr := (*[1 << 30]*C.char)(unsafe.Pointer(carr))[:length:length]
arr := unsafe.Slice(carr, length)
for i := 0; i < int(length); i++ {
strs[i] = C.GoString(arr[i])
}
Expand Down Expand Up @@ -124,8 +120,8 @@ func minifyConfig(ckeys **C.char, cvals **C.char, length C.longlong) *C.char {
//export minifyString
func minifyString(cmediatype, cinput *C.char, input_length C.longlong, coutput *C.char, output_length *C.longlong) *C.char {
mediatype := C.GoString(cmediatype) // copy
input := goBytes(cinput, input_length)
output := goBytes(coutput, input_length)
input := C.GoBytes(unsafe.Pointer(cinput), C.int(input_length))
output := C.GoBytes(unsafe.Pointer(coutput), C.int(input_length))

out := buffer.NewStaticWriter(output[:0])
if err := m.Minify(mediatype, out, buffer.NewReader(input)); err != nil {
Expand Down
10 changes: 3 additions & 7 deletions bindings/py/minify.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ func init() {
minifyConfig(nil, nil, 0)
}

func goBytes(str *C.char, length C.longlong) []byte {
return (*[1 << 30]byte)(unsafe.Pointer(str))[:length:length]
}

func goStringArray(carr **C.char, length C.longlong) []string {
if length == 0 {
return []string{}
}

strs := make([]string, length)
arr := (*[1 << 30]*C.char)(unsafe.Pointer(carr))[:length:length]
arr := unsafe.Slice(carr, length)
for i := 0; i < int(length); i++ {
strs[i] = C.GoString(arr[i])
}
Expand Down Expand Up @@ -124,8 +120,8 @@ func minifyConfig(ckeys **C.char, cvals **C.char, length C.longlong) *C.char {
//export minifyString
func minifyString(cmediatype, cinput *C.char, input_length C.longlong, coutput *C.char, output_length *C.longlong) *C.char {
mediatype := C.GoString(cmediatype) // copy
input := goBytes(cinput, input_length)
output := goBytes(coutput, input_length)
input := C.GoBytes(unsafe.Pointer(cinput), C.int(input_length))
output := C.GoBytes(unsafe.Pointer(coutput), C.int(input_length))

out := buffer.NewStaticWriter(output[:0])
if err := m.Minify(mediatype, out, buffer.NewReader(input)); err != nil {
Expand Down

0 comments on commit d4342bd

Please sign in to comment.