当前位置: 首页>>代码示例>>Python>>正文


Python FFI.typeof方法代码示例

本文整理汇总了Python中ffi.FFI.typeof方法的典型用法代码示例。如果您正苦于以下问题:Python FFI.typeof方法的具体用法?Python FFI.typeof怎么用?Python FFI.typeof使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ffi.FFI的用法示例。


在下文中一共展示了FFI.typeof方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_function_has_a_c_type

# 需要导入模块: from ffi import FFI [as 别名]
# 或者: from ffi.FFI import typeof [as 别名]
 def test_function_has_a_c_type(self):
     ffi = FFI(backend=self.Backend())
     ffi.cdef("""
         int puts(const char *);
     """)
     fptr = ffi.C.puts
     assert ffi.typeof(fptr) == ffi.typeof("int(*)(const char*)")
     if self.Backend is CTypesBackend:
         assert repr(fptr) == "<cdata 'int puts(char *)'>"
开发者ID:AN2016,项目名称:ffi,代码行数:11,代码来源:test_function.py

示例2: test_typedef_more_complex

# 需要导入模块: from ffi import FFI [as 别名]
# 或者: from ffi.FFI import typeof [as 别名]
def test_typedef_more_complex():
    ffi = FFI(backend=FakeBackend())
    ffi.cdef("""
        typedef struct { int a, b; } foo_t, *foo_p;
        int foo(foo_p[]);
        """)
    assert str(ffi.typeof("foo_t")) == '<int>a, <int>b'
    assert ffi.typeof("foo_p") == '<pointer to <int>a, <int>b>'
    assert ffi.C.foo.BType == ('<func (<pointer to <pointer to '
                               '<int>a, <int>b>>), <int>, False>')
开发者ID:AN2016,项目名称:ffi,代码行数:12,代码来源:test_parsing.py

示例3: test_char_cast

# 需要导入模块: from ffi import FFI [as 别名]
# 或者: from ffi.FFI import typeof [as 别名]
 def test_char_cast(self):
     ffi = FFI(backend=self.Backend())
     p = ffi.cast("int", '\x01')
     assert ffi.typeof(p) is ffi.typeof("int")
     assert int(p) == 1
     p = ffi.cast("int", ffi.cast("char", "a"))
     assert int(p) == ord("a")
     p = ffi.cast("int", ffi.cast("char", "\x80"))
     assert int(p) == 0x80     # "char" is considered unsigned in this case
     p = ffi.cast("int", "\x81")
     assert int(p) == 0x81
开发者ID:AN2016,项目名称:ffi,代码行数:13,代码来源:backend_tests.py

示例4: test_typedef

# 需要导入模块: from ffi import FFI [as 别名]
# 或者: from ffi.FFI import typeof [as 别名]
def test_typedef():
    ffi = FFI(backend=FakeBackend())
    ffi.cdef("""
        typedef unsigned int UInt;
        typedef UInt UIntReally;
        UInt foo(void);
        """)
    assert ffi.typeof("UIntReally") == '<unsigned int>'
    assert ffi.C.foo.BType == '<func (), <unsigned int>, False>'
开发者ID:AN2016,项目名称:ffi,代码行数:11,代码来源:test_parsing.py

示例5: test_functionptr_simple

# 需要导入模块: from ffi import FFI [as 别名]
# 或者: from ffi.FFI import typeof [as 别名]
 def test_functionptr_simple(self):
     ffi = FFI(backend=self.Backend())
     py.test.raises(TypeError, ffi.callback, "int(*)(int)")
     py.test.raises(TypeError, ffi.callback, "int(*)(int)", 0)
     def cb(n):
         return n + 1
     p = ffi.callback("int(*)(int)", cb)
     res = p(41)     # calling an 'int(*)(int)', i.e. a function pointer
     assert res == 42 and type(res) is int
     res = p(ffi.cast("int", -41))
     assert res == -40 and type(res) is int
     assert repr(p).startswith(
         "<cdata 'int(*)(int)' calling <function cb at 0x")
     assert ffi.typeof(p) is ffi.typeof("int(*)(int)")
     q = ffi.new("int(*)(int)", p)
     assert repr(q) == "<cdata 'int(* *)(int)' owning %d bytes>" % (
         SIZE_OF_PTR)
     py.test.raises(TypeError, "q(43)")
     res = q[0](43)
     assert res == 44
     q = ffi.cast("int(*)(int)", p)
     assert repr(q) == "<cdata 'int(*)(int)'>"
     res = q(45)
     assert res == 46
开发者ID:AN2016,项目名称:ffi,代码行数:26,代码来源:backend_tests.py

示例6: test_functionptr_advanced

# 需要导入模块: from ffi import FFI [as 别名]
# 或者: from ffi.FFI import typeof [as 别名]
 def test_functionptr_advanced(self):
     ffi = FFI(backend=self.Backend())
     t = ffi.typeof("int(*(*)(int))(int)")
     assert repr(t) == self.TypeRepr % "int(*(*)(int))(int)"
开发者ID:AN2016,项目名称:ffi,代码行数:6,代码来源:backend_tests.py

示例7: test_repr

# 需要导入模块: from ffi import FFI [as 别名]
# 或者: from ffi.FFI import typeof [as 别名]
 def test_repr(self):
     typerepr = self.TypeRepr
     ffi = FFI(backend=self.Backend())
     ffi.cdef("struct foo { short a, b, c; };")
     p = ffi.cast("unsigned short int", 0)
     assert repr(p) == "<cdata 'unsigned short'>"
     assert repr(ffi.typeof(p)) == typerepr % "unsigned short"
     p = ffi.cast("int*", 0)
     assert repr(p) == "<cdata 'int *'>"
     assert repr(ffi.typeof(p)) == typerepr % "int *"
     #
     p = ffi.new("int")
     assert repr(p) == "<cdata 'int *' owning %d bytes>" % SIZE_OF_INT
     assert repr(ffi.typeof(p)) == typerepr % "int *"
     p = ffi.new("int*")
     assert repr(p) == "<cdata 'int * *' owning %d bytes>" % SIZE_OF_PTR
     assert repr(ffi.typeof(p)) == typerepr % "int * *"
     p = ffi.new("int [2]")
     assert repr(p) == "<cdata 'int[2]' owning %d bytes>" % (2*SIZE_OF_INT)
     assert repr(ffi.typeof(p)) == typerepr % "int[2]"
     p = ffi.new("int*[2][3]")
     assert repr(p) == "<cdata 'int *[2][3]' owning %d bytes>" % (
         6*SIZE_OF_PTR)
     assert repr(ffi.typeof(p)) == typerepr % "int *[2][3]"
     p = ffi.new("struct foo")
     assert repr(p) == "<cdata 'struct foo *' owning %d bytes>" % (
         3*SIZE_OF_SHORT)
     assert repr(ffi.typeof(p)) == typerepr % "struct foo *"
     #
     q = ffi.cast("short", -123)
     assert repr(q) == "<cdata 'short'>"
     assert repr(ffi.typeof(q)) == typerepr % "short"
     p = ffi.new("int")
     q = ffi.cast("short*", p)
     assert repr(q) == "<cdata 'short *'>"
     assert repr(ffi.typeof(q)) == typerepr % "short *"
     p = ffi.new("int [2]")
     q = ffi.cast("int*", p)
     assert repr(q) == "<cdata 'int *'>"
     assert repr(ffi.typeof(q)) == typerepr % "int *"
     p = ffi.new("struct foo")
     q = ffi.cast("struct foo *", p)
     assert repr(q) == "<cdata 'struct foo *'>"
     assert repr(ffi.typeof(q)) == typerepr % "struct foo *"
     q = q[0]
     assert repr(q) == "<cdata 'struct foo'>"
     assert repr(ffi.typeof(q)) == typerepr % "struct foo"
开发者ID:AN2016,项目名称:ffi,代码行数:49,代码来源:backend_tests.py

示例8: test_typeof

# 需要导入模块: from ffi import FFI [as 别名]
# 或者: from ffi.FFI import typeof [as 别名]
def test_typeof():
    ffi = FFI(backend=FakeBackend())
    clong = ffi.typeof("signed long int")
    assert isinstance(clong, FakePrimitiveType)
    assert clong.cdecl == 'long'
开发者ID:AN2016,项目名称:ffi,代码行数:7,代码来源:test_cdata.py


注:本文中的ffi.FFI.typeof方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。