jeudi 8 avril 2021

Reflect Value.Interface() panic: bad indir on CGo type after v1.15.4

I'm using a C Library called GEOS which provides a C-backed implementation for handling Geometric operations. A struct containing this C type was used during some reflection operations, but upon upgrading to Go v1.15.4 (Or any version after) this results in a panic.

I've isolated the problem, and it appears that when using a reflect Type to create a new reflect Value, a subsequent call of Interface() results in the panic: bad indir:

var test *C.GEOSGeometry

reflectType := reflect.ValueOf(test).Type().Elem()
value := reflect.New(reflectType)

// Panics in 1.15.4+
value.Interface()

The actual panic comes from within func packEface inside reflect/value.go where the following occurs:

switch {
    case ifaceIndir(t):
        if v.flag&flagIndir == 0 {   // here v.flag = 22 and flagIndir = 128
            panic("bad indir")
        }
        ...

Does it appear that something I'm doing is incorrect here, or is it more likely that this was a bug introduced in 1.15.4?





Aucun commentaire:

Enregistrer un commentaire