FAQ
I was looking at the source for
github.com/youtube/vitess/go/cgzip/zstream.go
<https://github.com/youtube/vitess/blob/master/go/cgzip/zstream.go#L86-L89>,
and it curiously says:
// z_stream is a buffer that's big enough to fit a C.z_stream.
// This lets us allocate a C.z_stream within Go, while keeping the contents
// opaque to the Go GC. Otherwise, the GC would look inside and complain
that
// the pointers are invalid, since they point to objects allocated by C
code.

Before the commit that changed this
<https://github.com/youtube/vitess/commit/071d0e649f22034ad4285c7431ac0a2c9c20090d#diff-61a5b337943f83de2390afaddf93fb45>,
the previous implementation simply declared type zstream C.z_stream,
instead of the complicated array of bytes it is now. When I run the package
prior to the change, my program crashes randomly with:
runtime:objectstart Span weird: p=0xc8206c2000 k=0x6410361
s.start=0xc8206c2000 s.limit=0xc820220000 s.state=2
fatal error: objectstart: bad pointer in unexpected span
which is oddly similar to issue 13289
<https://github.com/golang/go/issues/13289>.

My questions is (assuming the above comment is correct): if the Go compiler
knows that zstream is just a C struct, why does it care about the pointers
inside the C struct when they almost certainly managed by a C malloc
instead? Also, doesn't the bzip2 example from The Go Programming Language
<https://github.com/adonovan/gopl.io/blob/master/ch13/bzip/bzip2.go> pretty
much do things the way that cgzip moved away from?

Thanks,
JT

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 6 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 18, '15 at 8:13a
activeNov 19, '15 at 3:03a
posts6
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase