@@ -53,7 +53,7 @@ inline PyTypeObject *make_static_property_type() {
5353 issue no Python C API calls which could potentially invoke the
5454 garbage collector (the GC will call type_traverse(), which will in
5555 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 ) );
5757 if (!heap_type)
5858 pybind11_fail (" make_static_property_type(): error allocating type!" );
5959
@@ -72,7 +72,7 @@ inline PyTypeObject *make_static_property_type() {
7272 if (PyType_Ready (type) < 0 )
7373 pybind11_fail (" make_static_property_type(): failure in PyType_Ready()!" );
7474
75- setattr (( PyObject *) type, " __module__" , str (" pybind11_builtins" ));
75+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (" pybind11_builtins" ));
7676 PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
7777
7878 return type;
@@ -192,7 +192,7 @@ inline PyTypeObject* make_default_metaclass() {
192192 issue no Python C API calls which could potentially invoke the
193193 garbage collector (the GC will call type_traverse(), which will in
194194 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 ) );
196196 if (!heap_type)
197197 pybind11_fail (" make_default_metaclass(): error allocating metaclass!" );
198198
@@ -216,7 +216,7 @@ inline PyTypeObject* make_default_metaclass() {
216216 if (PyType_Ready (type) < 0 )
217217 pybind11_fail (" make_default_metaclass(): failure in PyType_Ready()!" );
218218
219- setattr (( PyObject *) type, " __module__" , str (" pybind11_builtins" ));
219+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (" pybind11_builtins" ));
220220 PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
221221
222222 return type;
@@ -228,7 +228,7 @@ inline PyTypeObject* make_default_metaclass() {
228228inline void traverse_offset_bases (void *valueptr, const detail::type_info *tinfo, instance *self,
229229 bool (*f)(void * /* parentptr*/ , instance * /* self*/ )) {
230230 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 () ))) {
232232 for (auto &c : parent_tinfo->implicit_casts ) {
233233 if (c.first == tinfo->cpptype ) {
234234 auto *parentptr = c.second (valueptr);
@@ -403,7 +403,7 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
403403 issue no Python C API calls which could potentially invoke the
404404 garbage collector (the GC will call type_traverse(), which will in
405405 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 ) );
407407 if (!heap_type)
408408 pybind11_fail (" make_object_base_type(): error allocating type!" );
409409
@@ -428,11 +428,11 @@ inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
428428 if (PyType_Ready (type) < 0 )
429429 pybind11_fail (" PyType_Ready failed in make_object_base_type():" + error_string ());
430430
431- setattr (( PyObject *) type, " __module__" , str (" pybind11_builtins" ));
431+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , str (" pybind11_builtins" ));
432432 PYBIND11_SET_OLDPY_QUALNAME (type, name_obj);
433433
434434 assert (!PyType_HasFeature (type, Py_TPFLAGS_HAVE_GC));
435- return ( PyObject *) heap_type;
435+ return reinterpret_cast < PyObject *>( heap_type) ;
436436}
437437
438438// / dynamic_attr: Support for `d = instance.__dict__`.
@@ -482,7 +482,7 @@ inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
482482#endif
483483 type->tp_flags |= Py_TPFLAGS_HAVE_GC;
484484 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
486486 type->tp_traverse = pybind11_traverse;
487487 type->tp_clear = pybind11_clear;
488488
@@ -586,7 +586,7 @@ inline PyObject* make_new_python_type(const type_record &rec) {
586586 /* Allocate memory for docstring (using PyObject_MALLOC, since
587587 Python will free this later on) */
588588 size_t size = strlen (rec.doc ) + 1 ;
589- tp_doc = ( char *) PyObject_MALLOC (size);
589+ tp_doc = static_cast < char *>( PyObject_MALLOC (size) );
590590 memcpy ((void *) tp_doc, rec.doc , size);
591591 }
592592
@@ -599,10 +599,10 @@ inline PyObject* make_new_python_type(const type_record &rec) {
599599 issue no Python C API calls which could potentially invoke the
600600 garbage collector (the GC will call type_traverse(), which will in
601601 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 () )
603603 : internals.default_metaclass ;
604604
605- auto heap_type = ( PyHeapTypeObject *) metaclass->tp_alloc (metaclass, 0 );
605+ auto heap_type = reinterpret_cast < PyHeapTypeObject *>( metaclass->tp_alloc (metaclass, 0 ) );
606606 if (!heap_type)
607607 pybind11_fail (std::string (rec.name ) + " : Unable to create type object!" );
608608
@@ -614,7 +614,7 @@ inline PyObject* make_new_python_type(const type_record &rec) {
614614 auto type = &heap_type->ht_type ;
615615 type->tp_name = full_name;
616616 type->tp_doc = tp_doc;
617- type->tp_base = type_incref (( PyTypeObject *) base);
617+ type->tp_base = type_incref (reinterpret_cast < PyTypeObject *>( base) );
618618 type->tp_basicsize = static_cast <ssize_t >(sizeof (instance));
619619 if (!bases.empty ())
620620 type->tp_bases = bases.release ().ptr ();
@@ -652,16 +652,16 @@ inline PyObject* make_new_python_type(const type_record &rec) {
652652
653653 /* Register type with the parent scope */
654654 if (rec.scope )
655- setattr (rec.scope , rec.name , ( PyObject *) type);
655+ setattr (rec.scope , rec.name , reinterpret_cast < PyObject *>( type) );
656656 else
657657 Py_INCREF (type); // Keep it alive forever (reference leak)
658658
659659 if (module ) // Needed by pydoc
660- setattr (( PyObject *) type, " __module__" , module );
660+ setattr (reinterpret_cast < PyObject *>( type) , " __module__" , module );
661661
662662 PYBIND11_SET_OLDPY_QUALNAME (type, qualname);
663663
664- return ( PyObject *) type;
664+ return reinterpret_cast < PyObject *>( type) ;
665665}
666666
667667PYBIND11_NAMESPACE_END (detail)
0 commit comments