[go-nuts] Re: Converting Panic into Error

2017-03-23 Thread Andrei Tudor Călin
Hello. You can achieve this by using a named return value and overwriting it in a deferred function, like so: https://play.golang.org/p/4HvVQ6N-I9 Note that the value returned by recover() is not guaranteed to be an error. In my toy example, I work around this fact by passing it to fmt.Errorf i

[go-nuts] Converting Panic into Error

2017-03-23 Thread Jérôme LAFORGE
Hello, Try this: func MustNotPanic() (err error) { defer func(){ err=recover() }() PanicFunction() } -- 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, se

[go-nuts] Converting Panic into Error

2017-03-23 Thread Henry
Hi, I would like to shield my application from any possible panicking by the third-party library. There was an occasion when a third party library crashed my application due to unnecessary panicking. I am thinking of creating a thin wrapper that will also catch any panic into error. How can I

Re: [go-nuts] Re: Unsafe string/slice conversions

2017-03-23 Thread Caleb Spare
Filed: https://github.com/golang/go/issues/19687 On Thu, Mar 23, 2017 at 4:41 PM, 'Keith Randall' via golang-nuts wrote: > > > On Thursday, March 23, 2017 at 4:24:40 PM UTC-7, Caleb Spare wrote: >> >> That's very good to know. Thanks, Ian. >> >> Unfortunately if I use this KeepAlive-based fix, p

[go-nuts] Re: Unsafe string/slice conversions

2017-03-23 Thread 'Keith Randall' via golang-nuts
On Thursday, March 23, 2017 at 4:24:40 PM UTC-7, Caleb Spare wrote: > > That's very good to know. Thanks, Ian. > > Unfortunately if I use this KeepAlive-based fix, p escapes and so the > function now allocates. I guess I'll stick with the original version > from my first email. > > Does this

[go-nuts] Re: Unsafe string/slice conversions

2017-03-23 Thread Caleb Spare
That's very good to know. Thanks, Ian. Unfortunately if I use this KeepAlive-based fix, p escapes and so the function now allocates. I guess I'll stick with the original version from my first email. Does this indicate a shortcoming of either compiler support for KeepAlive or escape analysis in ge

Re: [go-nuts] Are these types discarded? Is this a compiler bug?

2017-03-23 Thread Ian Lance Taylor
On Thu, Mar 23, 2017 at 11:56 AM, Peter Kleiweg wrote: > Op donderdag 23 maart 2017 17:46:18 UTC+1 schreef Ian Lance Taylor: >> >> On Thu, Mar 23, 2017 at 8:54 AM, Peter Kleiweg wrote: >> > Some code that includes C code compiles fine on Linux, but gives strange >> > errors on Darwin. >> > >> > >

Re: [go-nuts] Are these types discarded? Is this a compiler bug?

2017-03-23 Thread Peter Kleiweg
Op donderdag 23 maart 2017 17:46:18 UTC+1 schreef Ian Lance Taylor: > > On Thu, Mar 23, 2017 at 8:54 AM, Peter Kleiweg > wrote: > > Some code that includes C code compiles fine on Linux, but gives strange > > errors on Darwin. > > > > > > In one source file, that doesn't include C, I have thi

[go-nuts] Re: Unsafe string/slice conversions

2017-03-23 Thread Ian Lance Taylor
On Thu, Mar 23, 2017 at 9:16 AM, Caleb Spare wrote: > > Brief follow-up: does the seeming validity of the code rely at all on > the fact that the indicated line is written as a single line? What if, > instead, a *StringHeader var were extracted? > > func stringToSliceUnsafe(s string) []uint64 { >

Re: [go-nuts] Are these types discarded? Is this a compiler bug?

2017-03-23 Thread Ian Lance Taylor
On Thu, Mar 23, 2017 at 8:54 AM, Peter Kleiweg wrote: > Some code that includes C code compiles fine on Linux, but gives strange > errors on Darwin. > > > In one source file, that doesn't include C, I have this: > > type reactor_socket struct { > e State > f func(State)

[go-nuts] Re: Unsafe string/slice conversions

2017-03-23 Thread Caleb Spare
Thanks Ian, that's very helpful. Brief follow-up: does the seeming validity of the code rely at all on the fact that the indicated line is written as a single line? What if, instead, a *StringHeader var were extracted? func stringToSliceUnsafe(s string) []uint64 { var v []uint64 h

[go-nuts] Are these types discarded? Is this a compiler bug?

2017-03-23 Thread Peter Kleiweg
Some code that includes C code compiles fine on Linux, but gives strange errors on Darwin. In one source file, that doesn't include C, I have this: type reactor_socket struct { e State

Re: [go-nuts] Re: how to use go generate to generate generic code .

2017-03-23 Thread Tong Sun
Quite agree. code generation will be especially helpful if it is not something trivial, and you need several rounds to make it perfect. @hui zhang, If you need something generic, take a look at https://github.com/go-easygen/easygen, For e.g., here is how I generate the command line CLI ha