@@ -71,7 +71,7 @@ inline PyTypeObject *make_static_property_type() {
7171 issue no Python C API calls which could potentially invoke the
7272 garbage collector (the GC will call type_traverse(), which will in
7373 turn find the newly constructed type in an invalid state) */
74- auto *heap_type = ( PyHeapTypeObject *) PyType_Type.tp_alloc (&PyType_Type, 0 );
74+ auto *heap_type = reinterpret_cast < PyHeapTypeObject *>( PyType_Type.tp_alloc (&PyType_Type, 0 ) );
7575 if (!heap_type) {
7676 pybind11_fail (" make_static_property_type(): error allocating type!" );
7777 }
@@ -98,7 +98,7 @@ inline PyTypeObject *make_static_property_type() {
9898 pybind11_fail (" make_static_property_type(): failure in PyType_Ready()!" );
9999 }
100100
101- setattr (( PyObject *) type, " __module__" , str (PYBIND11_DUMMY_MODULE_NAME));
101+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (PYBIND11_DUMMY_MODULE_NAME));
102102 PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
103103
104104 return type;
@@ -265,7 +265,7 @@ inline PyTypeObject *make_default_metaclass() {
265265 issue no Python C API calls which could potentially invoke the
266266 garbage collector (the GC will call type_traverse(), which will in
267267 turn find the newly constructed type in an invalid state) */
268- auto *heap_type = ( PyHeapTypeObject *) PyType_Type.tp_alloc (&PyType_Type, 0 );
268+ auto *heap_type = reinterpret_cast < PyHeapTypeObject *>( PyType_Type.tp_alloc (&PyType_Type, 0 ) );
269269 if (!heap_type) {
270270 pybind11_fail (" make_default_metaclass(): error allocating metaclass!" );
271271 }
@@ -291,7 +291,7 @@ inline PyTypeObject *make_default_metaclass() {
291291 pybind11_fail (" make_default_metaclass(): failure in PyType_Ready()!" );
292292 }
293293
294- setattr (( PyObject *) type, " __module__" , str (PYBIND11_DUMMY_MODULE_NAME));
294+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (PYBIND11_DUMMY_MODULE_NAME));
295295 PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
296296
297297 return type;
@@ -306,7 +306,7 @@ inline void traverse_offset_bases(void *valueptr,
306306 instance *self,
307307 bool (*f)(void * /* parentptr*/ , instance * /* self*/ )) {
308308 for (handle h : reinterpret_borrow<tuple>(tinfo->type ->tp_bases )) {
309- if (auto *parent_tinfo = get_type_info (( PyTypeObject *) h.ptr ())) {
309+ if (auto *parent_tinfo = get_type_info (reinterpret_cast < PyTypeObject *>( h.ptr () ))) {
310310 for (auto &c : parent_tinfo->implicit_casts ) {
311311 if (c.first == tinfo->cpptype ) {
312312 auto *parentptr = c.second (valueptr);
@@ -530,7 +530,7 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
530530 issue no Python C API calls which could potentially invoke the
531531 garbage collector (the GC will call type_traverse(), which will in
532532 turn find the newly constructed type in an invalid state) */
533- auto *heap_type = ( PyHeapTypeObject *) metaclass->tp_alloc (metaclass, 0 );
533+ auto *heap_type = reinterpret_cast < PyHeapTypeObject *>( metaclass->tp_alloc (metaclass, 0 ) );
534534 if (!heap_type) {
535535 pybind11_fail (" make_object_base_type(): error allocating type!" );
536536 }
@@ -557,11 +557,11 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
557557 pybind11_fail (" PyType_Ready failed in make_object_base_type(): " + error_string ());
558558 }
559559
560- setattr (( PyObject *) type, " __module__" , str (PYBIND11_DUMMY_MODULE_NAME));
560+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (PYBIND11_DUMMY_MODULE_NAME));
561561 PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
562562
563563 assert (!PyType_HasFeature (type, Py_TPFLAGS_HAVE_GC));
564- return ( PyObject *) heap_type;
564+ return reinterpret_cast < PyObject *>( heap_type) ;
565565}
566566
567567// / dynamic_attr: Allow the garbage collector to traverse the internal instance `__dict__`.
@@ -746,7 +746,7 @@ inline PyObject *make_new_python_type(const type_record &rec) {
746746 /* Allocate memory for docstring (Python will free this later on) */
747747 size_t size = std::strlen (rec.doc ) + 1 ;
748748#if PY_VERSION_HEX >= 0x030D0000
749- tp_doc = ( char *) PyMem_MALLOC (size);
749+ tp_doc = static_cast < char *>( PyMem_MALLOC (size) );
750750#else
751751 tp_doc = (char *) PyObject_MALLOC (size);
752752#endif
@@ -761,10 +761,10 @@ inline PyObject *make_new_python_type(const type_record &rec) {
761761 issue no Python C API calls which could potentially invoke the
762762 garbage collector (the GC will call type_traverse(), which will in
763763 turn find the newly constructed type in an invalid state) */
764- auto *metaclass
765- = rec. metaclass . ptr () ? (PyTypeObject *) rec. metaclass . ptr () : internals.default_metaclass ;
764+ auto *metaclass = rec. metaclass . ptr () ? reinterpret_cast <PyTypeObject *>(rec. metaclass . ptr ())
765+ : internals.default_metaclass ;
766766
767- auto *heap_type = ( PyHeapTypeObject *) metaclass->tp_alloc (metaclass, 0 );
767+ auto *heap_type = reinterpret_cast < PyHeapTypeObject *>( metaclass->tp_alloc (metaclass, 0 ) );
768768 if (!heap_type) {
769769 pybind11_fail (std::string (rec.name ) + " : Unable to create type object!" );
770770 }
@@ -777,7 +777,7 @@ inline PyObject *make_new_python_type(const type_record &rec) {
777777 auto *type = &heap_type->ht_type ;
778778 type->tp_name = full_name;
779779 type->tp_doc = tp_doc;
780- type->tp_base = type_incref (( PyTypeObject *) base);
780+ type->tp_base = type_incref (reinterpret_cast < PyTypeObject *>( base) );
781781 type->tp_basicsize = static_cast <ssize_t >(sizeof (instance));
782782 if (!bases.empty ()) {
783783 type->tp_bases = bases.release ().ptr ();
@@ -818,18 +818,18 @@ inline PyObject *make_new_python_type(const type_record &rec) {
818818
819819 /* Register type with the parent scope */
820820 if (rec.scope ) {
821- setattr (rec.scope , rec.name , ( PyObject *) type);
821+ setattr (rec.scope , rec.name , reinterpret_cast < PyObject *>( type) );
822822 } else {
823823 Py_INCREF (type); // Keep it alive forever (reference leak)
824824 }
825825
826826 if (module_) { // Needed by pydoc
827- setattr (( PyObject *) type, " __module__" , module_);
827+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , module_);
828828 }
829829
830830 PYBIND11_SET_OLDPY_QUALNAME (type, qualname);
831831
832- return ( PyObject *) type;
832+ return reinterpret_cast < PyObject *>( type) ;
833833}
834834
835835PYBIND11_NAMESPACE_END (detail)
0 commit comments