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


Python ctypes.memset方法代码示例

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


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

示例1: zerome

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def zerome(bufferObject):
    '''
    clear a string value from memory

    :param bufferObject: the string variable, which should be cleared
    :type  bufferObject: string or key buffer

    :return:    - nothing -
    '''
    data = ctypes.POINTER(ctypes.c_char)()
    size = ctypes.c_int()  # Note, int only valid for python 2.5
    ctypes.pythonapi.PyObject_AsCharBuffer(ctypes.py_object(bufferObject),
                                           ctypes.pointer(data),
                                           ctypes.pointer(size))
    ctypes.memset(data, 0, size.value)

    return 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:19,代码来源:crypto.py

示例2: add_dline

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def add_dline(buf: ctypes.Array, cell_width: int, position: int, thickness: int, cell_height: int) -> None:
    a = min(position - thickness, cell_height - 1)
    b = min(position, cell_height - 1)
    top, bottom = min(a, b), max(a, b)
    deficit = 2 - (bottom - top)
    if deficit > 0:
        if bottom + deficit < cell_height:
            bottom += deficit
        elif bottom < cell_height - 1:
            bottom += 1
            if deficit > 1:
                top -= deficit - 1
        else:
            top -= deficit
    top = max(0, min(top, cell_height - 1))
    bottom = max(0, min(bottom, cell_height - 1))
    for y in {top, bottom}:
        ctypes.memset(ctypes.addressof(buf) + (cell_width * y), 255, cell_width) 
开发者ID:kovidgoyal,项目名称:kitty,代码行数:20,代码来源:render.py

示例3: ioctl

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def ioctl(self, driver_handle: ctypes.c_void_p, ioctl_code: ctypes.c_ulong, input_bytes: ctypes.c_void_p, input_bytes_count: ctypes.c_size_t, output_bytes: ctypes.c_void_p, output_bytes_count: ctypes.c_size_t):
        """ Wrapper for DeviceIoControl """
        overlapped = self.libk.OVERLAPPED()
        ctypes.memset(ctypes.addressof(overlapped), 0, ctypes.sizeof(overlapped))

        ret = ctypes.windll.kernel32.DeviceIoControl(driver_handle, ioctl_code, input_bytes, input_bytes_count, output_bytes, output_bytes_count, None, ctypes.byref(overlapped))

        # We expect this to error, which matches the others ^_^
        if ret == False:
            raise ctypes.WinError() 
开发者ID:Qyriad,项目名称:fusee-launcher,代码行数:12,代码来源:fusee-launcher.py

示例4: fill

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def fill( rgn, length=None, offset=0, value=0 ):
        if value not in range(256):
            raise ValueError( "invalid fill value" )
        if length is None:
            length = rgn.mappable
        # map ctypes instance (does all necessary error checking)
        mem = (ubyte * length).from_buffer( rgn._mmap, offset )
        ctypes.memset( mem, value, length )

    # write data into region at given offset 
开发者ID:mvduin,项目名称:py-uio,代码行数:12,代码来源:device.py

示例5: _set_argv

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [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

示例6: memset

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def memset(self, allocation, value, size):
        """set the memory in allocation to the value in value

        :param allocation: An Argument for some memory allocation unit
        :type allocation: Argument

        :param value: The value to set the memory to
        :type value: a single 8-bit unsigned int

        :param size: The size of to the allocation unit in bytes
        :type size: int
        """
        C.memset(allocation.ctypes, value, size) 
开发者ID:benvanwerkhoven,项目名称:kernel_tuner,代码行数:15,代码来源:c.py

示例7: RawValue

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def RawValue(typecode_or_type, *args):
    '''
    Returns a ctypes object allocated from shared memory
    '''
    type_ = typecode_to_type.get(typecode_or_type, typecode_or_type)
    obj = _new_value(type_)
    ctypes.memset(ctypes.addressof(obj), 0, ctypes.sizeof(obj))
    obj.__init__(*args)
    return obj 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:sharedctypes.py

示例8: RawArray

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def RawArray(typecode_or_type, size_or_initializer):
    '''
    Returns a ctypes array allocated from shared memory
    '''
    type_ = typecode_to_type.get(typecode_or_type, typecode_or_type)
    if isinstance(size_or_initializer, (int, long)):
        type_ = type_ * size_or_initializer
        obj = _new_value(type_)
        ctypes.memset(ctypes.addressof(obj), 0, ctypes.sizeof(obj))
        return obj
    else:
        type_ = type_ * len(size_or_initializer)
        result = _new_value(type_)
        result.__init__(*size_or_initializer)
        return result 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:sharedctypes.py

示例9: _win32_load_kernel

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def _win32_load_kernel (self):
		if self.unix:
			return False
		import ctypes
		if not self.kernel32:
			self.kernel32 = ctypes.windll.LoadLibrary("kernel32.dll")
		if not self.textdata:
			self.textdata = ctypes.create_string_buffer('0' * 2048)
		ctypes.memset(self.textdata, 0, 2048)
		return True 
开发者ID:skywind3000,项目名称:terminal,代码行数:12,代码来源:terminal.py

示例10: segfault

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def segfault():
    """this will segfault"""
    import ctypes
    ctypes.memset(-1,0,1) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:clienttest.py

示例11: write

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def write(self, audio_data, length=None):
        # Pass audio_data=None, length>0 to write silence
        if length is None:
            write_size = self.get_write_size()
            length = min(audio_data.length, write_size)
        if length == 0:
            return 0

        if self._data_size < self._buffer_size:
            self._data_size = min(self._data_size + length, self._buffer_size)

        p1 = ctypes.c_void_p()
        l1 = lib.DWORD()
        p2 = ctypes.c_void_p()
        l2 = lib.DWORD()
        self._buffer.Lock(self._write_cursor, length,
            ctypes.byref(p1), l1, ctypes.byref(p2), l2, 0)
        assert length == l1.value + l2.value

        if audio_data:
            if self._write_cursor >= self._play_cursor:
                wc = self._write_cursor
            else:
                wc = self._write_cursor + self._buffer_size
            self._timestamps.append((wc, audio_data.timestamp))

            ctypes.memmove(p1, audio_data.data, l1.value)
            audio_data.consume(l1.value, self.audio_format)
            if l2.value:
                ctypes.memmove(p2, audio_data.data, l2.value)
                audio_data.consume(l2.value, self.audio_format)
        else:
            ctypes.memset(p1, 0, l1.value)
            if l2.value:
                ctypes.memset(p2, 0, l2.value)
                pass
        self._buffer.Unlock(p1, l1, p2, l2)

        self._write_cursor += length
        self._write_cursor %= self._buffer_size 
开发者ID:shrimpboyho,项目名称:flappy-bird-py,代码行数:42,代码来源:__init__.py

示例12: RawArray

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def RawArray(typecode_or_type, size_or_initializer):
    '''
    Returns a ctypes array allocated from shared memory
    '''
    type_ = typecode_to_type.get(typecode_or_type, typecode_or_type)
    if isinstance(size_or_initializer, int):
        type_ = type_ * size_or_initializer
        obj = _new_value(type_)
        ctypes.memset(ctypes.addressof(obj), 0, ctypes.sizeof(obj))
        return obj
    else:
        type_ = type_ * len(size_or_initializer)
        result = _new_value(type_)
        result.__init__(*size_or_initializer)
        return result 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:sharedctypes.py

示例13: zero_bytes

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def zero_bytes(s):
    """Zero string of bytes in memory"""
    bufsize = len(s) + 1
    offset = sys.getsizeof(s) - bufsize
    ctypes.memset(id(s) + offset, 0, bufsize) 
开发者ID:xmikos,项目名称:pyxolotl,代码行数:7,代码来源:cryptostorage.py

示例14: memset

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def memset(self, offset: int, value: int, size: int) -> int:
        # self.asan_raw(offset, size) -> pasted here for speed
        if offset > self.__size or offset + size > self.__size:
            raise MemoryError(
                f'Not enough memory (tried to write to address range '
                f'0x{offset:08x}-0x{offset + size:08x} ({size} bytes), maximum address: 0x{self.size:08x} bytes)'
            )

        assert offset >= 0, f'Invalid memory address: {hex(offset)}'

        return memset(self.base + offset, value, size) - self.base

    # def set_addr(self, offset: int, size: int, addr: int) -> None:
    #     memmove(self.base + offset, addr, size) 
开发者ID:ForceBru,项目名称:PyVM,代码行数:16,代码来源:Memory.py

示例15: add_line

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import memset [as 别名]
def add_line(buf: ctypes.Array, cell_width: int, position: int, thickness: int, cell_height: int) -> None:
    y = position - thickness // 2
    while thickness > 0 and -1 < y < cell_height:
        thickness -= 1
        ctypes.memset(ctypes.addressof(buf) + (cell_width * y), 255, cell_width)
        y += 1 
开发者ID:kovidgoyal,项目名称:kitty,代码行数:8,代码来源:render.py


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