@@ -141,16 +141,20 @@ extern "C"
141
141
}
142
142
}
143
143
144
- static PyTypeObject static_data_object = {
145
- PyVarObject_HEAD_INIT (NULL , 0 )
146
- .tp_name = const_cast <char *>(" Boost.Python.StaticProperty" ),
147
- .tp_basicsize = sizeof (propertyobject),
148
- .tp_flags = Py_TPFLAGS_DEFAULT // | Py_TPFLAGS_HAVE_GC
149
- | Py_TPFLAGS_BASETYPE, /* tp_flags */
150
- .tp_descr_get = static_data_descr_get,
151
- .tp_descr_set = static_data_descr_set,
152
- .tp_init = property_init,
144
+ static PyType_Slot static_data_object_slots[] = {
145
+ {Py_tp_descr_get, (void *)static_data_descr_get},
146
+ {Py_tp_descr_set, (void *)static_data_descr_set},
147
+ {Py_tp_init, (void *)property_init},
153
148
};
149
+ static PyType_Spec static_data_object_spec = {
150
+ const_cast <char *>(" Boost.Python.StaticProperty" ),
151
+ sizeof (propertyobject),
152
+ 0 ,
153
+ Py_TPFLAGS_DEFAULT // | Py_TPFLAGS_HAVE_GC
154
+ | Py_TPFLAGS_BASETYPE,
155
+ static_data_object_slots,
156
+ };
157
+
154
158
155
159
namespace objects
156
160
{
@@ -165,14 +169,16 @@ namespace objects
165
169
166
170
BOOST_PYTHON_DECL PyObject* static_data ()
167
171
{
168
- if (static_data_object.tp_dict == 0 )
172
+
173
+ PyTypeObject* not_static_data_object = (PyTypeObject*)PyType_FromSpec (&static_data_object_spec);
174
+ if (not_static_data_object->tp_dict == 0 )
169
175
{
170
- Py_TYPE (&static_data_object ) = &PyType_Type;
171
- static_data_object. tp_base = &PyProperty_Type;
172
- if (PyType_Ready (&static_data_object ))
176
+ Py_TYPE (not_static_data_object ) = &PyType_Type;
177
+ not_static_data_object-> tp_base = &PyProperty_Type;
178
+ if (PyType_Ready (not_static_data_object ))
173
179
return 0 ;
174
180
}
175
- return upcast<PyObject>(&static_data_object );
181
+ return upcast<PyObject>(not_static_data_object );
176
182
}
177
183
}
178
184
@@ -206,21 +212,26 @@ extern "C"
206
212
}
207
213
}
208
214
209
- static PyTypeObject class_metatype_object = {
210
- PyVarObject_HEAD_INIT (NULL , 0 )
211
- .tp_name = const_cast <char *>(" Boost.Python.class" ),
212
- .tp_basicsize = PyType_Type.tp_basicsize ,
213
- .tp_setattro = class_setattro,
214
- .tp_flags = Py_TPFLAGS_DEFAULT // | Py_TPFLAGS_HAVE_GC
215
- | Py_TPFLAGS_BASETYPE, /* tp_flags */
216
- .tp_is_gc = (inquiry)type_is_gc,
215
+ static PyType_Slot class_metatype_object_slots[] = {
216
+ {Py_tp_setattro, (void *)class_setattro},
217
+ {Py_tp_is_gc, (void *)type_is_gc},
218
+ };
219
+ static PyType_Spec class_metatype_object_spec = {
220
+ const_cast <char *>(" Boost.Python.class" ),
221
+ PyType_Type.tp_basicsize ,
222
+ 0 ,
223
+ Py_TPFLAGS_DEFAULT // | Py_TPFLAGS_HAVE_GC
224
+ | Py_TPFLAGS_BASETYPE,
225
+ class_metatype_object_slots,
217
226
};
218
227
228
+
219
229
// Install the instance data for a C++ object into a Python instance
220
230
// object.
221
231
void instance_holder::install (PyObject* self) throw()
222
232
{
223
- assert (PyType_IsSubtype (Py_TYPE (Py_TYPE (self)), &class_metatype_object));
233
+ PyTypeObject* class_metatype_object = (PyTypeObject*)PyType_FromSpec (&class_metatype_object_spec);
234
+ assert (PyType_IsSubtype (Py_TYPE (Py_TYPE (self)), class_metatype_object));
224
235
m_next = ((objects::instance<>*)self)->objects ;
225
236
((objects::instance<>*)self)->objects = this ;
226
237
}
@@ -231,14 +242,15 @@ namespace objects
231
242
// Get the metatype object for all extension classes.
232
243
BOOST_PYTHON_DECL type_handle class_metatype ()
233
244
{
234
- if (class_metatype_object.tp_dict == 0 )
245
+ PyTypeObject* class_metatype_object = (PyTypeObject*)PyType_FromSpec (&class_metatype_object_spec);
246
+ if (class_metatype_object->tp_dict == 0 )
235
247
{
236
- Py_TYPE (& class_metatype_object) = &PyType_Type;
237
- class_metatype_object. tp_base = &PyType_Type;
238
- if (PyType_Ready (& class_metatype_object))
248
+ Py_TYPE (class_metatype_object) = &PyType_Type;
249
+ class_metatype_object-> tp_base = &PyType_Type;
250
+ if (PyType_Ready (class_metatype_object))
239
251
return type_handle ();
240
252
}
241
- return type_handle (borrowed (& class_metatype_object));
253
+ return type_handle (borrowed (class_metatype_object));
242
254
}
243
255
extern " C"
244
256
{
@@ -331,40 +343,45 @@ namespace objects
331
343
{0 , 0 , 0 , 0 , 0 }
332
344
};
333
345
334
- static PyTypeObject class_type_object = {
335
- PyVarObject_HEAD_INIT ( NULL , 0 )
336
- . tp_name = const_cast < char *>( " Boost.Python.instance " ) ,
337
- . tp_basicsize = offsetof (instance<>,storage) ,
338
- . tp_itemsize = 1 ,
339
- . tp_dealloc = instance_dealloc ,
340
- . tp_flags = Py_TPFLAGS_DEFAULT // | Py_TPFLAGS_HAVE_GC
341
- | Py_TPFLAGS_BASETYPE, /* tp_flags */
342
- . tp_weaklistoffset = offsetof (instance<>,weakrefs ),
343
- . tp_members = instance_members ,
344
- . tp_getset = instance_getsets ,
345
- . tp_dictoffset = offsetof (instance<>,dict),
346
- . tp_alloc = PyType_GenericAlloc ,
347
- . tp_new = instance_new ,
346
+ static PyType_Slot class_type_object_slots[] = {
347
+ {Py_tp_dealloc, ( void *)instance_dealloc},
348
+ {Py_tp_members, instance_members} ,
349
+ {Py_tp_getset, instance_getsets} ,
350
+ {Py_tp_alloc, ( void *)PyType_GenericAlloc} ,
351
+ {Py_tp_new, ( void *)instance_new} ,
352
+ };
353
+ static PyType_Spec class_type_object_spec = {
354
+ const_cast < char *>( " Boost.Python.instance " ),
355
+ offsetof (instance<>,storage) ,
356
+ 1 ,
357
+ Py_TPFLAGS_DEFAULT // | Py_TPFLAGS_HAVE_GC
358
+ | Py_TPFLAGS_BASETYPE ,
359
+ class_type_object_slots ,
348
360
};
349
361
362
+
350
363
BOOST_PYTHON_DECL type_handle class_type ()
351
364
{
352
- if (class_type_object.tp_dict == 0 )
365
+ PyTypeObject* class_type_object = (PyTypeObject*)PyType_FromSpec (&class_type_object_spec);
366
+ class_type_object->tp_weaklistoffset = offsetof (instance<>,weakrefs);
367
+ class_type_object->tp_dictoffset = offsetof (instance<>,dict);
368
+ if (class_type_object->tp_dict == 0 )
353
369
{
354
370
Py_TYPE (&class_type_object) = incref (class_metatype ().get ());
355
- class_type_object. tp_base = &PyBaseObject_Type;
356
- if (PyType_Ready (& class_type_object))
371
+ class_type_object-> tp_base = &PyBaseObject_Type;
372
+ if (PyType_Ready (class_type_object))
357
373
return type_handle ();
358
- // class_type_object. tp_setattro = class_setattro;
374
+ // class_type_object-> tp_setattro = class_setattro;
359
375
}
360
- return type_handle (borrowed (& class_type_object));
376
+ return type_handle (borrowed (class_type_object));
361
377
}
362
378
363
379
BOOST_PYTHON_DECL void *
364
380
find_instance_impl (PyObject* inst, type_info type, bool null_shared_ptr_only)
365
381
{
382
+ PyTypeObject* class_metatype_object = (PyTypeObject*)PyType_FromSpec (&class_metatype_object_spec);
366
383
if (!Py_TYPE (Py_TYPE (inst)) ||
367
- !PyType_IsSubtype (Py_TYPE (Py_TYPE (inst)), & class_metatype_object))
384
+ !PyType_IsSubtype (Py_TYPE (Py_TYPE (inst)), class_metatype_object))
368
385
return 0 ;
369
386
370
387
instance<>* self = reinterpret_cast <instance<>*>(inst);
@@ -440,8 +457,8 @@ namespace objects
440
457
for (ssize_t i = 1 ; i <= num_bases; ++i)
441
458
{
442
459
type_handle c = (i >= static_cast <ssize_t >(num_types)) ? class_type () : get_class (types[i]);
443
- // PyTuple_SetItem steals this reference
444
- PyTuple_SetItem (bases.get (), static_cast <ssize_t >(i - 1 ), upcast<PyObject>(c.release ()));
460
+ // PyTuple_SET_ITEM steals this reference
461
+ PyTuple_SET_ITEM (bases.get (), static_cast <ssize_t >(i - 1 ), upcast<PyObject>(c.release ()));
445
462
}
446
463
447
464
// Call the class metatype to create a new class
@@ -609,7 +626,8 @@ namespace objects
609
626
610
627
void * instance_holder::allocate (PyObject* self_, std::size_t holder_offset, std::size_t holder_size)
611
628
{
612
- assert (PyType_IsSubtype (Py_TYPE (Py_TYPE (self_)), &class_metatype_object));
629
+ assert (PyType_IsSubtype (Py_TYPE (Py_TYPE (self_)),
630
+ (PyTypeObject*)PyType_FromSpec (&class_metatype_object_spec)));
613
631
objects::instance<>* self = (objects::instance<>*)self_;
614
632
615
633
int total_size_needed = holder_offset + holder_size;
@@ -634,7 +652,8 @@ void* instance_holder::allocate(PyObject* self_, std::size_t holder_offset, std:
634
652
635
653
void instance_holder::deallocate (PyObject* self_, void * storage) throw()
636
654
{
637
- assert (PyType_IsSubtype (Py_TYPE (Py_TYPE (self_)), &class_metatype_object));
655
+ assert (PyType_IsSubtype (Py_TYPE (Py_TYPE (self_)),
656
+ (PyTypeObject*)PyType_FromSpec (&class_metatype_object_spec)));
638
657
objects::instance<>* self = (objects::instance<>*)self_;
639
658
if (storage != (char *)self + Py_SIZE (self))
640
659
{
0 commit comments