c-for-go icon indicating copy to clipboard operation
c-for-go copied to clipboard

cgogen generate variable-argument lists code

Open 9yx opened this issue 9 years ago • 3 comments

Based on a bug in the cgo (https://github.com/golang/go/issues/975) cgogen generate

// Krb5buildPrincipal function as declared in krb5/krb5.h:4028
func Krb5buildPrincipal(context Krb5context, princ []*Krb5principal, rlen uint32, realm string) Krb5errorCode {
    ccontext, _ := *(*C.krb5_context)(unsafe.Pointer(&context)), cgoAllocsUnknown
    cprinc, _ := unpackArgSPKrb5principal(princ)
    crlen, _ := (C.uint)(rlen), cgoAllocsUnknown
    crealm, _ := unpackPCharString(realm)
    __ret := C.krb5_build_principal(ccontext, cprinc, crlen, crealm) //<-- here bug
    packSPKrb5principal(princ, cprinc)
    __v := (Krb5errorCode)(__ret)
    return __v
}

krb5_build_principal is variable-argument lists function

krb5_error_code KRB5_CALLCONV_C
krb5_build_principal(krb5_context context,
                     krb5_principal * princ,
                     unsigned int rlen,
                     const char * realm, ...)

when build code:

# cgo/krb5
./krb5.go:1706:11: unexpected type: ...

kerberos.yaml

9yx avatar Sep 29 '16 12:09 9yx

Surely, I usually just ignore these functions in manifest. When CGO will support variadic argument lists I'll implement that in cgogen too. There is an idea of implementing a helper for that in .c and .h helpers, but variadics in C are not portable and I have no enough motivation to deal with this problem.

xlab avatar Sep 29 '16 13:09 xlab

Code generation from https://github.com/cimgui/cimgui would heavily depend on this feature, because cimgui is pretty much unusable without variadic argument lists. Right now, it cannot be used at all.

Is there any chance that variadic argument lists might still be implemented?

lotodore avatar Jul 29 '22 10:07 lotodore

@lotodore https://github.com/golang/go/issues/975 no movement there for 6 freaking years :(

So it has to generate C bridge functions, if we want to have this support. Cgogen already generates bridges for the callbacks.. So it might worth a shot.

xlab avatar Jul 30 '22 18:07 xlab