Skip to content

Commit 0a68a73

Browse files
junkmdsrinivasreddy
authored andcommitted
pythongh-127255: Make CopyComPointer public and add to ctypes doc. (pythonGH-127275)
1 parent dae9eef commit 0a68a73

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

Doc/library/ctypes.rst

+18
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,24 @@ Utility functions
19491949
It behaves similar to ``pointer(obj)``, but the construction is a lot faster.
19501950

19511951

1952+
.. function:: CopyComPointer(src, dst)
1953+
1954+
Copies a COM pointer from *src* to *dst* and returns the Windows specific
1955+
:c:type:`!HRESULT` value.
1956+
1957+
If *src* is not ``NULL``, its ``AddRef`` method is called, incrementing the
1958+
reference count.
1959+
1960+
In contrast, the reference count of *dst* will not be decremented before
1961+
assigning the new value. Unless *dst* is ``NULL``, the caller is responsible
1962+
for decrementing the reference count by calling its ``Release`` method when
1963+
necessary.
1964+
1965+
.. availability:: Windows
1966+
1967+
.. versionadded:: next
1968+
1969+
19521970
.. function:: cast(obj, type)
19531971

19541972
This function is similar to the cast operator in C. It returns a new instance

Doc/whatsnew/3.14.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,12 @@ ctypes
313313
to help match a non-default ABI.
314314
(Contributed by Petr Viktorin in :gh:`97702`.)
315315

316-
* The :exc:`~ctypes.COMError` exception is now public.
316+
* On Windows, the :exc:`~ctypes.COMError` exception is now public.
317317
(Contributed by Jun Komoda in :gh:`126686`.)
318318

319+
* On Windows, the :func:`~ctypes.CopyComPointer` function is now public.
320+
(Contributed by Jun Komoda in :gh:`127275`.)
321+
319322
datetime
320323
--------
321324

Lib/ctypes/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
raise Exception("Version number mismatch", __version__, _ctypes_version)
2020

2121
if _os.name == "nt":
22-
from _ctypes import COMError, FormatError
22+
from _ctypes import COMError, CopyComPointer, FormatError
2323

2424
DEFAULT_MODE = RTLD_LOCAL
2525
if _os.name == "posix" and _sys.platform == "darwin":

Lib/test/test_ctypes/test_win32_com_foreign_func.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
raise unittest.SkipTest("Windows-specific test")
1010

1111

12-
from _ctypes import COMError, CopyComPointer
13-
from ctypes import HRESULT
12+
from ctypes import COMError, CopyComPointer, HRESULT
1413

1514

1615
COINIT_APARTMENTTHREADED = 0x2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The :func:`~ctypes.CopyComPointer` function is now public.
2+
Previously, this was private and only available in ``_ctypes``.

0 commit comments

Comments
 (0)