File tree 3 files changed +11
-4
lines changed
3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -185,7 +185,10 @@ public static int magic(IntPtr type)
185
185
186
186
public static int TypeDictOffset ( IntPtr type )
187
187
{
188
- return ManagedDataOffsets . DictOffset ( type ) ;
188
+ Debug . Assert ( TypeOffset . tp_dictoffset > 0 ) ;
189
+ int dictOffset = Marshal . ReadInt32 ( type , TypeOffset . tp_dictoffset ) ;
190
+ Debug . Assert ( dictOffset > 0 ) ;
191
+ return dictOffset ;
189
192
}
190
193
191
194
public static int Size ( IntPtr pyType )
Original file line number Diff line number Diff line change @@ -260,13 +260,17 @@ protected static void ClearObjectDict(IntPtr ob)
260
260
protected static IntPtr GetObjectDict ( IntPtr ob )
261
261
{
262
262
IntPtr type = Runtime . PyObject_TYPE ( ob ) ;
263
- return Marshal . ReadIntPtr ( ob , ObjectOffset . TypeDictOffset ( type ) ) ;
263
+ int dictOffset = ObjectOffset . TypeDictOffset ( type ) ;
264
+ if ( dictOffset == 0 ) return IntPtr . Zero ;
265
+ return Marshal . ReadIntPtr ( ob , dictOffset ) ;
264
266
}
265
267
266
268
protected static void SetObjectDict ( IntPtr ob , IntPtr value )
267
269
{
268
270
IntPtr type = Runtime . PyObject_TYPE ( ob ) ;
269
- Marshal . WriteIntPtr ( ob , ObjectOffset . TypeDictOffset ( type ) , value ) ;
271
+ int dictOffset = ObjectOffset . TypeDictOffset ( type ) ;
272
+ Debug . Assert ( dictOffset > 0 ) ;
273
+ Marshal . WriteIntPtr ( ob , dictOffset , value ) ;
270
274
}
271
275
}
272
276
}
Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ internal static IntPtr CreateType(Type impl)
165
165
// Set tp_basicsize to the size of our managed instance objects.
166
166
Marshal . WriteIntPtr ( type , TypeOffset . tp_basicsize , ( IntPtr ) ob_size ) ;
167
167
168
- var offset = ( IntPtr ) ObjectOffset . TypeDictOffset ( type ) ;
168
+ var offset = ( IntPtr ) ManagedDataOffsets . DictOffset ( type ) ;
169
169
Marshal . WriteIntPtr ( type , TypeOffset . tp_dictoffset , offset ) ;
170
170
171
171
SlotsHolder slotsHolder = CreateSolotsHolder ( type ) ;
You can’t perform that action at this time.
0 commit comments