@@ -8,7 +8,7 @@ namespace Python.Runtime
88{
99 static partial class InternString
1010 {
11- private static readonly Dictionary < string , PyObject > _string2interns = new ( ) ;
11+ private static readonly Dictionary < string , PyString > _string2interns = new ( ) ;
1212 private static readonly Dictionary < IntPtr , string > _intern2strings = new ( ) ;
1313 const BindingFlags PyIdentifierFieldFlags = BindingFlags . Static | BindingFlags . NonPublic ;
1414
@@ -37,7 +37,9 @@ public static void Initialize()
3737 Type type = typeof ( PyIdentifier ) ;
3838 foreach ( string name in _builtinNames )
3939 {
40- var op = Runtime . PyUnicode_InternFromString ( name ) . MoveToPyObject ( ) ;
40+ NewReference pyStr = Runtime . PyUnicode_InternFromString ( name ) ;
41+ var op = new PyString ( pyStr . StealOrThrow ( ) ) ;
42+ Debug . Assert ( name == op . ToString ( ) ) ;
4143 SetIntern ( name , op ) ;
4244 var field = type . GetField ( "f" + name , PyIdentifierFieldFlags ) ! ;
4345 field . SetValue ( null , op . rawPtr ) ;
@@ -48,8 +50,8 @@ public static void Shutdown()
4850 {
4951 foreach ( var entry in _string2interns )
5052 {
51- entry . Value . Dispose ( ) ;
5253 var field = typeof ( PyIdentifier ) . GetField ( "f" + entry . Value , PyIdentifierFieldFlags ) ! ;
54+ entry . Value . Dispose ( ) ;
5355 field . SetValue ( null , IntPtr . Zero ) ;
5456 }
5557
@@ -72,7 +74,7 @@ public static bool TryGetInterned(BorrowedReference op, out string s)
7274 return _intern2strings . TryGetValue ( op . DangerousGetAddress ( ) , out s ) ;
7375 }
7476
75- private static void SetIntern ( string s , PyObject op )
77+ private static void SetIntern ( string s , PyString op )
7678 {
7779 _string2interns . Add ( s , op ) ;
7880 _intern2strings . Add ( op . rawPtr , s ) ;
0 commit comments