Beispiel #1
0
def unmarshal_Long(space, u, tc):
    # XXX access internals
    from pypy.rlib.rbigint import rbigint
    lng = u.get_int()
    if lng < 0:
        sign = -1
        lng = -lng
    elif lng > 0:
        sign = 1
    else:
        sign = 0
    if long_bits != 15:
        SHIFT = 15
        result = rbigint([0], 0)
        for i in range(lng):
            shift = i * SHIFT
            result = result.add(rbigint.fromint(u.get_short()).lshift(shift))
        if lng and not result.tobool():
            raise_exception(space, 'bad marshal data')
        if sign == -1:
            result = result.neg()
    else:
        digits = [0] * lng
        for i in range(lng):
            digit = u.get_int()
            if digit < 0:
                raise_exception(space, 'bad marshal data')
            digits[i] = digit
        if digits[-1] == 0:
            raise_exception(space, 'bad marshal data')
        result = rbigint(digits, sign)
    w_long = W_LongObject(result)
    return w_long
Beispiel #2
0
 def test_integer_strategy_with_w_long(self):
     # tests all calls to is_plain_int1() so far
     space = self.space
     w = W_LongObject(rbigint.fromlong(42))
     s1 = W_SetObject(space, self.wrapped([]))
     s1.add(w)
     assert s1.strategy is space.fromcache(IntegerSetStrategy)
     #
     s1 = W_SetObject(space, space.newlist([w]))
     assert s1.strategy is space.fromcache(IntegerSetStrategy)
Beispiel #3
0
    def test_integer_strategy_with_w_long(self):
        space = self.space
        w_x = space.wrap("x")
        w_A, w_B, w_C = self.get_three_classes()
        atag = w_A.version_tag()
        w = W_LongObject(rbigint.fromlong(42))
        space.setattr(w_A, w_x, w)
        assert w_A.version_tag() is not atag
        assert space.int_w(space.getattr(w_A, w_x)) == 42

        atag = w_A.version_tag()
        w = W_LongObject(rbigint.fromlong(43))
        space.setattr(w_A, w_x, w)
        assert w_A.version_tag() is not atag
        assert space.int_w(space.getattr(w_A, w_x)) == 43
        cell = w_A._getdictvalue_no_unwrapping(space, "x")
        assert cell.intvalue == 43

        atag = w_A.version_tag()
        w = W_LongObject(rbigint.fromlong(44))
        space.setattr(w_A, w_x, w)
        assert w_A.version_tag() is atag
        assert space.int_w(space.getattr(w_A, w_x)) == 44
        assert cell.intvalue == 44
Beispiel #4
0
def unmarshal_Long(space, u, tc):
    from pypy.rlib import rbigint
    lng = u.get_int()
    if lng < 0:
        sign = -1
        lng = -lng
    elif lng > 0:
        sign = 1
    else:
        sign = 0
    digits = [0] * lng
    i = 0
    while i < lng:
        digit = u.get_short()
        if digit < 0:
            raise_exception(space, 'bad marshal data')
        digits[i] = digit
        i += 1
    # XXX poking at internals
    w_long = W_LongObject(rbigint.rbigint(digits, sign))
    w_long.num._normalize()
    return w_long
Beispiel #5
0
def delegate_SmallLong2Long(space, w_small):
    return W_LongObject(w_small.asbigint())
Beispiel #6
0
 def int(self, space):
     if type(self) is W_SmallLongObject:
         return self
     if not space.is_overloaded(self, space.w_int, '__int__'):
         return W_LongObject(self.num)
     return W_Root.int(self, space)
Beispiel #7
0
def _small2long(space, w_small):
    return W_LongObject(w_small.asbigint())
Beispiel #8
0
 def test_integer_strategy_with_w_long(self):
     w = W_LongObject(rbigint.fromlong(42))
     w_tuple = self.space.newtuple([w, w])
     assert w_tuple.__class__.__name__ == 'W_SpecialisedTupleObject_ii'