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


Python ctypes._Pointer方法代码示例

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


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

示例1: as_array

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _Pointer [as 别名]
def as_array(obj, shape=None):
        """
        Create a numpy array from a ctypes array or POINTER.

        The numpy array shares the memory with the ctypes object.

        The shape parameter must be given if converting from a ctypes POINTER.
        The shape parameter is ignored if converting from a ctypes array
        """
        if isinstance(obj, ctypes._Pointer):
            # convert pointers to an array of the desired shape
            if shape is None:
                raise TypeError(
                    'as_array() requires a shape argument when called on a '
                    'pointer')
            p_arr_type = ctypes.POINTER(_ctype_ndarray(obj._type_, shape))
            obj = ctypes.cast(obj, p_arr_type).contents

        return array(obj, copy=False) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:ctypeslib.py

示例2: _cast_signature_pointers_to_void

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _Pointer [as 别名]
def _cast_signature_pointers_to_void(self, signature):
        c_void_p  = ctypes.c_void_p
        c_char_p  = ctypes.c_char_p
        c_wchar_p = ctypes.c_wchar_p
        _Pointer  = ctypes._Pointer
        cast      = ctypes.cast
        for i in compat.xrange(len(signature)):
            t = signature[i]
            if t is not c_void_p and (issubclass(t, _Pointer) \
                                            or t in [c_char_p, c_wchar_p]):
                signature[i] = cast(t, c_void_p) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:13,代码来源:breakpoint.py

示例3: _cast_signature_pointers_to_void

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _Pointer [as 别名]
def _cast_signature_pointers_to_void(self, signature):
        c_void_p  = ctypes.c_void_p
        c_char_p  = ctypes.c_char_p
        c_wchar_p = ctypes.c_wchar_p
        _Pointer  = ctypes._Pointer
        cast      = ctypes.cast
        for i in xrange(len(signature)):
            t = signature[i]
            if t is not c_void_p and (issubclass(t, _Pointer) \
                                            or t in [c_char_p, c_wchar_p]):
                signature[i] = cast(t, c_void_p) 
开发者ID:debasishm89,项目名称:OpenXMolar,代码行数:13,代码来源:breakpoint.py

示例4: ctypes_to_cstr

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _Pointer [as 别名]
def ctypes_to_cstr(ctype, toarray=None):
    """Translate ctypes types into C strings."""
    if issubclass(ctype, ctypes.Structure):
        return 'struct %s' % ctype.__name__
    elif issubclass(ctype, ctypes.Union):
        return 'union %s' % ctype.__name__
    elif issubclass(ctype, ctypes._Pointer):
        if toarray:
            return ctypes_to_cstr(ctype._type_, '(* %s)' % toarray)
        else:
            return '%s *' % ctypes_to_cstr(ctype._type_)
    elif issubclass(ctype, ctypes.Array):
        return '%s[%d]' % (ctypes_to_cstr(ctype._type_, toarray), ctype._length_)
    elif ctype.__name__.startswith('c_'):
        # A primitive datatype
        # FIXME: Is there a better way of extracting the C typename ?
        # Here, we're following the ctypes convention that each basic type has
        # either the format c_X_p or c_X, where X is the C typename, for instance
        # `int` or `float`.
        if ctype.__name__.endswith('_p'):
            return '%s *' % ctype.__name__[2:-2]
        elif toarray:
            return '%s %s' % (ctype.__name__[2:], toarray)
        else:
            return ctype.__name__[2:]
    else:
        # A custom datatype (e.g., a typedef-ed pointer to struct)
        return ctype.__name__ 
开发者ID:devitocodes,项目名称:devito,代码行数:30,代码来源:utils.py

示例5: enumerate_winstructs

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import _Pointer [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) 
开发者ID:ohjeongwook,项目名称:windbgtool,代码行数:38,代码来源:enumerate_windef.py


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