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 of 
the defer list, then I could encapsulate the construction with the defer in 
a function.

e.g. roughly :

func NewCString(s string, deferList List) *C.char {
   cs := C.CString(s)
   deferList.PushBack(func() { C.free(cs) }
   return cs
}

Then in an *imagined world* I could write my wrapper simply as :

func wrapper(s1 string, s2 string, s3 string) {
  deferList := runtime.DeferList()
  return C.inner(NewCString(s1,deferList), NewCString(s2,deferList), 
NewCString(s2,deferList))
}

Basically, I cant seem to find a clean solution to ensure all these C.char* 
are 100% freed... swig allows me to wrap the C.char* with string, but swig 
is pretty awkward to use especially when wrapping the libraries I have. Im 
currently preferring cgo which seems much simpler and cleaner, but I dont 
have the equivalent of swigs typemaps to ensure all allocs are correctly 
freed... :o(





On Wednesday, October 19, 2016 at 8:41:25 PM UTC+1, Pietro Gagliardi 
(andlabs) wrote:
>
> What do you want to do with it?
>
> On Oct 19, 2016, at 3:31 PM, andrew...@miracl.com <javascript:> 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
>
> -- 
> 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...@googlegroups.com <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>
>

-- 
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.

Reply via email to