I was looking at the source for
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
// the pointers are invalid, since they point to objects allocated by C

Before the commit that changed this
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

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?


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 @
postedNov 18, '15 at 8:13a
activeNov 19, '15 at 3:03a



site design / logo © 2021 Grokbase