GSoC Week #8 & #9
I was a bit unwell in the last week so the progress is a bit slow and I have to merge the two weeks’ reports…
The test mechanism for .py test cases under pure Python is done. Renaming the pure.pyx test case to shadow.py reveals some issues in the shadow module, and I got them fixed. The decorators for cdef class/function and cpdef function, @cython.cclass, @cython. cfunc and @cython.ccall respectively, are done.
Due to the limitation of Python, the shadow mode, which is to simulate Cython’s pure Python syntax under Python interpreter, cannot fully support all the things that Cython supported. The most obvious one is you cannot use positional argument to initialize a struct or union. For example, assume we declared a struct:
MyStruct = cython.struct(foo=cython.int, bar=cython.bint)
s1 = MyStruct(1, True) # this is valid Cython but cannot work in shadow mode s2 = MyStruct(foo=1, bar=True) # this works in both mode
This is due to when we calling cython.struct with keyword arguments, the passed in **kwds dict is not ordered.
The decorators that replaces the cdef syntax should works well now. In addition to use them as decorator, I also make them able to be used in with statement, it would be useful when you are going to define several cdef function in a batch:
with cython.cfunc: def foo(): ... def bar(x): return x
There’s no extra work to make them working in ‘with’ statement, thanks to Cython’s flexible directive system. Though, I’m feeling a bit strange to treat these decorators as directive. :p
Leave a Comment
Be the first to comment!