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

Runtime out of memory #111

Open
duysqubix opened this issue Oct 11, 2023 · 0 comments
Open

Runtime out of memory #111

duysqubix opened this issue Oct 11, 2023 · 0 comments

Comments

@duysqubix
Copy link
Contributor

Hi, I'm trying to use .go as .so lib which then is imported to python.

extsoundmix.go

//extsoundmix.go
package main

import (
	"C"
	"log"
	"os"
	"time"

	"github.com/faiface/beep"
	"github.com/faiface/beep/mp3"
	"github.com/faiface/beep/speaker"
)

//export PlaySong
func PlaySong(s string) {
	f, err := os.Open(s)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	streamer, format, err := mp3.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	defer streamer.Close()

	done := make(chan bool)
	speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
	speaker.Play(beep.Seq(streamer, beep.Callback(func() {
		done <- true
	})))
	<-done
	// defer f.Close()
}

func main() {
	// PlaySong("/home/dfsad/Downloads/black-alert.mp3")
}

app.py

from ctypes import cdll

lib = cdll.LoadLibrary('/home/dfsad/go/src/extsound/extsoundmix.so')
print("Loaded go generated SO library")
result = lib.PlaySong("/home/dfsad/Downloads/black-alert.mp3")


runtime: out of memory: cannot allocate 140648171077632-byte block (66748416 in use)
fatal error: out of memory

runtime stack:
runtime.throw(0x7feb2017abc4, 0xd)
	/usr/local/go/src/runtime/panic.go:617 +0x74
runtime.largeAlloc(0x7feb34467ccf, 0x7feb204b0100, 0xc0000b2120)
	/usr/local/go/src/runtime/malloc.go:1057 +0x16d
runtime.mallocgc.func1()
	/usr/local/go/src/runtime/malloc.go:950 +0x48
runtime.systemstack(0x7ffcee70f2e0)
	/usr/local/go/src/runtime/asm_amd64.s:351 +0x63
runtime.mstart()
	/usr/local/go/src/runtime/proc.go:1153

goroutine 17 [running, locked to thread]:
runtime.systemstack_switch()
	/usr/local/go/src/runtime/asm_amd64.s:311 fp=0xc000046920 sp=0xc000046918 pc=0x7feb2011c650
runtime.mallocgc(0x7feb34467ccf, 0x0, 0x7feb18aec900, 0x20300000000000)
	/usr/local/go/src/runtime/malloc.go:949 +0x884 fp=0xc0000469c0 sp=0xc000046920 pc=0x7feb200d4cd4
runtime.rawstring(0x7feb34467ccf, 0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/go/src/runtime/string.go:259 +0x51 fp=0xc0000469f0 sp=0xc0000469c0 pc=0x7feb2010c3b1
runtime.rawstringtmp(0x0, 0x7feb34467ccf, 0xc000046af0, 0x7feb200d1fa3, 0x7feb203d18e0, 0x7feb0002fa80, 0x7feb203c66a0)
	/usr/local/go/src/runtime/string.go:123 +0x74 fp=0xc000046a30 sp=0xc0000469f0 pc=0x7feb2010bd74
runtime.concatstrings(0x0, 0xc000046b10, 0x5, 0x5, 0x7feb2017b1e7, 0x10)
	/usr/local/go/src/runtime/string.go:49 +0xb0 fp=0xc000046ac8 sp=0xc000046a30 pc=0x7feb2010b7f0
runtime.concatstring5(0x0, 0x7feb2017995a, 0x4, 0x7feb20179780, 0x1, 0x7feb21580c10, 0x7feb34467cb8, 0x7feb201797b4, 0x2, 0x7feb2017b1e7, ...)
	/usr/local/go/src/runtime/string.go:70 +0x49 fp=0xc000046b08 sp=0xc000046ac8 pc=0x7feb2010bbd9
os.(*PathError).Error(0xc000096180, 0x7feb203ee9c0, 0xc0000d2000)
	/usr/local/go/src/os/error.go:33 +0xad fp=0xc000046b80 sp=0xc000046b08 pc=0x7feb201562fd
fmt.(*pp).handleMethods(0xc0000d2000, 0xc000000076, 0xc000046c01)
	/usr/local/go/src/fmt/print.go:610 +0x198 fp=0xc000046c20 sp=0xc000046b80 pc=0x7feb2015dbb8
fmt.(*pp).printArg(0xc0000d2000, 0x7feb203d18e0, 0xc000096180, 0x7feb00000076)
	/usr/local/go/src/fmt/print.go:699 +0x20c fp=0xc000046cb8 sp=0xc000046c20 pc=0x7feb2015e13c
fmt.(*pp).doPrint(0xc0000d2000, 0xc000046e70, 0x1, 0x1)
	/usr/local/go/src/fmt/print.go:1147 +0xff fp=0xc000046d40 sp=0xc000046cb8 pc=0x7feb20162c4f
fmt.Sprint(0xc000046e70, 0x1, 0x1, 0x0, 0x7feb203f0a60)
	/usr/local/go/src/fmt/print.go:250 +0x54 fp=0xc000046d98 sp=0xc000046d40 pc=0x7feb2015af74
log.Fatal(0xc000046e70, 0x1, 0x1)
	/usr/local/go/src/log/log.go:313 +0x41 fp=0xc000046dd8 sp=0xc000046d98 pc=0x7feb20164131
main.PlaySong(0x7feb21580c10, 0x7feb34467cb8)
	/home/dfsad/go/src/extsound/extsoundmix.go:19 +0xbe fp=0xc000046e90 sp=0xc000046dd8 pc=0x7feb2017858e
main._cgoexpwrap_11df64b4c5a5_PlaySong(0x7feb21580c10, 0x7feb34467cb8)
	_cgo_gotypes.go:45 +0x37 fp=0xc000046eb0 sp=0xc000046e90 pc=0x7feb201784b7
runtime.call32(0x0, 0x7ffcee70f330, 0x7ffcee70f3c0, 0x10)
	/usr/local/go/src/runtime/asm_amd64.s:519 +0x3d fp=0xc000046ee0 sp=0xc000046eb0 pc=0x7feb2011c9ed
runtime.cgocallbackg1(0x0)
	/usr/local/go/src/runtime/cgocall.go:314 +0x17b fp=0xc000046f58 sp=0xc000046ee0 pc=0x7feb200cc80b
runtime.cgocallbackg(0x0)
	/usr/local/go/src/runtime/cgocall.go:191 +0xcb fp=0xc000046fc0 sp=0xc000046f58 pc=0x7feb200cc5eb
runtime.cgocallback_gofunc(0x0, 0x0, 0x0, 0x0)
	/usr/local/go/src/runtime/asm_amd64.s:773 +0x9a fp=0xc000046fe0 sp=0xc000046fc0 pc=0x7feb2011dffa
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000046fe8 sp=0xc000046fe0 pc=0x7feb2011e751

Original issue: faiface/beep#51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant