@@ -76,7 +76,6 @@ internal static partial class TypeOffset
7676 internal static class ManagedDataOffsets
7777 {
7878 public static int Magic { get ; internal set ; }
79- public static readonly Dictionary < string , int > NameMapping = new Dictionary < string , int > ( ) ;
8079
8180 static class DataOffsets
8281 {
@@ -95,17 +94,10 @@ static DataOffsets()
9594
9695 static ManagedDataOffsets ( )
9796 {
98- NameMapping = TypeOffset . GetOffsets ( ) ;
99-
10097 FieldInfo [ ] fields = typeof ( DataOffsets ) . GetFields ( BindingFlags . Static | BindingFlags . Public ) ;
10198 size = fields . Length * IntPtr . Size ;
10299 }
103100
104- public static int GetSlotOffset ( string name )
105- {
106- return NameMapping [ name ] ;
107- }
108-
109101 private static int BaseOffset ( IntPtr type )
110102 {
111103 Debug . Assert ( type != IntPtr . Zero ) ;
@@ -135,30 +127,15 @@ internal static class OriginalObjectOffsets
135127 {
136128 static OriginalObjectOffsets ( )
137129 {
138- int size = IntPtr . Size ;
139- var n = 0 ; // Py_TRACE_REFS add two pointers to PyObject_HEAD
140- #if PYTHON_WITH_PYDEBUG
141- _ob_next = 0 ;
142- _ob_prev = 1 * size ;
143- n = 2 ;
144- #endif
145- ob_refcnt = ( n + 0 ) * size ;
146- ob_type = ( n + 1 ) * size ;
130+ ob_refcnt = Native . ABI . ObjectHeadOffset ;
131+ ob_type = ob_refcnt + IntPtr . Size ;
132+ size = ob_type + IntPtr . Size ;
147133 }
148134
149135 public static int Size { get { return size ; } }
150136
151- private static readonly int size =
152- #if PYTHON_WITH_PYDEBUG
153- 4 * IntPtr . Size ;
154- #else
155- 2 * IntPtr . Size ;
156- #endif
157-
158- #if PYTHON_WITH_PYDEBUG
159- public static int _ob_next ;
160- public static int _ob_prev ;
161- #endif
137+ private static readonly int size ;
138+
162139 public static int ob_refcnt ;
163140 public static int ob_type ;
164141 }
@@ -168,10 +145,6 @@ internal class ObjectOffset
168145 {
169146 static ObjectOffset ( )
170147 {
171- #if PYTHON_WITH_PYDEBUG
172- _ob_next = OriginalObjectOffsets . _ob_next ;
173- _ob_prev = OriginalObjectOffsets . _ob_prev ;
174- #endif
175148 ob_refcnt = OriginalObjectOffsets . ob_refcnt ;
176149 ob_type = OriginalObjectOffsets . ob_type ;
177150
@@ -198,10 +171,6 @@ public static int Size(IntPtr pyType)
198171 return size ;
199172 }
200173
201- #if PYTHON_WITH_PYDEBUG
202- public static int _ob_next ;
203- public static int _ob_prev ;
204- #endif
205174 public static int ob_refcnt ;
206175 public static int ob_type ;
207176 private static readonly int size ;
@@ -256,17 +225,12 @@ static BytesOffset()
256225 int size = IntPtr . Size ;
257226 for ( int i = 0 ; i < fi . Length ; i ++ )
258227 {
259- fi [ i ] . SetValue ( null , i * size ) ;
228+ fi [ i ] . SetValue ( null , i * size + Native . ABI . ObjectHeadOffset ) ;
260229 }
261230 }
262231
263232 /* The *real* layout of a type object when allocated on the heap */
264233 //typedef struct _heaptypeobject {
265- #if PYTHON_WITH_PYDEBUG
266- /* _PyObject_HEAD_EXTRA defines pointers to support a doubly-linked list of all live heap objects. */
267- public static int _ob_next = 0 ;
268- public static int _ob_prev = 0 ;
269- #endif
270234 // PyObject_VAR_HEAD {
271235 // PyObject_HEAD {
272236 public static int ob_refcnt = 0 ;
0 commit comments