@@ -53,7 +53,7 @@ inline PyTypeObject *make_static_property_type() {
53
53
issue no Python C API calls which could potentially invoke the
54
54
garbage collector (the GC will call type_traverse(), which will in
55
55
turn find the newly constructed type in an invalid state) */
56
- auto heap_type = ( PyHeapTypeObject *) PyType_Type.tp_alloc (&PyType_Type, 0 );
56
+ auto heap_type = reinterpret_cast < PyHeapTypeObject *>( PyType_Type.tp_alloc (&PyType_Type, 0 ) );
57
57
if (!heap_type)
58
58
pybind11_fail (" make_static_property_type(): error allocating type!" );
59
59
@@ -72,7 +72,7 @@ inline PyTypeObject *make_static_property_type() {
72
72
if (PyType_Ready (type) < 0 )
73
73
pybind11_fail (" make_static_property_type(): failure in PyType_Ready()!" );
74
74
75
- setattr (( PyObject *) type, " __module__" , str (" pybind11_builtins" ));
75
+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (" pybind11_builtins" ));
76
76
PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
77
77
78
78
return type;
@@ -192,7 +192,7 @@ inline PyTypeObject* make_default_metaclass() {
192
192
issue no Python C API calls which could potentially invoke the
193
193
garbage collector (the GC will call type_traverse(), which will in
194
194
turn find the newly constructed type in an invalid state) */
195
- auto heap_type = ( PyHeapTypeObject *) PyType_Type.tp_alloc (&PyType_Type, 0 );
195
+ auto heap_type = reinterpret_cast < PyHeapTypeObject *>( PyType_Type.tp_alloc (&PyType_Type, 0 ) );
196
196
if (!heap_type)
197
197
pybind11_fail (" make_default_metaclass(): error allocating metaclass!" );
198
198
@@ -216,7 +216,7 @@ inline PyTypeObject* make_default_metaclass() {
216
216
if (PyType_Ready (type) < 0 )
217
217
pybind11_fail (" make_default_metaclass(): failure in PyType_Ready()!" );
218
218
219
- setattr (( PyObject *) type, " __module__" , str (" pybind11_builtins" ));
219
+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (" pybind11_builtins" ));
220
220
PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
221
221
222
222
return type;
@@ -228,7 +228,7 @@ inline PyTypeObject* make_default_metaclass() {
228
228
inline void traverse_offset_bases (void *valueptr, const detail::type_info *tinfo, instance *self,
229
229
bool (*f)(void * /* parentptr*/ , instance * /* self*/ )) {
230
230
for (handle h : reinterpret_borrow<tuple>(tinfo->type ->tp_bases )) {
231
- if (auto parent_tinfo = get_type_info (( PyTypeObject *) h.ptr ())) {
231
+ if (auto parent_tinfo = get_type_info (reinterpret_cast < PyTypeObject *>( h.ptr () ))) {
232
232
for (auto &c : parent_tinfo->implicit_casts ) {
233
233
if (c.first == tinfo->cpptype ) {
234
234
auto *parentptr = c.second (valueptr);
@@ -403,7 +403,7 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
403
403
issue no Python C API calls which could potentially invoke the
404
404
garbage collector (the GC will call type_traverse(), which will in
405
405
turn find the newly constructed type in an invalid state) */
406
- auto heap_type = ( PyHeapTypeObject *) metaclass->tp_alloc (metaclass, 0 );
406
+ auto heap_type = reinterpret_cast < PyHeapTypeObject *>( metaclass->tp_alloc (metaclass, 0 ) );
407
407
if (!heap_type)
408
408
pybind11_fail (" make_object_base_type(): error allocating type!" );
409
409
@@ -428,11 +428,11 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
428
428
if (PyType_Ready (type) < 0 )
429
429
pybind11_fail (" PyType_Ready failed in make_object_base_type():" + error_string ());
430
430
431
- setattr (( PyObject *) type, " __module__" , str (" pybind11_builtins" ));
431
+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (" pybind11_builtins" ));
432
432
PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
433
433
434
434
assert (!PyType_HasFeature (type, Py_TPFLAGS_HAVE_GC));
435
- return ( PyObject *) heap_type;
435
+ return reinterpret_cast < PyObject *>( heap_type) ;
436
436
}
437
437
438
438
// / dynamic_attr: Support for `d = instance.__dict__`.
@@ -482,7 +482,7 @@ inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
482
482
#endif
483
483
type->tp_flags |= Py_TPFLAGS_HAVE_GC;
484
484
type->tp_dictoffset = type->tp_basicsize ; // place dict at the end
485
- type->tp_basicsize += ( ssize_t ) sizeof (PyObject *); // and allocate enough space for it
485
+ type->tp_basicsize += static_cast < ssize_t >( sizeof (PyObject *) ); // and allocate enough space for it
486
486
type->tp_traverse = pybind11_traverse;
487
487
type->tp_clear = pybind11_clear;
488
488
@@ -586,7 +586,7 @@ inline PyObject* make_new_python_type(const type_record &rec) {
586
586
/* Allocate memory for docstring (using PyObject_MALLOC, since
587
587
Python will free this later on) */
588
588
size_t size = strlen (rec.doc ) + 1 ;
589
- tp_doc = ( char *) PyObject_MALLOC (size);
589
+ tp_doc = static_cast < char *>( PyObject_MALLOC (size) );
590
590
memcpy ((void *) tp_doc, rec.doc , size);
591
591
}
592
592
@@ -599,10 +599,10 @@ inline PyObject* make_new_python_type(const type_record &rec) {
599
599
issue no Python C API calls which could potentially invoke the
600
600
garbage collector (the GC will call type_traverse(), which will in
601
601
turn find the newly constructed type in an invalid state) */
602
- auto metaclass = rec.metaclass .ptr () ? ( PyTypeObject *) rec.metaclass .ptr ()
602
+ auto metaclass = rec.metaclass .ptr () ? reinterpret_cast < PyTypeObject *>( rec.metaclass .ptr () )
603
603
: internals.default_metaclass ;
604
604
605
- auto heap_type = ( PyHeapTypeObject *) metaclass->tp_alloc (metaclass, 0 );
605
+ auto heap_type = reinterpret_cast < PyHeapTypeObject *>( metaclass->tp_alloc (metaclass, 0 ) );
606
606
if (!heap_type)
607
607
pybind11_fail (std::string (rec.name ) + " : Unable to create type object!" );
608
608
@@ -614,7 +614,7 @@ inline PyObject* make_new_python_type(const type_record &rec) {
614
614
auto type = &heap_type->ht_type ;
615
615
type->tp_name = full_name;
616
616
type->tp_doc = tp_doc;
617
- type->tp_base = type_incref (( PyTypeObject *) base);
617
+ type->tp_base = type_incref (reinterpret_cast < PyTypeObject *>( base) );
618
618
type->tp_basicsize = static_cast <ssize_t >(sizeof (instance));
619
619
if (!bases.empty ())
620
620
type->tp_bases = bases.release ().ptr ();
@@ -652,16 +652,16 @@ inline PyObject* make_new_python_type(const type_record &rec) {
652
652
653
653
/* Register type with the parent scope */
654
654
if (rec.scope )
655
- setattr (rec.scope , rec.name , ( PyObject *) type);
655
+ setattr (rec.scope , rec.name , reinterpret_cast < PyObject *>( type) );
656
656
else
657
657
Py_INCREF (type); // Keep it alive forever (reference leak)
658
658
659
659
if (module ) // Needed by pydoc
660
- setattr (( PyObject *) type, " __module__" , module );
660
+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , module );
661
661
662
662
PYBIND11_SET_OLDPY_QUALNAME (type, qualname);
663
663
664
- return ( PyObject *) type;
664
+ return reinterpret_cast < PyObject *>( type) ;
665
665
}
666
666
667
667
PYBIND11_NAMESPACE_END (detail)
0 commit comments