This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2018-12-18.12:04:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1545134641.38.0.788709270274.issue35523@psf.upfronthosting.co.za>
In-reply-to
Content
ctypes._reset_cache() contains the following code:

    # XXX for whatever reasons, creating the first instance of a callback
    # function is needed for the unittests on Win64 to succeed.  This MAY
    # be a compiler bug, since the problem occurs only when _ctypes is
    # compiled with the MS SDK compiler.  Or an uninitialized variable?
    CFUNCTYPE(c_int)(lambda: None)

This code has been added 11 years ago:

commit 674e9389e9fdadd622829f4833367ac3b38475b5
Author: Thomas Heller <theller@ctypes.org>
Date:   Fri Aug 31 13:06:44 2007 +0000

    Add a workaround for a strange bug on win64, when _ctypes is compiled
    with the SDK compiler.  This should fix the failing
    Lib\ctypes\test\test_as_parameter.py test.

diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
index cdf6d36e47..f55d194b8f 100644
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -535,3 +535,9 @@ for kind in [c_ushort, c_uint, c_ulong, c_ulonglong]:
     elif sizeof(kind) == 4: c_uint32 = kind
     elif sizeof(kind) == 8: c_uint64 = kind
 del(kind)
+
+# XXX for whatever reasons, creating the first instance of a callback
+# function is needed for the unittests on Win64 to succeed.  This MAY
+# be a compiler bug, since the problem occurs only when _ctypes is
+# compiled with the MS SDK compiler.  Or an uninitialized variable?
+CFUNCTYPE(c_int)(lambda: None)

--

This call is removed from Fedora package by the following patch:

https://src.fedoraproject.org/rpms/python3/blob/master/f/00155-avoid-ctypes-thunks.patch

Extract of Fedora python3.spec:

# 00155 #
# Avoid allocating thunks in ctypes unless absolutely necessary, to avoid
# generating SELinux denials on "import ctypes" and "import uuid" when
# embedding Python within httpd
# See https://bugzilla.redhat.com/show_bug.cgi?id=814391
Patch155: 00155-avoid-ctypes-thunks.patch

The patch has been added 6 years ago in Fedora:

commit 8a28107df1670a03a12cf6a7787160f103d8d8c8
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Fri Apr 20 15:28:39 2012 -0400

    3.2.3-4: avoid allocating thunks in ctypes unless absolutely necessary (patch 155; rhbz#814391)
    
    * Fri Apr 20 2012 David Malcolm <dmalcolm@redhat.com> - 3.2.3-4
    - avoid allocating thunks in ctypes unless absolutely necessary, to avoid
    generating SELinux denials on "import ctypes" and "import uuid" when embedding
    Python within httpd (patch 155; rhbz#814391)

https://src.fedoraproject.org/rpms/python3/c/8a28107df1670a03a12cf6a7787160f103d8d8c8?branch=master

--

I don't understand the purpose of the workaround and ctypes is working well on Fedora. I propose to also remove the workaround in the master branch.

In case of doubt, I prefer to keep the workaround in Python 3.7.

Attached PR removes the workaround.
History
Date User Action Args
2018-12-18 12:04:01vstinnersetrecipients: + vstinner
2018-12-18 12:04:01vstinnersetmessageid: <1545134641.38.0.788709270274.issue35523@psf.upfronthosting.co.za>
2018-12-18 12:04:01vstinnerlinkissue35523 messages
2018-12-18 12:04:01vstinnercreate