error: too many arguments to function

280 views
Skip to first unread message

Peter Gaultney

unread,
Apr 9, 2012, 12:29:16 PM4/9/12
to cython...@googlegroups.com
I am trying to learn how to use Cython. I have created a public Mercurial repository on Bitbucket with the code that anyone can pull to verify this issue.
The following happens when I build my test project with the shell command python setup.py build_ext --inplace

running build_ext
skipping 'something_test.c' Cython extension (up-to-date)
building 'something_test' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c something_test.c -o build/temp.linux-x86_64-2.7/something_test.o
something_test.c: In function ‘__pyx_pf_14something_test_func’:
something_test.c:482:13: error: incompatible types when assigning to type ‘char[6]’ from type ‘char *’
something_test.c:482:69: warning: the address of ‘__pyx_t_1’ will always evaluate as ‘true’ [-Waddress]
something_test.c:483:25: error: incompatible types when assigning to type ‘char[6]’ from type ‘char *’
something_test.c:537:13: error: incompatible types when assigning to type ‘char[6]’ from type ‘char *’
something_test.c:537:69: warning: the address of ‘__pyx_t_1’ will always evaluate as ‘true’ [-Waddress]
something_test.c:538:41: error: incompatible types when assigning to type ‘char[6]’ from type ‘char *’
something_test.c:556:3: error: too many arguments to function ‘does_something_with_struct’
something.h:21:5: note: declared here
something_test.c:575:3: error: too many arguments to function ‘does_nothing_with_struct’
something.h:22:6: note: declared here
error: command 'gcc' failed with exit status 1

I get the same errors with versions 0.14.1 and 0.15.1, and on both Ubuntu Linux and Mac OS X.

The one that really bothers me is the "error: too many arguments to function" one. A look at the generated C code shows that the call to the function has the integer 0 added as a third argument to both of those calls. 

/* "something_test.pyx":21
* brill.weird_int = 29
*
* ret = does_something_with_struct(24, &brill) # <<<<<<<<<<<<<<
*
* print(ret)
*/
__pyx_v_ret = does_something_with_struct(24, (&__pyx_v_brill), 0);

does_nothing_with_struct((&__pyx_v_brill), 0);

Removing them manually allows me to build the code into a shared object, but this is not a workable solution for larger projects.

I would also appreciate help regarding the proper Cython syntax to copy a string into a char array, since assignment doesn't work (of course, in C a simple strcpy would do the trick, but I don't know what my options are in Cython).

Peter Gaultney

unread,
Apr 9, 2012, 1:15:23 PM4/9/12
to cython...@googlegroups.com
small clarification: the second line of the build should read: cythoning something_test.pyx to something_test.c
I pasted the wrong set of output.

Vitja Makarov

unread,
Apr 9, 2012, 1:20:57 PM4/9/12
to cython...@googlegroups.com
2012/4/9 Peter Gaultney <peterg...@gmail.com>:

> small clarification: the second line of the build should read: cythoning
> something_test.pyx to something_test.c
> I pasted the wrong set of output.

cpdef int does_something_with_struct(int times, something * thing)

C function must be declared with cdef, not cpdef.

--
vitja.

Peter Gaultney

unread,
Apr 9, 2012, 1:24:09 PM4/9/12
to cython...@googlegroups.com
Perfect - that fixed it. Any clue about how to fix the other (char array) problem?

Thank you so much... I've been tearing my hair out since Saturday.

On Monday, April 9, 2012 1:20:57 PM UTC-4, Vitja wrote:
2012/4/9 Peter Gaultney

Vitja Makarov

unread,
Apr 9, 2012, 1:41:55 PM4/9/12
to cython...@googlegroups.com
2012/4/9 Peter Gaultney <peterg...@gmail.com>:

> Perfect - that fixed it. Any clue about how to fix the other (char array)
> problem?
>

The char issue isn't cython related.

int main()
{
char foo[10];
foo = "bar";
return 0;
}

This isn't valid C program. You can change foo[10] to *foo or use
strncpy() instead.

> Thank you so much... I've been tearing my hair out since Saturday.
>
> On Monday, April 9, 2012 1:20:57 PM UTC-4, Vitja wrote:
>>
>> 2012/4/9 Peter Gaultney
>>
>> > small clarification: the second line of the build should read: cythoning
>> > something_test.pyx to something_test.c
>> > I pasted the wrong set of output.
>>
>> cpdef int does_something_with_struct(int times, something * thing)
>>
>> C function must be declared with cdef, not cpdef.
>>
>> --
>> vitja.

--
vitja.

Peter Gaultney

unread,
Apr 9, 2012, 1:55:25 PM4/9/12
to cython...@googlegroups.com
Well, you are correct that your example is not valid C. But check out something.c for a main function that IS valid C, in which I do in fact use strncpy to copy into that array. The point of my repository is to test out various potential use cases, and having a struct with a char array inside it is a valid use case. I simply need to know how to copy a string into a char array (not a char *) at the Cython level.  I didn't really expect assignment to work, but there has to be some solution, right?

Thanks!

mark florisson

unread,
Apr 9, 2012, 3:56:12 PM4/9/12
to cython...@googlegroups.com
On 9 April 2012 18:55, Peter Gaultney <peterg...@gmail.com> wrote:
> Well, you are correct that your example is not valid C. But check out
> something.c for a main function that IS valid C, in which I do in fact use
> strncpy to copy into that array. The point of my repository is to test out
> various potential use cases, and having a struct with a char array inside it
> is a valid use case. I simply need to know how to copy a string into a char
> array (not a char *) at the Cython level.  I didn't really expect assignment
> to work, but there has to be some solution, right?
>
> Thanks!
>
>

Cython accepting that code is a bug, as it currently does not support
such assignments, although it could. This is fixed in the upcoming
Cython 0.16 release though, which will issue errors.

Peter Gaultney

unread,
Apr 9, 2012, 6:31:03 PM4/9/12
to cython...@googlegroups.com
I didn't even think about how the compiler ought to have complained. Well, again, what I would like most is a suggestion for how to accomplish this, but I am getting the impression that there's really no way to do it other than writing a Cython-level str(n)cpy wrapper. 

Thanks again for all the help. I have been testing the waters of Cython for about a week now, and I think I am finally seeing some encouraging results. 

Vitja Makarov

unread,
Apr 10, 2012, 12:44:51 AM4/10/12
to cython...@googlegroups.com
2012/4/9 mark florisson <markflo...@gmail.com>:

> On 9 April 2012 18:55, Peter Gaultney <peterg...@gmail.com> wrote:
>> Well, you are correct that your example is not valid C. But check out
>> something.c for a main function that IS valid C, in which I do in fact use
>> strncpy to copy into that array. The point of my repository is to test out
>> various potential use cases, and having a struct with a char array inside it
>> is a valid use case. I simply need to know how to copy a string into a char
>> array (not a char *) at the Cython level.  I didn't really expect assignment
>> to work, but there has to be some solution, right?
>>
>> Thanks!
>>
>>
>
> Cython accepting that code is a bug, as it currently does not support
> such assignments, although it could. This is fixed in the upcoming
> Cython 0.16 release though, which will issue errors.
>

Yeah, it's a bug.

2Peter: You can use same strncpy for your problem:

from libc cimport string
def testit():
cdef char dst[10]
string.strncpy(dst, "Hello, world!", sizeof(dst))
dst[sizeof(dst) - 1] = '\0'
print dst


--
vitja.

Reply all
Reply to author
Forward
0 new messages