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