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


Python ctypes.memmove方法代码示例

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


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

示例1: ctypes2buffer

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def ctypes2buffer(cptr, length):
    """Convert ctypes pointer to buffer type.

    Parameters
    ----------
    cptr : ctypes.POINTER(ctypes.c_char)
        Pointer to the raw memory region.
    length : int
        The length of the buffer.

    Returns
    -------
    buffer : bytearray
        The raw byte memory buffer.
    """
    if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)):
        raise TypeError('expected char pointer')
    res = bytearray(length)
    rptr = (ctypes.c_char * length).from_buffer(res)
    if not ctypes.memmove(rptr, cptr, length):
        raise RuntimeError('memmove failed')
    return res 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:24,代码来源:base.py

示例2: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def __init__(self, event_property, event_filters):
        """
        Initializes an ENABLE_TRACE_PARAMETERS structure.

        :param event_property: Property to enable.
                         See https://msdn.microsoft.com/en-us/library/windows/desktop/dd392306(v=vs.85).aspx
        :param event_filters: List of EVENT_FILTER_DESCRIPTOR structures
        """

        self._props = ct.pointer(et.ENABLE_TRACE_PARAMETERS())

        filter_buf_size = ct.sizeof(ep.EVENT_FILTER_DESCRIPTOR) * len(event_filters)
        # noinspection PyCallingNonCallable
        filter_buf = (ct.c_char * filter_buf_size)()
        # copy contents to buffer
        for i in range(len(event_filters)):
            ct.memmove(ct.cast(ct.addressof(filter_buf) + (ct.sizeof(ep.EVENT_FILTER_DESCRIPTOR) * i), ct.c_void_p),
                       ct.byref(event_filters[i]),
                       ct.sizeof(ep.EVENT_FILTER_DESCRIPTOR))

        self._props.contents.Version = et.ENABLE_TRACE_PARAMETERS_VERSION_2
        self._props.contents.EnableProperty = event_property
        self._props.contents.ControlFlags = 0
        self._props.contents.EnableFilterDesc = ct.cast(ct.pointer(filter_buf), ct.POINTER(ep.EVENT_FILTER_DESCRIPTOR))
        self._props.contents.FilterDescCount = len(event_filters) 
开发者ID:fireeye,项目名称:pywintrace,代码行数:27,代码来源:etw.py

示例3: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def __init__(self, match_any, match_all, level, filter_in, names):
        struct_size = ((sum([len(name) for name in names]) * ct.sizeof(wt.CHAR)) + (ct.sizeof(wt.CHAR) * len(names))) +\
                      ct.sizeof(EVENT_FILTER_EVENT_NAME)
        self._buf = (ct.c_char * struct_size)()
        self._props = ct.cast(ct.pointer(self._buf), ct.POINTER(EVENT_FILTER_EVENT_NAME))
        self._props.contents.MatchAnyKeyword = match_any
        self._props.contents.MatchAllKeyword = match_all
        self._props.contents.Level = level
        self._props.contents.FilterIn = filter_in
        self._props.contents.NameCount = len(names)

        str_off = 0
        for i in range(len(names)):
            ct.memmove(ct.cast(ct.addressof(self._buf) + ct.sizeof(EVENT_FILTER_EVENT_NAME) + str_off,
                               ct.c_void_p),
                       names[i],
                       len(names[i]))
            str_off += len(names[i]) + ct.sizeof(wt.CHAR) 
开发者ID:fireeye,项目名称:pywintrace,代码行数:20,代码来源:evntprov.py

示例4: ctypes2buffer

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def ctypes2buffer(cptr, length):
    """Convert ctypes pointer to buffer type.

    Parameters
    ----------
    cptr : ctypes.POINTER(ctypes.c_char)
        pointer to the raw memory region
    length : int
        the length of the buffer

    Returns
    -------
    buffer : bytearray
        The raw byte memory buffer
    """
    if not isinstance(cptr, ctypes.POINTER(ctypes.c_char)):
        raise TypeError('expected char pointer')
    res = bytearray(length)
    rptr = (ctypes.c_char * length).from_buffer(res)
    if not ctypes.memmove(rptr, cptr, length):
        raise RuntimeError('memmove failed')
    return res 
开发者ID:mlperf,项目名称:training_results_v0.6,代码行数:24,代码来源:_base.py

示例5: test_jlink_compatible_firmware_version

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def test_jlink_compatible_firmware_version(self):
        """Tests that getting a compatible firmware version from the DLL.

        Args:
          self (TestJLink): the ``TestJLink`` instance

        Returns:
          ``None``
        """
        firmware = 'J-Trace Cortex-M Rev.3 compiled Mar 30 2015 13:52:25'

        def set_firmware_string(buf, buf_size):
            ctypes.memmove(buf, firmware.encode(), len(firmware))

        self.dll.JLINKARM_GetFirmwareString = set_firmware_string

        self.dll.JLINKARM_GetEmbeddedFWString.return_value = -1
        with self.assertRaises(JLinkException):
            self.jlink.compatible_firmware_version

        self.dll.JLINKARM_GetEmbeddedFWString.return_value = 0
        self.dll.JLINKARM_GetEmbeddedFWString.assert_called()
        self.assertEqual('', self.jlink.compatible_firmware_version) 
开发者ID:square,项目名称:pylink,代码行数:25,代码来源:test_jlink.py

示例6: test_jlink_features_has_features

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def test_jlink_features_has_features(self):
        """Tests the J-Link ``features`` property returns a feature list.

        Args:
          self (TestJLink): the ``TestJLink`` instance

        Returns:
          ``None``
        """
        feature_string = 'RDI, JFlash, FlashDL'

        def func(b):
            ctypes.memmove(b, feature_string.encode(), len(feature_string))

        self.dll.JLINKARM_GetFeatureString = func

        result = self.jlink.features

        self.assertTrue(isinstance(result, list))
        self.assertEqual(3, len(result))
        self.assertEqual('RDI', result[0])
        self.assertEqual('JFlash', result[1])
        self.assertEqual('FlashDL', result[2]) 
开发者ID:square,项目名称:pylink,代码行数:25,代码来源:test_jlink.py

示例7: consume

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def consume(self, bytes, audio_format):
        '''Remove some data from beginning of packet.'''
        if bytes == self.length:
            self.data = None
            self.length = 0
            self.timestamp += self.duration
            self.duration = 0.
            return
        elif bytes == 0:
            return

        if not isinstance(self.data, str):
            # XXX Create a string buffer for the whole packet then
            #     chop it up.  Could do some pointer arith here and
            #     save a bit of data pushing, but my guess is this is
            #     faster than fudging aruond with ctypes (and easier).
            data = ctypes.create_string_buffer(self.length)
            ctypes.memmove(data, self.data, self.length)
            self.data = data
        self.data = self.data[bytes:]
        self.length -= bytes
        self.duration -= bytes / float(audio_format.bytes_per_second)
        self.timestamp += bytes / float(audio_format.bytes_per_second) 
开发者ID:shrimpboyho,项目名称:flappy-bird-py,代码行数:25,代码来源:__init__.py

示例8: __capture

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def __capture(self, data, _sdr):
        timestamp = time.time()
        dst = ctypes.byref(self._capture, 0)
        ctypes.memmove(dst, data, len(data))

        iq = self.__stream_to_complex(self._capture)
        l, f = psd(iq, BINS, SAMPLE_RATE,
                   scale_by_freq=False,
                   noverlap=-SAMPLES / 64)
        f /= 1e6
        f += self._freq

        event = Event(Events.SCAN_DATA, timestamp=timestamp, l=l, f=f)
        post_event(self._eventHandler, event) 
开发者ID:EarToEarOak,项目名称:RF-Monitor,代码行数:16,代码来源:receive.py

示例9: read_struct

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def read_struct(li, struct):
    s = struct()
    slen = ctypes.sizeof(s)
    #DEBUG_PRINT("slen:%d" % slen)
    bytes = li.read(slen)
    fit = min(len(bytes), slen)
    ctypes.memmove(ctypes.addressof(s), bytes, fit)
    return s

# ----------------------------------------------------------------------- 
开发者ID:feicong,项目名称:lua_re,代码行数:12,代码来源:luac_loader.py

示例10: write_to_buffer

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def write_to_buffer(buffer, data, offset=0):
        if isinstance(buffer, ctypes.POINTER(ctypes.c_byte)):
            ctypes.memmove(buffer, data, len(data))
            return

        if offset == 0:
            buffer.value = data
        else:
            buffer.value = buffer.raw[0:offset] + data 
开发者ID:wbond,项目名称:oscrypto,代码行数:11,代码来源:_ffi.py

示例11: struct_from_buffer

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def struct_from_buffer(library, type_, buffer):
        class_ = getattr(library, type_)
        value = class_()
        ctypes.memmove(ctypes.addressof(value), buffer, ctypes.sizeof(class_))
        return ctypes.pointer(value) 
开发者ID:wbond,项目名称:oscrypto,代码行数:7,代码来源:_ffi.py

示例12: paste

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def paste(s):
    if not isinstance(s, unicode_type):
        s = s.decode('mbcs')
    data = s.encode('utf-16le')
    OpenClipboard(None)
    EmptyClipboard()
    handle = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, len(data) + 2)
    pcontents = GlobalLock(handle)
    ctypes.memmove(pcontents, data, len(data))
    GlobalUnlock(handle)
    SetClipboardData(CF_UNICODETEXT, handle)
    CloseClipboard() 
开发者ID:FSecureLABS,项目名称:win_driver_plugin,代码行数:14,代码来源:create_tab_table.py

示例13: set_geom_rgba

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def set_geom_rgba(model, value):
    """Does what model.geom_rgba = ... should do, but doesn't because of a bug in mujoco-py."""
    val_ptr = np.array(value, dtype=np.float32).ctypes.data_as(ctypes.POINTER(ctypes.c_float))
    ctypes.memmove(
        model._wrapped.contents.geom_rgba, val_ptr, model.ngeom * 4 * ctypes.sizeof(ctypes.c_float)
    ) 
开发者ID:HumanCompatibleAI,项目名称:adversarial-policies,代码行数:8,代码来源:annotated_gym_compete.py

示例14: _set_argv

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def _set_argv(process_name: str) -> None:
  """
  Overwrites our argv in a similar fashion to how it's done in C with:
  strcpy(argv[0], 'new_name');
  """

  if Py_GetArgcArgv is None:
    return

  global _PROCESS_NAME

  # both gets the current process name and initializes _MAX_NAME_LENGTH

  current_name = get_process_name()

  argv, argc = ctypes.c_int(0), argc_t()
  Py_GetArgcArgv(argv, ctypes.pointer(argc))

  if len(process_name) > _MAX_NAME_LENGTH:
    raise IOError("Can't rename process to something longer than our initial name (this would overwrite memory used for the env)")

  # space we need to clear
  zero_size = max(len(current_name), len(process_name))

  ctypes.memset(argc.contents, 0, zero_size + 1)  # null terminate the string's end
  process_name_encoded = process_name.encode('utf8')
  ctypes.memmove(argc.contents, process_name_encoded, len(process_name))
  _PROCESS_NAME = process_name 
开发者ID:torproject,项目名称:stem,代码行数:30,代码来源:system.py

示例15: _return_bytes

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memmove [as 别名]
def _return_bytes(x):
    """return handle"""
    handle = x.v_handle
    if not isinstance(handle, ctypes.c_void_p):
        handle = ctypes.c_void_p(handle)
    arr = ctypes.cast(handle, ctypes.POINTER(DGLByteArray))[0]
    size = arr.size
    res = bytearray(size)
    rptr = (ctypes.c_byte * size).from_buffer(res)
    if not ctypes.memmove(rptr, arr.data, size):
        raise RuntimeError('memmove failed')
    return res 
开发者ID:dmlc,项目名称:dgl,代码行数:14,代码来源:types.py


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