Repository: zopefoundation/AccessControl (language: python)

Issue:
Update header files in include directory
The `include` directory contains copies of the needed header files.
They should be updated to the current versions of the original so we do not get out our sync.


Discussion / hints:

Fix patch:
diff --git a/.meta.toml b/.meta.toml
index 7a12127..a07dee6 100644
--- a/.meta.toml
+++ b/.meta.toml
@@ -2,7 +2,7 @@
 # https://github.com/zopefoundation/meta/tree/master/config/c-code
 [meta]
 template = "c-code"
-commit-id = "c7a64084"
+commit-id = "fe63cb4c"
 
 [python]
 with-appveyor = true
diff --git a/CHANGES.rst b/CHANGES.rst
index be81b4f..3b7ab45 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -5,6 +5,9 @@ For changes before version 3.0, see ``HISTORY.rst``.
 
 6.1 (unreleased)
 ----------------
+- Update C header files for ``ExtensionClass`` and ``Acquisition``
+  from the original packages where needed.
+  (`#140 <https://github.com/zopefoundation/AccessControl/issues/140>`_)
 
 - Add preliminary support for Python 3.12a5.
 
diff --git a/include/ExtensionClass/_compat.h b/include/ExtensionClass/_compat.h
index 9249333..f391fe6 100644
--- a/include/ExtensionClass/_compat.h
+++ b/include/ExtensionClass/_compat.h
@@ -17,11 +17,6 @@
 
 #include "Python.h"
 
-#if PY_MAJOR_VERSION >= 3
-#define PY3K
-#endif
-
-#ifdef PY3K
 #define INTERN PyUnicode_InternFromString
 #define INTERN_INPLACE PyUnicode_InternInPlace
 #define NATIVE_CHECK PyUnicode_Check
@@ -35,19 +30,33 @@
 
 #define HAS_TP_DESCR_GET(ob) 1
 
-#else
-#define INTERN PyString_InternFromString
-#define INTERN_INPLACE PyString_InternInPlace
-#define NATIVE_CHECK PyString_Check
-#define NATIVE_CHECK_EXACT PyString_CheckExact
-#define NATIVE_FROM_STRING PyString_FromString
-#define NATIVE_FROM_STRING_AND_SIZE PyString_FromStringAndSize
+#endif
+
+/* Python compatibility shims */
 
-#define INT_FROM_LONG(x) PyInt_FromLong(x)
-#define INT_CHECK(x) PyInt_Check(x)
-#define INT_AS_LONG(x) PyInt_AS_LONG(x)
+// Compatibility with Visual Studio 2013 and older which don't support
+// the inline keyword in C (only in C++): use __inline instead.
+#if (defined(_MSC_VER) && _MSC_VER < 1900 \
+     && !defined(__cplusplus) && !defined(inline))
+#  define inline __inline
+#  define PYTHONCAPI_COMPAT_MSC_INLINE
+   // These two macros are undefined at the end of this file
+#endif
+
+#ifndef _PyObject_CAST
+#  define _PyObject_CAST(op) ((PyObject*)(op))
+#endif
 
-#define HAS_TP_DESCR_GET(ob) PyType_HasFeature(Py_TYPE(ob), Py_TPFLAGS_HAVE_CLASS)
+#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
+static inline void
+_Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
+{
+    ob->ob_type = type;
+}
+#define Py_SET_TYPE(ob, type) _Py_SET_TYPE(_PyObject_CAST(ob), type)
 #endif
 
+#ifdef PYTHONCAPI_COMPAT_MSC_INLINE
+#  undef inline
+#  undef PYTHONCAPI_COMPAT_MSC_INLINE
 #endif
diff --git a/setup.cfg b/setup.cfg
index e952477..8fbcf77 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -24,7 +24,7 @@ ignore =
 force_single_line = True
 combine_as_imports = True
 sections = FUTURE,STDLIB,THIRDPARTY,ZOPE,FIRSTPARTY,LOCALFOLDER
-known_third_party = six, docutils, pkg_resources, pytz
+known_third_party = docutils, pkg_resources, pytz
 known_zope =
 known_first_party =
 default_section = ZOPE


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index c8d75de..3bfc5d5 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -101,7 +101,7 @@ jobs:
           - "3.9"
           - "3.10"
           - "3.11"
-          - "3.12.0-alpha.5"
+          - "3.12.0-alpha.7"
         os: [ubuntu-20.04, macos-11]
 
     steps:
@@ -174,15 +174,15 @@ jobs:
           python setup.py build_ext -i
           python setup.py bdist_wheel
 
-      - name: Install AccessControl and dependencies (3.12.0-alpha.5)
-        if: matrix.python-version == '3.12.0-alpha.5'
+      - name: Install AccessControl and dependencies (3.12.0-alpha.7)
+        if: matrix.python-version == '3.12.0-alpha.7'
         run: |
           # Install to collect dependencies into the (pip) cache.
           # Use "--pre" here because dependencies with support for this future
           # Python release may only be available as pre-releases
           pip install --pre .[test]
       - name: Install AccessControl and dependencies
-        if: matrix.python-version != '3.12.0-alpha.5'
+        if: matrix.python-version != '3.12.0-alpha.7'
         run: |
           # Install to collect dependencies into the (pip) cache.
           pip install .[test]
@@ -226,7 +226,7 @@ jobs:
           && startsWith(github.ref, 'refs/tags')
           && startsWith(runner.os, 'Mac')
           && !startsWith(matrix.python-version, 'pypy')
-          && !startsWith(matrix.python-version, '3.12.0-alpha.5')
+          && !startsWith(matrix.python-version, '3.12.0-alpha.7')
         env:
           TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
         run: |
@@ -244,7 +244,7 @@ jobs:
           - "3.9"
           - "3.10"
           - "3.11"
-          - "3.12.0-alpha.5"
+          - "3.12.0-alpha.7"
         os: [ubuntu-20.04, macos-11]
 
     steps:
@@ -278,8 +278,8 @@ jobs:
         with:
           name: AccessControl-${{ runner.os }}-${{ matrix.python-version }}.whl
           path: dist/
-      - name: Install AccessControl 3.12.0-alpha.5
-        if: ${{ startsWith(matrix.python-version, '3.12.0-alpha.5') }}
+      - name: Install AccessControl 3.12.0-alpha.7
+        if: ${{ startsWith(matrix.python-version, '3.12.0-alpha.7') }}
         run: |
           pip install -U wheel setuptools
           # coverage has a wheel on PyPI for a future python version which is
@@ -293,7 +293,7 @@ jobs:
           # Python release may only be available as pre-releases
           pip install --pre -U -e .[test]
       - name: Install AccessControl
-        if: ${{ !startsWith(matrix.python-version, '3.12.0-alpha.5') }}
+        if: ${{ !startsWith(matrix.python-version, '3.12.0-alpha.7') }}
         run: |
           pip install -U wheel setuptools
           pip install -U coverage
diff --git a/src/AccessControl/tests/testZopeGuards.py b/src/AccessControl/tests/testZopeGuards.py
index 3f459a0..533bfa2 100644
--- a/src/AccessControl/tests/testZopeGuards.py
+++ b/src/AccessControl/tests/testZopeGuards.py
@@ -98,7 +98,7 @@ def test_miss(self):
 
     def test_unhashable_key(self):
         from AccessControl.ZopeGuards import guarded_getattr
-        obj, name = object(), {}
+        obj, name = object(), []
         self.assertRaises(TypeError, guarded_getattr, obj, name)
         self.assertEqual(len(self.__sm.calls), 0)
 
@@ -180,7 +180,7 @@ def test_miss(self):
 
     def test_unhashable_key(self):
         from AccessControl.ZopeGuards import guarded_hasattr
-        obj, name = object(), {}
+        obj, name = object(), []
         self.assertFalse(guarded_hasattr(obj, name))
         self.assertEqual(len(self.__sm.calls), 0)