From 1262934baf85bc2ff2ae26d99e877ecb67d1f8c7 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 22 Jan 2017 19:45:14 +0100 Subject: [PATCH] Fix llAbs raising a run-time exception in Mono. llAbs(-2147483648) raises this: System.OverflowException: Value is too small. at System.Math.Abs (Int32 value) [0x00000] in :0 at LindenLab.SecondLife.Library.llAbs (Int32 i) [0x00000] in :0 So it's actually not computable. In LSO it returns -2147483648, though. --- lslopt/lslbasefuncs.py | 14 ++++++++++++-- lslopt/lslcommon.py | 5 ----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index ff85432..a975b5b 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -94,6 +94,11 @@ class ELSLInvalidType(Exception): class ELSLCantCompute(Exception): pass +# We don't yet support the LSO string model (arbitrary zero-terminated byte +# sequences). This exception is triggered to report attempts at using it. +class ELSONotSupported(Exception): + pass + # LSL types are translated to Python types as follows: # * LSL string -> Python unicode # * LSL key -> Key (class derived from unicode, no significant changes except __repr__) @@ -726,7 +731,7 @@ def mod(a, b, f32=True): def compare(a, b, Eq = True): """Calculate a == b when Eq is True, or a != b when not""" - # Defined for all types as long as there's one that can be cast to the other + # Defined for all types as long as one of them can be auto-cast to the other ta = type(a) tb = type(b) if ta in (int, float) and tb in (int, float): @@ -808,7 +813,12 @@ def reduce(t): def llAbs(i): assert isinteger(i) - return abs(i) if i != -2147483648 else i + if i != -2147483648: + return abs(i) + if lslcommon.LSO: + return i + # Mono raises an OverflowException in this case. + raise ELSLCantCompute def llAcos(f): assert isfloat(f) diff --git a/lslopt/lslcommon.py b/lslopt/lslcommon.py index 91025a1..de65374 100644 --- a/lslopt/lslcommon.py +++ b/lslopt/lslcommon.py @@ -30,11 +30,6 @@ class Quaternion(tuple): def __repr__(self): return 'Quaternion(' + super(Quaternion, self).__repr__() + ')' -# We don't yet support the LSO string model (arbitrary zero-terminated byte -# sequences). This exception is triggered to report attempts at using it. -class ELSONotSupported(Exception): - pass - # Recognized: 3763, 6466, 6495 # BUG-3763 affected llXorBase64 (see lslbasefuncs.py). It's been fixed. # BUG-6466 is about some valid numbers in JSON not being accepted. It's fixed.