@@ -8,7 +8,7 @@ namespace Python.Runtime
8
8
{
9
9
static partial class InternString
10
10
{
11
- private static readonly Dictionary < string , PyObject > _string2interns = new ( ) ;
11
+ private static readonly Dictionary < string , PyString > _string2interns = new ( ) ;
12
12
private static readonly Dictionary < IntPtr , string > _intern2strings = new ( ) ;
13
13
const BindingFlags PyIdentifierFieldFlags = BindingFlags . Static | BindingFlags . NonPublic ;
14
14
@@ -37,7 +37,9 @@ public static void Initialize()
37
37
Type type = typeof ( PyIdentifier ) ;
38
38
foreach ( string name in _builtinNames )
39
39
{
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 ( ) ) ;
41
43
SetIntern ( name , op ) ;
42
44
var field = type . GetField ( "f" + name , PyIdentifierFieldFlags ) ! ;
43
45
field . SetValue ( null , op . rawPtr ) ;
@@ -48,8 +50,8 @@ public static void Shutdown()
48
50
{
49
51
foreach ( var entry in _string2interns )
50
52
{
51
- entry . Value . Dispose ( ) ;
52
53
var field = typeof ( PyIdentifier ) . GetField ( "f" + entry . Value , PyIdentifierFieldFlags ) ! ;
54
+ entry . Value . Dispose ( ) ;
53
55
field . SetValue ( null , IntPtr . Zero ) ;
54
56
}
55
57
@@ -72,7 +74,7 @@ public static bool TryGetInterned(BorrowedReference op, out string s)
72
74
return _intern2strings . TryGetValue ( op . DangerousGetAddress ( ) , out s ) ;
73
75
}
74
76
75
- private static void SetIntern ( string s , PyObject op )
77
+ private static void SetIntern ( string s , PyString op )
76
78
{
77
79
_string2interns . Add ( s , op ) ;
78
80
_intern2strings . Add ( op . rawPtr , s ) ;
0 commit comments