1- // WARNING: Please don't edit this file. It was generated by Python/WinRT v1.0.0-beta.7
1+ // WARNING: Please don't edit this file. It was generated by Python/WinRT v1.0.0-beta.8
22
33#include " pybase.h"
44#include < Shobjidl.h>
@@ -9,6 +9,7 @@ namespace py::cpp::_winrt
99 struct module_state
1010 {
1111 PyTypeObject* Object_type;
12+ PyTypeObject* Array_type;
1213 PyTypeObject* MappingIter_type;
1314 };
1415
@@ -31,7 +32,13 @@ namespace py::cpp::_winrt
3132 py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self)
3233 {
3334 auto tp = Py_TYPE (self);
34- self->obj = nullptr ;
35+
36+ if (PyType_IS_GC (tp))
37+ {
38+ PyObject_GC_UnTrack (self);
39+ }
40+
41+ std::destroy_at (&self->obj );
3542 tp->tp_free (self);
3643 Py_DECREF (tp);
3744 }
@@ -52,6 +59,15 @@ namespace py::cpp::_winrt
5259
5360 // END: class _winrt.Object:
5461
62+ // BEGIN: class _winrt.Array:
63+
64+ extern PyType_Spec Array_type_spec;
65+ #if PY_VERSION_HEX < 0x03090000
66+ extern PyBufferProcs Array_buffer_procs;
67+ #endif
68+
69+ // END: class _winrt.Array:
70+
5571 // BEGIN: class _winrt.MappingIter:
5672
5773 // This class is used to wrap the iterator returned by IMap/IMapView so
@@ -238,6 +254,7 @@ namespace py::cpp::_winrt
238254 assert (state);
239255
240256 Py_VISIT (state->Object_type );
257+ Py_VISIT (state->Array_type );
241258 Py_VISIT (state->MappingIter_type );
242259
243260 return 0 ;
@@ -249,6 +266,7 @@ namespace py::cpp::_winrt
249266 assert (state);
250267
251268 Py_CLEAR (state->Object_type );
269+ Py_CLEAR (state->Array_type );
252270 Py_CLEAR (state->MappingIter_type );
253271
254272 return 0 ;
@@ -272,6 +290,29 @@ namespace py::cpp::_winrt
272290 static const auto kSTA
273291 = static_cast <long >(winrt::apartment_type::single_threaded);
274292
293+ py::pyobj_handle collections_abc_module{
294+ PyImport_ImportModule (" collections.abc" )};
295+
296+ if (!collections_abc_module)
297+ {
298+ return nullptr ;
299+ }
300+
301+ py::pyobj_handle mutable_sequence_type{
302+ PyObject_GetAttrString (collections_abc_module.get (), " MutableSequence" )};
303+
304+ if (!mutable_sequence_type)
305+ {
306+ return nullptr ;
307+ }
308+
309+ py::pyobj_handle array_bases{PyTuple_Pack (1 , mutable_sequence_type.get ())};
310+
311+ if (!array_bases)
312+ {
313+ return nullptr ;
314+ }
315+
275316 py::pyobj_handle module {PyModule_Create (&module_def)};
276317
277318 if (!module )
@@ -283,25 +324,33 @@ namespace py::cpp::_winrt
283324 assert (state);
284325
285326 state->Object_type = py::register_python_type (
286- module .get (), _type_name_Object, &Object_type_spec, nullptr );
327+ module .get (), _type_name_Object, &Object_type_spec, nullptr , nullptr );
287328
288329 if (!state->Object_type )
289330 {
290331 return nullptr ;
291332 }
292333
293- Py_INCREF (state->Object_type );
334+ state->Array_type = py::register_python_type (
335+ module .get (), " Array" , &Array_type_spec, array_bases.get (), nullptr );
336+
337+ if (!state->Array_type )
338+ {
339+ return nullptr ;
340+ }
341+
342+ #if PY_VERSION_HEX < 0x03090000
343+ state->Array_type ->tp_as_buffer = &Array_buffer_procs;
344+ #endif
294345
295346 state->MappingIter_type = py::register_python_type (
296- module .get (), " MappingIter" , &MappingIter_type_spec, nullptr );
347+ module .get (), " MappingIter" , &MappingIter_type_spec, nullptr , nullptr );
297348
298349 if (!state->MappingIter_type )
299350 {
300351 return nullptr ;
301352 }
302353
303- Py_INCREF (state->MappingIter_type );
304-
305354 if (PyModule_AddIntConstant (module .get (), " MTA" , kMTA ) == -1 )
306355 {
307356 return nullptr ;
@@ -339,6 +388,24 @@ PyTypeObject* py::winrt_type<py::Object>::get_python_type() noexcept
339388 return state->Object_type ;
340389}
341390
391+ PyTypeObject* py::winrt_type<py::Array>::get_python_type() noexcept
392+ {
393+ // borrowed ref
394+ auto module = PyState_FindModule (&py::cpp::_winrt::module_def);
395+
396+ if (!module )
397+ {
398+ PyErr_SetString (PyExc_RuntimeError, " could not find _winrt module" );
399+ return nullptr ;
400+ }
401+
402+ auto state
403+ = reinterpret_cast <py::cpp::_winrt::module_state*>(PyModule_GetState (module ));
404+ assert (state);
405+
406+ return state->Array_type ;
407+ }
408+
342409PyTypeObject* py::winrt_type<py::MappingIter>::get_python_type() noexcept
343410{
344411 // borrowed ref
0 commit comments