[go-nuts] err variable shadowing — is it a bad practice?

2016-11-23 Thread iakov . davydov
Hi, Occasionally go vet complains about shadowing of the err variable. Consider the following code. package main import ( "flag" "io" "os" ) func main() { inFilename := flag.String("in", "infile", "input file") outFilename := flag.String("out", "outfile", "output file") flag.Parse() in, err :=

[go-nuts] Re: premature defer in method when using cgo

2016-11-10 Thread iakov . davydov
e been violating cgo rules by passing Go pointer to an integer to the C code for storage. C.nlopt_set_max_objective(n.gopt, (C.nlopt_func)(unsafe.Pointer(C.callback_adaptor)), unsafe.Pointer(&nID)) Now I do it like this instead: C.nlopt_set_max_objective(n.gopt, (C.nlopt_func)(unsafe.Pointer(

Re: [go-nuts] premature defer in method when using cgo

2016-11-10 Thread iakov . davydov
Hi, As far as I understand, os.Stdout & os.Stderr are not buffered. log.Debug writes to stderr. I replaced log.Debug with println, the result is the same. Cheers, Iakov P.S. Struggling with creating a minimal example; the results is not very stable. Will put it here if I will manage. On Thursda

[go-nuts] premature defer in method when using cgo

2016-11-10 Thread iakov . davydov
Hi, I don't have a minimal example yet, but this looks very suspicious. It seems that sometimes defer called before the function finishes, if cgo code with callbacks is called in it. Here's the code: func (n *NLOPT) Run(iterations int) { log.Debug("entering Run method") ...