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


Python c_bool._type_方法代码示例

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


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

示例1: valid_ranges

# 需要导入模块: from ctypes import c_bool [as 别名]
# 或者: from ctypes.c_bool import _type_ [as 别名]
def valid_ranges(*types):
    # given a sequence of numeric types, collect their _type_
    # attribute, which is a single format character compatible with
    # the struct module, use the struct module to calculate the
    # minimum and maximum value allowed for this format.
    # Returns a list of (min, max) values.
    result = []
    for t in types:
        fmt = t._type_
        size = struct.calcsize(fmt)
        a = struct.unpack(fmt, ("\x00"*32)[:size])[0]
        b = struct.unpack(fmt, ("\xFF"*32)[:size])[0]
        c = struct.unpack(fmt, ("\x7F"+"\x00"*32)[:size])[0]
        d = struct.unpack(fmt, ("\x80"+"\xFF"*32)[:size])[0]
        result.append((min(a, b, c, d), max(a, b, c, d)))
    return result 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_numbers.py

示例2: test_int_from_address

# 需要导入模块: from ctypes import c_bool [as 别名]
# 或者: from ctypes.c_bool import _type_ [as 别名]
def test_int_from_address(self):
        from array import array
        for t in signed_types + unsigned_types:
            # the array module doesn't support all format codes
            # (no 'q' or 'Q')
            try:
                array(t._type_)
            except ValueError:
                continue
            a = array(t._type_, [100])

            # v now is an integer at an 'external' memory location
            v = t.from_address(a.buffer_info()[0])
            self.assertEqual(v.value, a[0])
            self.assertEqual(type(v), t)

            # changing the value at the memory location changes v's value also
            a[0] = 42
            self.assertEqual(v.value, a[0]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_numbers.py

示例3: valid_ranges

# 需要导入模块: from ctypes import c_bool [as 别名]
# 或者: from ctypes.c_bool import _type_ [as 别名]
def valid_ranges(*types):
    # given a sequence of numeric types, collect their _type_
    # attribute, which is a single format character compatible with
    # the struct module, use the struct module to calculate the
    # minimum and maximum value allowed for this format.
    # Returns a list of (min, max) values.
    result = []
    for t in types:
        fmt = t._type_
        size = struct.calcsize(fmt)
        a = struct.unpack(fmt, (b"\x00"*32)[:size])[0]
        b = struct.unpack(fmt, (b"\xFF"*32)[:size])[0]
        c = struct.unpack(fmt, (b"\x7F"+b"\x00"*32)[:size])[0]
        d = struct.unpack(fmt, (b"\x80"+b"\xFF"*32)[:size])[0]
        result.append((min(a, b, c, d), max(a, b, c, d)))
    return result 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_numbers.py

示例4: test_sizes

# 需要导入模块: from ctypes import c_bool [as 别名]
# 或者: from ctypes.c_bool import _type_ [as 别名]
def test_sizes(self):
        for t in signed_types + unsigned_types + float_types + bool_types:
            try:
                size = struct.calcsize(t._type_)
            except struct.error:
                continue
            # sizeof of the type...
            self.assertEqual(sizeof(t), size)
            # and sizeof of an instance
            self.assertEqual(sizeof(t()), size) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_numbers.py

示例5: test_alignments

# 需要导入模块: from ctypes import c_bool [as 别名]
# 或者: from ctypes.c_bool import _type_ [as 别名]
def test_alignments(self):
        for t in signed_types + unsigned_types + float_types:
            code = t._type_ # the typecode
            align = struct.calcsize("c%c" % code) - struct.calcsize(code)

            # alignment of the type...
            self.assertEqual((code, alignment(t)),
                                 (code, align))
            # and alignment of an instance
            self.assertEqual((code, alignment(t())),
                                 (code, align)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_numbers.py

示例6: test_float_from_address

# 需要导入模块: from ctypes import c_bool [as 别名]
# 或者: from ctypes.c_bool import _type_ [as 别名]
def test_float_from_address(self):
        from array import array
        for t in float_types:
            a = array(t._type_, [3.14])
            v = t.from_address(a.buffer_info()[0])
            self.assertEqual(v.value, a[0])
            self.assertIs(type(v), t)
            a[0] = 2.3456e17
            self.assertEqual(v.value, a[0])
            self.assertIs(type(v), t) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_numbers.py


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