hg clone ssh://h...@bitbucket.org/petergaultney/cython_test
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
/* "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);
cpdef int does_something_with_struct(int times, something * thing)
C function must be declared with cdef, not cpdef.
--
vitja.
2012/4/9 Peter Gaultney
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.
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.