Branch: Tag:

2020-10-25

2020-10-25 21:18:32 by Arne Goedeke <el@laramies.com>

Standards.JSON.encode: only cycle check complex types

Since the reorganization of the enum PIKE_TYPE, complex types were
no longer starting at 0. Since then, checking for
TYPEOF(svalue) < MAX_COMPLEX was not enough to decide if a given type
may be part of a cyclic structure.

In the JSON encoder this led to integers and floats being interpreted
as pointers an added to the cycle check hash. This could lead to false
negatives in cycle detection if a JSON structure contains an interger or
floating point number which has the same byte sequence as the pointer to
one of its parent structures. It also made JSON encoding slower.

This commit introduces a new function IS_COMPLEX_TYPE to correctly check
if a given type is complex and uses that in the JSON encoder.

357:      #define REFCOUNTED_TYPE(T) (((T) & ~(MIN_REF_TYPE - 1)) == MIN_REF_TYPE)    + /** +  * Returns true if the given type is one of the complex types defined +  * by BIT_COMPLEX. +  */ + static inline int IS_COMPLEX_TYPE(enum PIKE_TYPE type) { +  return type <= MAX_TYPE && (1 << type) & BIT_COMPLEX; + } +    #define NUMBER_NUMBER 0   #define NUMBER_UNDEFINED 1   #define NUMBER_DESTRUCTED 2