Error in the parameters of the function cgo

39 views
Skip to first unread message

Ruslan Mezentsev

unread,
Jul 8, 2011, 7:36:17 AM7/8/11
to golang-nuts
Hi, my question is, why call in cgo function, the parameters are
shifted by 1 from 2 and shows an error.

C code:

static inline dom_exception dom_document_rename_node(struct
dom_document *doc,
struct dom_node *node,
dom_string *namespace, dom_string *qname,
struct dom_node **result)
{
return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
dom_document_rename_node(doc, node, namespace, qname,
result);
}
#define dom_document_rename_node(d, n, ns, q, r)
dom_document_rename_node( \
(dom_document *) (d), (dom_string *) (ns), \
(dom_string *) (q), (dom_node **) (r))

Go code:

type Document struct {
dom_document *C.struct_dom_document
}

type Node struct {
dom_node *C.struct_dom_node
}

type DOMString struct {
dom_string *C.dom_string
}

func (doc *Document) RenameNode(node *Node, namespace *DOMString,
qname *DOMString) (result *Node, err os.Error) {
result = new(Node)
c_doc := doc.dom_document
c_node := node.dom_node
c_namespace := namespace.dom_string
c_qname := qname.dom_string
c_result := result.dom_node
errCode := int(C.dom_document_rename_node(c_doc, c_node, c_namespace,
c_qname, &c_result))
err = getDOMErrorByCode(errCode)
return
}

Error:
godom.go: In function
'_cgo_a6024184c721_Cfunc_dom_document_rename_node':
godom.go:218:2: warning: passing argument 2 of
'dom_document_rename_node' from incompatible pointer type
/usr/local/include/dom/core/document.h:430:29: note: expected 'struct
dom_node *' but argument is of type 'struct dom_string *'

godom.go:218:2: warning: passing argument 4 of
'dom_document_rename_node' from incompatible pointer type
/usr/local/include/dom/core/document.h:430:29: note: expected 'struct
dom_string *' but argument is of type 'struct dom_node **'
godom.go:218:2: error: too few arguments to function
'dom_document_rename_node'
/usr/local/include/dom/core/document.h:430:29: note: declared here

Thanks

bflm

unread,
Jul 8, 2011, 7:42:53 AM7/8/11
to golan...@googlegroups.com
On Friday, July 8, 2011 1:36:17 PM UTC+2, Ruslan Mezentsev wrote:
Hi, my question is, why call in cgo function, the parameters are
shifted by 1 from 2 and shows an error.

C code:

static inline dom_exception dom_document_rename_node(struct
dom_document *doc,
struct dom_node *node,
dom_string *namespace, dom_string *qname,
struct dom_node **result)
{

Could the 'inline' modifier has something to do with it? Just a wild guess.

Ruslan Mezentsev

unread,
Jul 8, 2011, 9:43:27 AM7/8/11
to golang-nuts
Sorry this is not the fault of Go, I got the same error in C.

Ian Lance Taylor

unread,
Jul 8, 2011, 10:24:13 AM7/8/11
to Ruslan Mezentsev, golang-nuts
Ruslan Mezentsev <rmib....@gmail.com> writes:

> Hi, my question is, why call in cgo function, the parameters are
> shifted by 1 from 2 and shows an error.
>
> C code:
>
> static inline dom_exception dom_document_rename_node(struct
> dom_document *doc,
> struct dom_node *node,
> dom_string *namespace, dom_string *qname,
> struct dom_node **result)
> {
> return ((dom_document_vtable *) ((dom_node *) doc)->vtable)->
> dom_document_rename_node(doc, node, namespace, qname,
> result);
> }
> #define dom_document_rename_node(d, n, ns, q, r)
> dom_document_rename_node( \
> (dom_document *) (d), (dom_string *) (ns), \
> (dom_string *) (q), (dom_node **) (r))

I believe cgo is going to see the actual function definition, not the
macro, and it is going to generate code that calls the function.
However, the generated C code will #include the header and will see the
macro; thus the generated code which expects to call the function will
call the macro instead. The function and the macro do not take the same
arguments.

Giving the same name to both a function and a macro but having them act
differently seems like a very confusing way to program.

Ian

Ruslan Mezentsev

unread,
Jul 8, 2011, 11:21:22 AM7/8/11
to golang-nuts
Thank you, I have not noticed a different number of arguments in
define. I think this is a bug library (libdom) and arguments should be
five. I have not found a function with four arguments. )
Reply all
Reply to author
Forward
0 new messages