本文整理汇总了Python中ctypes._SimpleCData方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes._SimpleCData方法的具体用法?Python ctypes._SimpleCData怎么用?Python ctypes._SimpleCData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes._SimpleCData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: synchronized
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _SimpleCData [as 别名]
def synchronized(obj, lock=None):
assert not isinstance(obj, SynchronizedBase), 'object already synchronized'
if isinstance(obj, ctypes._SimpleCData):
return Synchronized(obj, lock)
elif isinstance(obj, ctypes.Array):
if obj._type_ is ctypes.c_char:
return SynchronizedString(obj, lock)
return SynchronizedArray(obj, lock)
else:
cls = type(obj)
try:
scls = class_cache[cls]
except KeyError:
names = [field[0] for field in cls._fields_]
d = dict((name, make_property(name)) for name in names)
classname = 'Synchronized' + cls.__name__
scls = class_cache[cls] = type(classname, (SynchronizedBase,), d)
return scls(obj, lock)
#
# Functions for pickling/unpickling
#
示例2: synchronized
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _SimpleCData [as 别名]
def synchronized(obj, lock=None, ctx=None):
assert not isinstance(obj, SynchronizedBase), 'object already synchronized'
ctx = ctx or get_context()
if isinstance(obj, ctypes._SimpleCData):
return Synchronized(obj, lock, ctx)
elif isinstance(obj, ctypes.Array):
if obj._type_ is ctypes.c_char:
return SynchronizedString(obj, lock, ctx)
return SynchronizedArray(obj, lock, ctx)
else:
cls = type(obj)
try:
scls = class_cache[cls]
except KeyError:
names = [field[0] for field in cls._fields_]
d = dict((name, make_property(name)) for name in names)
classname = 'Synchronized' + cls.__name__
scls = class_cache[cls] = type(classname, (SynchronizedBase,), d)
return scls(obj, lock, ctx)
#
# Functions for pickling/unpickling
#
示例3: synchronized
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _SimpleCData [as 别名]
def synchronized(obj, lock=None, ctx=None):
assert not isinstance(obj, SynchronizedBase), 'object already synchronized'
ctx = ctx or get_context()
if isinstance(obj, ctypes._SimpleCData):
return Synchronized(obj, lock, ctx)
elif isinstance(obj, ctypes.Array):
if obj._type_ is ctypes.c_char:
return SynchronizedString(obj, lock, ctx)
return SynchronizedArray(obj, lock, ctx)
else:
cls = type(obj)
try:
scls = class_cache[cls]
except KeyError:
names = [field[0] for field in cls._fields_]
d = {name: make_property(name) for name in names}
classname = 'Synchronized' + cls.__name__
scls = class_cache[cls] = type(classname, (SynchronizedBase,), d)
return scls(obj, lock, ctx)
#
# Functions for pickling/unpickling
#
示例4: enumerate_winstructs
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _SimpleCData [as 别名]
def enumerate_winstructs(self):
for obj in vars(windows.generated_def.winstructs):
instance = eval("windows.generated_def.winstructs." + obj)
if hasattr(instance, '__bases__'):
if instance.__bases__[0] is Structure or instance.__bases__[0] is Union or hasattr(instance, '_fields_'):
self.structures[obj] = {}
self.structures[obj]['type'] = instance.__bases__[0].__name__
self.structures[obj]['fields'] = self.get_fields(instance)
elif instance.__bases__[0] is windows.generated_def.winstructs.EnumType:
self.enums[obj] = {}
enum_values = []
for value in instance.values:
enum_values.append({'name': value.name, 'real': value.real})
self.enums[obj]['values'] = enum_values
elif instance.__bases__[0] is _Pointer:
self.pointers[obj] = {}
self.pointers[obj]['type_name'] = instance._type_.__name__
elif instance.__bases__[0] is _SimpleCData:
continue
elif instance.__bases__[0] is CDLL:
continue
elif instance.__bases__[0] is object:
continue
elif instance.__bases__[0] is dict:
continue
elif instance.__bases__[0] is c_ulong:
continue
elif instance.__bases__[0] is Exception:
continue
else:
if self.debug_level > 0:
self.dump_object(obj, instance)
示例5: test_itemsize
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _SimpleCData [as 别名]
def test_itemsize(self):
for size in [1, 2, 4, 8]:
a = Array((1,), 'i', size)
ct = a._ctype
self.assertTrue(issubclass(ct, ctypes._SimpleCData))
self.assertEqual(sizeof(ct), size)