Allow llModPow and llXorBase64Strings to work in calculator mode.

e16fad0 was somewhat hurried. Revert it and use ELSLCantCompute, which is intended exactly for that purpose.
This commit is contained in:
Sei Lisa 2017-01-07 20:46:14 +01:00
parent ab8f8a28a9
commit 19dec1d79e
2 changed files with 88 additions and 75 deletions

View file

@ -1464,11 +1464,14 @@ def llMD5String(s, salt):
assert isinteger(salt) assert isinteger(salt)
return hashlib.md5(zstr(s).encode('utf8') + b':' + bytes(salt)).hexdigest().decode('utf8') return hashlib.md5(zstr(s).encode('utf8') + b':' + bytes(salt)).hexdigest().decode('utf8')
# This function has a delay, therefore it's not safe to compute it. def llModPow(base, exp, mod):
def x_llModPow(base, exp, mod):
assert isinteger(base) assert isinteger(base)
assert isinteger(exp) assert isinteger(exp)
assert isinteger(mod) assert isinteger(mod)
if not lslcommon.IsCalc:
# This function has a delay, therefore it's not safe to compute it
# unless in calculator mode.
raise ELSLCantCompute
# With some luck, this works fully with native ints on 64 bit machines. # With some luck, this works fully with native ints on 64 bit machines.
if mod in (0, 1): if mod in (0, 1):
return 0 return 0
@ -1813,11 +1816,15 @@ def llXorBase64(s, xor):
L2 += 1 L2 += 1
return b64encode(ret).decode('utf8') return b64encode(ret).decode('utf8')
# This function has a delay, therefore it's not safe to compute it. def llXorBase64Strings(s, xor):
def x_llXorBase64Strings(s, xor):
assert isstring(s) assert isstring(s)
assert isstring(xor) assert isstring(xor)
if not lslcommon.IsCalc:
# This function has a delay, therefore it's not safe to compute it
# unless in calculator mode.
raise ELSLCantCompute
if xor == u'': if xor == u'':
return s return s

View file

@ -129,7 +129,11 @@ def testXB64S(s1, s2, expect):
s2 = s2.decode('utf8') s2 = s2.decode('utf8')
if type(expect) == str: if type(expect) == str:
expect = expect.decode('utf8') expect = expect.decode('utf8')
test('x_llXorBase64Strings(' + repr(s1) + ',' + repr(s2) + ')', expect) # llXorBase64Strings can only be executed in calculator mode
SaveIsCalc = lslcommon.IsCalc
lslcommon.IsCalc = True
test('llXorBase64Strings(' + repr(s1) + ',' + repr(s2) + ')', expect)
lslcommon.IsCalc = SaveIsCalc
def testXB64SC(s1, s2, expect): def testXB64SC(s1, s2, expect):
if type(s1) == str: if type(s1) == str:
@ -947,7 +951,7 @@ def do_tests():
test('llRot2Up(Quaternion((0.,0.,0.,1.)))', Vector((0.,0.,1.))) test('llRot2Up(Quaternion((0.,0.,0.,1.)))', Vector((0.,0.,1.)))
test('llRot2Up(Quaternion((0.,0.,0.,0.)))', Vector((0.,0.,1.))) test('llRot2Up(Quaternion((0.,0.,0.,0.)))', Vector((0.,0.,1.)))
lslcommon.IsCalc = True lslcommon.IsCalc = True # llGenerateKey() only works in calculator mode
test('cond(llGenerateKey())', True) test('cond(llGenerateKey())', True)
lslcommon.IsCalc = False lslcommon.IsCalc = False
shouldexcept('llGenerateKey()', ELSLCantCompute) shouldexcept('llGenerateKey()', ELSLCantCompute)
@ -1064,75 +1068,77 @@ def do_tests():
testXB64 ("AQCDAQCD", "AQC=", "AACCAQGD") # the only correct one testXB64 ("AQCDAQCD", "AQC=", "AACCAQGD") # the only correct one
test('x_llModPow(65535, 3, 0)', 0) lslcommon.IsCalc = True # llModPow can only be computed in calculator mode
test('x_llModPow(65535, 3, 41)', 34) test('llModPow(65535, 3, 0)', 0)
test('x_llModPow(65535, 3, -2147483648)', 196607) test('llModPow(65535, 3, 41)', 34)
test('x_llModPow(65535, 3, -2147483647)', 131071) test('llModPow(65535, 3, -2147483648)', 196607)
test('x_llModPow(65533, 3, -2147483648)', 1769445) test('llModPow(65535, 3, -2147483647)', 131071)
test('x_llModPow(65533, 3, -2147483645)', 1572843) test('llModPow(65533, 3, -2147483648)', 1769445)
test('x_llModPow(65533, 3, 2147483645)', 1966047) test('llModPow(65533, 3, -2147483645)', 1572843)
test('x_llModPow(65533, 3, 555)', 142) test('llModPow(65533, 3, 2147483645)', 1966047)
test('x_llModPow(65533, 3, 1073741823)', 1966045) test('llModPow(65533, 3, 555)', 142)
test('x_llModPow(65533, 3, 1073741824)', 1769445) test('llModPow(65533, 3, 1073741823)', 1966045)
test('x_llModPow(65533, 3, 1073741825)', 1572845) test('llModPow(65533, 3, 1073741824)', 1769445)
test('x_llModPow(32767, 3, 1073741825)', 98302) test('llModPow(65533, 3, 1073741825)', 1572845)
test('x_llModPow(32767, 3, 107374182)', 216275) test('llModPow(32767, 3, 1073741825)', 98302)
test('x_llModPow(32767, 3, 10737418)', 876887) test('llModPow(32767, 3, 107374182)', 216275)
test('x_llModPow(32767, 3, 1073741)', 230066) test('llModPow(32767, 3, 10737418)', 876887)
test('x_llModPow(32767, 3, 107374)', 54345) test('llModPow(32767, 3, 1073741)', 230066)
test('x_llModPow(32767, 3, 507374)', 161343) test('llModPow(32767, 3, 107374)', 54345)
test('x_llModPow(32767, 3, 907374)', 346875) test('llModPow(32767, 3, 507374)', 161343)
test('x_llModPow(32767, 3, 707374)', 690307) test('llModPow(32767, 3, 907374)', 346875)
test('x_llModPow(32767, 3, 607374)', 139309) test('llModPow(32767, 3, 707374)', 690307)
test('x_llModPow(32767, 3, 600374)', 146813) test('llModPow(32767, 3, 607374)', 139309)
test('x_llModPow(32767, 3, 550374)', 389875) test('llModPow(32767, 3, 600374)', 146813)
test('x_llModPow(32767, 3, 520374)', 301047) test('llModPow(32767, 3, 550374)', 389875)
test('x_llModPow(32767, 3, 510374)', 36839) test('llModPow(32767, 3, 520374)', 301047)
test('x_llModPow(32767, 3, 500374)', 115989) test('llModPow(32767, 3, 510374)', 36839)
test('x_llModPow(32767, 3, 300374)', 83681) test('llModPow(32767, 3, 500374)', 115989)
test('x_llModPow(32767, 3, 100374)', 23425) test('llModPow(32767, 3, 300374)', 83681)
test('x_llModPow(32767, 3, 130374)', 64819) test('llModPow(32767, 3, 100374)', 23425)
test('x_llModPow(32767, 3, 132374)', 66641) test('llModPow(32767, 3, 130374)', 64819)
test('x_llModPow(32767, 3, 142374)', 93049) test('llModPow(32767, 3, 132374)', 66641)
test('x_llModPow(32767, 3, 172374)', 59569) test('llModPow(32767, 3, 142374)', 93049)
test('x_llModPow(32767, 3, 192374)', 66591) test('llModPow(32767, 3, 172374)', 59569)
test('x_llModPow(32767, 3, 199374)', 112231) test('llModPow(32767, 3, 192374)', 66591)
test('x_llModPow(32767, 3, 209374)', 54343) test('llModPow(32767, 3, 199374)', 112231)
test('x_llModPow(32767, 3, 259374)', 84733) test('llModPow(32767, 3, 209374)', 54343)
test('x_llModPow(32767, 3, 269374)', 49913) test('llModPow(32767, 3, 259374)', 84733)
test('x_llModPow(32767, 3, 261374)', 85865) test('llModPow(32767, 3, 269374)', 49913)
test('x_llModPow(32767, 3, 260374)', 2379) test('llModPow(32767, 3, 261374)', 85865)
test('x_llModPow(32767, 3, 250374)', 78307) test('llModPow(32767, 3, 260374)', 2379)
test('x_llModPow(32767, 3, 259375)', 99163) test('llModPow(32767, 3, 250374)', 78307)
test('x_llModPow(32767, 3, 260000)', 254367) test('llModPow(32767, 3, 259375)', 99163)
test('x_llModPow(32767, 3, 259999)', 90487) test('llModPow(32767, 3, 260000)', 254367)
test('x_llModPow(32767, 3, 259500)', 19663) test('llModPow(32767, 3, 259999)', 90487)
test('x_llModPow(32767, 3, 259750)', 29663) test('llModPow(32767, 3, 259500)', 19663)
test('x_llModPow(32767, 3, 259850)', 49367) test('llModPow(32767, 3, 259750)', 29663)
test('x_llModPow(32767, 3, 259800)', 164967) test('llModPow(32767, 3, 259850)', 49367)
test('x_llModPow(32767, 3, 259790)', 137017) test('llModPow(32767, 3, 259800)', 164967)
test('x_llModPow(32767, 3, 259770)', 64183) test('llModPow(32767, 3, 259790)', 137017)
test('x_llModPow(32767, 3, 259780)', 237863) test('llModPow(32767, 3, 259770)', 64183)
test('x_llModPow(32767, 3, 259785)', 162132) test('llModPow(32767, 3, 259780)', 237863)
test('x_llModPow(32767, 3, 259782)', 85797) test('llModPow(32767, 3, 259785)', 162132)
test('x_llModPow(32767, 3, 259781)', 157054) test('llModPow(32767, 3, 259782)', 85797)
test('x_llModPow(32767, 2, 259781)', 1416) test('llModPow(32767, 3, 259781)', 157054)
test('x_llModPow(32767, 2, 259782)', 257065) test('llModPow(32767, 2, 259781)', 1416)
test('x_llModPow(32767, 3, 259782)', 85797) test('llModPow(32767, 2, 259782)', 257065)
test('x_llModPow(-1, 3, 259782)', 251271) test('llModPow(32767, 3, 259782)', 85797)
test('x_llModPow(-1, -3, 259782)', 251271) test('llModPow(-1, 3, 259782)', 251271)
test('x_llModPow(0, 0, 0)', 0) test('llModPow(-1, -3, 259782)', 251271)
test('x_llModPow(1, 0, 0)', 0) test('llModPow(0, 0, 0)', 0)
test('x_llModPow(1, 0, 1)', 0) test('llModPow(1, 0, 0)', 0)
test('x_llModPow(1, 0, 2)', 1) test('llModPow(1, 0, 1)', 0)
test('x_llModPow(1, 0, 3)', 1) test('llModPow(1, 0, 2)', 1)
test('x_llModPow(1, 0, 4)', 1) test('llModPow(1, 0, 3)', 1)
test('x_llModPow(1, 1, 1)', 0) test('llModPow(1, 0, 4)', 1)
test('x_llModPow(5, 1, 1)', 0) test('llModPow(1, 1, 1)', 0)
test('x_llModPow(5, 25, 7)', 5) test('llModPow(5, 1, 1)', 0)
test('x_llModPow(5, 25, 13)', 5) test('llModPow(5, 25, 7)', 5)
test('x_llModPow(5, 25, 17)', 12) test('llModPow(5, 25, 13)', 5)
test('x_llModPow(41, 1, 17)', 7) test('llModPow(5, 25, 17)', 12)
test('llModPow(41, 1, 17)', 7)
lslcommon.IsCalc = False
test('llListFindList([], [])', 0) test('llListFindList([], [])', 0)
test('llListFindList([NaN], [NaN])', 0) # I swear. test('llListFindList([NaN], [NaN])', 0) # I swear.