FAQ
I know that cgo doesn't do varargs, but I came across a stack overflow
question suggesting to wrap it, however, as far as I can tell, there's no
way to pass an array as varargs either. Does anyone know a workaround?

I can't refactor to eliminate varargs, I'm trying to fix go-python:

https://github.com/sbinet/go-python

The Python API heavily relies on varargs, right now the only workaround is
really tedious tuple fiddling if you want to do complicated things like
"calling a function."

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Ian Lance Taylor at Jun 4, 2015 at 9:38 pm

    On Thu, Jun 4, 2015 at 1:47 PM, Jsor wrote:
    I know that cgo doesn't do varargs, but I came across a stack overflow
    question suggesting to wrap it, however, as far as I can tell, there's no
    way to pass an array as varargs either. Does anyone know a workaround?
    cgo works by generating C code to call the C function. The nature of
    C varargs is that the arguments must actually be written out in the
    calling C code. C has no equivalent to Go's F(args...). So this is
    insoluble in principle. There is no way to generate C code to call a
    C function with an unknown number of arguments.

    That said, if there is some reasonable limit on the number of
    arguments, you can force the Go side to extra unused arguments to each
    call. That is basically what the syscall package does, with Syscall3,
    Syscall6, and Syscall9.

    Ian

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Julian Phillips at Jun 5, 2015 at 3:16 am

    On 04/06/2015 21:47, Jsor wrote:
    I know that cgo doesn't do varargs, but I came across a stack overflow
    question suggesting to wrap it, however, as far as I can tell, there's
    no
    way to pass an array as varargs either. Does anyone know a workaround?

    I can't refactor to eliminate varargs, I'm trying to fix go-python:

    https://github.com/sbinet/go-python

    The Python API heavily relies on varargs, right now the only workaround
    is
    really tedious tuple fiddling if you want to do complicated things like
    "calling a function."
    This is what I did for my Python bindings (in this case, wrapping
    PyArg_ParseTuple):

    https://github.com/qur/gopy/blob/master/lib/utils.c#L25

    called from here:

    https://github.com/qur/gopy/blob/master/lib/arg.go#L89

    --
    Julian

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Sebastien Binet at Jun 5, 2015 at 8:28 am

    On Fri, Jun 5, 2015 at 12:41 AM, Julian Phillips wrote:
    On 04/06/2015 21:47, Jsor wrote:

    I know that cgo doesn't do varargs, but I came across a stack overflow
    question suggesting to wrap it, however, as far as I can tell, there's no
    way to pass an array as varargs either. Does anyone know a workaround?

    I can't refactor to eliminate varargs, I'm trying to fix go-python:

    https://github.com/sbinet/go-python

    The Python API heavily relies on varargs, right now the only workaround is
    really tedious tuple fiddling if you want to do complicated things like
    "calling a function."

    This is what I did for my Python bindings (in this case, wrapping
    PyArg_ParseTuple):

    https://github.com/qur/gopy/blob/master/lib/utils.c#L25

    called from here:

    https://github.com/qur/gopy/blob/master/lib/arg.go#L89
    ah! nice.
    I could dust off my old ffi wrapper for this :)
    https://github.com/gonuts/ffi

    -s

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 4, '15 at 9:25p
activeJun 5, '15 at 8:28a
posts4
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase