Re: [go-nuts] the defer list

2016-10-20 Thread andrew . smith
Yeah, thanks for that Konstantin. I have done something fairly similar, although all my objects support a Destroyable interface with one method Destroy(). However, I think your idea to closely mimic the defer list and simply push functions is much cleaner. The basic concept seems to work quite

Re: [go-nuts] the defer list

2016-10-20 Thread Konstantin Khomoutov
On Wed, 19 Oct 2016 15:35:40 -0700 (PDT) andrew.sm...@miracl.com wrote: [...] > Im considering a scheme where I push every CString onto an > implementation of a stack, and then call defer once. Im sure some > people might think it overkill... Kinda like this : > > func Outer(arg1 string, arg2

Re: [go-nuts] the defer list

2016-10-19 Thread andrew . smith
Thanks for the advice. Im fairly new to golang, but Im used to the guarantees of C++ destructors. I think defer is a great thing and similar to the scope guard idiom. I dont think Im trying to fight the language, just trying to see if there is a way to protect myself from stupid mistakes that

Re: [go-nuts] the defer list

2016-10-19 Thread 'Thomas Bushnell, BSG' via golang-nuts
Ah, yes, that's true indeed. On Wed, Oct 19, 2016 at 2:33 PM adonovan via golang-nuts < golang-nuts@googlegroups.com> wrote: > On Wednesday, 19 October 2016 16:50:55 UTC-4, Thomas Bushnell, BSG wrote: > > On Wed, Oct 19, 2016 at 1:47 PM Pietro Gagliardi > wrote: > > Manual

Re: [go-nuts] the defer list

2016-10-19 Thread adonovan via golang-nuts
On Wednesday, 19 October 2016 16:50:55 UTC-4, Thomas Bushnell, BSG wrote: > > On Wed, Oct 19, 2016 at 1:47 PM Pietro Gagliardi > wrote: > >> Manual memory management is a part of life in the C world. defer is the >> solution that Go comes up with to situations where

Re: [go-nuts] the defer list

2016-10-19 Thread 'Thomas Bushnell, BSG' via golang-nuts
On Wed, Oct 19, 2016 at 1:47 PM Pietro Gagliardi wrote: > Manual memory management is a part of life in the C world. defer is the > solution that Go comes up with to situations where explicit cleanup is > necessary, and it's a powerful tool that I'm pretty sure *is* an

Re: [go-nuts] the defer list

2016-10-19 Thread Pietro Gagliardi
All right then. Good to know, thanks. > On Oct 19, 2016, at 4:50 PM, Thomas Bushnell, BSG > wrote: > > On Wed, Oct 19, 2016 at 1:47 PM Pietro Gagliardi > wrote: > Manual memory management is a part of life in the C world.

Re: [go-nuts] the defer list

2016-10-19 Thread Pietro Gagliardi
Manual memory management is a part of life in the C world. defer is the solution that Go comes up with to situations where explicit cleanup is necessary, and it's a powerful tool that I'm pretty sure *is* an innovation Go did first. If you just follow the idiom cstr := C.CString(str)

Re: [go-nuts] the defer list

2016-10-19 Thread andrew . smith
I thought someone might ask! Im writing many wrapper functions to C functions that take multiple C.char* arguments. All of these require a call to C.free() before the wrapper function terminates. I can do this with defer but Im absolutely sure Im going to miss one or more of these out. So I

Re: [go-nuts] the defer list

2016-10-19 Thread andrew . smith
I thought you might Im writing many wrapper functions to C functions that take multiple C.char*. All of these require a defer statement to free the C string when the wrapper function terminates. Im absolutely sure Im going to miss one or more of these out, so I was wondering if I could get hold

Re: [go-nuts] the defer list

2016-10-19 Thread andrew . smith
I thought you might Im writing many wrapper functions to C functions that take multiple C.char*. All of these require a defer statement to free the C string when the wrapper function terminates. Im absolutely sure Im going to miss one or more of these out, so I was wondering if I could get hold

Re: [go-nuts] the defer list

2016-10-19 Thread Ian Lance Taylor
On Wed, Oct 19, 2016 at 12:31 PM, wrote: > > This is probably a long shot, but is it possible to get a reference to the > list of functions that the 'defer' statement populates? Is it exposed and/or > is it specific? The list is not available. Ian -- You received

Re: [go-nuts] the defer list

2016-10-19 Thread Pietro Gagliardi
What do you want to do with it? > On Oct 19, 2016, at 3:31 PM, andrew.sm...@miracl.com wrote: > > Hi, > > This is probably a long shot, but is it possible to get a reference to the > list of functions that the 'defer' statement populates? Is it exposed and/or > is it specific? > > Andy > >

[go-nuts] the defer list

2016-10-19 Thread andrew . smith
Hi, This is probably a long shot, but is it possible to get a reference to the list of functions that the 'defer' statement populates? Is it exposed and/or is it specific? Andy -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe