Python ctypes._Pointer() Examples
The following are 15
code examples of ctypes._Pointer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ctypes
, or try the search function
.
Example #1
Source File: ctypeslib.py From recruit with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: ctypeslib.py From lambda-packs with MIT License | 6 votes |
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)
Example #3
Source File: ctypeslib.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #4
Source File: ctypeslib.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)
Example #5
Source File: ctypeslib.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: ctypeslib.py From pySINDy with MIT License | 6 votes |
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)
Example #7
Source File: ctypeslib.py From coffeegrindsize with MIT License | 6 votes |
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)
Example #8
Source File: ctypeslib.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #9
Source File: ctypeslib.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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)
Example #10
Source File: ctypeslib.py From twitter-stock-recommendation with MIT License | 6 votes |
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)
Example #11
Source File: breakpoint.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
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)
Example #12
Source File: breakpoint.py From OpenXMolar with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #13
Source File: utils.py From devito with MIT License | 5 votes |
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__
Example #14
Source File: breakpoint.py From filmkodi with Apache License 2.0 | 5 votes |
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)
Example #15
Source File: enumerate_windef.py From windbgtool with MIT License | 5 votes |
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)