winrt-runtime 4.1.0__tar.gz → 4.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. {winrt_runtime-4.1.0/python/winrt_runtime.egg-info → winrt_runtime-4.2.1}/PKG-INFO +2 -2
  2. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/_winrt.pyi +11 -2
  3. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/runtime/_internals.py +40 -0
  4. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/runtime/interop.py +2 -0
  5. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1/python/winrt_runtime.egg-info}/PKG-INFO +2 -2
  6. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt_runtime.egg-info/SOURCES.txt +1 -0
  7. winrt_runtime-4.2.1/python/winrt_runtime.egg-info/requires.txt +1 -0
  8. winrt_runtime-4.2.1/requirements.txt +1 -0
  9. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/_winrt.cpp +42 -82
  10. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/_winrt_array.h +2 -0
  11. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/_winrt_box.cpp +2 -0
  12. winrt_runtime-4.2.1/src/_winrt_box.h +44 -0
  13. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/_winrt_buffer.cpp +108 -1
  14. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/errors.cpp +2 -11
  15. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.System.0.h +58 -0
  16. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.System.1.h +14 -0
  17. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.System.2.h +6 -1
  18. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/abi.h +2 -4
  19. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/errors.h +9 -5
  20. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/interp.cpp +290 -84
  21. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/interp.h +17 -5
  22. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/members.cpp +88 -41
  23. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/members.h +4 -1
  24. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/module_state.h +28 -14
  25. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/objects.cpp +343 -20
  26. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/objects.h +11 -0
  27. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/runtime.cpp +43 -27
  28. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/runtime.h +2 -0
  29. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/table.cpp +4 -4
  30. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/table.h +9 -0
  31. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/types.cpp +15 -7
  32. winrt_runtime-4.2.1/version.txt +1 -0
  33. winrt_runtime-4.1.0/python/winrt_runtime.egg-info/requires.txt +0 -1
  34. winrt_runtime-4.1.0/requirements.txt +0 -1
  35. winrt_runtime-4.1.0/version.txt +0 -1
  36. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/LICENSE +0 -0
  37. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/MANIFEST.in +0 -0
  38. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/README.md +0 -0
  39. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/pyproject.toml +0 -0
  40. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/__pyinstaller/__init__.py +0 -0
  41. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/__pyinstaller/hook-winrt.py +0 -0
  42. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/py.typed +0 -0
  43. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/runtime/__init__.py +0 -0
  44. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/runtime/py.typed +0 -0
  45. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/system/__init__.py +0 -0
  46. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/system/hresult.py +0 -0
  47. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt/system/py.typed +0 -0
  48. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt_runtime.egg-info/dependency_links.txt +0 -0
  49. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt_runtime.egg-info/entry_points.txt +0 -0
  50. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/python/winrt_runtime.egg-info/top_level.txt +0 -0
  51. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/setup.cfg +0 -0
  52. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/setup.py +0 -0
  53. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/_winrt_array.cpp +0 -0
  54. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/_winrt_buffer.h +0 -0
  55. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/arrays.cpp +0 -0
  56. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/arrays.h +0 -0
  57. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/async.cpp +0 -0
  58. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/async.h +0 -0
  59. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/callbacks.cpp +0 -0
  60. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/callbacks.h +0 -0
  61. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/collections.cpp +0 -0
  62. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/collections.h +0 -0
  63. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/compose.cpp +0 -0
  64. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/compose.h +0 -0
  65. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/delegates.cpp +0 -0
  66. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/delegates.h +0 -0
  67. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/enums.cpp +0 -0
  68. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/enums.h +0 -0
  69. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/generics.cpp +0 -0
  70. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/generics.h +0 -0
  71. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/handles.cpp +0 -0
  72. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/implements.cpp +0 -0
  73. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/implements.h +0 -0
  74. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/Windows.Foundation.Collections.h +0 -0
  75. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/Windows.Foundation.Metadata.h +0 -0
  76. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/Windows.Foundation.h +0 -0
  77. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/Windows.Storage.Streams.h +0 -0
  78. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/Windows.Storage.h +0 -0
  79. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/base.h +0 -0
  80. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/base_macros.h +0 -0
  81. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Devices.Geolocation.0.h +0 -0
  82. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Devices.Geolocation.1.h +0 -0
  83. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.0.h +0 -0
  84. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.1.h +0 -0
  85. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.2.h +0 -0
  86. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.Collections.0.h +0 -0
  87. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.Collections.1.h +0 -0
  88. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.Collections.2.h +0 -0
  89. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.Metadata.0.h +0 -0
  90. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.Metadata.1.h +0 -0
  91. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Foundation.Metadata.2.h +0 -0
  92. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.0.h +0 -0
  93. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.1.h +0 -0
  94. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.2.h +0 -0
  95. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.FileProperties.0.h +0 -0
  96. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.FileProperties.1.h +0 -0
  97. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.FileProperties.2.h +0 -0
  98. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Provider.0.h +0 -0
  99. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Provider.1.h +0 -0
  100. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Provider.2.h +0 -0
  101. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Search.0.h +0 -0
  102. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Search.1.h +0 -0
  103. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Search.2.h +0 -0
  104. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Streams.0.h +0 -0
  105. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Streams.1.h +0 -0
  106. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.Storage.Streams.2.h +0 -0
  107. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.System.RemoteSystems.0.h +0 -0
  108. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/cppwinrt/winrt/impl/Windows.System.RemoteSystems.1.h +0 -0
  109. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pythoncapi_compat.h +0 -0
  110. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/array.h +0 -0
  111. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/async.h +0 -0
  112. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/base.h +0 -0
  113. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/buffer.h +0 -0
  114. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/convert.h +0 -0
  115. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/handles.h +0 -0
  116. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/prelude.h +0 -0
  117. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/throw_helpers.h +0 -0
  118. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/traits.h +0 -0
  119. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/include/pywinrt/wrappers.h +0 -0
  120. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/metaclass.h +0 -0
  121. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/numerics-buffer.cpp +0 -0
  122. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/numerics-buffer.h +0 -0
  123. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/numerics-statics.cpp +0 -0
  124. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/numerics-statics.h +0 -0
  125. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/numerics-traits.h +0 -0
  126. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/numerics-values.h +0 -0
  127. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/numerics.cpp +0 -0
  128. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/numerics.h +0 -0
  129. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/protocols.cpp +0 -0
  130. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/protocols.h +0 -0
  131. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/pycollections.cpp +0 -0
  132. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/pycollections.h +0 -0
  133. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/pymapping.cpp +0 -0
  134. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/pymapping.h +0 -0
  135. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/pysequence.cpp +0 -0
  136. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/pysequence.h +0 -0
  137. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/shapes-generated.h +0 -0
  138. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/shapes.cpp +0 -0
  139. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/shapes.h +0 -0
  140. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/structs.cpp +0 -0
  141. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/structs.h +0 -0
  142. {winrt_runtime-4.1.0 → winrt_runtime-4.2.1}/src/types.h +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winrt-runtime
3
- Version: 4.1.0
3
+ Version: 4.2.1
4
4
  Summary: The runtime that every PyWinRT projection package runs on
5
5
  License-Expression: MIT
6
6
  Project-URL: Documentation, https://pywinrt.readthedocs.io
@@ -20,7 +20,7 @@ Classifier: Typing :: Typed
20
20
  Requires-Python: >=3.11
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
- Requires-Dist: typing_extensions>=4.12.2
23
+ Requires-Dist: typing_extensions>=4.13.0
24
24
  Dynamic: license-file
25
25
 
26
26
  # winrt-runtime
@@ -42,6 +42,9 @@ def wrap_interface(
42
42
  def wrap_interface(capsule: InterfaceCapsule, qualified_name: str, /) -> Any: ...
43
43
  @overload
44
44
  def wrap_interface(capsule: None, type: type[Object] | str, /) -> None: ...
45
+ def interface_pointer(
46
+ obj: Object | InterfaceCapsule | _SupportsInterfaceCapsule, /
47
+ ) -> int: ...
45
48
  def hresult_error(
46
49
  hresult: SupportsIndex, error_info: InterfaceCapsule | None = None, /
47
50
  ) -> OSError: ...
@@ -79,8 +82,8 @@ def unbox_date_time(value: Object, /) -> datetime: ...
79
82
  def unbox_time_span(value: Object, /) -> timedelta: ...
80
83
 
81
84
  # Reads a projection table and returns its contents as plain Python objects, so
82
- # that test/test_table.py can check that the generator's writer and this
83
- # module's reader agree on the format. The shape of the result follows
85
+ # that test/projection/test_table.py can check that the generator's writer and
86
+ # this module's reader agree on the format. The shape of the result follows
84
87
  # runtime/src/table-format.md rather than a type of its own.
85
88
  def read_table(data: Buffer, /) -> dict[str, Any]: ...
86
89
 
@@ -95,6 +98,12 @@ class _SupportsQueryInterface(Protocol):
95
98
 
96
99
  _TQueryInterface = TypeVar("_TQueryInterface", bound=_SupportsQueryInterface)
97
100
 
101
+ # What interface_pointer() needs from an interop class instance: a method that
102
+ # returns the capsule the instance holds. It must return the same capsule for
103
+ # the life of the instance.
104
+ class _SupportsInterfaceCapsule(Protocol):
105
+ def _interface_capsule_(self) -> InterfaceCapsule: ...
106
+
98
107
  # Declared as an ABCMeta although at run time it derives from type: a type
99
108
  # checker requires an abstract member to be implemented only under ABCMeta, and
100
109
  # the members of an interface are abstract.
@@ -72,6 +72,46 @@ def load_projection(spec: ModuleSpec) -> None:
72
72
  ) from error
73
73
 
74
74
 
75
+ def note_missing_package(
76
+ error: ModuleNotFoundError, module: str, namespace: str
77
+ ) -> None:
78
+ """
79
+ Adds a note to ``error`` naming the package that provides ``module``, the
80
+ module of the WinRT namespace ``namespace``, when ``error`` is about
81
+ ``module`` or a package it sits in, ``module`` is of the Windows SDK and
82
+ ``error`` has no note yet.
83
+
84
+ The runtime calls this when it cannot import the module of a type or
85
+ delegate that a table refers to, or finds it only a namespace package. The
86
+ error is about the first module of ``module``'s packages that is missing,
87
+ which is ``module`` itself only if the packages it sits in are installed.
88
+ The note names the module when the error does not.
89
+
90
+ An error that has a note already is left as it is. The runtime meets one
91
+ when ``module`` is installed but importing it fails: a type it builds then,
92
+ such as a base class, needs a package ``module`` sits in that is missing,
93
+ and the runtime has noted that package.
94
+
95
+ Every package of the Windows SDK provides one namespace and is named after
96
+ it, as ``winrt-Windows.Storage`` provides ``winrt.windows.storage``, and
97
+ nothing else may define a ``Windows`` namespace, so the name of the module
98
+ is all it takes. The package of another family may be named after a
99
+ namespace that its own sits under, so its module does not say which it is.
100
+ """
101
+ if not module.startswith("winrt.windows."):
102
+ return
103
+
104
+ if getattr(error, "__notes__", None):
105
+ return
106
+
107
+ name = error.name
108
+ if not name or (name != module and not module.startswith(f"{name}.")):
109
+ return
110
+
111
+ subject = "it" if name == module else module
112
+ error.add_note(f"The winrt-{namespace} package provides {subject}.")
113
+
114
+
75
115
  class WinrtIntEnum(IntEnum):
76
116
  """
77
117
  The base of every projected WinRT enum that is not a set of flags.
@@ -7,6 +7,7 @@ from winrt._winrt import (
7
7
  get_activation_factory,
8
8
  hresult_error,
9
9
  initialize_with_window,
10
+ interface_pointer,
10
11
  wrap_interface,
11
12
  )
12
13
 
@@ -16,6 +17,7 @@ __all__ = [
16
17
  "get_activation_factory",
17
18
  "hresult_error",
18
19
  "initialize_with_window",
20
+ "interface_pointer",
19
21
  "wrap_interface",
20
22
  ]
21
23
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: winrt-runtime
3
- Version: 4.1.0
3
+ Version: 4.2.1
4
4
  Summary: The runtime that every PyWinRT projection package runs on
5
5
  License-Expression: MIT
6
6
  Project-URL: Documentation, https://pywinrt.readthedocs.io
@@ -20,7 +20,7 @@ Classifier: Typing :: Typed
20
20
  Requires-Python: >=3.11
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
- Requires-Dist: typing_extensions>=4.12.2
23
+ Requires-Dist: typing_extensions>=4.13.0
24
24
  Dynamic: license-file
25
25
 
26
26
  # winrt-runtime
@@ -26,6 +26,7 @@ src/_winrt.cpp
26
26
  src/_winrt_array.cpp
27
27
  src/_winrt_array.h
28
28
  src/_winrt_box.cpp
29
+ src/_winrt_box.h
29
30
  src/_winrt_buffer.cpp
30
31
  src/_winrt_buffer.h
31
32
  src/arrays.cpp
@@ -0,0 +1 @@
1
+ typing_extensions>=4.13.0
@@ -0,0 +1 @@
1
+ typing_extensions>=4.13.0
@@ -8,10 +8,13 @@
8
8
  #include <libloaderapi.h>
9
9
 
10
10
  #include <pywinrt/base.h>
11
+ #include "_winrt_array.h"
12
+ #include "_winrt_box.h"
11
13
  #include "module_state.h"
12
14
  #include "implements.h"
13
15
  #include "members.h"
14
16
  #include "objects.h"
17
+ #include "table.h"
15
18
  #include "types.h"
16
19
  #include <winrt/base.h>
17
20
 
@@ -555,12 +558,6 @@ namespace py::cpp::_winrt
555
558
 
556
559
  // END: class _winrt.Object:
557
560
 
558
- // BEGIN: class _winrt.Array:
559
-
560
- extern PyType_Spec Array_type_spec;
561
-
562
- // END: class _winrt.Array:
563
-
564
561
  // BEGIN: class _winrt.MappingIter:
565
562
 
566
563
  // This class is used to wrap the iterator returned by IMap/IMapView so
@@ -731,7 +728,21 @@ namespace py::cpp::_winrt
731
728
  static PyObject* uninit_apartment(
732
729
  PyObject* /*unused*/, PyObject* /*unused*/) noexcept
733
730
  {
734
- winrt::uninit_apartment();
731
+ // The last CoUninitialize() of the process unloads the DLLs that
732
+ // implement the classes, so a factory kept past it would point into
733
+ // code that is no longer there. The runtime's own are let go of first,
734
+ // and so are the ones C++/WinRT keeps, which boxing a value asks for.
735
+ if (!py::interp::release_factories())
736
+ {
737
+ return nullptr;
738
+ }
739
+
740
+ {
741
+ auto _gil = py::release_gil();
742
+ winrt::clear_factory_cache();
743
+ winrt::uninit_apartment();
744
+ }
745
+
735
746
  Py_RETURN_NONE;
736
747
  }
737
748
 
@@ -846,6 +857,15 @@ namespace py::cpp::_winrt
846
857
  */
847
858
  static std::atomic<module_state*> main_state{};
848
859
 
860
+ /**
861
+ * Lets go of wrap_async_func, the one reference the state owns that is not
862
+ * a handle. The members go after it, in the reverse of their order.
863
+ */
864
+ module_state::~module_state()
865
+ {
866
+ Py_XDECREF(wrap_async_func);
867
+ }
868
+
849
869
  static int module_traverse(PyObject* module, visitproc visit, void* arg) noexcept
850
870
  {
851
871
  auto state = reinterpret_cast<module_state*>(PyModule_GetState(module));
@@ -913,64 +933,9 @@ namespace py::cpp::_winrt
913
933
  main_state.compare_exchange_strong(
914
934
  expected, nullptr, std::memory_order_acq_rel);
915
935
 
916
- std::destroy_at(&state->object_meta_type);
917
- std::destroy_at(&state->object_type);
918
- std::destroy_at(&state->array_type);
919
- std::destroy_at(&state->mapping_iter_type);
920
- std::destroy_at(&state->projected_method_type);
921
- std::destroy_at(&state->to_uuid_func);
922
- std::destroy_at(&state->uuid_type);
923
- Py_XDECREF(state->wrap_async_func);
924
-
925
- std::destroy_at(&state->type_cache);
926
-
927
- std::destroy_at(&state->type_entries);
928
- std::destroy_at(&state->generic_types);
929
- std::destroy_at(&state->buffer_exports);
930
-
931
- std::destroy_at(&state->projections);
936
+ std::destroy_at(state);
932
937
  }
933
938
 
934
- // Not using a header file for thes because setuptools doesn't have a nice
935
- // way to pick up private header files.
936
- PyObject* box_boolean(PyObject* /*unused*/, PyObject* obj) noexcept;
937
- PyObject* box_int8(PyObject* /*unused*/, PyObject* obj) noexcept;
938
- PyObject* box_uint8(PyObject* /*unused*/, PyObject* obj) noexcept;
939
- PyObject* box_int16(PyObject* /*unused*/, PyObject* obj) noexcept;
940
- PyObject* box_uint16(PyObject* /*unused*/, PyObject* obj) noexcept;
941
- PyObject* box_int32(PyObject* /*unused*/, PyObject* obj) noexcept;
942
- PyObject* box_uint32(PyObject* /*unused*/, PyObject* obj) noexcept;
943
- PyObject* box_int64(PyObject* /*unused*/, PyObject* obj) noexcept;
944
- PyObject* box_uint64(PyObject* /*unused*/, PyObject* obj) noexcept;
945
- PyObject* box_single(PyObject* /*unused*/, PyObject* obj) noexcept;
946
- PyObject* box_double(PyObject* /*unused*/, PyObject* obj) noexcept;
947
- PyObject* box_char16(PyObject* /*unused*/, PyObject* obj) noexcept;
948
- PyObject* box_string(PyObject* /*unused*/, PyObject* obj) noexcept;
949
- PyObject* box_guid(PyObject* /*unused*/, PyObject* obj) noexcept;
950
- PyObject* box_date_time(PyObject* /*unused*/, PyObject* obj) noexcept;
951
- PyObject* box_time_span(PyObject* /*unused*/, PyObject* obj) noexcept;
952
- PyObject* unbox_boolean(PyObject* /*unused*/, PyObject* obj) noexcept;
953
- PyObject* unbox_int8(PyObject* /*unused*/, PyObject* obj) noexcept;
954
- PyObject* unbox_uint8(PyObject* /*unused*/, PyObject* obj) noexcept;
955
- PyObject* unbox_int16(PyObject* /*unused*/, PyObject* obj) noexcept;
956
- PyObject* unbox_uint16(PyObject* /*unused*/, PyObject* obj) noexcept;
957
- PyObject* unbox_int32(PyObject* /*unused*/, PyObject* obj) noexcept;
958
- PyObject* unbox_uint32(PyObject* /*unused*/, PyObject* obj) noexcept;
959
- PyObject* unbox_int64(PyObject* /*unused*/, PyObject* obj) noexcept;
960
- PyObject* unbox_uint64(PyObject* /*unused*/, PyObject* obj) noexcept;
961
- PyObject* unbox_single(PyObject* /*unused*/, PyObject* obj) noexcept;
962
- PyObject* unbox_double(PyObject* /*unused*/, PyObject* obj) noexcept;
963
- PyObject* unbox_char16(PyObject* /*unused*/, PyObject* obj) noexcept;
964
- PyObject* unbox_string(PyObject* /*unused*/, PyObject* obj) noexcept;
965
- PyObject* unbox_guid(PyObject* /*unused*/, PyObject* obj) noexcept;
966
- PyObject* unbox_date_time(PyObject* /*unused*/, PyObject* obj) noexcept;
967
- PyObject* unbox_time_span(PyObject* /*unused*/, PyObject* obj) noexcept;
968
- PyObject* read_table(PyObject* /*unused*/, PyObject* obj) noexcept;
969
- PyObject* as_interface(PyObject* /*unused*/, PyObject* args) noexcept;
970
- PyObject* get_activation_factory(PyObject* /*unused*/, PyObject* args) noexcept;
971
- PyObject* wrap_interface(PyObject* /*unused*/, PyObject* args) noexcept;
972
- PyObject* hresult_error(PyObject* /*unused*/, PyObject* args) noexcept;
973
-
974
939
  static PyMethodDef module_methods[]{
975
940
  {"init_apartment", init_apartment, METH_O, "initialize the apartment"},
976
941
  {"uninit_apartment",
@@ -1038,8 +1003,8 @@ namespace py::cpp::_winrt
1038
1003
  METH_O,
1039
1004
  PyDoc_STR(
1040
1005
  "Reads a projection table and returns its contents as plain Python objects. "
1041
- "This is how test/test_table.py checks that the generator's writer and the "
1042
- "runtime's reader agree on the format.")},
1006
+ "This is how test/projection/test_table.py checks that the generator's "
1007
+ "writer and the runtime's reader agree on the format.")},
1043
1008
  {"as_interface",
1044
1009
  as_interface,
1045
1010
  METH_VARARGS,
@@ -1058,6 +1023,13 @@ namespace py::cpp::_winrt
1058
1023
  wrap_interface,
1059
1024
  METH_VARARGS,
1060
1025
  PyDoc_STR("The WinRT object an interface pointer capsule holds.")},
1026
+ {"interface_pointer",
1027
+ interface_pointer,
1028
+ METH_O,
1029
+ PyDoc_STR(
1030
+ "The raw COM pointer an object holds, as an int. It is borrowed: no "
1031
+ "reference is added, it is valid only while the object is alive, and "
1032
+ "a receiver that keeps it must AddRef() it.")},
1061
1033
  {"hresult_error",
1062
1034
  hresult_error,
1063
1035
  METH_VARARGS,
@@ -1073,22 +1045,11 @@ namespace py::cpp::_winrt
1073
1045
  static const auto kSTA
1074
1046
  = static_cast<long>(winrt::apartment_type::single_threaded);
1075
1047
 
1076
- // CPython allocates the state zeroed just before this runs, and does
1077
- // not call traverse, clear or free before it has, so constructing the
1078
- // handles and maps first is what lets those three assume them.
1079
- auto state = reinterpret_cast<module_state*>(PyModule_GetState(module));
1080
- std::construct_at(&state->object_meta_type);
1081
- std::construct_at(&state->object_type);
1082
- std::construct_at(&state->array_type);
1083
- std::construct_at(&state->mapping_iter_type);
1084
- std::construct_at(&state->projected_method_type);
1085
- std::construct_at(&state->to_uuid_func);
1086
- std::construct_at(&state->uuid_type);
1087
- std::construct_at(&state->type_cache);
1088
- std::construct_at(&state->projections);
1089
- std::construct_at(&state->type_entries);
1090
- std::construct_at(&state->generic_types);
1091
- std::construct_at(&state->buffer_exports);
1048
+ // CPython allocates the state just before this runs, and does not call
1049
+ // traverse, clear or free before it has, so constructing it first is
1050
+ // what lets those three assume it.
1051
+ auto state = std::construct_at(
1052
+ reinterpret_cast<module_state*>(PyModule_GetState(module)));
1092
1053
 
1093
1054
  // The slot below says the same, but CPython only enforces it in an
1094
1055
  // interpreter configured to check, which a legacy subinterpreter on a
@@ -1169,7 +1130,6 @@ namespace py::cpp::_winrt
1169
1130
  state->projected_method_type = std::move(projected_method_type);
1170
1131
  state->to_uuid_func = std::move(to_uuid_func);
1171
1132
  state->uuid_type = std::move(uuid_type);
1172
- state->wrap_async_func = nullptr; // lazy-initialized
1173
1133
 
1174
1134
  main_state.store(state, std::memory_order_release);
1175
1135
 
@@ -11,6 +11,8 @@
11
11
 
12
12
  namespace py::cpp::_winrt
13
13
  {
14
+ extern PyType_Spec Array_type_spec;
15
+
14
16
  bool Array_Assign(PyObject* obj, std::unique_ptr<py::Array> array) noexcept;
15
17
 
16
18
  py::Array* Array_Get(PyObject* obj) noexcept;
@@ -3,6 +3,8 @@
3
3
  #include <winrt/base.h>
4
4
  #include <Python.h>
5
5
 
6
+ #include "_winrt_box.h"
7
+
6
8
  namespace
7
9
  {
8
10
  /**
@@ -0,0 +1,44 @@
1
+ // Boxing a Python value as the IReference<T> that WinRT takes where a parameter
2
+ // is an Object, and unboxing one: winrt._winrt.box_*() and unbox_*(), which
3
+ // winrt.system exports.
4
+
5
+ #pragma once
6
+
7
+ #include <Python.h>
8
+
9
+ namespace py::cpp::_winrt
10
+ {
11
+ PyObject* box_boolean(PyObject* /*unused*/, PyObject* obj) noexcept;
12
+ PyObject* box_int8(PyObject* /*unused*/, PyObject* obj) noexcept;
13
+ PyObject* box_uint8(PyObject* /*unused*/, PyObject* obj) noexcept;
14
+ PyObject* box_int16(PyObject* /*unused*/, PyObject* obj) noexcept;
15
+ PyObject* box_uint16(PyObject* /*unused*/, PyObject* obj) noexcept;
16
+ PyObject* box_int32(PyObject* /*unused*/, PyObject* obj) noexcept;
17
+ PyObject* box_uint32(PyObject* /*unused*/, PyObject* obj) noexcept;
18
+ PyObject* box_int64(PyObject* /*unused*/, PyObject* obj) noexcept;
19
+ PyObject* box_uint64(PyObject* /*unused*/, PyObject* obj) noexcept;
20
+ PyObject* box_single(PyObject* /*unused*/, PyObject* obj) noexcept;
21
+ PyObject* box_double(PyObject* /*unused*/, PyObject* obj) noexcept;
22
+ PyObject* box_char16(PyObject* /*unused*/, PyObject* obj) noexcept;
23
+ PyObject* box_string(PyObject* /*unused*/, PyObject* obj) noexcept;
24
+ PyObject* box_guid(PyObject* /*unused*/, PyObject* obj) noexcept;
25
+ PyObject* box_date_time(PyObject* /*unused*/, PyObject* obj) noexcept;
26
+ PyObject* box_time_span(PyObject* /*unused*/, PyObject* obj) noexcept;
27
+
28
+ PyObject* unbox_boolean(PyObject* /*unused*/, PyObject* obj) noexcept;
29
+ PyObject* unbox_int8(PyObject* /*unused*/, PyObject* obj) noexcept;
30
+ PyObject* unbox_uint8(PyObject* /*unused*/, PyObject* obj) noexcept;
31
+ PyObject* unbox_int16(PyObject* /*unused*/, PyObject* obj) noexcept;
32
+ PyObject* unbox_uint16(PyObject* /*unused*/, PyObject* obj) noexcept;
33
+ PyObject* unbox_int32(PyObject* /*unused*/, PyObject* obj) noexcept;
34
+ PyObject* unbox_uint32(PyObject* /*unused*/, PyObject* obj) noexcept;
35
+ PyObject* unbox_int64(PyObject* /*unused*/, PyObject* obj) noexcept;
36
+ PyObject* unbox_uint64(PyObject* /*unused*/, PyObject* obj) noexcept;
37
+ PyObject* unbox_single(PyObject* /*unused*/, PyObject* obj) noexcept;
38
+ PyObject* unbox_double(PyObject* /*unused*/, PyObject* obj) noexcept;
39
+ PyObject* unbox_char16(PyObject* /*unused*/, PyObject* obj) noexcept;
40
+ PyObject* unbox_string(PyObject* /*unused*/, PyObject* obj) noexcept;
41
+ PyObject* unbox_guid(PyObject* /*unused*/, PyObject* obj) noexcept;
42
+ PyObject* unbox_date_time(PyObject* /*unused*/, PyObject* obj) noexcept;
43
+ PyObject* unbox_time_span(PyObject* /*unused*/, PyObject* obj) noexcept;
44
+ } // namespace py::cpp::_winrt
@@ -38,13 +38,56 @@ __CRT_UUID_DECL(
38
38
 
39
39
  namespace py::cpp::_winrt
40
40
  {
41
+ /**
42
+ * A Python buffer as an IBuffer.
43
+ *
44
+ * It marshals by value, as Windows.Storage.Streams.Buffer does, rather than
45
+ * with the free-threaded marshaler that C++/WinRT gives an object by
46
+ * default. A buffer passed to a service in another process, as a GATT write
47
+ * passes its value to the Bluetooth service, then arrives there as a copy
48
+ * of its bytes. Marshaled by reference, it arrives as a proxy, the service
49
+ * never reads through it, and the write fails with ACCESS_DENIED.
50
+ *
51
+ * COM calls the IMarshal methods on whatever thread marshals the buffer,
52
+ * and the buffer marshaler reads Length, Capacity and Buffer() there, in
53
+ * MarshalInterface, to copy the bytes. That thread need not hold the GIL,
54
+ * and the thread that does may be waiting for the call to return, so
55
+ * nothing here but final_release() takes the GIL or touches a Python
56
+ * object: the view is taken once, with the GIL, when the buffer is made,
57
+ * and holds the memory still until it is released, so its pointer and size
58
+ * are plain values that any thread may read, and the length is atomic. The
59
+ * view is released only when the last reference goes, on whatever thread
60
+ * that is, and final_release() takes the GIL for it as the runtime's other
61
+ * objects do.
62
+ */
41
63
  struct PyWinRTBuffer : winrt::implements<
42
64
  PyWinRTBuffer,
43
65
  winrt::Windows::Storage::Streams::IBuffer,
44
66
  Windows::Storage::Streams::IBufferByteAccess,
45
- IPywinrtBuffer>
67
+ IPywinrtBuffer,
68
+ ::IMarshal>
46
69
  {
47
70
  private:
71
+ /**
72
+ * Calls @p f with the marshaler that Windows provides for IBuffer
73
+ * implementations (RoGetBufferMarshaler), the one that
74
+ * Windows.Storage.Streams.Buffer and .NET's WindowsRuntimeBuffer use.
75
+ *
76
+ * It is asked for on every call rather than kept, so there is nothing
77
+ * for two threads to fill in at once, and it takes no GIL.
78
+ */
79
+ template <typename F>
80
+ static HRESULT with_buffer_marshaler(F&& f) noexcept
81
+ {
82
+ winrt::com_ptr<::IMarshal> marshaler;
83
+ if (HRESULT const hr = ::RoGetBufferMarshaler(marshaler.put()); FAILED(hr))
84
+ {
85
+ return hr;
86
+ }
87
+
88
+ return f(marshaler.get());
89
+ }
90
+
48
91
  py::buffer_view buffer;
49
92
  /// How many of the bytes hold data: none at first for WinRT to fill,
50
93
  /// all of them for it to read, and what a writer sets after it has
@@ -130,6 +173,70 @@ namespace py::cpp::_winrt
130
173
  value = read_only;
131
174
  return S_OK;
132
175
  }
176
+
177
+ HRESULT __stdcall GetUnmarshalClass(
178
+ REFIID riid,
179
+ void* pv,
180
+ DWORD dest_context,
181
+ void* reserved,
182
+ DWORD flags,
183
+ CLSID* clsid) noexcept final
184
+ {
185
+ return with_buffer_marshaler([&](::IMarshal* marshaler) {
186
+ return marshaler->GetUnmarshalClass(
187
+ riid, pv, dest_context, reserved, flags, clsid);
188
+ });
189
+ }
190
+
191
+ HRESULT __stdcall GetMarshalSizeMax(
192
+ REFIID riid,
193
+ void* pv,
194
+ DWORD dest_context,
195
+ void* reserved,
196
+ DWORD flags,
197
+ DWORD* size) noexcept final
198
+ {
199
+ return with_buffer_marshaler([&](::IMarshal* marshaler) {
200
+ return marshaler->GetMarshalSizeMax(
201
+ riid, pv, dest_context, reserved, flags, size);
202
+ });
203
+ }
204
+
205
+ HRESULT __stdcall MarshalInterface(
206
+ IStream* stream,
207
+ REFIID riid,
208
+ void* pv,
209
+ DWORD dest_context,
210
+ void* reserved,
211
+ DWORD flags) noexcept final
212
+ {
213
+ return with_buffer_marshaler([&](::IMarshal* marshaler) {
214
+ return marshaler->MarshalInterface(
215
+ stream, riid, pv, dest_context, reserved, flags);
216
+ });
217
+ }
218
+
219
+ HRESULT __stdcall UnmarshalInterface(
220
+ IStream* stream, REFIID riid, void** object) noexcept final
221
+ {
222
+ return with_buffer_marshaler([&](::IMarshal* marshaler) {
223
+ return marshaler->UnmarshalInterface(stream, riid, object);
224
+ });
225
+ }
226
+
227
+ HRESULT __stdcall ReleaseMarshalData(IStream* stream) noexcept final
228
+ {
229
+ return with_buffer_marshaler([&](::IMarshal* marshaler) {
230
+ return marshaler->ReleaseMarshalData(stream);
231
+ });
232
+ }
233
+
234
+ HRESULT __stdcall DisconnectObject(DWORD reserved) noexcept final
235
+ {
236
+ return with_buffer_marshaler([&](::IMarshal* marshaler) {
237
+ return marshaler->DisconnectObject(reserved);
238
+ });
239
+ }
133
240
  };
134
241
 
135
242
  } // namespace py::cpp::_winrt
@@ -38,9 +38,6 @@ namespace
38
38
  return "event";
39
39
  }
40
40
 
41
- // The kind is read from another module, so it can hold a value this
42
- // one does not know about, and calling that an event would be a
43
- // guess rather than an answer.
44
41
  return "member";
45
42
  }
46
43
 
@@ -393,18 +390,12 @@ void py::set_member_not_available_error(py::member_not_available const& info) no
393
390
  info.interface_name);
394
391
  }
395
392
 
396
- void py::set_call_error(
397
- py::call_error error, py::member_site const* site, Py_ssize_t arg_count) noexcept
393
+ void py::set_call_error(py::call_error error, py::member_site const* site) noexcept
398
394
  {
399
395
  switch (error)
400
396
  {
401
397
  case call_error::invalid_arg_count:
402
- // -1 is how the generated code reports an argument tuple it could not
403
- // even count, which it only fails to do with a Python error already set
404
- if (arg_count != -1)
405
- {
406
- PyErr_SetString(PyExc_TypeError, "invalid parameter count");
407
- }
398
+ PyErr_SetString(PyExc_TypeError, "invalid parameter count");
408
399
  break;
409
400
 
410
401
  case call_error::keyword_arguments: