sbinet / go-python

naive go bindings to the CPython2 C-API
Other
1.53k stars 138 forks source link

PyObject_CallFunction and PyObject_CallMethod - not implemented #27

Closed bavovna closed 8 years ago

bavovna commented 9 years ago
// PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...)
// Return value: New reference.
// Call a callable Python object callable, with a variable number of C arguments. The C arguments are described using a Py_BuildValue() style format string. The format may be NULL, indicating that no arguments are provided. Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression apply(callable, args) or callable(*args). Note that if you only pass PyObject * args, PyObject_CallFunctionObjArgs() is a faster alternative.
func (self *PyObject) CallFunction(format string, args ...interface{}) *PyObject {
    //FIXME
    panic("not implemented")
    return nil
}

// PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...)
// Return value: New reference.
// Call the method named method of object o with a variable number of C arguments. The C arguments are described by a Py_BuildValue() format string that should produce a tuple. The format may be NULL, indicating that no arguments are provided. Returns the result of the call on success, or NULL on failure. This is the equivalent of the Python expression o.method(args). Note that if you only pass PyObject * args, PyObject_CallMethodObjArgs() is a faster alternative.
func (self *PyObject) CallMethod(format string, args ...interface{}) *PyObject {
    //FIXME
    panic("not implemented")
    return nil
}
sbinet commented 9 years ago

variadic C functions can not be called from cgo (that's actually one of the reasons why I started go-python/gopy)

that said, I could hardcode a maximum number of arguments (8?) one could call CallFunction and CallMethod and then call a custom C non-variadic shim function (which would forward to PyObject_CallXYZ)

how does that sound?

bavovna commented 9 years ago

@sbinet thank you, 8 arguments are more than enough for me.

sbinet commented 9 years ago

please give dcbfa20 a try and let me know.

sbinet commented 9 years ago

actually, make that 7991d39

bavovna commented 9 years ago

It worked with the basic use cases (primitive types as parameters). Will test some more complex cases (dictionaries, function pointers, etc.) a little bit later.