Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-127255: Make CopyComPointer public and add to ctypes doc. #127275

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,23 @@ Utility functions
It behaves similar to ``pointer(obj)``, but the construction is a lot faster.


.. function:: CopyComPointer(src, dst)

Copies a COM pointer from *src* to *dst* and returns the Windows specific
:c:type:`!HRESULT` value.

If *src* is not ``NULL``, its ``AddRef`` method is called, incrementing the
reference count.

In contrast, even if *dst* is not ``NULL``, its reference count will not be
decremented before assigning the new value. You need to call its ``Release``
to free it appropriately.

.. availability:: Windows

.. versionadded:: next


.. function:: cast(obj, type)

This function is similar to the cast operator in C. It returns a new instance
Expand Down
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ ctypes
* The :exc:`~ctypes.COMError` exception is now public.
(Contributed by Jun Komoda in :gh:`126686`.)

* The :func:`~ctypes.CopyComPointer` function is now public.
(Contributed by Jun Komoda in :gh:`127275`.)

datetime
--------

Expand Down
2 changes: 1 addition & 1 deletion Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
raise Exception("Version number mismatch", __version__, _ctypes_version)

if _os.name == "nt":
from _ctypes import COMError, FormatError
from _ctypes import COMError, CopyComPointer, FormatError

DEFAULT_MODE = RTLD_LOCAL
if _os.name == "posix" and _sys.platform == "darwin":
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_ctypes/test_win32_com_foreign_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
raise unittest.SkipTest("Windows-specific test")


from _ctypes import COMError, CopyComPointer
from ctypes import HRESULT
from ctypes import COMError, CopyComPointer, HRESULT


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