-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
package main
import (
"C"
"fmt"
)
var (
c chan string
)
func init() {
c = make(chan string)
go func() {
n := 1
for {
switch {
case n%15 == 0:
c <- "FizzBuzz"
case n%3 == 0:
c <- "Fizz"
case n%5 == 0:
c <- "Buzz"
default:
c <- fmt.Sprint(n)
}
n++
}
}()
}
//export fizzbuzz
func fizzbuzz() *C.char {
return C.CString(<-c)
}
func main() {
}
build this with
$ go build -buildmode=c-shared -o libfizzbuzz.so libfizzbuzz.go
then go
from ctypes import *
import _ctypes
lib = CDLL("./libfizzbuzz.so")
lib.fizzbuzz.restype = c_char_p
print lib.fizzbuzz()
print lib.fizzbuzz()
print lib.fizzbuzz()
print lib.fizzbuzz()
print lib.fizzbuzz()
print lib.fizzbuzz()
_ctypes.dlclose(lib._handle)
1
2
Fizz
4
Buzz
Fizz
Segmentation fault
GeertJohan, jnardone, maxxant, doylecnn, bartlomiej-dawidow and 19 moreravendcode
Metadata
Metadata
Assignees
Labels
compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.