本文整理汇总了Python中ctypes.pointer方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.pointer方法的具体用法?Python ctypes.pointer怎么用?Python ctypes.pointer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.pointer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QueryInterface
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def QueryInterface(self, riid):
prototype = ctypes.WINFUNCTYPE(HRESULT,
ctypes.POINTER(winapi.GUID),
ctypes.POINTER(wintypes.LPVOID))
paramflags = ((_In_, 'riid'),
(_Out_, 'ppvObject', ctypes.pointer(wintypes.LPVOID(None)))
)
_QueryInterface = prototype(IUnknown_QueryInterface_Idx,
'QueryInterface',
paramflags)
_QueryInterface.errcheck = winapi.RAISE_NON_ZERO_ERR
return_ptr = _QueryInterface(self.this,
ctypes.byref(riid))
return IUnknown(return_ptr.contents)
示例2: SafeArrayAccessData
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def SafeArrayAccessData(sa):
prototype = ctypes.WINFUNCTYPE(
HRESULT,
ctypes.POINTER(SAFEARRAY),
ctypes.POINTER(wintypes.LPVOID)
)
paramflags = (
(_In_, 'psa'),
(_Out_, 'ppvData', ctypes.pointer(wintypes.LPVOID(None))),
)
_SafeArrayAccessData = prototype(('SafeArrayAccessData', oleaut32), paramflags)
_SafeArrayAccessData.errcheck = RAISE_NON_ZERO_ERR
return_obj = _SafeArrayAccessData(sa)
return return_obj.contents
示例3: attach_grad
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def attach_grad(self, grad_req='write', stype=None):
"""Attach a gradient buffer to this NDArray, so that `backward`
can compute gradient with respect to it.
Parameters
----------
grad_req : {'write', 'add', 'null'}
How gradient will be accumulated.
- 'write': gradient will be overwritten on every backward.
- 'add': gradient will be added to existing value on every backward.
- 'null': do not compute gradient for this NDArray.
stype : str, optional
The storage type of the gradient array. Defaults to the same stype of this NDArray.
"""
from . import zeros as _zeros
if stype is not None:
grad = _zeros(self.shape, stype=stype)
else:
grad = op.zeros_like(self) # pylint: disable=undefined-variable
grad_req = _GRAD_REQ_MAP[grad_req]
check_call(_LIB.MXAutogradMarkVariables(
1, ctypes.pointer(self.handle),
ctypes.pointer(mx_uint(grad_req)),
ctypes.pointer(grad.handle)))
示例4: to_dlpack_for_read
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def to_dlpack_for_read(self):
"""Returns a reference view of NDArray that represents as DLManagedTensor until
all previous write operations on the current array are finished.
Returns
-------
PyCapsule (the pointer of DLManagedTensor)
a reference view of NDArray that represents as DLManagedTensor.
Examples
--------
>>> x = mx.nd.ones((2,3))
>>> y = mx.nd.to_dlpack_for_read(x)
>>> type(y)
<class 'PyCapsule'>
>>> z = mx.nd.from_dlpack(y)
>>> z
[[1. 1. 1.]
[1. 1. 1.]]
<NDArray 2x3 @cpu(0)>
"""
return to_dlpack_for_read(self)
示例5: to_dlpack_for_write
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def to_dlpack_for_write(self):
"""Returns a reference view of NDArray that represents as DLManagedTensor until
all previous read/write operations on the current array are finished.
Returns
-------
PyCapsule (the pointer of DLManagedTensor)
a reference view of NDArray that represents as DLManagedTensor.
Examples
--------
>>> x = mx.nd.ones((2,3))
>>> w = mx.nd.to_dlpack_for_write(x)
>>> type(w)
<class 'PyCapsule'>
>>> u = mx.nd.from_dlpack(w)
>>> u += 1
>>> x
[[2. 2. 2.]
[2. 2. 2.]]
<NDArray 2x3 @cpu(0)>
"""
return to_dlpack_for_write(self)
示例6: new
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def new(library, type_, value=None):
is_pointer, is_array, type_ = _type_info(library, type_)
if is_array:
if is_array is True:
type_ = type_ * value
value = None
else:
type_ = type_ * is_array
params = []
if value is not None:
params.append(value)
output = type_(*params)
if is_pointer:
output = pointer(output)
return output
示例7: _add_fd_to_loop
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def _add_fd_to_loop(self, fd, cb, fd_events, userdata=None):
if cb is None:
self.logger.info(
"Cannot add fd '{}' to pomp loop without "
"a valid callback function".format(fd)
)
return None
self.fd_userdata[fd] = userdata
userdata = ctypes.cast(
ctypes.pointer(ctypes.py_object(userdata)), ctypes.c_void_p
)
self.c_fd_userdata[fd] = userdata
self.pomp_fd_callbacks[fd] = od.pomp_fd_event_cb_t(cb)
res = od.pomp_loop_add(
self.pomp_loop,
ctypes.c_int32(fd),
od.uint32_t(int(fd_events)),
self.pomp_fd_callbacks[fd],
userdata
)
if res != 0:
raise RuntimeError(
"Cannot add fd '{}' to pomp loop: {} ({})".format(
fd, os.strerror(-res), res)
)
示例8: get_session_metadata
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def get_session_metadata(self):
"""
Returns a dictionary of video stream session metadata
"""
if self.pdraw is None:
self.logger.error("Error Pdraw interface seems to be destroyed")
return None
if self.session_metadata:
return self.session_metadata
vmeta_session = od.struct_vmeta_session()
res = od.pdraw_get_peer_session_metadata(
self.pdraw, ctypes.pointer(vmeta_session))
if res != 0:
msg = "Unable to get sessions metata"
self.logger.error(msg)
return None
self.session_metadata = od.struct_vmeta_session.as_dict(
vmeta_session)
return self.session_metadata
示例9: from_arsdk_device
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def from_arsdk_device(cls, backend, device):
device_info = ctypes.POINTER(od.struct_arsdk_device_info)()
res = od.arsdk_device_get_info(device, ctypes.pointer(device_info))
if res != 0:
raise RuntimeError("ERROR: failed to get device info: {}".format(res))
return Device(
serial=od.string_cast(device_info.contents.id) or "",
name=od.string_cast(device_info.contents.name) or "",
device_type=int(device_info.contents.type),
ip_addr=od.string_cast(device_info.contents.addr) or "",
port=int(device_info.contents.port),
proto_v=int(getattr(device_info.contents, "proto_v", 1)),
state=DeviceState(device_info.contents.state),
json=od.string_cast(device_info.contents.json) or "",
arsdk_device=device,
backend=backend,
)
示例10: _create_discovery
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def _create_discovery(self):
"""
Start net discovery in order to detect devices
"""
discovery = od.POINTER_T(od.struct_arsdk_discovery_net)()
res = od.arsdk_discovery_net_new(
self._backend._arsdk_ctrl,
self._backend._backend_net,
ctypes.pointer(self.discovery_cfg),
od.char_pointer_cast(self.ip_addr),
ctypes.byref(discovery),
)
if res != 0:
self.logger.error("arsdk_discovery_net_new: {}".format(res))
return None
return discovery
示例11: _create_command_interface
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def _create_command_interface(self):
"""
Create a command interface to send command to the device
"""
cmd_itf = od.POINTER_T(od.struct_arsdk_cmd_itf)()
res = od.arsdk_device_create_cmd_itf(
self._device.arsdk_device,
self._cmd_itf_cbs,
ctypes.pointer(cmd_itf))
if res != 0:
self.logger.error(
"Error while creating command interface: {}".format(res))
cmd_itf = None
else:
self.logger.info("Command interface has been created: itf=%s"
% self._cmd_itf)
return cmd_itf
示例12: _createShader
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def _createShader(self, strings, shadertype):
# create the shader handle
shader = gl.glCreateShader(shadertype)
# convert the source strings into a ctypes pointer-to-char array, and upload them
# this is deep, dark, dangerous black magick - don't try stuff like this at home!
strings = tuple(s.encode('ascii') for s in strings) # Nick added, for python3
src = (c_char_p * len(strings))(*strings)
gl.glShaderSource(shader, len(strings), cast(pointer(src), POINTER(POINTER(c_char))), None)
# compile the shader
gl.glCompileShader(shader)
# retrieve the compile status
compile_success = c_int(0)
gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS, byref(compile_success))
# if compilation failed, print the log
if compile_success:
gl.glAttachShader(self.id, shader)
else:
gl.glGetShaderiv(shader, gl.GL_INFO_LOG_LENGTH, byref(compile_success)) # retrieve the log length
buffer = create_string_buffer(compile_success.value) # create a buffer for the log
gl.glGetShaderInfoLog(shader, compile_success, None, buffer) # retrieve the log text
print(buffer.value) # print the log to the console
示例13: make_i2c_rdwr_data
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def make_i2c_rdwr_data(messages):
"""Utility function to create and return an i2c_rdwr_ioctl_data structure
populated with a list of specified I2C messages. The messages parameter
should be a list of tuples which represent the individual I2C messages to
send in this transaction. Tuples should contain 4 elements: address value,
flags value, buffer length, ctypes c_uint8 pointer to buffer.
"""
# Create message array and populate with provided data.
msg_data_type = i2c_msg * len(messages)
msg_data = msg_data_type()
for i, message in enumerate(messages):
msg_data[i].addr = message[0] & 0x7F
msg_data[i].flags = message[1]
msg_data[i].len = message[2]
msg_data[i].buf = message[3]
# Now build the data structure.
data = i2c_rdwr_ioctl_data()
data.msgs = msg_data
data.nmsgs = len(messages)
return data
# Create an interface that mimics the Python SMBus API.
示例14: read_byte_data
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def read_byte_data(self, addr, cmd):
"""Read a single byte from the specified cmd register of the device."""
assert (
self._device is not None
), "Bus must be opened before operations are made against it!"
# Build ctypes values to marshall between ioctl and Python.
reg = c_uint8(cmd)
result = c_uint8()
# Build ioctl request.
request = make_i2c_rdwr_data(
[
(addr, 0, 1, pointer(reg)), # Write cmd register.
(addr, I2C_M_RD, 1, pointer(result)), # Read 1 byte as result.
]
)
# Make ioctl call and return result data.
ioctl(self._device.fileno(), I2C_RDWR, request)
return result.value
示例15: test_reference_cycles
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import pointer [as 别名]
def test_reference_cycles(self):
# related to gh-6511
import ctypes
# create array to work with
# don't use int/long to avoid running into bpo-10746
N = 100
a = np.arange(N, dtype=np.short)
# get pointer to array
pnt = np.ctypeslib.as_ctypes(a)
with np.testing.assert_no_gc_cycles():
# decay the array above to a pointer to its first element
newpnt = ctypes.cast(pnt, ctypes.POINTER(ctypes.c_short))
# and construct an array using this data
b = np.ctypeslib.as_array(newpnt, (N,))
# now delete both, which should cleanup both objects
del newpnt, b