Add runtime.KeepAlive guards when unsafe slices are in use temporarily, add -gcflags=-d=checkptr to tests
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
a9f6468f00
commit
62ee2b9f2b
24
.drone.yml
24
.drone.yml
|
@ -28,10 +28,10 @@ steps:
|
|||
- DEBIAN_FRONTEND=noninteractive apt install -y git build-essential autoconf automake libtool libflac-dev libopus-dev libopusfile-dev libsamplerate0-dev libmp3lame-dev libebur128-dev libfdk-aac-dev
|
||||
- git clone --depth 1 https://gitlab.xiph.org/xiph/libopusenc.git && cd libopusenc && ./autogen.sh && ./configure --prefix /usr && make && make install && cd ..
|
||||
- git clone --depth 1 https://git.gammaspectra.live/S.O.N.G/alac.git && cd alac && autoreconf -fi && ./configure --prefix /usr && make && make install && cd ..
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v -tags=disable_codec_libfdk_aac,disable_codec_lame,disable_codec_tta,disable_codec_libflac ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v -tags=disable_format_aac,disable_format_alac,disable_format_mp3,disable_format_opus,disable_format_tta,disable_format_vorbis ./...
|
||||
- CGO_ENABLED=0 go test -p 1 -failfast -timeout 20m -cover -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v -tags=disable_codec_libfdk_aac,disable_codec_lame,disable_codec_tta,disable_codec_libflac ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v -tags=disable_format_aac,disable_format_alac,disable_format_mp3,disable_format_opus,disable_format_tta,disable_format_vorbis ./...
|
||||
- CGO_ENABLED=0 go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v ./...
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
|
@ -68,10 +68,10 @@ steps:
|
|||
- git clone --depth 1 https://gitlab.xiph.org/xiph/libopusenc.git && cd libopusenc && ./autogen.sh && ./configure --prefix /usr && make && make install && cd ..
|
||||
- git clone --depth 1 https://github.com/mstorsjo/fdk-aac.git && cd fdk-aac && ./autogen.sh && ./configure --prefix /usr && make -j$(nproc) && make install && cd ..
|
||||
- git clone --depth 1 https://git.gammaspectra.live/S.O.N.G/alac.git && cd alac && autoreconf -fi && ./configure --prefix /usr && make && make install && cd ..
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v -tags=disable_codec_libfdk_aac,disable_codec_lame,disable_codec_tta,disable_codec_libflac ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v -tags=disable_format_aac,disable_format_alac,disable_format_mp3,disable_format_opus,disable_format_tta,disable_format_vorbis ./...
|
||||
- CGO_ENABLED=0 go test -p 1 -failfast -timeout 20m -cover -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v -tags=disable_codec_libfdk_aac,disable_codec_lame,disable_codec_tta,disable_codec_libflac ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v -tags=disable_format_aac,disable_format_alac,disable_format_mp3,disable_format_opus,disable_format_tta,disable_format_vorbis ./...
|
||||
- CGO_ENABLED=0 go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v ./...
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
|
@ -108,9 +108,9 @@ steps:
|
|||
- git clone --depth 1 https://gitlab.xiph.org/xiph/libopusenc.git && cd libopusenc && ./autogen.sh && ./configure --prefix /usr && make && make install && cd ..
|
||||
- git clone --depth 1 https://github.com/mstorsjo/fdk-aac.git && cd fdk-aac && ./autogen.sh && ./configure --prefix /usr && make -j$(nproc) && make install && cd ..
|
||||
- git clone --depth 1 https://git.gammaspectra.live/S.O.N.G/alac.git && cd alac && autoreconf -fi && ./configure --prefix /usr && make && make install && cd ..
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v -tags=disable_codec_libfdk_aac,disable_codec_lame,disable_codec_tta,disable_codec_libflac ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -v -tags=disable_format_aac,disable_format_alac,disable_format_mp3,disable_format_opus,disable_format_tta,disable_format_vorbis ./...
|
||||
- CGO_ENABLED=0 go test -p 1 -failfast -timeout 20m -cover -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v -tags=disable_codec_libfdk_aac,disable_codec_lame,disable_codec_tta,disable_codec_libflac ./...
|
||||
- go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v -tags=disable_format_aac,disable_format_alac,disable_format_mp3,disable_format_opus,disable_format_tta,disable_format_vorbis ./...
|
||||
- CGO_ENABLED=0 go test -p 1 -failfast -timeout 20m -cover -gcflags=-d=checkptr -v ./...
|
||||
...
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
aac_adts "github.com/edgeware/mp4ff/aac"
|
||||
"github.com/edgeware/mp4ff/mp4"
|
||||
"io"
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
@ -77,6 +78,7 @@ func tryDecodeFrame(decoder *fdkaac.AacDecoder) ([]int16, error) {
|
|||
if pcm != nil {
|
||||
out := make([]int16, len(pcm)/2)
|
||||
copy(out, unsafe.Slice((*int16)(unsafe.Pointer(&pcm[0])), len(pcm)/2))
|
||||
runtime.KeepAlive(pcm)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
@ -350,6 +352,7 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
|
|||
}
|
||||
|
||||
tempBuffer = tempBuffer[frameSize:]
|
||||
runtime.KeepAlive(sl)
|
||||
}
|
||||
|
||||
if len(tempBuffer) > 0 {
|
||||
|
@ -373,6 +376,7 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
|
|||
return err
|
||||
}
|
||||
}
|
||||
runtime.KeepAlive(buffer)
|
||||
}
|
||||
|
||||
//Do flush
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"git.gammaspectra.live/S.O.N.G/Kirika/vector"
|
||||
go_alac "git.gammaspectra.live/S.O.N.G/go-alac"
|
||||
"io"
|
||||
"runtime"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
@ -108,20 +109,24 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
|
|||
case 32:
|
||||
for block := range source.ToInt32(32).GetBlocks() {
|
||||
encoder.Write(unsafe.Slice((*byte)(unsafe.Pointer(&block[0])), len(block)*4))
|
||||
runtime.KeepAlive(block)
|
||||
}
|
||||
case 24:
|
||||
for block := range source.ToInt32(24).GetBlocks() {
|
||||
samples := vector.Int32ToBytes(block, 24)
|
||||
encoder.Write(unsafe.Slice((*byte)(unsafe.Pointer(&samples[0])), len(samples)))
|
||||
runtime.KeepAlive(samples)
|
||||
}
|
||||
case 16:
|
||||
for block := range source.ToInt16().GetBlocks() {
|
||||
encoder.Write(unsafe.Slice((*byte)(unsafe.Pointer(&block[0])), len(block)*2))
|
||||
runtime.KeepAlive(block)
|
||||
}
|
||||
case 8:
|
||||
for block := range source.ToInt32(8).GetBlocks() {
|
||||
samples := vector.Int32ToBytes(block, 8)
|
||||
encoder.Write(unsafe.Slice((*byte)(unsafe.Pointer(&samples[0])), len(samples)))
|
||||
runtime.KeepAlive(samples)
|
||||
}
|
||||
default:
|
||||
return errors.New("not supported bits per sample")
|
||||
|
|
|
@ -41,9 +41,8 @@ func (f Format) Open(r io.ReadSeekCloser) (audio.Source, error) {
|
|||
defer source.Close()
|
||||
samples := make([]int16, BlockSize*2)
|
||||
const SizeofInt16 = int(unsafe.Sizeof(int16(0)))
|
||||
byteSlice := unsafe.Slice((*byte)(unsafe.Pointer(&samples[0])), len(samples)*SizeofInt16)
|
||||
for {
|
||||
n, err := decoder.Read(byteSlice)
|
||||
n, err := decoder.Read(unsafe.Slice((*byte)(unsafe.Pointer(&samples[0])), len(samples)*SizeofInt16))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
|
||||
"github.com/viert/go-lame"
|
||||
"io"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -122,6 +123,7 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
|
|||
|
||||
for block := range source.ToInt16().GetBlocks() {
|
||||
_, err := encoder.Write(unsafe.Slice((*byte)(unsafe.Pointer(&block[0])), len(block)*2))
|
||||
runtime.KeepAlive(block)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -39,9 +39,8 @@ func (f Format) Open(r io.ReadSeekCloser) (audio.Source, error) {
|
|||
defer source.Close()
|
||||
samples := make([]int16, BlockSize*2)
|
||||
const SizeofInt16 = int(unsafe.Sizeof(int16(0)))
|
||||
byteSlice := unsafe.Slice((*byte)(unsafe.Pointer(&samples[0])), len(samples)*SizeofInt16)
|
||||
for {
|
||||
n, err := decoder.Read(byteSlice)
|
||||
n, err := decoder.Read(unsafe.Slice((*byte)(unsafe.Pointer(&samples[0])), len(samples)*SizeofInt16))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
libtta "git.gammaspectra.live/S.O.N.G/go-tta"
|
||||
"io"
|
||||
"math"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -150,20 +151,24 @@ func (f Format) Encode(source audio.Source, writer io.WriteCloser, options map[s
|
|||
case 32:
|
||||
for block := range source.ToInt32(32).GetBlocks() {
|
||||
encoder.ProcessStream(unsafe.Slice((*byte)(unsafe.Pointer(&block[0])), len(block)*4), nil)
|
||||
runtime.KeepAlive(block)
|
||||
}
|
||||
case 24:
|
||||
for block := range source.ToInt32(24).GetBlocks() {
|
||||
samples := vector.Int32ToBytes(block, 24)
|
||||
encoder.ProcessStream(unsafe.Slice((*byte)(unsafe.Pointer(&samples[0])), len(samples)), nil)
|
||||
runtime.KeepAlive(samples)
|
||||
}
|
||||
case 16:
|
||||
for block := range source.ToInt16().GetBlocks() {
|
||||
encoder.ProcessStream(unsafe.Slice((*byte)(unsafe.Pointer(&block[0])), len(block)*2), nil)
|
||||
runtime.KeepAlive(block)
|
||||
}
|
||||
case 8:
|
||||
for block := range source.ToInt32(8).GetBlocks() {
|
||||
samples := vector.Int32ToBytes(block, 8)
|
||||
encoder.ProcessStream(unsafe.Slice((*byte)(unsafe.Pointer(&samples[0])), len(samples)), nil)
|
||||
runtime.KeepAlive(samples)
|
||||
}
|
||||
default:
|
||||
return errors.New("not supported bits per sample")
|
||||
|
|
|
@ -2,6 +2,7 @@ package audio
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -107,19 +108,23 @@ func Ingest(s Source, buf interface{}, bitDepth int) error {
|
|||
switch bitDepth {
|
||||
case 32:
|
||||
out := make([]int32, nsamples)
|
||||
copy(out, unsafe.Slice((*int32)(unsafe.Pointer(&bufferSlice)), nsamples))
|
||||
copy(out, unsafe.Slice((*int32)(unsafe.Pointer(&bufferSlice[0])), nsamples))
|
||||
s.IngestInt32(out, bitDepth)
|
||||
runtime.KeepAlive(bufferSlice)
|
||||
return nil
|
||||
case 24:
|
||||
s.IngestInt24(unsafe.Slice((*byte)(unsafe.Pointer(&bufferSlice)), nsamples*3), bitDepth)
|
||||
s.IngestInt24(unsafe.Slice((*byte)(unsafe.Pointer(&bufferSlice[0])), nsamples*3), bitDepth)
|
||||
runtime.KeepAlive(bufferSlice)
|
||||
return nil
|
||||
case 16:
|
||||
out := make([]int16, nsamples)
|
||||
copy(out, unsafe.Slice((*int16)(unsafe.Pointer(&bufferSlice)), nsamples))
|
||||
copy(out, unsafe.Slice((*int16)(unsafe.Pointer(&bufferSlice[0])), nsamples))
|
||||
s.IngestInt16(out, bitDepth)
|
||||
runtime.KeepAlive(bufferSlice)
|
||||
return nil
|
||||
case 8:
|
||||
s.IngestInt8(unsafe.Slice((*int8)(unsafe.Pointer(&bufferSlice)), nsamples), bitDepth)
|
||||
s.IngestInt8(unsafe.Slice((*int8)(unsafe.Pointer(&bufferSlice[0])), nsamples), bitDepth)
|
||||
runtime.KeepAlive(bufferSlice)
|
||||
return nil
|
||||
default:
|
||||
return errors.New("not supported bit depth")
|
||||
|
|
|
@ -8,6 +8,7 @@ package vector
|
|||
*/
|
||||
import "C"
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -15,6 +16,7 @@ import (
|
|||
func MultipleChannelsToMonoFloat32(buffer []float32, channels int) (buf []float32) {
|
||||
buf = make([]float32, len(buffer)/channels)
|
||||
C.audio_multiple_channels_to_mono((*C.float)(&buffer[0]), C.size_t(len(buffer)), (*C.float)(&buf[0]), C.int(channels))
|
||||
runtime.KeepAlive(buffer)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -22,6 +24,7 @@ func MultipleChannelsToMonoFloat32(buffer []float32, channels int) (buf []float3
|
|||
func MultipleChannelsToStereoFloat32(buffer []float32, channels int) (buf []float32) {
|
||||
buf = make([]float32, (len(buffer)/channels)*2)
|
||||
C.audio_multiple_channels_to_stereo((*C.float)(&buffer[0]), C.size_t(len(buffer)), (*C.float)(&buf[0]), C.int(channels))
|
||||
runtime.KeepAlive(buffer)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -29,6 +32,7 @@ func MultipleChannelsToStereoFloat32(buffer []float32, channels int) (buf []floa
|
|||
func MultipleChannelsToMonoInt32(buffer []int32, channels int) (buf []int32) {
|
||||
buf = make([]int32, len(buffer)/channels)
|
||||
C.audio_multiple_channels_to_mono_int32((*C.int32_t)(&buffer[0]), C.size_t(len(buffer)), (*C.int32_t)(&buf[0]), C.int(channels))
|
||||
runtime.KeepAlive(buffer)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -36,36 +40,42 @@ func MultipleChannelsToMonoInt32(buffer []int32, channels int) (buf []int32) {
|
|||
func MultipleChannelsToStereoInt32(buffer []int32, channels int) (buf []int32) {
|
||||
buf = make([]int32, (len(buffer)/channels)*2)
|
||||
C.audio_multiple_channels_to_stereo_int32((*C.int32_t)(&buffer[0]), C.size_t(len(buffer)), (*C.int32_t)(&buf[0]), C.int(channels))
|
||||
runtime.KeepAlive(buffer)
|
||||
return
|
||||
}
|
||||
|
||||
func Int32ToInt16(data []int32, bitDepth int) (buf []int16) {
|
||||
buf = make([]int16, len(data))
|
||||
C.audio_int32_to_int16((*C.int32_t)(&data[0]), C.size_t(len(data)), (*C.int16_t)(unsafe.Pointer(&buf[0])), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Int16ToInt32(data []int32, bitDepth int) (buf []int16) {
|
||||
buf = make([]int16, len(data))
|
||||
C.audio_int32_to_int16((*C.int32_t)(&data[0]), C.size_t(len(data)), (*C.int16_t)(unsafe.Pointer(&buf[0])), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Int32ToBytes(data []int32, bitDepth int) (buf []byte) {
|
||||
buf = make([]byte, len(data)*(bitDepth/8))
|
||||
C.audio_int32_to_bytes((*C.int32_t)(&data[0]), C.size_t(len(data)), (*C.int8_t)(unsafe.Pointer(&buf[0])), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func BytesToInt32(data []byte, bitDepth int) (buf []int32) {
|
||||
buf = make([]int32, len(data)/(bitDepth/8))
|
||||
C.audio_bytes_to_int32((*C.int8_t)(unsafe.Pointer(&data[0])), C.size_t(len(data)), (*C.int32_t)(&buf[0]), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Int32ToFloat32(data []int32, bitDepth int) (buf []float32) {
|
||||
buf = make([]float32, len(data))
|
||||
C.audio_int32_to_float32((*C.int32_t)(&data[0]), C.size_t(len(data)), (*C.float)(&buf[0]), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -73,41 +83,48 @@ func Int32ToFloat32(data []int32, bitDepth int) (buf []float32) {
|
|||
func Int24ToFloat32(data []byte, bitDepth int) (buf []float32) {
|
||||
buf = make([]float32, len(data)/3)
|
||||
C.audio_int24_to_float32((*C.int8_t)(unsafe.Pointer(&data[0])), C.size_t(len(data)), (*C.float)(&buf[0]), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Int16ToFloat32(data []int16, bitDepth int) (buf []float32) {
|
||||
buf = make([]float32, len(data))
|
||||
C.audio_int16_to_float32((*C.int16_t)(&data[0]), C.size_t(len(data)), (*C.float)(&buf[0]), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Int8ToFloat32(data []int8, bitDepth int) (buf []float32) {
|
||||
buf = make([]float32, len(data))
|
||||
C.audio_int8_to_float32((*C.int8_t)(&data[0]), C.size_t(len(data)), (*C.float)(&buf[0]), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Float32ToInt32(data []float32, bitDepth int) (buf []int32) {
|
||||
buf = make([]int32, len(data))
|
||||
C.audio_float32_to_int32((*C.float)(&data[0]), C.size_t(len(data)), (*C.int32_t)(&buf[0]), C.int(bitDepth))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Float32ToInt24(data []float32) (buf []byte) {
|
||||
buf = make([]byte, len(data)*3)
|
||||
C.audio_float32_to_int24((*C.float)(&data[0]), C.size_t(len(data)), (*C.int8_t)(unsafe.Pointer(&buf[0])))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Float32ToInt16(data []float32) (buf []int16) {
|
||||
buf = make([]int16, len(data))
|
||||
C.audio_float32_to_int16((*C.float)(&data[0]), C.size_t(len(data)), (*C.int16_t)(&buf[0]))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
||||
func Float32ToInt8(data []float32) (buf []int8) {
|
||||
buf = make([]int8, len(data))
|
||||
C.audio_float32_to_int8((*C.float)(&data[0]), C.size_t(len(data)), (*C.int8_t)(&buf[0]))
|
||||
runtime.KeepAlive(data)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ package vector
|
|||
import (
|
||||
"encoding/binary"
|
||||
"math"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
|
@ -207,6 +208,7 @@ func Int32ToBytes(data []int32, bitDepth int) (buf []byte) {
|
|||
break
|
||||
case 32:
|
||||
copy(buf, unsafe.Slice((*byte)(unsafe.Pointer(&data[0])), len(data)*4))
|
||||
runtime.KeepAlive(data)
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -246,6 +248,7 @@ func BytesToInt32(data []byte, bitDepth int) (buf []int32) {
|
|||
break
|
||||
case 32:
|
||||
copy(buf, unsafe.Slice((*int32)(unsafe.Pointer(&data[0])), len(data)/4))
|
||||
runtime.KeepAlive(data)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
package vector
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func Int8ToBytes(data []int8) (buf []byte) {
|
||||
buf = make([]byte, len(data))
|
||||
copy(buf, unsafe.Slice((*byte)(unsafe.Pointer(&data[0])), len(data)))
|
||||
runtime.KeepAlive(data)
|
||||
return buf
|
||||
}
|
||||
|
||||
func Int16ToBytes(data []int16) (buf []byte) {
|
||||
buf = make([]byte, len(data)*2)
|
||||
copy(buf, unsafe.Slice((*byte)(unsafe.Pointer(&data[0])), len(data)*2))
|
||||
runtime.KeepAlive(data)
|
||||
return buf
|
||||
}
|
||||
|
||||
func Float32ToBytes(data []float32) (buf []byte) {
|
||||
buf = make([]byte, len(data)*4)
|
||||
copy(buf, unsafe.Slice((*byte)(unsafe.Pointer(&data[0])), len(data)*4))
|
||||
runtime.KeepAlive(data)
|
||||
return buf
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue