/* C code: struct PKCS15_Ret { int error_code; int len; };
struct PKCS15_Ret PKCS15_wrap(int hash_type, octet message, octet receive) { int error_code = PKCS15(hashType, &mOct, &cOct); return struct PKCS15_Ret{ error_code, cOct.len }; } */ func PKCS15_PLAIN(hashType, RFS int, msg []byte) ([]byte, error) { // input mOct := C.octet{ C.int(len(msg)), C.int(len(msg)), (*C.char)(unsafe.Pointer(&msg[0])), } // output r := make([]byte, RFS) cOct := C.octet{ C.int(0), C.int(RFS), (*C.char)(unsafe.Pointer(&r[0])), } rtn := C.PKCS15_wrap(C.int(hashType), mOct, cOct) if rtn.error_code != 1 { return nil, &Error{code: int(rtn.error_code)} } return r[:rtn.len], nil } On Wednesday, November 29, 2017 at 3:12:31 PM UTC-8, xingtao zhao wrote: > > Make your C function to accept octet parameter, instead of *octet parameter? > Then there will be no allocations. > > On Wednesday, November 29, 2017 at 2:39:38 PM UTC-8, Владислав Митов wrote: >> >> So no way around 4 allocations for 2 values? > > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.