https://github.com/python/cpython/commit/412e11fe6e37f15971ef855f88b8b01bb3297679
commit: 412e11fe6e37f15971ef855f88b8b01bb3297679
branch: main
author: Jun Komoda <[email protected]>
committer: encukou <[email protected]>
date: 2024-12-03T16:35:08+01:00
summary:
gh-127255: Make `CopyComPointer` public and add to `ctypes` doc. (GH-127275)
files:
A Misc/NEWS.d/next/Library/2024-11-25-15-02-44.gh-issue-127255.UXeljc.rst
M Doc/library/ctypes.rst
M Doc/whatsnew/3.14.rst
M Lib/ctypes/__init__.py
M Lib/test/test_ctypes/test_win32_com_foreign_func.py
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst
index bd9529db9ee65a..bd88fa377fb39d 100644
--- a/Doc/library/ctypes.rst
+++ b/Doc/library/ctypes.rst
@@ -1949,6 +1949,24 @@ 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, the reference count of *dst* will not be decremented before
+ assigning the new value. Unless *dst* is ``NULL``, the caller is responsible
+ for decrementing the reference count by calling its ``Release`` method when
+ necessary.
+
+ .. availability:: Windows
+
+ .. versionadded:: next
+
+
.. function:: cast(obj, type)
This function is similar to the cast operator in C. It returns a new
instance
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index 7bb9657e6ed9da..52a6d6e4340194 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -313,9 +313,12 @@ ctypes
to help match a non-default ABI.
(Contributed by Petr Viktorin in :gh:`97702`.)
-* The :exc:`~ctypes.COMError` exception is now public.
+* On Windows, the :exc:`~ctypes.COMError` exception is now public.
(Contributed by Jun Komoda in :gh:`126686`.)
+* On Windows, the :func:`~ctypes.CopyComPointer` function is now public.
+ (Contributed by Jun Komoda in :gh:`127275`.)
+
datetime
--------
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
index ac6493892068e9..2f2b0ca9f38633 100644
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -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":
diff --git a/Lib/test/test_ctypes/test_win32_com_foreign_func.py
b/Lib/test/test_ctypes/test_win32_com_foreign_func.py
index 8d217fc17efa02..7e54f8f6c31d33 100644
--- a/Lib/test/test_ctypes/test_win32_com_foreign_func.py
+++ b/Lib/test/test_ctypes/test_win32_com_foreign_func.py
@@ -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
diff --git
a/Misc/NEWS.d/next/Library/2024-11-25-15-02-44.gh-issue-127255.UXeljc.rst
b/Misc/NEWS.d/next/Library/2024-11-25-15-02-44.gh-issue-127255.UXeljc.rst
new file mode 100644
index 00000000000000..9fe7815e93cf4f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-11-25-15-02-44.gh-issue-127255.UXeljc.rst
@@ -0,0 +1,2 @@
+The :func:`~ctypes.CopyComPointer` function is now public.
+Previously, this was private and only available in ``_ctypes``.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]