• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rarithmetic.intmask函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: digits_for_most_neg_long

def digits_for_most_neg_long(l):
    # This helper only works if 'l' is the most negative integer of its
    # type, which in base 2 looks like: 1000000..0000
    digits = []
    while (intmask(l) & MASK) == 0:
        digits.append(0)
        l = l >> SHIFT
    # now 'l' looks like: ...111100000
    # turn it into:       ...000100000
    # to drop the extra unwanted 1's introduced by the signed right shift
    l = -intmask(l)
    assert l >= 0
    digits.append(l)
    return digits
开发者ID:antoine1fr,项目名称:pygirl,代码行数:14,代码来源:rbigint.py


示例17: ll_stat_result

 def ll_stat_result(stat0, stat1, stat2, stat3, stat4,
                    stat5, stat6, stat7, stat8, stat9):
     tup = lltype.malloc(STAT_RESULT)
     tup.item0 = intmask(stat0)
     tup.item1 = intmask(stat1)
     tup.item2 = intmask(stat2)
     tup.item3 = intmask(stat3)
     tup.item4 = intmask(stat4)
     tup.item5 = intmask(stat5)
     tup.item6 = intmask(stat6)
     tup.item7 = intmask(stat7)
     tup.item8 = intmask(stat8)
     tup.item9 = intmask(stat9)
     return tup
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:14,代码来源:ll_os.py


示例18: compute_additional_info

    def compute_additional_info(self):
        additional_info = GlobalRopeInfo()
        charbitmask = 0
        partial_hash = 0
        for c in self.u:
            ordc = ord(c)
            charbitmask |= intmask(1 << (ordc & 0x1F))
            partial_hash = (1000003 * partial_hash) + ordc
        partial_hash = intmask(partial_hash)
        partial_hash |= HIGHEST_BIT_SET

        additional_info.charbitmask = intmask(charbitmask)
        additional_info.hash = partial_hash
        self._additional_info = additional_info
        return additional_info
开发者ID:alkorzt,项目名称:pypy,代码行数:15,代码来源:rope.py


示例19: makeipaddr

def makeipaddr(name, result=None):
    # Convert a string specifying a host name or one of a few symbolic
    # names to an IPAddress instance.  This usually calls getaddrinfo()
    # to do the work; the names "" and "<broadcast>" are special.
    # If 'result' is specified it must be a prebuilt INETAddress or
    # INET6Address that is filled; otherwise a new INETXAddress is returned.
    if result is None:
        family = AF_UNSPEC
    else:
        family = result.family

    if len(name) == 0:
        info = getaddrinfo(None, "0",
                           family=family,
                           socktype=SOCK_DGRAM,   # dummy
                           flags=AI_PASSIVE,
                           address_to_fill=result)
        if len(info) > 1:
            raise RSocketError("wildcard resolved to "
                               "multiple addresses")
        return info[0][4]

    # IPv4 also supports the special name "<broadcast>".
    if name == '<broadcast>':
        return makeipv4addr(intmask(INADDR_BROADCAST), result)

    # "dd.dd.dd.dd" format.
    digits = name.split('.')
    if len(digits) == 4:
        try:
            d0 = int(digits[0])
            d1 = int(digits[1])
            d2 = int(digits[2])
            d3 = int(digits[3])
        except ValueError:
            pass
        else:
            if (0 <= d0 <= 255 and
                0 <= d1 <= 255 and
                0 <= d2 <= 255 and
                0 <= d3 <= 255):
                return makeipv4addr(intmask(htonl(
                    (intmask(d0 << 24)) | (d1 << 16) | (d2 << 8) | (d3 << 0))),
                                    result)

    # generic host name to IP conversion
    info = getaddrinfo(name, None, family=family, address_to_fill=result)
    return info[0][4]
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:48,代码来源:rsocket.py


示例20: lookup_where_with_method_cache

    def lookup_where_with_method_cache(w_self, name):
        space = w_self.space
        assert space.config.objspace.std.withmethodcache
        ec = space.getexecutioncontext()
        version_tag = w_self.version_tag
        if version_tag is None:
            tup = w_self._lookup_where(name)
            return tup
        SHIFT = r_uint.BITS - space.config.objspace.std.methodcachesizeexp
        method_hash = r_uint(intmask(id(version_tag) * hash(name))) >> SHIFT
        cached_version_tag = ec.method_cache_versions[method_hash]
        if cached_version_tag is version_tag:
            cached_name = ec.method_cache_names[method_hash]
            if cached_name is name:
                tup = ec.method_cache_lookup_where[method_hash]
                if space.config.objspace.std.withmethodcachecounter:
                    ec.method_cache_hits[name] = \
                            ec.method_cache_hits.get(name, 0) + 1
#                print "hit", w_self, name
                return tup
        tup = w_self._lookup_where(name)
        ec.method_cache_versions[method_hash] = version_tag
        ec.method_cache_names[method_hash] = name
        ec.method_cache_lookup_where[method_hash] = tup
        if space.config.objspace.std.withmethodcachecounter:
            ec.method_cache_misses[name] = \
                    ec.method_cache_misses.get(name, 0) + 1
#        print "miss", w_self, name
        return tup
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:29,代码来源:typeobject.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rarithmetic.ovfcheck函数代码示例发布时间:2022-05-27
下一篇:
Python ebnfparse.parse_ebnf函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap