當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。