File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -800,6 +800,24 @@ def test_c_complex_round_trip(self):
800800 round_trip = struct .unpack (f , struct .pack (f , z ))[0 ]
801801 self .assertComplexesAreIdentical (z , round_trip )
802802
803+ def test_endian_table_init_subinterpreters (self ):
804+ # Verify that struct works correctly in subinterpreters after
805+ # once-only endian table initialization (gh-140260).
806+ # Use struct in the main interpreter first.
807+ self .assertEqual (struct .unpack ('>i' , struct .pack ('>i' , 1 ))[0 ], 1 )
808+ self .assertEqual (struct .unpack ('<i' , struct .pack ('<i' , 1 ))[0 ], 1 )
809+
810+ code = (
811+ "import struct\n "
812+ "x = struct.pack('>i', 1)\n "
813+ "assert struct.unpack('>i', x)[0] == 1\n "
814+ "y = struct.pack('<i', 1)\n "
815+ "assert struct.unpack('<i', y)[0] == 1\n "
816+ )
817+ for _ in range (3 ):
818+ ret = support .run_in_subinterp (code )
819+ self .assertEqual (ret , 0 )
820+
803821
804822class UnpackIteratorTest (unittest .TestCase ):
805823 """
You can’t perform that action at this time.
0 commit comments