@@ -686,8 +686,8 @@ class generic_type : public object {
686
686
/* Create a custom metaclass if requested (used for static properties) */
687
687
object metaclass;
688
688
if (rec->metaclass ) {
689
- std::string name_ = full_name + " __Meta" ;
690
- object name = reinterpret_steal<object>(PYBIND11_FROM_STRING (name_ .c_str ()));
689
+ std::string meta_name_ = full_name + " __Meta" ;
690
+ object meta_name = reinterpret_steal<object>(PYBIND11_FROM_STRING (meta_name_ .c_str ()));
691
691
metaclass = reinterpret_steal<object>(PyType_Type.tp_alloc (&PyType_Type, 0 ));
692
692
if (!metaclass || !name)
693
693
pybind11_fail (" generic_type::generic_type(): unable to create metaclass!" );
@@ -698,14 +698,13 @@ class generic_type : public object {
698
698
turn find the newly constructed type in an invalid state) */
699
699
700
700
auto type = (PyHeapTypeObject*) metaclass.ptr ();
701
- type->ht_name = name.release ().ptr ();
702
-
701
+ type->ht_name = meta_name.release ().ptr ();
703
702
704
703
#if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 3
705
704
/* Qualified names for Python >= 3.3 */
706
705
type->ht_qualname = ht_qualname.release ().ptr ();
707
706
#endif
708
- type->ht_type .tp_name = strdup (name_ .c_str ());
707
+ type->ht_type .tp_name = strdup (meta_name_ .c_str ());
709
708
type->ht_type .tp_base = &PyType_Type;
710
709
type->ht_type .tp_flags |= (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE) &
711
710
~Py_TPFLAGS_HAVE_GC;
@@ -878,9 +877,8 @@ class generic_type : public object {
878
877
PyObject_ClearWeakRefs ((PyObject *) self);
879
878
880
879
PyObject **dict_ptr = _PyObject_GetDictPtr ((PyObject *) self);
881
- if (dict_ptr) {
880
+ if (dict_ptr)
882
881
Py_CLEAR (*dict_ptr);
883
- }
884
882
}
885
883
Py_TYPE (self)->tp_free ((PyObject*) self);
886
884
}
@@ -902,12 +900,14 @@ class generic_type : public object {
902
900
void *get_buffer_data) {
903
901
PyHeapTypeObject *type = (PyHeapTypeObject*) m_ptr;
904
902
auto tinfo = detail::get_type_info (&type->ht_type );
905
- if ((type->ht_type .tp_flags & Py_TPFLAGS_HAVE_NEWBUFFER) == 0 )
903
+
904
+ if (!type->ht_type .tp_as_buffer )
906
905
pybind11_fail (
907
906
" To be able to register buffer protocol support for the type '" +
908
907
std::string (tinfo->type ->tp_name ) +
909
908
" ' the associated class<>(..) invocation must "
910
909
" include the pybind11::buffer_protocol() annotation!" );
910
+
911
911
tinfo->get_buffer = get_buffer;
912
912
tinfo->get_buffer_data = get_buffer_data;
913
913
}
0 commit comments