Commit graph

127 commits

Author SHA1 Message Date
Sei Lisa
dd1b7ed594 Fix llAngleBetween when given a quaternion with all zeros.
LSL behaves as if it was ZERO_ROTATION instead, so we fix it by creating a function that returns ZERO_ROTATION when given <0,0,0,0>. Use it for llRot2{Fwd,Left,Up} as well.
2017-01-23 00:08:24 +01:00
Sei Lisa
1262934baf 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 <filename unknown>:0
  at LindenLab.SecondLife.Library.llAbs (Int32 i) [0x00000] in <filename unknown>:0

So it's actually not computable. In LSO it returns -2147483648, though.
2017-01-22 19:54:01 +01:00
Sei Lisa
ac775c9999 Join Internal{Get|Delete}SubSequence, fixing a bug in Get.
llGetSubString and llList2List could produce output longer than the input for some params. Fix that, and join the functions into one unique function for uniformity. Also, get rid of the special case of empty elements, because it can be treated properly by the general case, and it's not so common as to merit special attention.
2017-01-22 18:08:44 +01:00
Sei Lisa
9b812a2d2a Add no-coverage markers to Windows-specific code.
It won't be reached. Also, simplify the expected errors line to make it shorter.
2017-01-22 01:32:50 +01:00
Sei Lisa
007a726bee Fix llUnescapeURL with % in place of the second hex character.
When the input was of the form e.g. "%4%40", the second "%" was erroneously starting another quoted character. LSL doesn't behave that way: parsing resumes without starting another quoted character. Disturbingly, the expected result in the corresponding test was wrong. Fixed both the test case and the code to match actual LSL behaviour.
2017-01-20 01:59:59 +01:00
Sei Lisa
b0f8b7036b A bit of reordering, to put some similar tests together. 2017-01-20 01:40:19 +01:00
Sei Lisa
551a6ece12 Make llGetListEntryType of a list-type element return 0 (TYPE_INVALID).
It was triggering ELSLInvalidType, which is not a good approach.
2017-01-20 01:18:13 +01:00
Sei Lisa
d1ff8a86dd Additional fixes to llBase64ToString behaviour.
llBase64ToString hid another surprise: characters in range from U+0000 to U+001F are substituted by "?" except for tabs (\x09), form feeds (\x0A), shift ins (\x0F) and unit separators (\x1F), which were kept verbatim. So, mimic this behaviour.
2017-01-19 07:00:06 +01:00
Sei Lisa
a6955c4057 Fix llGetListEntryType. 2017-01-19 04:46:57 +01:00
Sei Lisa
94550af95a Minor style change. 2017-01-19 03:31:02 +01:00
Sei Lisa
7c2b76949e Make one more llXorBase64[StringsCorrect] case computable.
When the input string is at most 1 byte (2 base64 characters), the result is computable because the first byte is always zero.
2017-01-19 02:58:42 +01:00
Sei Lisa
7f8cb4ec58 Fix llAbs corner case.
As an exception, llAbs(-2147483648) equals -2147483648.
2017-01-18 00:50:59 +01:00
Sei Lisa
a65300ed49 Typo in a comment. 2017-01-17 02:53:26 +01:00
Sei Lisa
c8bfd40c66 Ensure that floats are compared with 32-bit precision.
The equality operator was comparing the raw floats when two were given. Also, type() was called when it was not needed.
2017-01-17 02:38:52 +01:00
Sei Lisa
6591b5dfd8 Fix return type of cross product.
mod(Vector, Vector) was returning tuple, not Vector.
2017-01-17 02:22:10 +01:00
Sei Lisa
f657d3e875 Use hex notation for a denormal float. 2017-01-16 23:33:49 +01:00
Sei Lisa
1a06bf4eb9 Fix minus zero in llFrand().
llFrand returns minus zero when given a negative denormal.
2017-01-16 20:37:11 +01:00
Sei Lisa
4ec9396688 (float)"-NaN" should produce NaN, not Indet.
But (vector)"<-NaN, 0, 0>" produces Indet, not NaN.
2017-01-12 03:29:38 +01:00
Sei Lisa
19dec1d79e 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.
2017-01-07 20:46:14 +01:00
Sei Lisa
8609c38451 In LSO, lists of 1 element also evaluate to false (SVC-689). 2017-01-04 05:06:56 +01:00
Sei Lisa
e16fad0366 llXorBase64Strings and llModPow are not safe to precompute.
The reason is they have an embedded delay. A script might rely on it, therefore substituting the call with its value is not equivalent to leaving the call. They were both already excluded from the SEF table for the same reason.
2016-12-25 05:25:24 +01:00
Sei Lisa
d54ba42330 Fix more test failures on Windows.
On Windows, float('nan') produces Indeterminate. To fix, set Indet first and then set NaN to the opposite.
2016-12-22 06:05:47 +01:00
Sei Lisa
efcf1cb1df Fix llListSort problem on Windows.
Apparently, under Windows, Python does a UTF-16 word-by-word comparison when comparing two strings:

>>> u'\ud700' < u'\U0001d41a'
True
>>> u'\ue000' < u'\U0001d41a'
False

Fix it by encoding as UTF-32 big endian before comparison, when that happens.
2016-12-22 05:50:18 +01:00
Sei Lisa
91fd9734c8 Fix llRot2Fwd/llRot2Left/llRot2Up and add regression tests. 2016-12-22 03:06:56 +01:00
Sei Lisa
14488ddd92 Improve behaviour of llAtan2 to make it closer to SL's.
Especially regarding NaN inputs. Add regression tests.
2016-12-22 01:08:07 +01:00
Sei Lisa
159fae90bf Improve llFrand.
- Remove it from lslextrafuncs, and move all the code to lslbasefuncs.
- Make it behave like SL's more accurately. Denormals return 0 always in SL.
- Use int() for truncation rather then floor/ceil.
- Add test cases.
2016-12-22 01:05:21 +01:00
Sei Lisa
fc97ce42df Be explicit about corner cases for llFrand.
inf and nan already did the right thing in Python, but just in case that doesn't happen in all platforms, we handle them explicitly. Also, that will make it more immune to bugs in future.
2016-12-21 21:49:43 +01:00
Sei Lisa
2327613423 Follow-up to ba9511e: Fix rounding of result. 2016-12-21 20:26:40 +01:00
Sei Lisa
6879037735 Fix type conversion on calling LSL functions.
We had a big chaos with type conversion. That caused a bug where passing a key to a function that required a string, or vice versa, crashed the script.

Diminish the chaos by modifying the parameters just prior to invocation (in lslfoldconst). We also remove the, now unnecessary, calls to force floats, either alone or within vectors or quaternions.
2016-12-21 06:01:03 +01:00
Sei Lisa
5105cee2e4 We already had imported hashlib. 2016-12-21 02:45:17 +01:00
Sei Lisa
7ebd68c7b2 llGenerateKey() returns key, not string 2016-12-21 01:32:54 +01:00
Sei Lisa
ba9511e2ff Implement llFrand and llGenerateKey when in Calc mode. 2016-12-21 01:18:25 +01:00
Sei Lisa
991e811f2d Fix Python gotcha with module globals, and missing 'cond' in lslextrafuncs.
The previous commit didn't work as expected. "from module import var" freezes the value at load time; changing it later has no effect. A reference to the module needs to be used.

Fix that and the similar problem with LSO. Also revert some "from lslcommon import *" introduced earlier.

That also revealed another bug about missing 'cond' in the import list of lslextrafuncs. This should fix all functions that return values on null key input.
2016-12-21 00:22:49 +01:00
Sei Lisa
39261cbfc8 Make Unicode some strings that should be, and improve error reporting in builtins.txt
Also work towards the convention that strings that represent text (possibly translatable) are in double quotes, not single.
2016-12-20 20:13:53 +01:00
Sei Lisa
43beb767f2 Fix llBase64ToString's behaviour with invalid UTF-8.
llBase64ToString doesn't behave like llUnescapeURL wrt invalid UTF-8. First, the last NUL if any is removed, and the remaining NULs are converted to "?". Second, all overlong sequences are converted to a single "?", *including the 5- and 6-byte UTF-8*.

Implement this behavour and the corresponding unit tests.
2016-12-13 15:04:02 +01:00
Sei Lisa
e8201d6956 Err when invalid UTF-8 should have been generated in LSO mode.
LSO strings are byte arrays, but our strings are made for Mono which uses Unicode, and invalid UTF-8 sequences can't be stored in Unicode without using a custom representation.

One possible representation is to only use the codepoints 0-255 in the Unicode string, to avoid supporting multiple types for strings. Something to study in future.
2016-12-13 14:26:48 +01:00
Sei Lisa
b593141f9f Fix UTF-8 in the surrogate range passing as good.
Our UTF-8 validity checker failed to recognize that characters in the surrogate range (D800-DFFF) were invalid. Fortunately, Python 2 is happy about that, therefore it doesn't crash (Python 3 fixed that range too). Unfortunately, SL isn't, therefore we fix it.

Added corresponding unit tests.
2016-12-13 03:30:32 +01:00
Sei Lisa
47013f87e2 Fix minor typo in a comment. 2016-11-14 03:10:29 +01:00
Sei Lisa
74115345f0 Fix blunder in operator priority
-a//-b did the wrong thing. Use -(a//-b) and add corresponding regression tests.
2016-11-06 04:09:43 +01:00
Sei Lisa
79dff25769 Update copyright years of some files; add legalese to seftable.txt 2016-06-27 20:06:41 +02:00
Sei Lisa
ee091c63a6 Someone's been misusing Python's re.match... O:) 2016-06-26 22:33:10 +02:00
Sei Lisa
51a7e6d199 Fix bug with reduction, and remove useless code.
Oops, we have to reduce *after* testing for range!

Also, the special cases for the tangent are unnecessary, because the results are already correct.
2016-05-21 04:16:34 +02:00
Sei Lisa
9cf9478270 Improve the (in)accuracy of llSin, llCos, llTan
All three functions have in SL the Intel problem of inaccuracy with high values. Since we work in single precision, it's barely detectable usually, but for large input numbers the difference between the imprecise results of SL and the more accurate results of recent glibc become more obvious.

This change brings back the Intel inaccuracy, even across systems (different versions of Python/C might behave differently otherwise).

Reference:
https://randomascii.wordpress.com/2014/10/09/intel-underestimates-error-bounds-by-1-3-quintillion/
2016-05-21 03:56:27 +02:00
Sei Lisa
e40c52075b Make ForceFloat more robust on non-float input.
It was designed so that only ints and floats should be accepted. But for safety, and for reuse, make that "any non-float" so that long integers are also truncated to F32.
2016-05-21 03:10:31 +02:00
Sei Lisa
13663ff077 -0x1p63 is not included in the valid range of trig functions. 2016-05-21 02:50:55 +02:00
Sei Lisa
7b70bfe55f Fix precision error in llTan special values. 2016-05-21 02:27:15 +02:00
Sei Lisa
4172f02439 One more way to transform a float to single (commented out) 2016-05-21 01:59:05 +02:00
Sei Lisa
60f257279b Use math.copysign to distinguish indeterminates
We were using a very dubious method to distinguish an indeterminate from a NaN, via struct.unpack. Turns out that math.copysign gets the job done and seems more robust.
2016-05-15 19:55:45 +02:00
Sei Lisa
b06ac33b5f Fix misspelling in the latest commit. 2016-05-15 18:44:45 +02:00
Sei Lisa
23b27bd3af Produce more math errors in division
Besides dividing by zero, any result producing NaN including inf/inf, NaN/anything, anything/NaN causes a math error as well. We only contemplated NaN/anything and neglected the rest, so we generalize it.
2016-05-15 18:21:24 +02:00