Change strategy for the checking of function input types.

Rather than assert that the types are correct, use the force type functions on the parameters:
ff, fk, fs, q2f, v2f, and the new fi, fl.

These functions have also been modified to ensure that the input type supports an implicit typecast to the target type and perform it, or emit ELSLInvalidType otherwise, rather than an assertion failure. fl in particular returns the original list if it isn't changed, or a copy if it is.

A couple bugs were found in testfuncs.py as a result, which have been fixed as well. A test has been added to ensure that the exception that caught these bugs remains in place.

The isxxxx functions are no longer necessary, so they are removed. Same goes for the painful cast handling process in foldconst, which was basically performing this task, and not necessarily well.

This approach is much more robust and should have been used since the beginning, but I didn't figure it out then.
This commit is contained in:
Sei Lisa 2017-10-12 16:14:48 +02:00
parent 41d2c68cf8
commit 9e7a5d1cdf
5 changed files with 218 additions and 226 deletions

View file

@ -20,7 +20,7 @@
import re
import math
from lslcommon import *
from lslbasefuncs import llStringTrim, isstring, islist, InternalTypecast
from lslbasefuncs import llStringTrim, fs, fl, InternalTypecast
# INCOMPATIBILITY NOTE: The JSON functions in SL have very weird behaviour
# in corner cases. Despite our best efforts, that behaviour is not replicated
@ -494,7 +494,7 @@ def InternalJson2Elem(json):
return json
def llJson2List(json):
assert isstring(json)
json = fs(json)
json = llStringTrim(json, 3) # STRING_TRIM
if json == u'':
@ -577,8 +577,8 @@ def llJson2List(json):
return [InternalJson2Elem(json)]
def llJsonGetValue(json, lst):
assert isstring(json)
assert islist(lst)
json = fs(json)
lst = fl(lst)
return InternalJsonFindValue(json, lst, ReturnsToken=False)
# llJsonSetValue was finally not implemented. This is a failed attempt
@ -613,9 +613,9 @@ def llJsonGetValue(json, lst):
def llJsonSetValue(json, lst, val):
assert isstring(json)
assert islist(lst)
assert isstring(val)
json = fs(json)
lst = fl(lst)
val = fs(val)
if lst == []:
# [] replaces the entire string no matter if it was invalid
if val == JSON_DELETE:
@ -631,16 +631,16 @@ def llJsonSetValue(json, lst, val):
'''
def llJsonValueType(json, lst):
assert isstring(json)
assert islist(lst)
json = fs(json)
lst = fl(lst)
ret = InternalJsonFindValue(json, lst, ReturnsToken=True)
if ret == JSON_INVALID:
return ret
return ret[2]
def llList2Json(kind, lst):
assert isstring(kind)
assert islist(lst)
kind = fs(kind)
lst = fl(lst)
if kind == JSON_OBJECT:
ret = u'{'