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


Python ctypes.addressof方法代码示例

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


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

示例1: ctypes2numpy_shared

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def ctypes2numpy_shared(cptr, shape):
    """Convert a ctypes pointer to a numpy array.

    The resulting NumPy array shares the memory with the pointer.

    Parameters
    ----------
    cptr : ctypes.POINTER(mx_float)
        pointer to the memory region

    shape : tuple
        Shape of target `NDArray`.

    Returns
    -------
    out : numpy_array
        A numpy array : numpy array.
    """
    if not isinstance(cptr, ctypes.POINTER(mx_float)):
        raise RuntimeError('expected float pointer')
    size = 1
    for s in shape:
        size *= s
    dbuffer = (mx_float * size).from_address(ctypes.addressof(cptr.contents))
    return np.frombuffer(dbuffer, dtype=np.float32).reshape(shape) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:27,代码来源:base.py

示例2: unref

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def unref(self):
        """
        This function decrements the reference counter of the underlying buffer(s)
        """
        try:
            res = od.vbuf_unref(self._buf)
            if res != 0:
                self.logger.error("vbuf_unref unpacked frame error: {} {} {}".format(
                    self._media_id,
                    os.strerror(-res),
                    ctypes.addressof(self._buf.contents)
                ))
        finally:
            if self._yuv_packed_buffer:
                res = od.vbuf_unref(self._yuv_packed_buffer)
                if res != 0:
                    self.logger.error("vbuf_unref packed frame error: {} {} {}".format(
                        self._media_id,
                        os.strerror(-res),
                        ctypes.addressof(self._buf.contents)
                    )) 
开发者ID:Parrot-Developers,项目名称:olympe,代码行数:23,代码来源:pdraw.py

示例3: feature_name

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def feature_name(self):
        """Get names of features.

        Returns
        -------
        result : list
            List with names of features.
        """
        num_feature = self.num_feature()
        # Get name of features
        tmp_out_len = ctypes.c_int(0)
        string_buffers = [ctypes.create_string_buffer(255) for i in range_(num_feature)]
        ptr_string_buffers = (ctypes.c_char_p * num_feature)(*map(ctypes.addressof, string_buffers))
        _safe_call(_LIB.LGBM_BoosterGetFeatureNames(
            self.handle,
            ctypes.byref(tmp_out_len),
            ptr_string_buffers))
        if num_feature != tmp_out_len.value:
            raise ValueError("Length of feature names doesn't equal with num_feature")
        return [string_buffers[i].value.decode() for i in range_(num_feature)] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:22,代码来源:basic.py

示例4: __get_eval_info

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def __get_eval_info(self):
        """Get inner evaluation count and names."""
        if self.__need_reload_eval_info:
            self.__need_reload_eval_info = False
            out_num_eval = ctypes.c_int(0)
            # Get num of inner evals
            _safe_call(_LIB.LGBM_BoosterGetEvalCounts(
                self.handle,
                ctypes.byref(out_num_eval)))
            self.__num_inner_eval = out_num_eval.value
            if self.__num_inner_eval > 0:
                # Get name of evals
                tmp_out_len = ctypes.c_int(0)
                string_buffers = [ctypes.create_string_buffer(255) for i in range_(self.__num_inner_eval)]
                ptr_string_buffers = (ctypes.c_char_p * self.__num_inner_eval)(*map(ctypes.addressof, string_buffers))
                _safe_call(_LIB.LGBM_BoosterGetEvalNames(
                    self.handle,
                    ctypes.byref(tmp_out_len),
                    ptr_string_buffers))
                if self.__num_inner_eval != tmp_out_len.value:
                    raise ValueError("Length of eval names doesn't equal with num_evals")
                self.__name_inner_eval = \
                    [string_buffers[i].value.decode() for i in range_(self.__num_inner_eval)]
                self.__higher_better_inner_eval = \
                    [name.startswith(('auc', 'ndcg@', 'map@')) for name in self.__name_inner_eval] 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:basic.py

示例5: platformParseBinaryPe

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def platformParseBinaryPe(self, filename, baseaddr, normname):

        # If we're on windows, fake out the PE header and use dbghelp
        #if platform.system() in ['Microsoft', 'Windows']:
        if False:
            # FIXME this code is stolen and should be a function!
            import vtrace.platforms.win32 as vt_win32
            fakepe = self.readMemory(baseaddr, 1024)
            tfile = tempfile.NamedTemporaryFile(delete=False)
            tfilename = tfile.name
            import ctypes
            pebuf = ctypes.create_string_buffer(fakepe)
            try:
                try:
                    tfile.write(fakepe)
                    tfile.close()
                    #parser = vt_win32.Win32SymbolParser(-1, tfilename, baseaddr)
                    parser = vt_win32.Win32SymbolParser(-1, None, ctypes.addressof(pebuf))
                    parser.parse()
                    parser.loadSymsIntoTrace(self, normname)
                finally:
                    os.unlink(tfilename)
            except Exception, e:
                print e 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:26,代码来源:gdbstub.py

示例6: __init__

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

示例7: __init__

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

示例8: arg_split

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def arg_split(commandline, posix=False, strict=True):
        """Split a command line's arguments in a shell-like manner.

        This is a special version for windows that use a ctypes call to CommandLineToArgvW
        to do the argv splitting. The posix paramter is ignored.
        
        If strict=False, process_common.arg_split(...strict=False) is used instead.
        """
        #CommandLineToArgvW returns path to executable if called with empty string.
        if commandline.strip() == "":
            return []
        if not strict:
            # not really a cl-arg, fallback on _process_common
            return py_arg_split(commandline, posix=posix, strict=strict)
        argvn = c_int()
        result_pointer = CommandLineToArgvW(py3compat.cast_unicode(commandline.lstrip()), ctypes.byref(argvn))
        result_array_type = LPCWSTR * argvn.value
        result = [arg for arg in result_array_type.from_address(ctypes.addressof(result_pointer.contents))]
        retval = LocalFree(result_pointer)
        return result 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:_process_win32.py

示例9: xfer

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def xfer(self, txbuff=None):
        length = len(txbuff)
        if PYTHON_MAJOR >= 3:
            _txbuff = bytes(txbuff)
            _txptr = ctypes.create_string_buffer(_txbuff)
        else:
            _txbuff = str(bytearray(txbuff))
            _txptr = ctypes.create_string_buffer(_txbuff)
        _rxptr = ctypes.create_string_buffer(length)
        
        data = struct.pack("QQLLHBBL",  #64 64 32 32 16 8 8 32 b = 32B
                    ctypes.addressof(_txptr),
                    ctypes.addressof(_rxptr),
                    length,
                    self.speed,
                    0, #delay
                    self.bits,
                    0, # cs_change,
                    0  # pad
                    )
        
        fcntl.ioctl(self.fd, SPI_IOC_MESSAGE(len(data)), data)
        _rxbuff = ctypes.string_at(_rxptr, length)
        return bytearray(_rxbuff) 
开发者ID:thortex,项目名称:rpi3-webiopi,代码行数:26,代码来源:spi.py

示例10: ctypes2numpy_shared

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def ctypes2numpy_shared(cptr, shape):
    """Convert a ctypes pointer to a numpy array

    The result numpy array shares the memory with the pointer

    Parameters
    ----------
    cptr : ctypes.POINTER(mx_float)
        pointer to the memory region

    shape : tuple
        shape of target ndarray

    Returns
    -------
    out : numpy_array
        A numpy array : numpy array
    """
    if not isinstance(cptr, ctypes.POINTER(mx_float)):
        raise RuntimeError('expected float pointer')
    size = 1
    for s in shape:
        size *= s
    dbuffer = (mx_float * size).from_address(ctypes.addressof(cptr.contents))
    return np.frombuffer(dbuffer, dtype=np.float32).reshape(shape) 
开发者ID:mlperf,项目名称:training_results_v0.6,代码行数:27,代码来源:_base.py

示例11: _get_ipv4_routing_table

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def _get_ipv4_routing_table(self):
        routing_table = []
        with self._get_forward_table() as p_forward_table:
            forward_table = p_forward_table.contents
            table = ctypes.cast(
                ctypes.addressof(forward_table.table),
                ctypes.POINTER(Win32_MIB_IPFORWARDROW *
                               forward_table.dwNumEntries)).contents

            for row in table:
                destination = Ws2_32.inet_ntoa(
                    row.dwForwardDest).decode()
                netmask = Ws2_32.inet_ntoa(
                    row.dwForwardMask).decode()
                gateway = Ws2_32.inet_ntoa(
                    row.dwForwardNextHop).decode()
                routing_table.append((
                    destination,
                    netmask,
                    gateway,
                    row.dwForwardIfIndex,
                    row.dwForwardMetric1))

        return routing_table 
开发者ID:cloudbase,项目名称:cloudbase-init,代码行数:26,代码来源:windows.py

示例12: encode

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def encode(self):
        '''Compress the associated encodable payload,
        prepend the header then encode with base64 if requested

        Returns:
            the b64 encoded wire encoding of the histogram (as a string)
            or the compressed payload (as a string, if b64 wrappinb is disabled)
        '''
        # only compress the first non zero buckets
        # if histogram is empty we do not encode any counter
        if self.histogram.total_count:
            relevant_length = \
                self.histogram.get_counts_array_index(self.histogram.max_value) + 1
        else:
            relevant_length = 0
        cpayload = self.payload.compress(relevant_length)
        if self.b64_wrap:
            self.header.length = len(cpayload)
            header_str = ctypes.string_at(addressof(self.header), ext_header_size)
            return base64.b64encode(header_str + cpayload)
        return cpayload 
开发者ID:HdrHistogram,项目名称:HdrHistogram_py,代码行数:23,代码来源:codec.py

示例13: test_zz_encode_errors

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def test_zz_encode_errors():
    with pytest.raises(TypeError):
        encode()
    with pytest.raises(TypeError):
        encode(None, None, 0, 0)
    src_array = (c_uint16 * ARRAY_SIZE)()
    src_array_addr = addressof(src_array)
    dst_len = 9 * ARRAY_SIZE

    # negative length
    with pytest.raises(ValueError):
        encode(src_array_addr, -1, sizeof(c_uint16), 0, dst_len)
    # dest length too small
    with pytest.raises(ValueError):
        encode(src_array_addr, ARRAY_SIZE, 4, 0, 4)
    # invalid word size
    with pytest.raises(ValueError):
        encode(src_array_addr, ARRAY_SIZE, 3, 0, 0)
    # Null dest ptr
    with pytest.raises(ValueError):
        encode(src_array_addr, ARRAY_SIZE, 4, 0, dst_len) 
开发者ID:HdrHistogram,项目名称:HdrHistogram_py,代码行数:23,代码来源:test_hdrhistogram.py

示例14: check_zz_identity

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def check_zz_identity(src_array, int_type, min_nz_index, max_nz_index, total_count, offset):
    dst_len = (sizeof(int_type) + 1) * ARRAY_SIZE
    dst = (c_uint8 * (offset + dst_len))()

    varint_len = encode(addressof(src_array), ARRAY_SIZE, sizeof(int_type),
                        addressof(dst) + offset, dst_len)
    varint_string = string_at(dst, varint_len + offset)

    dst_array = (int_type * ARRAY_SIZE)()
    res = decode(varint_string, offset, addressof(dst_array), ARRAY_SIZE, sizeof(int_type))
    assert res['total'] == total_count
    if total_count:
        assert res['min_nonzero_index'] == min_nz_index
        assert res['max_nonzero_index'] == max_nz_index
    for index in range(ARRAY_SIZE):
        assert dst_array[index] == src_array[index]


# A large positive value that can fit 16-bit signed 
开发者ID:HdrHistogram,项目名称:HdrHistogram_py,代码行数:21,代码来源:test_hdrhistogram.py

示例15: getindex

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import addressof [as 别名]
def getindex(self):
        index_size = ctypes.c_uint64(0)
        index_data = ctypes.POINTER(ctypes.c_uint64)()
        check_call(_LIB.MXDataIterGetIndex(self.handle,
                                           ctypes.byref(index_data),
                                           ctypes.byref(index_size)))
        if index_size.value:
            address = ctypes.addressof(index_data.contents)
            dbuffer = (ctypes.c_uint64* index_size.value).from_address(address)
            np_index = np.frombuffer(dbuffer, dtype=np.uint64)
            return np_index.copy()
        else:
            return None 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:15,代码来源:io.py


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