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


Python rarithmetic.intmask函数代码示例

本文整理汇总了Python中pypy.rlib.rarithmetic.intmask函数的典型用法代码示例。如果您正苦于以下问题:Python intmask函数的具体用法?Python intmask怎么用?Python intmask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _AsLong

def _AsLong(v):
    """
    Get an integer from a bigint object.
    Raises OverflowError if overflow occurs.
    """
    # This version by Tim Peters
    i = len(v.digits) - 1
    sign = v.sign
    if not sign:
        return 0
    x = r_uint(0)
    while i >= 0:
        prev = x
        x = (x << SHIFT) + v.digits[i]
        if (x >> SHIFT) != prev:
            raise OverflowError
        i -= 1

    # Haven't lost any bits, but if the sign bit is set we're in
    # trouble *unless* this is the min negative number.  So,
    # trouble iff sign bit set && (positive || some bit set other
    # than the sign bit).
    if intmask(x) < 0 and (sign > 0 or (x << 1) != 0):
        raise OverflowError
    return intmask(x * sign)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:25,代码来源:rbigint.py

示例2: _PyLong_FromByteArray

def _PyLong_FromByteArray(space, bytes, n, little_endian, signed):
    little_endian = rffi.cast(lltype.Signed, little_endian)
    signed = rffi.cast(lltype.Signed, signed)

    result = rbigint()
    negative = False

    for i in range(0, n):
        if little_endian:
            c = intmask(bytes[i])
        else:
            c = intmask(bytes[n - i - 1])
        if i == 0 and signed and c & 0x80:
            negative = True
        if negative:
            c = c ^ 0xFF
        digit = rbigint.fromint(c)

        result = result.lshift(8)
        result = result.add(digit)

    if negative:
        result = result.neg()

    return space.newlong_from_rbigint(result)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:longobject.py

示例3: time_time_llimpl

        def time_time_llimpl():
            void = lltype.nullptr(rffi.VOIDP.TO)
            result = -1.0
            if self.HAVE_GETTIMEOFDAY:
                t = lltype.malloc(self.TIMEVAL, flavor='raw')

                errcode = -1
                if self.GETTIMEOFDAY_NO_TZ:
                    errcode = c_gettimeofday(t)
                else:
                    errcode = c_gettimeofday(t, void)

                if rffi.cast(rffi.LONG, errcode) == 0:
                    result = decode_timeval(t)
                lltype.free(t, flavor='raw')
            if result != -1:
                return result
            if self.HAVE_FTIME:
                t = lltype.malloc(self.TIMEB, flavor='raw')
                c_ftime(t)
                result = (float(intmask(t.c_time)) +
                          float(intmask(t.c_millitm)) * 0.001)
                lltype.free(t, flavor='raw')
                return result
            return float(c_time(void))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:25,代码来源:ll_time.py

示例4: do_poll

    def do_poll(self, space, timeout):
        from pypy.module._multiprocessing.interp_win32 import (
            _PeekNamedPipe, _GetTickCount, _Sleep)
        from pypy.rlib import rwin32
        from pypy.interpreter.error import wrap_windowserror
        bytes_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
                                 flavor='raw')
        try:
            if not _PeekNamedPipe(self.handle, rffi.NULL, 0,
                                  lltype.nullptr(rwin32.LPDWORD.TO),
                                  bytes_ptr,
                                  lltype.nullptr(rwin32.LPDWORD.TO)):
                raise wrap_windowserror(space, rwin32.lastWindowsError())
            bytes = bytes_ptr[0]
        finally:
            lltype.free(bytes_ptr, flavor='raw')

        if timeout == 0.0:
            return bytes > 0

        block = timeout < 0
        if not block:
            # XXX does not check for overflow
            deadline = intmask(_GetTickCount()) + int(1000 * timeout + 0.5)
        else:
            deadline = 0

        _Sleep(0)

        delay = 1
        while True:
            bytes_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
                                     flavor='raw')
            try:
                if not _PeekNamedPipe(self.handle, rffi.NULL, 0,
                                      lltype.nullptr(rwin32.LPDWORD.TO),
                                      bytes_ptr,
                                      lltype.nullptr(rwin32.LPDWORD.TO)):
                    raise wrap_windowserror(space, rwin32.lastWindowsError())
                bytes = bytes_ptr[0]
            finally:
                lltype.free(bytes_ptr, flavor='raw')

            if bytes > 0:
                return True

            if not block:
                now = intmask(_GetTickCount())
                if now > deadline:
                    return False
                diff = deadline - now
                if delay > diff:
                    delay = diff
            else:
                delay += 1

            if delay >= 20:
                delay = 20
            _Sleep(delay)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:interp_connection.py

示例5: func

 def func(no):
     m = mmap.mmap(no, 6, access=mmap.ACCESS_WRITE)
     f_size = os.fstat(no).st_size
     assert intmask(m.file_size()) == f_size == 6
     m.resize(10)
     f_size = os.fstat(no).st_size
     assert intmask(m.file_size()) == f_size == 10
     m.close()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:test_rmmap.py

示例6: test_truncate

 def test_truncate(self):
     def f(n):
         m = r_longlong(n) << 20
         return r_uint(m)
     res = self.interp_operations(f, [0x01234567])
     assert res == 0x56700000
     res = self.interp_operations(f, [0x56789ABC])
     assert intmask(res) == intmask(0xABC00000)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:8,代码来源:test_longlong.py

示例7: _ssl_thread_locking_function

def _ssl_thread_locking_function(mode, n, filename, line):
    n = intmask(n)
    if n < 0 or n >= len(_ssl_locks):
        return

    if intmask(mode) & CRYPTO_LOCK:
        _ssl_locks[n].acquire(True)
    else:
        _ssl_locks[n].release()
开发者ID:gorakhargosh,项目名称:pypy,代码行数:9,代码来源:interp_ssl.py

示例8: ll_hash

 def ll_hash(t):
     retval = 0x345678
     mult = 1000003
     for i, hash_func in autounrolling_funclist:
         attrname = 'item%d' % i
         item = getattr(t, attrname)
         retval = intmask((retval ^ hash_func(item)) * intmask(mult))
         mult = mult + 82520 + 2*len(items_r)
     return retval
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:rtuple.py

示例9: test_args_from_long

 def test_args_from_long(self):
     BASE = 1 << SHIFT
     assert rbigint.fromlong(0).eq(bigint([0], 0))
     assert rbigint.fromlong(17).eq(bigint([17], 1))
     assert rbigint.fromlong(BASE-1).eq(bigint([intmask(BASE-1)], 1))
     assert rbigint.fromlong(BASE).eq(bigint([0, 1], 1))
     assert rbigint.fromlong(BASE**2).eq(bigint([0, 0, 1], 1))
     assert rbigint.fromlong(-17).eq(bigint([17], -1))
     assert rbigint.fromlong(-(BASE-1)).eq(bigint([intmask(BASE-1)], -1))
     assert rbigint.fromlong(-BASE).eq(bigint([0, 1], -1))
     assert rbigint.fromlong(-(BASE**2)).eq(bigint([0, 0, 1], -1))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:11,代码来源:test_rbigint.py

示例10: do_recv_string

    def do_recv_string(self, space, buflength, maxlength):
        from pypy.module._multiprocessing.interp_win32 import (
            _ReadFile, _PeekNamedPipe, ERROR_BROKEN_PIPE, ERROR_MORE_DATA)
        from pypy.rlib import rwin32
        from pypy.interpreter.error import wrap_windowserror

        read_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
                                 flavor='raw')
        left_ptr = lltype.malloc(rffi.CArrayPtr(rwin32.DWORD).TO, 1,
                                 flavor='raw')
        try:
            result = _ReadFile(self.handle,
                               self.buffer, min(self.BUFFER_SIZE, buflength),
                               read_ptr, rffi.NULL)
            if result:
                return intmask(read_ptr[0]), lltype.nullptr(rffi.CCHARP.TO)

            err = rwin32.GetLastError()
            if err == ERROR_BROKEN_PIPE:
                raise OperationError(space.w_EOFError, space.w_None)
            elif err != ERROR_MORE_DATA:
                raise wrap_windowserror(space, WindowsError(err, "_ReadFile"))

            # More data...
            if not _PeekNamedPipe(self.handle, rffi.NULL, 0,
                                  lltype.nullptr(rwin32.LPDWORD.TO),
                                  lltype.nullptr(rwin32.LPDWORD.TO),
                                  left_ptr):
                raise wrap_windowserror(space, rwin32.lastWindowsError())

            length = intmask(read_ptr[0] + left_ptr[0])
            if length > maxlength: # bad message, close connection
                self.flags &= ~READABLE
                if self.flags == 0:
                    self.close()
                raise OperationError(space.w_IOError, space.wrap(
                    "bad message length"))

            newbuf = lltype.malloc(rffi.CCHARP.TO, length + 1, flavor='raw')
            for i in range(read_ptr[0]):
                newbuf[i] = self.buffer[i]

            result = _ReadFile(self.handle,
                               rffi.ptradd(newbuf, read_ptr[0]), left_ptr[0],
                               read_ptr, rffi.NULL)
            if not result:
                rffi.free_charp(newbuf)
                raise wrap_windowserror(space, rwin32.lastWindowsError())

            assert read_ptr[0] == left_ptr[0]
            return length, newbuf
        finally:
            lltype.free(read_ptr, flavor='raw')
            lltype.free(left_ptr, flavor='raw')
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:54,代码来源:interp_connection.py

示例11: test_args_from_int

 def test_args_from_int(self):
     BASE = 1 << SHIFT
     assert rbigint.fromrarith_int(0).eq(rbigint([0], 0))
     assert rbigint.fromrarith_int(17).eq(rbigint([17], 1))
     assert rbigint.fromrarith_int(BASE-1).eq(rbigint([intmask(BASE-1)], 1))
     assert rbigint.fromrarith_int(BASE).eq(rbigint([0, 1], 1))
     assert rbigint.fromrarith_int(BASE**2).eq(rbigint([0, 0, 1], 1))
     assert rbigint.fromrarith_int(-17).eq(rbigint([17], -1))
     assert rbigint.fromrarith_int(-(BASE-1)).eq(rbigint([intmask(BASE-1)], -1))
     assert rbigint.fromrarith_int(-BASE).eq(rbigint([0, 1], -1))
     assert rbigint.fromrarith_int(-(BASE**2)).eq(rbigint([0, 0, 1], -1))
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:test_rbigint.py

示例12: hash

 def hash(self, storage):
     storage = self.unerase(storage)
     length = len(storage)
     if length == 0:
         return -1
     x = ord(storage[0]) << 7
     i = 0
     while i < length:
         x = intmask((1000003 * x) ^ ord(storage[i]))
         i += 1
     x ^= length
     return intmask(x)
开发者ID:gnprice,项目名称:rupypy,代码行数:12,代码来源:stringobject.py

示例13: make_struct_passwd

def make_struct_passwd(space, pw):
    w_passwd_struct = space.getattr(space.getbuiltinmodule('pwd'),
                                    space.wrap('struct_passwd'))
    w_tuple = space.newtuple([
        space.wrap(rffi.charp2str(pw.c_pw_name)),
        space.wrap(rffi.charp2str(pw.c_pw_passwd)),
        space.wrap(intmask(pw.c_pw_uid)),
        space.wrap(intmask(pw.c_pw_gid)),
        space.wrap(rffi.charp2str(pw.c_pw_gecos)),
        space.wrap(rffi.charp2str(pw.c_pw_dir)),
        space.wrap(rffi.charp2str(pw.c_pw_shell)),
        ])
    return space.call_function(w_passwd_struct, w_tuple)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:13,代码来源:interp_pwd.py

示例14: _int_binary_operations

def _int_binary_operations():
    minint = -sys.maxint-1
    # Test cases.  Note that for each operation there should be at least
    # one case in which the two input arguments are equal.
    for opnum, testcases in [
        (rop.INT_ADD, [(10, -2, 8),
                       (-60, -60, -120)]),
        (rop.INT_SUB, [(10, -2, 12),
                       (133, 133, 0)]),
        (rop.INT_MUL, [(-6, -3, 18),
                       (15, 15, 225)]),
        (rop.INT_FLOORDIV, [(110, 3, 36),
                            (-110, 3, -36),
                            (110, -3, -36),
                            (-110, -3, 36),
                            (-110, -1, 110),
                            (minint, 1, minint),
                            (-87, -87, 1)]),
        (rop.INT_MOD, [(11, 3, 2),
                       (-11, 3, -2),
                       (11, -3, 2),
                       (-11, -3, -2),
                       (-87, -87, 0)]),
        (rop.INT_AND, [(0xFF00, 0x0FF0, 0x0F00),
                       (-111, -111, -111)]),
        (rop.INT_OR, [(0xFF00, 0x0FF0, 0xFFF0),
                      (-111, -111, -111)]),
        (rop.INT_XOR, [(0xFF00, 0x0FF0, 0xF0F0),
                       (-111, -111, 0)]),
        (rop.INT_LSHIFT, [(10, 4, 10<<4),
                          (-5, 2, -20),
                          (-5, 0, -5),
                          (3, 3, 24)]),
        (rop.INT_RSHIFT, [(-17, 2, -5),
                          (19, 1, 9),
                          (3, 3, 0)]),
        (rop.UINT_RSHIFT, [(-1, 4, intmask(r_uint(-1) >> r_uint(4))),
                           ( 1, 4, intmask(r_uint(1) >> r_uint(4))),
                           ( 3, 3, 0)]),
        (rop.UINT_FLOORDIV, [(4, 3, intmask(r_uint(4) / r_uint(3))),
                             (1, -1, intmask(r_uint(1) / r_uint(-1))),
                             (110, 3, 36),
                             (-110, 3, intmask(r_uint(-110) / r_uint(3))),
                             (110, -3, intmask(r_uint(110) / r_uint(-3))),
                             (-110, -3, intmask(r_uint(-110) / r_uint(-3))),
                             (-110, -1, intmask(r_uint(-110) / r_uint(-1))),
                             (minint, 1, intmask(r_uint(minint) / r_uint(1))),
                             (-87, -87, intmask(r_uint(-87) / r_uint(-87)))])
        ]:
        for x, y, z in testcases:
            yield opnum, [x, y], z
开发者ID:alkorzt,项目名称:pypy,代码行数:51,代码来源:test_executor.py

示例15: toint

 def toint(self):
     """
     Get an integer from a bigint object.
     Raises OverflowError if overflow occurs.
     """
     x = self._touint_helper()
     # Haven't lost any bits, but if the sign bit is set we're in
     # trouble *unless* this is the min negative number.  So,
     # trouble iff sign bit set && (positive || some bit set other
     # than the sign bit).
     sign = self.sign
     if intmask(x) < 0 and (sign > 0 or (x << 1) != 0):
         raise OverflowError
     return intmask(x * sign)
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:rbigint.py


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