File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -1022,10 +1022,11 @@ class generic_type : public object {
10221022 " \" is already registered!" );
10231023
10241024 m_ptr = make_new_python_type (rec);
1025+ auto type = (PyTypeObject *) m_ptr;
10251026
10261027 /* Register supplemental type information in C++ dict */
10271028 auto *tinfo = new detail::type_info ();
1028- tinfo->type = (PyTypeObject *) m_ptr ;
1029+ tinfo->type = type ;
10291030 tinfo->cpptype = rec.type ;
10301031 tinfo->type_size = rec.type_size ;
10311032 tinfo->type_align = rec.type_align ;
@@ -1045,7 +1046,11 @@ class generic_type : public object {
10451046 registered_local_types_cpp ()[tindex] = tinfo;
10461047 else
10471048 internals.registered_types_cpp [tindex] = tinfo;
1048- internals.registered_types_py [(PyTypeObject *) m_ptr] = { tinfo };
1049+ internals.registered_types_py [type] = { tinfo };
1050+ weakref (m_ptr, cpp_function ([type](handle wr) {
1051+ get_internals ().registered_types_py .erase (type);
1052+ wr.dec_ref ();
1053+ })).release ();
10491054
10501055 if (rec.bases .size () > 1 || rec.multiple_inheritance ) {
10511056 mark_parents_nonsimple (tinfo->type );
You can’t perform that action at this time.
0 commit comments