Testsuite gets a predictable ordered array for comparison
This patch fixes a `TypeError` in the GCC testsuite by ensuring arrays used for comparison have a predictable order without attempting to hash dictionaries.
The GCC testsuite’s test-p1689.py script previously encountered a TypeError when attempting to compare arrays that contained unhashable dictionary objects. This occurred because Python’s set() function, used for comparison, requires its elements to be hashable. To resolve this, the patch now converts dictionary elements to string representations before sorting the array and then back to objects, allowing for proper comparison without type errors.
In Details
The g++.dg/modules/test-p1689.py test in the GCC testsuite, which is the only known Python script within the testsuite, was failing due to a TypeError: unhashable type: 'dict'. This happened during the validate_p1689 function when compare_json passed a list of dictionaries to set(). The fix explicitly transforms the dictionary elements within the array into string representations to make them hashable for sorting, ensuring a predictable order for comparison without directly hashing the dictionaries, which would otherwise lead to runtime errors.
For Context
When GCC runs its tests, it uses a variety of scripts, including some written in Python. One such Python script in the C++ modules testsuite was failing because it tried to compare lists of complex data (dictionaries) in a way that Python doesn't allow directly. Specifically, it was attempting to create a 'set' from a list that contained dictionaries, but dictionaries are not 'hashable' in Python, meaning they can't be uniquely identified in the way a set requires. This patch introduces a step to convert these complex data structures into a string format, which can be easily compared and sorted, and then converts them back. This ensures the test comparisons work correctly and consistently without errors.