In the failing example below, it seems that the size of an argument type for a
cdef function is not resolved at runtime when that argument type is an extern
ctypedef. All the arguments to bfn() are therefore ints, which is incorrect.
It seems that this falls under ticket 303's domain, since the user shouldn't
care about the 'true' size of a datatype, whether its used inside a function or
in the function's argument list.
external_defs.h:
[snip]
typedef char CharTypedef;
typedef short ShortTypedef;
typedef int IntTypedef;
typedef long LongTypedef;
#if defined(T_LONGLONG)
typedef PY_LONG_LONG LongLongTypedef;
#else
typedef long LongLongTypedef;
#endif
[snip]
bug_T1000.pyx:
"""
>>> test_ints()
"""
cdef extern from "external_defs.h":
ctypedef int CharTypedef
ctypedef int ShortTypedef
ctypedef int IntTypedef
ctypedef int LongTypedef
ctypedef int LongLongTypedef
def test_ints():
cdef CharTypedef ct = 2**(8*sizeof(CharTypedef)-1)-1 # 127
cdef ShortTypedef st = 2**(8*sizeof(ShortTypedef)-1)-1 # 32767
cdef IntTypedef it = 2**(8*sizeof(IntTypedef)-1)-1 # 2147483647
cdef LongTypedef lt = 2**(8*sizeof(LongTypedef)-1)-1 #
processor dependent...
cdef LongLongTypedef llt = 2**(8*sizeof(LongLongTypedef)-1)-1 #
processor dependent...
assert (ct, st, it, lt, llt) == bfn(ct, st, it, lt, llt)
def bfn(CharTypedef ct, ShortTypedef st, IntTypedef it, LongTypedef
lt, LongLongTypedef llt):
return (ct, st, it, lt, llt)
8<-------------------------------------------------------------------------------------
Running the above gives:
======================================================================
FAIL: Doctest: bug_T1000
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/doctest.py", line 2145, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for bug_T1000
File "/home/ksmith/GSoC/cython-devel-303-reg/BUILD/run/c/bug_T1000.so",
line 164, in bug_T1000
----------------------------------------------------------------------
File "/home/ksmith/GSoC/cython-devel-303-reg/BUILD/run/c/bug_T1000.so",
line 166, in bug_T1000
Failed example:
test_ints()
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.6/doctest.py", line 1241, in __run
compileflags, 1) in test.globs
File "<doctest bug_T1000[0]>", line 1, in <module>
test_ints()
File "bug_T1000.pyx", line 18, in bug_T1000.test_ints (bug_T1000.c:525)
File "bug_T1000.pyx", line 20, in bug_T1000.bfn (bug_T1000.c:647)
OverflowError: value too large to convert to int
======================================================================
FAIL: Doctest: bug_T1000
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/doctest.py", line 2145, in runTest
raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for bug_T1000
File "/home/ksmith/GSoC/cython-devel-303-reg/BUILD/run/cpp/bug_T1000.so",
line 115, in bug_T1000
----------------------------------------------------------------------
File "/home/ksmith/GSoC/cython-devel-303-reg/BUILD/run/cpp/bug_T1000.so",
line 117, in bug_T1000
Failed example:
test_ints()
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python2.6/doctest.py", line 1241, in __run
compileflags, 1) in test.globs
File "<doctest bug_T1000[0]>", line 1, in <module>
test_ints()
File "bug_T1000.pyx", line 18, in bug_T1000.test_ints (bug_T1000.cpp:525)
File "bug_T1000.pyx", line 20, in bug_T1000.bfn (bug_T1000.cpp:647)
OverflowError: value too large to convert to int
----------------------------------------------------------------------
Ran 4 tests in 0.757s
FAILED (failures=2)
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev