Re:Purego – A library for calling C functions from Go withou...
by pknerd on Sunday February 12, 2023 @12:12PM
(#34764565)
CGo converts Go code to a C based .so library which you can call in Python.
[ Parent
| on HN ]
Re:Purego – A library for calling C functions from Go withou...
by Yoric on Sunday February 12, 2023 @04:21PM
(#34767133)
What's the garbage-collection story? One gc per .so? Or is there some mechanism to share a gc instance between several .so compiled by go?
Re:Purego – A library for calling C functions from Go withou...
by slimsag on Sunday February 12, 2023 @05:57PM
(#34768053)
GP is not exactly right; CGO is not involved in building a shared library except for exporting C functions which can be called. It doesn't "convert Go code to C code" or anything like that.
`-buildmode=c-shared` is what produces a shared library with a C ABI exposed; https://golang.org/s/execmodes was the design document for it, which explains:
> It follows that all Go code shares a single runtime. All Go code uses the same memory allocator, the same goroutine scheduler, and in general acts as though it were linked into a single Go program. This is true even when multiple shared libraries are involved.