def test_address(x): """ >>> test_address(39) 39 """ y = cython.address(x) return y[0]
def test_declare(n): """ >>> test_declare(100) (100, 100) >>> test_declare(100.5) (100, 100) """ x = cython.declare(cython.int) y = cython.declare(cython.int, n) if cython.compiled: cython.declare(xx=cython.int, yy=cython.long) i = cython.sizeof(xx) ptr = cython.declare(cython.p_int, cython.address(y)) return y, ptr[0]
def draw_text(self, x, y, text): self.dst.x = x self.dst.y = y for i, c in enumerate(text): if not 0 <= c < 256: logger.warn( f"Invalid character {c} in {bytes(text).decode('cp437')}" ) # This may error too... c = 0 self.src.y = 16 * c if self.dst.x > self.width - 8: logger.warn( f"Text overrun while printing {bytes(text).decode('cp437')}" ) break if cythonmode: sdl2.SDL_RenderCopy(self._sdlrenderer, self.font_texture, address(self.src), address(self.dst)) else: exec( "sdl2.SDL_RenderCopy(self._sdlrenderer, self.font_texture, self.src, self.dst)", globals(), locals()) self.dst.x += 8
def test_declare(n): """ >>> test_declare(100) (100, 100) >>> test_declare(100.5) (100, 100) >>> test_declare(None) #doctest: +ELLIPSIS Traceback (most recent call last): ... TypeError: ... """ x = cython.declare(cython.int) y = cython.declare(cython.int, n) if cython.compiled: cython.declare(xx=cython.int, yy=cython.long) i = cython.sizeof(xx) ptr = cython.declare(cython.p_int, cython.address(y)) return y, ptr[0]
# -*- coding: utf-8 -*- # @Author: lcl1026504480 # @Date: 2019-08-29 17:11:37 # @Last Modified by: lcl1026504480 # @Last Modified time: 2019-08-29 17:17:06 import cython cython.declare(x=cython.int, x_ptr=cython.p_int) x = 5 x_ptr = cython.address(x) cython.declare(n=cython.longlong) print(cython.sizeof(cython.longlong)) n = 400 print(cython.sizeof(n)) MyStruct = cython.struct(x=cython.int, y=cython.int, data=cython.double) a = cython.declare(MyStruct) T = cython.typedef(cython.p_int) # ctypedef int* T # t1 = cython.cast(T, t) # t2 = cython.cast(T, t, typecheck=True)
def test_typed_return(): """ >>> test_typed_return() """ x = cython.declare(int, 5) assert typed_return(cython.address(x))[0] is x