我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用ctypes.c_int64()。
def _return_ctype(self): """ Returns the associated ctype of a given datatype. """ _datatype_ctype = { DataType.Bool: ctypes.c_uint8, DataType.I8: ctypes.c_int8, DataType.U8: ctypes.c_uint8, DataType.I16: ctypes.c_int16, DataType.U16: ctypes.c_uint16, DataType.I32: ctypes.c_int32, DataType.U32: ctypes.c_uint32, DataType.I64: ctypes.c_int64, DataType.U64: ctypes.c_uint64, DataType.Sgl: ctypes.c_float, DataType.Dbl: ctypes.c_double, } return _datatype_ctype[self]
def empty(shape, ctx=cpu(0)): """Create an empty array given shape and device Parameters ---------- shape : tuple of int The shape of the array ctx : DLContext The context of the array Returns ------- arr : ndarray The array dlsys supported. """ shape = c_array(ctypes.c_int64, shape) ndim = ctypes.c_int(len(shape)) handle = DLArrayHandle() check_call(_LIB.DLArrayAlloc( shape, ndim, ctx, ctypes.byref(handle))) return NDArray(handle)
def hash(self, timestamp, latitude, longitude, altitude, authticket, sessiondata, requests): self.location_hash = None self.location_auth_hash = None self.request_hashes = [] first_hash = self.hash32(authticket, seed=HASH_SEED) location_bytes = d2h(latitude) + d2h(longitude) + d2h(altitude) loc_hash = self.hash32(location_bytes, seed=first_hash) self.location_auth_hash = ctypes.c_int32(loc_hash).value loc_hash = self.hash32(location_bytes, seed=HASH_SEED) self.location_hash = ctypes.c_int32(loc_hash).value first_hash = self.hash64salt32(authticket, seed=HASH_SEED) for request in requests: req_hash = self.hash64salt64(request.SerializeToString(), seed=first_hash) self.request_hashes.append(ctypes.c_int64(req_hash).value)
def generate_request_hash(authticket, request): first_hash = hash64salt32(authticket, seed=HASH_SEED) req_hash = hash64salt64(request, seed=first_hash) return ctypes.c_int64(req_hash).value
def hash32(buf, seed): buf = struct.pack(">I", seed) + buf hash64 = calcHash(buf) signedhash64 = ctypes.c_int64(hash64) return ctypes.c_uint(signedhash64.value).value ^ ctypes.c_uint(signedhash64.value >> 32).value
def libvlc_clock(): '''Return the current time as defined by LibVLC. The unit is the microsecond. Time increases monotonically (regardless of time zone changes and RTC adjustements). The origin is arbitrary but consistent across the whole system (e.g. the system uptim, the time since the system was booted). @note: On systems that support it, the POSIX monotonic clock is used. ''' f = _Cfunctions.get('libvlc_clock', None) or \ _Cfunction('libvlc_clock', (), None, ctypes.c_int64) return f()
def libvlc_video_get_spu_delay(p_mi): '''Get the current subtitle delay. Positive values means subtitles are being displayed later, negative values earlier. @param p_mi: media player. @return: time (in microseconds) the display of subtitles is being delayed. @version: LibVLC 2.0.0 or later. ''' f = _Cfunctions.get('libvlc_video_get_spu_delay', None) or \ _Cfunction('libvlc_video_get_spu_delay', ((1,),), None, ctypes.c_int64, MediaPlayer) return f(p_mi)
def libvlc_video_set_spu_delay(p_mi, i_delay): '''Set the subtitle delay. This affects the timing of when the subtitle will be displayed. Positive values result in subtitles being displayed later, while negative values will result in subtitles being displayed earlier. The subtitle delay will be reset to zero each time the media changes. @param p_mi: media player. @param i_delay: time (in microseconds) the display of subtitles should be delayed. @return: 0 on success, -1 on error. @version: LibVLC 2.0.0 or later. ''' f = _Cfunctions.get('libvlc_video_set_spu_delay', None) or \ _Cfunction('libvlc_video_set_spu_delay', ((1,), (1,),), None, ctypes.c_int, MediaPlayer, ctypes.c_int64) return f(p_mi, i_delay)
def libvlc_audio_get_delay(p_mi): '''Get current audio delay. @param p_mi: media player. @return: the audio delay (microseconds). @version: LibVLC 1.1.1 or later. ''' f = _Cfunctions.get('libvlc_audio_get_delay', None) or \ _Cfunction('libvlc_audio_get_delay', ((1,),), None, ctypes.c_int64, MediaPlayer) return f(p_mi)
def libvlc_audio_set_delay(p_mi, i_delay): '''Set current audio delay. The audio delay will be reset to zero each time the media changes. @param p_mi: media player. @param i_delay: the audio delay (microseconds). @return: 0 on success, -1 on error. @version: LibVLC 1.1.1 or later. ''' f = _Cfunctions.get('libvlc_audio_set_delay', None) or \ _Cfunction('libvlc_audio_set_delay', ((1,), (1,),), None, ctypes.c_int, MediaPlayer, ctypes.c_int64) return f(p_mi, i_delay)
def _disk_c(self): drive = unicode(os.getenv("SystemDrive")) freeuser = ctypes.c_int64() total = ctypes.c_int64() free = ctypes.c_int64() ctypes.windll.kernel32.GetDiskFreeSpaceExW(drive, ctypes.byref(freeuser), ctypes.byref(total), ctypes.byref(free)) return freeuser.value
def __init__(self, bit_len=16, signed=False, default_val=0, little_endian=False): super(IntField, self).__init__(default_val) if bit_len <= 0 or bit_len > 64: raise ValueError("bit_len must be between 1 and 64") self.default_val = default_val self.bit_len = bit_len self.little_endian = little_endian self.signed = signed if self.signed: self.c_type = ctypes.c_int64 else: self.c_type = ctypes.c_uint64
def validate_i64(val, p, key=None): if isinstance(val, (int, long)) and ctypes.c_int64(val).value == val: return raise_validation_error(ErrInvalidI64, val, p, key=key)
def OnPlayStateChanged(self, member, srcpath, message): """ (sxuuuiia(ssssxsssa{ss}a{sv}v)) """ message = Message.Message.FromHandle(message) arg = message.GetArg(0) play_state = C.c_char_p() position = C.c_int64() current_sample_rate = C.c_uint32() audio_channels = C.c_uint32() bits_per_sample = C.c_uint32() index_current_item = C.c_int32() index_next_item = C.c_int32() num = C.c_size_t() entries = MsgArg.MsgArg() arg.Get("(sxuuuii*)", [C.POINTER(C.c_char_p), C.POINTER(C.c_int64), C.POINTER(C.c_uint32), C.POINTER(C.c_uint32), C.POINTER(C.c_uint32), C.POINTER(C.c_int32), C.POINTER(C.c_int32), C.POINTER(C.c_size_t), C.POINTER(MsgArgHandle) ], [C.byref(play_state), C.byref(position), C.byref(current_sample_rate), C.byref(audio_channels), C.byref(bits_per_sample), C.byref(index_current_item), C.byref(index_next_item), C.byref(num), C.byref(entries.handle)]) print play_state.value
def GetPlayingState(self): param = MsgArg.MsgArg() self.proxyBusObject.GetProperty( "net.allplay.MediaPlayer", "PlayState", param) play_state = C.c_char_p() position = C.c_int64() current_sample_rate = C.c_uint32() audio_channels = C.c_uint32() bits_per_sample = C.c_uint32() index_current_item = C.c_int32() index_next_item = C.c_int32() num = C.c_size_t() entries = MsgArg.MsgArg() # (sxuuuiia(ssssxsssa{ss}a{sv}v)) param.Get("(sxuuuii*)", [C.POINTER(C.c_char_p), C.POINTER(C.c_int64), C.POINTER(C.c_uint32), C.POINTER(C.c_uint32), C.POINTER(C.c_uint32), C.POINTER(C.c_int32), C.POINTER(C.c_int32), C.POINTER(C.c_size_t), C.POINTER(MsgArgHandle) ], [C.byref(play_state), C.byref(position), C.byref(current_sample_rate), C.byref(audio_channels), C.byref(bits_per_sample), C.byref(index_current_item), C.byref(index_next_item), C.byref(num), C.byref(entries.handle)]) return play_state.value, position.value
def struct(cls, ea, **sid): """Return the structure_t at address ``ea`` as a dict of ctypes. If the structure ``sid`` is specified, then use that specific structure type. """ ea = interface.address.within(ea) if any(n in sid for n in ('sid','struc','structure','id')): res = sid['sid'] if 'sid' in sid else sid['struc'] if 'struc' in sid else sid['structure'] if 'structure' in sid else sid['id'] if 'id' in sid else None sid = res.id if isinstance(res, structure.structure_t) else res else: sid = type.structure.id(ea) st = structure.instance(sid, offset=ea) typelookup = { (int,-1) : ctypes.c_int8, (int,1) : ctypes.c_uint8, (int,-2) : ctypes.c_int16, (int,2) : ctypes.c_uint16, (int,-4) : ctypes.c_int32, (int,4) : ctypes.c_uint32, (int,-8) : ctypes.c_int64, (int,8) : ctypes.c_uint64, (float,4) : ctypes.c_float, (float,8) : ctypes.c_double, } res = {} for m in st.members: t, val = m.type, read(m.offset, m.size) or '' try: ct = typelookup[t] except KeyError: ty, sz = t if isinstance(t, __builtin__.tuple) else (m.type, 0) if isinstance(t, __builtin__.list): t = typelookup[tuple(ty)] ct = t*sz elif ty in (chr,str): ct = ctypes.c_char*sz else: ct = None finally: res[m.name] = val if any(_ is None for _ in (ct,val)) else ctypes.cast(ctypes.pointer(ctypes.c_buffer(val)),ctypes.POINTER(ct)).contents return res
def fadviseSeqNoCache(self, fileD): """Advise the kernel that we are only going to access file-descriptor fileD once, sequentially.""" POSIX_FADV_SEQUENTIAL = 2 POSIX_FADV_DONTNEED = 4 offset = ctypes.c_int64(0) length = ctypes.c_int64(0) clib.posix_fadvise(fileD, offset, length, POSIX_FADV_SEQUENTIAL) clib.posix_fadvise(fileD, offset, length, POSIX_FADV_DONTNEED)
def _disk_info(): drive = unicode(os.getenv("SystemDrive")) freeuser = ctypes.c_int64() total = ctypes.c_int64() free = ctypes.c_int64() ctypes.windll.kernel32.GetDiskFreeSpaceExW(drive, ctypes.byref(freeuser), ctypes.byref(total), ctypes.byref(free)) return freeuser.value
def _fallocate(): libc_name = ctypes.util.find_library('c') libc = ctypes.CDLL(libc_name) raw_fallocate = libc.fallocate raw_fallocate.restype = ctypes.c_int raw_fallocate.argtypes = [ ctypes.c_int, ctypes.c_int, ctypes.c_int64, ctypes.c_int64] def fallocate(fd, offs, size, mode=FALLOC_FL_KEEP_SIZE): ret = raw_fallocate(fd, mode, offs, size) if ret != 0: raise IOError(ctypes.get_errno()) return fallocate