pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/lang/python27



Module Name:    pkgsrc
Committed By:   schmonz
Date:           Wed Jun 23 18:30:24 UTC 2021

Modified Files:
        pkgsrc/lang/python27: distinfo
        pkgsrc/lang/python27/patches: patch-Lib_test_test__urllib2.py
            patch-Modules_getpath.c patch-configure patch-pyconfig.h.in
            patch-setup.py
Added Files:
        pkgsrc/lang/python27/patches: patch-Lib___osx__support.py
            patch-Lib_ctypes_macholib_dyld.py
            patch-Lib_ctypes_test_test__macholib.py
            patch-Lib_distutils_tests_test__build__ext.py
            patch-Lib_test_test__platform.py patch-Lib_test_test__unicode.py
            patch-Mac_Tools_pythonw.c patch-Modules___ctypes_callbacks.c
            patch-Modules___ctypes_callproc.c patch-Modules___ctypes_ctypes.h
            patch-Modules___ctypes_malloc__closure.c

Log Message:
Fix build on darwin20 and macOS arm64, via MacPorts. For other
platforms, NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 pkgsrc/lang/python27/distinfo
cvs rdiff -u -r0 -r1.1 \
    pkgsrc/lang/python27/patches/patch-Lib___osx__support.py \
    pkgsrc/lang/python27/patches/patch-Lib_ctypes_macholib_dyld.py \
    pkgsrc/lang/python27/patches/patch-Lib_ctypes_test_test__macholib.py \
    pkgsrc/lang/python27/patches/patch-Lib_distutils_tests_test__build__ext.py \
    pkgsrc/lang/python27/patches/patch-Lib_test_test__platform.py \
    pkgsrc/lang/python27/patches/patch-Lib_test_test__unicode.py \
    pkgsrc/lang/python27/patches/patch-Mac_Tools_pythonw.c \
    pkgsrc/lang/python27/patches/patch-Modules___ctypes_callbacks.c \
    pkgsrc/lang/python27/patches/patch-Modules___ctypes_callproc.c \
    pkgsrc/lang/python27/patches/patch-Modules___ctypes_ctypes.h \
    pkgsrc/lang/python27/patches/patch-Modules___ctypes_malloc__closure.c
cvs rdiff -u -r1.2 -r1.3 \
    pkgsrc/lang/python27/patches/patch-Lib_test_test__urllib2.py
cvs rdiff -u -r1.3 -r1.4 pkgsrc/lang/python27/patches/patch-Modules_getpath.c
cvs rdiff -u -r1.1 -r1.2 pkgsrc/lang/python27/patches/patch-configure \
    pkgsrc/lang/python27/patches/patch-setup.py
cvs rdiff -u -r1.5 -r1.6 pkgsrc/lang/python27/patches/patch-pyconfig.h.in

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/lang/python27/distinfo
diff -u pkgsrc/lang/python27/distinfo:1.81 pkgsrc/lang/python27/distinfo:1.82
--- pkgsrc/lang/python27/distinfo:1.81  Sun Sep 27 14:57:22 2020
+++ pkgsrc/lang/python27/distinfo       Wed Jun 23 18:30:24 2021
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.81 2020/09/27 14:57:22 leot Exp $
+$NetBSD: distinfo,v 1.82 2021/06/23 18:30:24 schmonz Exp $
 
 SHA1 (Python-2.7.18.tar.xz) = 678d4cf483a1c92efd347ee8e1e79326dc82810b
 RMD160 (Python-2.7.18.tar.xz) = 40a514bb05c9e631454ea8466e28f5bb229428ad
@@ -6,11 +6,15 @@ SHA512 (Python-2.7.18.tar.xz) = a7bb62b5
 Size (Python-2.7.18.tar.xz) = 12854736 bytes
 SHA1 (patch-Include_pyerrors.h) = 0d2cd52d18cc719b895fa32ed7e11c6cb15bae54
 SHA1 (patch-Include_pyport.h) = f3e4ddbc954425a65301465410911222ca471320
+SHA1 (patch-Lib___osx__support.py) = 4389472565616b3875c699f6e3e74850d5fde712
 SHA1 (patch-Lib_ctypes_____init____.py) = 31dd0546bbe29ad1b1d481edc525ba43479c06da
+SHA1 (patch-Lib_ctypes_macholib_dyld.py) = 9b7e972d4c71311742ca8b3501382182a4c9e2fe
+SHA1 (patch-Lib_ctypes_test_test__macholib.py) = 4479d315cd037f4c9138e8f5baa8eb1685932baa
 SHA1 (patch-Lib_ctypes_util.py) = 6fa516c7b43f08992427a0afcbe80c17bcc070f1
 SHA1 (patch-Lib_distutils_command_build__ext.py) = ea4feba4e93dbcff07050c82a00d591bb650e934
 SHA1 (patch-Lib_distutils_command_install.py) = e6aef090b444b455fe351308d251e670329b7dc3
 SHA1 (patch-Lib_distutils_command_install__egg__info.py) = ec7f9e0cd04489b1f6497c44d75bff6864ad1047
+SHA1 (patch-Lib_distutils_tests_test__build__ext.py) = 6b3c8c8d1d351836b239c049d34d132953bd4786
 SHA1 (patch-Lib_distutils_unixccompiler.py) = db16c9aca2f29730945f28247b88b18828739bbb
 SHA1 (patch-Lib_distutils_util.py) = 5bcfad96f8e490351160f1a7c1f4ece7706a33fa
 SHA1 (patch-Lib_httplib.py) = 375d80eb79209f53046c62db128d8d3f64d9e765
@@ -20,14 +24,21 @@ SHA1 (patch-Lib_plistlib.py) = 96ae70299
 SHA1 (patch-Lib_sysconfig.py) = 8a7a0e5cbfec279a05945dffafea1b1131a76f0e
 SHA1 (patch-Lib_tarfile.py) = df00aa1941367c42dcbbed4b6658b724a22ddcde
 SHA1 (patch-Lib_test_test__httplib.py) = 9d37263e36110838e0b5f413ff4747deb3966dfe
-SHA1 (patch-Lib_test_test__urllib2.py) = 09013a0b4a3e6064cbfe96572e47464c5d6ef047
+SHA1 (patch-Lib_test_test__platform.py) = 3a3b8c05f9bf9adf4862b1022ce864127d36b8b0
+SHA1 (patch-Lib_test_test__unicode.py) = 1bd182bdbd880d0a847f9d8b69277a607f9f0526
+SHA1 (patch-Lib_test_test__urllib2.py) = 89baa57daf2f3282e4fc5009915dbc4910b96ef1
 SHA1 (patch-Lib_urllib2.py) = 33a85593da702447fa3ea74b4e3d36d0016f70b5
+SHA1 (patch-Mac_Tools_pythonw.c) = 2b9a60d4b349c240471fd305be69c28e0f654cdc
 SHA1 (patch-Makefile.pre.in) = ceaf34237588b527478ce1f9163c9168382fa201
+SHA1 (patch-Modules___ctypes_callbacks.c) = 8c335edfc9d2ef47988c5bdf1c3dd8473757637b
+SHA1 (patch-Modules___ctypes_callproc.c) = adac5eb047eb58c14003ea9237d5d34e8b327b2f
+SHA1 (patch-Modules___ctypes_ctypes.h) = 07e9d5ecf8309a3ca4bf8382411d56dda08d7b27
+SHA1 (patch-Modules___ctypes_malloc__closure.c) = 25d470cc66d218446227c7c1bd7ade409c53b8d0
 SHA1 (patch-Modules___multiprocessing_multiprocessing.h) = 7ca8fe22ba4bdcde6d39dd50fe2e86c25994c146
 SHA1 (patch-Modules___multiprocessing_semaphore.c) = 03b9c33ef38da383d5f7c2c84c17fe38cdd2911e
 SHA1 (patch-Modules__ssl.c) = 6e68f88ad205106691900f091a897ffe0a4c363c
 SHA1 (patch-Modules_getaddrinfo.c) = aa699d257f1bc98b9a3183a21324053e134409d1
-SHA1 (patch-Modules_getpath.c) = 9bb2c040895ad6bbe4d0b5807803723b5437d47b
+SHA1 (patch-Modules_getpath.c) = 4e6445be9da49626800c03eaaab28fb3826be9f9
 SHA1 (patch-Modules_makesetup) = 9aad78714c4fe1a21cf66a6627d97d164ecea196
 SHA1 (patch-Modules_nismodule.c) = 129ef7b32779944c2f1827c6b078a3aafab60729
 SHA1 (patch-Modules_posixmodule.c) = 5105d380cd49bf49b8adbd9aa5ffb245195728ed
@@ -35,6 +46,6 @@ SHA1 (patch-Modules_selectmodule.c) = 01
 SHA1 (patch-Modules_socketmodule.c) = 16848d90947b3de1f921a0813fa5c317f76961d4
 SHA1 (patch-Modules_sunaudiodev.c) = d836d77854a2b3d79fa34a06a8e2493bf0a503e6
 SHA1 (patch-Python_thread__pthread.h) = 517cfefc2f2e13631d22bad28c327513cdf17c10
-SHA1 (patch-configure) = 999700e96dd227cdd16cea3ae1001eb887ab8fee
-SHA1 (patch-pyconfig.h.in) = a0143ecdc2a3fb10220d0e3ee94fb9779a45e9e1
-SHA1 (patch-setup.py) = bf9763d5a3584970474d5951ed1fc73eb03ea11c
+SHA1 (patch-configure) = a8bcacd360ca3a451c43a05a4be3bcea56f70617
+SHA1 (patch-pyconfig.h.in) = 66d1a685e17ef7977bf09cdc64bdf80087216bc7
+SHA1 (patch-setup.py) = 19aa0992ea75cd151be7e35f05d9af0a84d07e85

Index: pkgsrc/lang/python27/patches/patch-Lib_test_test__urllib2.py
diff -u pkgsrc/lang/python27/patches/patch-Lib_test_test__urllib2.py:1.2 pkgsrc/lang/python27/patches/patch-Lib_test_test__urllib2.py:1.3
--- pkgsrc/lang/python27/patches/patch-Lib_test_test__urllib2.py:1.2    Sun Sep 20 12:10:27 2020
+++ pkgsrc/lang/python27/patches/patch-Lib_test_test__urllib2.py        Wed Jun 23 18:30:24 2021
@@ -1,11 +1,11 @@
-$NetBSD: patch-Lib_test_test__urllib2.py,v 1.2 2020/09/20 12:10:27 mgorny Exp $
+$NetBSD: patch-Lib_test_test__urllib2.py,v 1.3 2021/06/23 18:30:24 schmonz Exp $
 
 bpo-39503 (CVE-2020-8492): ReDoS on AbstractBasicAuthHandler
 
 taken from:
 https://gitweb.gentoo.org/fork/cpython.git/commit/?h=gentoo-2.7-vanilla&id=2273e65e11dd0234f2f51ebaef61fc6e848d4059
 
---- Lib/test/test_urllib2.py.orig      2020-04-19 21:13:39.000000000 +0000
+--- Lib/test/test_urllib2.py.orig      2021-06-22 19:20:43.000000000 +0000
 +++ Lib/test/test_urllib2.py
 @@ -1128,42 +1128,67 @@ class HandlerTests(unittest.TestCase):
          self.assertEqual(req.get_host(), "proxy.example.com:3128")
@@ -29,26 +29,10 @@ https://gitweb.gentoo.org/fork/cpython.g
                                "http://acme.example.com/protected";,
 -                              "http://acme.example.com/protected";
 -                             )
-+                              "http://acme.example.com/protected";)
- 
+-
 -    def test_basic_auth_with_single_quoted_realm(self):
 -        self.test_basic_auth(quote_char="'")
-+    def test_basic_auth(self):
-+        realm = "realm2%example.com@localhost"
-+        realm2 = "realm2%example.com@localhost"
-+        basic = 'Basic realm="{realm}"'.format(realm=realm)
-+        basic2 = 'Basic realm="{realm2}"'.format(realm2=realm2)
-+        other_no_realm = 'Otherscheme xxx'
-+        digest = ('Digest realm="{realm2}", '
-+                  'qop="auth, auth-int", '
-+                  'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '
-+                  'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
-+                  .format(realm2=realm2))
-+        for realm_str in (
-+            # test "quote" and 'quote'
-+            'Basic realm="{realm}"'.format(realm=realm),
-+            "Basic realm='{realm}'".format(realm=realm),
- 
+-
 -    def test_basic_auth_with_unquoted_realm(self):
 -        opener = OpenerDirector()
 -        password_manager = MockPasswordManager()
@@ -65,6 +49,24 @@ https://gitweb.gentoo.org/fork/cpython.g
 -                                  "http://acme.example.com/protected";,
 -                                  "http://acme.example.com/protected";
 -                                 )
++                              "http://acme.example.com/protected";)
+ 
++    def test_basic_auth(self):
++        realm = "realm2%example.com@localhost"
++        realm2 = "realm2%example.com@localhost"
++        basic = 'Basic realm="{realm}"'.format(realm=realm)
++        basic2 = 'Basic realm="{realm2}"'.format(realm2=realm2)
++        other_no_realm = 'Otherscheme xxx'
++        digest = ('Digest realm="{realm2}", '
++                  'qop="auth, auth-int", '
++                  'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", '
++                  'opaque="5ccc069c403ebaf9f0171e9517f40e41"'
++                  .format(realm2=realm2))
++        for realm_str in (
++            # test "quote" and 'quote'
++            'Basic realm="{realm}"'.format(realm=realm),
++            "Basic realm='{realm}'".format(realm=realm),
++
 +            # charset is ignored
 +            'Basic realm="{realm}", charset="UTF-8"'.format(realm=realm),
 +
@@ -85,7 +87,7 @@ https://gitweb.gentoo.org/fork/cpython.g
 +            headers = ['WWW-Authenticate: Basic realm={realm}'
 +                       .format(realm=realm)]
 +            self.check_basic_auth(headers, realm)
- 
++
 +        # Multiple headers: one challenge per header.
 +        # Use the first Basic realm.
 +        for challenges in (

Index: pkgsrc/lang/python27/patches/patch-Modules_getpath.c
diff -u pkgsrc/lang/python27/patches/patch-Modules_getpath.c:1.3 pkgsrc/lang/python27/patches/patch-Modules_getpath.c:1.4
--- pkgsrc/lang/python27/patches/patch-Modules_getpath.c:1.3    Fri Apr 24 03:01:36 2015
+++ pkgsrc/lang/python27/patches/patch-Modules_getpath.c        Wed Jun 23 18:30:24 2021
@@ -1,10 +1,18 @@
-$NetBSD: patch-Modules_getpath.c,v 1.3 2015/04/24 03:01:36 rodent Exp $
+$NetBSD: patch-Modules_getpath.c,v 1.4 2021/06/23 18:30:24 schmonz Exp $
 
 * from cygport 2.7.3-getpath-exe-extension.patch
 
---- Modules/getpath.c.orig     2014-12-10 15:59:55.000000000 +0000
+--- Modules/getpath.c.orig     2021-06-22 19:20:43.000000000 +0000
 +++ Modules/getpath.c
-@@ -451,6 +451,28 @@ calculate_path(void)
+@@ -8,6 +8,7 @@
+ 
+ #ifdef __APPLE__
+ #include <mach-o/dyld.h>
++#include <AvailabilityMacros.h>
+ #endif
+ 
+ /* Search in some common locations for the associated Python libraries.
+@@ -428,6 +429,28 @@ calculate_path(void)
                          if (isxfile(progpath))
                                  break;
  

Index: pkgsrc/lang/python27/patches/patch-configure
diff -u pkgsrc/lang/python27/patches/patch-configure:1.1 pkgsrc/lang/python27/patches/patch-configure:1.2
--- pkgsrc/lang/python27/patches/patch-configure:1.1    Sun Jun 17 19:21:21 2018
+++ pkgsrc/lang/python27/patches/patch-configure        Wed Jun 23 18:30:24 2021
@@ -1,12 +1,13 @@
-$NetBSD: patch-configure,v 1.1 2018/06/17 19:21:21 adam Exp $
+$NetBSD: patch-configure,v 1.2 2021/06/23 18:30:24 schmonz Exp $
 
 - recognize MirBSD, Interix
 - remove special-case library version hack for FreeBSD
 - don't set Mac OS X target version: stick to the current one
 - honor pkgsrc LDFLAGS
+- macOS arm64 and darwin20 support, via MacPorts
 - other stuff not previously commented (XXX)
 
---- configure.orig     2018-04-29 22:47:33.000000000 +0000
+--- configure.orig     2021-06-22 19:20:43.000000000 +0000
 +++ configure
 @@ -3356,7 +3356,7 @@ case $ac_sys_system/$ac_sys_release in
    # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish.
@@ -17,6 +18,15 @@ $NetBSD: patch-configure,v 1.1 2018/06/1
      define_xopen_source=no
      # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is
      # also defined. This can be overridden by defining _BSD_SOURCE
+@@ -3407,7 +3407,7 @@ $as_echo "#define _BSD_SOURCE 1" >>confd
+   # has no effect, don't bother defining them
+   Darwin/[6789].*)
+     define_xopen_source=no;;
+-  Darwin/1[0-9].*)
++  Darwin/[12][0-9].*)
+     define_xopen_source=no;;
+   # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but
+   # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined
 @@ -5481,15 +5481,10 @@ $as_echo "#define Py_ENABLE_SHARED 1" >>
          RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
          INSTSONAME="$LDLIBRARY".$SOVERSION
@@ -57,7 +67,17 @@ $NetBSD: patch-configure,v 1.1 2018/06/1
          then
              # OS X 10.3 through 10.5
              cur_target=10.3
-@@ -8617,9 +8615,9 @@ then
+@@ -8474,6 +8472,9 @@ fi
+       ppc)
+               MACOSX_DEFAULT_ARCH="ppc64"
+               ;;
++      arm64)
++              MACOSX_DEFAULT_ARCH="arm64"
++              ;;
+       *)
+               as_fn_error $? "Unexpected output of 'arch' on OSX" "$LINENO" 5
+               ;;
+@@ -8624,9 +8625,9 @@ then
                        LDCXXSHARED="$LDCXXSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
                else
                        # No framework, use the Python app as bundle-loader
@@ -70,7 +90,7 @@ $NetBSD: patch-configure,v 1.1 2018/06/1
                fi ;;
        Darwin/*)
                # Use -undefined dynamic_lookup whenever possible (10.3 and later).
-@@ -8642,9 +8640,9 @@ then
+@@ -8649,9 +8650,9 @@ then
                                LDCXXSHARED="$LDCXXSHARED "'$(PYTHONFRAMEWORKPREFIX)/$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)'
                        else
                                # No framework, use the Python app as bundle-loader
@@ -83,7 +103,7 @@ $NetBSD: patch-configure,v 1.1 2018/06/1
                        fi
                else
                        # building for OS X 10.3 and later
-@@ -8655,7 +8653,7 @@ then
+@@ -8662,7 +8663,7 @@ then
                ;;
        Linux*|GNU*|QNX*)
                LDSHARED='$(CC) -shared'
@@ -92,7 +112,7 @@ $NetBSD: patch-configure,v 1.1 2018/06/1
        BSD/OS*/4*)
                LDSHARED="gcc -shared"
                LDCXXSHARED="g++ -shared";;
-@@ -8683,6 +8681,9 @@ then
+@@ -8690,6 +8691,9 @@ then
                                   ;;
                                esac
                fi;;
@@ -102,7 +122,7 @@ $NetBSD: patch-configure,v 1.1 2018/06/1
        NetBSD*|DragonFly*)
                LDSHARED='$(CC) -shared'
                LDCXXSHARED='$(CXX) -shared';;
-@@ -8729,7 +8730,8 @@ then
+@@ -8736,7 +8740,8 @@ then
                 fi;;
        Linux*|GNU*) CCSHARED="-fPIC";;
        BSD/OS*/4*) CCSHARED="-fpic";;
@@ -112,7 +132,7 @@ $NetBSD: patch-configure,v 1.1 2018/06/1
        OpenUNIX*|UnixWare*)
                if test "$GCC" = "yes"
                then CCSHARED="-fPIC"
-@@ -8781,11 +8783,12 @@ then
+@@ -8788,11 +8793,12 @@ then
        OpenUNIX*|UnixWare*) LINKFORSHARED="-Wl,-Bexport";;
        SCO_SV*) LINKFORSHARED="-Wl,-Bexport";;
        ReliantUNIX*) LINKFORSHARED="-W1 -Blargedynsym";;
@@ -126,7 +146,23 @@ $NetBSD: patch-configure,v 1.1 2018/06/1
        SunOS/5*) case $CC in
                  *gcc*)
                    if $CC -Xlinker --help 2>&1 | grep export-dynamic >/dev/null
-@@ -10798,6 +10801,10 @@ int
+@@ -10596,6 +10602,15 @@ fi
+ done
+ 
+ 
++ac_fn_c_check_decl "$LINENO" "_dyld_shared_cache_contains_path" "ac_cv_have_decl__dyld_shared_cache_contains_path" "#include <mach-o/dyld.h>
++"
++if test "x$ac_cv_have_decl__dyld_shared_cache_contains_path" = xyes; then :
++
++$as_echo "#define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH 1" >>confdefs.h
++
++fi
++
++
+ # DYNLOADFILE specifies which dynload_*.o file we will use for dynamic
+ # loading of modules.
+ 
+@@ -10883,6 +10898,10 @@ int
  main ()
  {
  int x=kqueue()
Index: pkgsrc/lang/python27/patches/patch-setup.py
diff -u pkgsrc/lang/python27/patches/patch-setup.py:1.1 pkgsrc/lang/python27/patches/patch-setup.py:1.2
--- pkgsrc/lang/python27/patches/patch-setup.py:1.1     Sun Jun 17 19:21:21 2018
+++ pkgsrc/lang/python27/patches/patch-setup.py Wed Jun 23 18:30:24 2021
@@ -1,4 +1,4 @@
-$NetBSD: patch-setup.py,v 1.1 2018/06/17 19:21:21 adam Exp $
+$NetBSD: patch-setup.py,v 1.2 2021/06/23 18:30:24 schmonz Exp $
 
 Disable certain modules, so they can be built as separate packages.
 Only check the BUILDLINK_DIR for libraries etc, do not pick up random
@@ -10,11 +10,21 @@ Assume panel_library is correct; this is
 
 Build the _ssl module with pkgsrc choiced OpenSSL.
 
+macOS arm64 support, via MacPorts.
+
 cygwin 2.7.3-no-libm.patch
 
---- setup.py.orig      2018-04-29 22:47:33.000000000 +0000
+--- setup.py.orig      2021-06-22 19:20:43.000000000 +0000
 +++ setup.py
-@@ -33,7 +33,7 @@ host_platform = get_platform()
+@@ -16,6 +16,7 @@ from distutils.command.build_ext import 
+ from distutils.command.install import install
+ from distutils.command.install_lib import install_lib
+ from distutils.spawn import find_executable
++import distutils.command.config
+ 
+ cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ
+ 
+@@ -33,7 +34,7 @@ host_platform = get_platform()
  COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
  
  # This global variable is used to hold the list of modules to be disabled.
@@ -23,7 +33,7 @@ cygwin 2.7.3-no-libm.patch
  
  def add_dir_to_list(dirlist, dir):
      """Add the directory 'dir' to the list 'dirlist' (at the front) if
-@@ -454,10 +454,15 @@ class PyBuildExt(build_ext):
+@@ -500,10 +501,15 @@ class PyBuildExt(build_ext):
              os.unlink(tmpfile)
  
      def detect_modules(self):
@@ -43,7 +53,7 @@ cygwin 2.7.3-no-libm.patch
          if cross_compiling:
              self.add_gcc_paths()
          self.add_multiarch_paths()
-@@ -569,7 +574,7 @@ class PyBuildExt(build_ext):
+@@ -615,7 +621,7 @@ class PyBuildExt(build_ext):
  
          # Check for MacOS X, which doesn't need libm.a at all
          math_libs = ['m']
@@ -52,7 +62,7 @@ cygwin 2.7.3-no-libm.patch
              math_libs = []
  
          # XXX Omitted modules: gl, pure, dl, SGI-specific modules
-@@ -745,8 +750,6 @@ class PyBuildExt(build_ext):
+@@ -791,8 +797,6 @@ class PyBuildExt(build_ext):
          # use the same library for the readline and curses modules.
          if 'curses' in readline_termcap_library:
              curses_library = readline_termcap_library
@@ -61,7 +71,7 @@ cygwin 2.7.3-no-libm.patch
          elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
              curses_library = 'ncurses'
          elif self.compiler.find_library_file(lib_dirs, 'curses'):
-@@ -809,11 +812,10 @@ class PyBuildExt(build_ext):
+@@ -855,11 +859,10 @@ class PyBuildExt(build_ext):
                                 libraries=math_libs) )
          # Detect SSL support for the socket module (via _ssl)
          search_for_ssl_incs_in = [
@@ -76,7 +86,7 @@ cygwin 2.7.3-no-libm.patch
                               )
          if ssl_incs is not None:
              krb5_h = find_file('krb5.h', inc_dirs,
-@@ -821,9 +823,7 @@ class PyBuildExt(build_ext):
+@@ -867,9 +870,7 @@ class PyBuildExt(build_ext):
              if krb5_h:
                  ssl_incs += krb5_h
          ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
@@ -87,7 +97,7 @@ cygwin 2.7.3-no-libm.patch
  
          if (ssl_incs is not None and
              ssl_libs is not None):
-@@ -842,7 +842,7 @@ class PyBuildExt(build_ext):
+@@ -888,7 +889,7 @@ class PyBuildExt(build_ext):
  
          # look for the openssl version header on the compiler search path.
          opensslv_h = find_file('openssl/opensslv.h', [],
@@ -96,7 +106,7 @@ cygwin 2.7.3-no-libm.patch
          if opensslv_h:
              name = os.path.join(opensslv_h[0], 'openssl/opensslv.h')
              if host_platform == 'darwin' and is_macosx_sdk_path(name):
-@@ -942,175 +942,6 @@ class PyBuildExt(build_ext):
+@@ -988,175 +989,6 @@ class PyBuildExt(build_ext):
              else:
                  raise ValueError("unknown major BerkeleyDB version", major)
  
@@ -272,7 +282,7 @@ cygwin 2.7.3-no-libm.patch
          # The sqlite interface
          sqlite_setup_debug = False   # verbose debug prints from this script?
  
-@@ -1216,46 +1047,32 @@ class PyBuildExt(build_ext):
+@@ -1262,46 +1094,32 @@ class PyBuildExt(build_ext):
          else:
              missing.append('_sqlite3')
  
@@ -342,7 +352,7 @@ cygwin 2.7.3-no-libm.patch
              config_args = [arg.strip("'")
                             for arg in sysconfig.get_config_var("CONFIG_ARGS").split()]
              dbm_args = [arg for arg in config_args
-@@ -1267,7 +1084,7 @@ class PyBuildExt(build_ext):
+@@ -1313,7 +1131,7 @@ class PyBuildExt(build_ext):
              dbmext = None
              for cand in dbm_order:
                  if cand == "ndbm":
@@ -351,7 +361,7 @@ cygwin 2.7.3-no-libm.patch
                          # Some systems have -lndbm, others have -lgdbm_compat,
                          # others don't have either
                          if self.compiler.find_library_file(lib_dirs,
-@@ -1311,18 +1128,14 @@ class PyBuildExt(build_ext):
+@@ -1357,18 +1175,14 @@ class PyBuildExt(build_ext):
                                  libraries = gdbm_libs)
                              break
                  elif cand == "bdb":
@@ -378,7 +388,7 @@ cygwin 2.7.3-no-libm.patch
              if dbmext is not None:
                  exts.append(dbmext)
              else:
-@@ -1383,8 +1196,7 @@ class PyBuildExt(build_ext):
+@@ -1429,8 +1243,7 @@ class PyBuildExt(build_ext):
              missing.append('_curses')
  
          # If the curses module is enabled, check for the panel module
@@ -388,7 +398,32 @@ cygwin 2.7.3-no-libm.patch
              exts.append( Extension('_curses_panel', ['_curses_panel.c'],
                                     include_dirs = curses_incs,
                                     libraries = [panel_library] + curses_libs) )
-@@ -2296,9 +2108,9 @@ def main():
+@@ -2129,6 +1942,7 @@ class PyBuildExt(build_ext):
+ 
+         if host_platform == 'darwin':
+             sources.append('_ctypes/malloc_closure.c')
++            extra_compile_args.append('-DUSING_MALLOC_CLOSURE_DOT_C=1')
+             sources.append('_ctypes/darwin/dlfcn_simple.c')
+             extra_compile_args.append('-DMACOSX')
+             include_dirs.append('_ctypes/darwin')
+@@ -2191,6 +2005,16 @@ class PyBuildExt(build_ext):
+                     break
+ 
+         if ffi_inc and ffi_lib:
++            config = distutils.command.config.config(self.distribution)
++            config._check_compiler()
++            if any(cc in config.compiler.compiler_so for cc in ('gcc', 'clang')):
++                config.compiler.compiler_so += ["-Wno-unguarded-availability-new", "-Wno-unused-value"]
++            if config.check_func("ffi_prep_closure_loc", headers=['ffi.h'], include_dirs=[ffi_inc]):
++                ext.extra_compile_args.append("-DHAVE_FFI_PREP_CLOSURE_LOC=1")
++            if config.check_func("ffi_prep_cif_var", headers=['ffi.h'], include_dirs=[ffi_inc]):
++                ext.extra_compile_args.append("-DHAVE_FFI_PREP_CIF_VAR=1")
++            if host_platform == 'darwin' and config.check_func("ffi_closure_alloc", headers=['ffi.h'], include_dirs=[ffi_inc]):
++                ext.extra_compile_args.append("-DHAVE_FFI_CLOSURE_ALLOC=1")
+             ext.include_dirs.extend(ffi_inc)
+             ext.libraries.append(ffi_lib)
+             self.use_system_libffi = True
+@@ -2342,9 +2166,9 @@ def main():
            ext_modules=[Extension('_struct', ['_struct.c'])],
  
            # Scripts to install

Index: pkgsrc/lang/python27/patches/patch-pyconfig.h.in
diff -u pkgsrc/lang/python27/patches/patch-pyconfig.h.in:1.5 pkgsrc/lang/python27/patches/patch-pyconfig.h.in:1.6
--- pkgsrc/lang/python27/patches/patch-pyconfig.h.in:1.5        Sun May 24 07:44:07 2015
+++ pkgsrc/lang/python27/patches/patch-pyconfig.h.in    Wed Jun 23 18:30:24 2021
@@ -1,10 +1,21 @@
-$NetBSD: patch-pyconfig.h.in,v 1.5 2015/05/24 07:44:07 adam Exp $
+$NetBSD: patch-pyconfig.h.in,v 1.6 2021/06/23 18:30:24 schmonz Exp $
 
 Fix build with LibreSSL.
+darwin20 support, via MacPorts.
 
---- pyconfig.h.in.orig 2015-05-23 16:09:25.000000000 +0000
+--- pyconfig.h.in.orig 2021-06-22 19:20:43.000000000 +0000
 +++ pyconfig.h.in
-@@ -1206,7 +1209,9 @@
+@@ -216,6 +216,9 @@
+ /* Define to 1 if you have the `dup2' function. */
+ #undef HAVE_DUP2
+ 
++/* Define if you have the '_dyld_shared_cache_contains_path' function. */
++#undef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
++
+ /* Defined when any dynamic module loading is enabled. */
+ #undef HAVE_DYNAMIC_LOADING
+ 
+@@ -1241,7 +1244,9 @@
  #undef _UINT64_T
  
  /* Define to the level of X/Open that your system supports */

Added files:

Index: pkgsrc/lang/python27/patches/patch-Lib___osx__support.py
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Lib___osx__support.py:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Lib___osx__support.py    Wed Jun 23 18:30:24 2021
@@ -0,0 +1,26 @@
+$NetBSD: patch-Lib___osx__support.py,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+macOS arm64 support, via MacPorts.
+
+--- Lib/_osx_support.py.orig   2021-06-22 19:20:03.000000000 +0000
++++ Lib/_osx_support.py
+@@ -470,6 +470,8 @@ def get_platform_osx(_config_vars, osnam
+ 
+             if len(archs) == 1:
+                 machine = archs[0]
++            elif archs == ('arm64', 'x86_64'):
++                machine = 'universal2'
+             elif archs == ('i386', 'ppc'):
+                 machine = 'fat'
+             elif archs == ('i386', 'x86_64'):
+@@ -484,6 +486,10 @@ def get_platform_osx(_config_vars, osnam
+                 raise ValueError(
+                    "Don't know machine value for archs=%r" % (archs,))
+ 
++        elif machine == 'arm':
++            # No 32-bit arm support on macOS
++            machine = 'arm64'
++
+         elif machine == 'i386':
+             # On OSX the machine type returned by uname is always the
+             # 32-bit variant, even if the executable architecture is
Index: pkgsrc/lang/python27/patches/patch-Lib_ctypes_macholib_dyld.py
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Lib_ctypes_macholib_dyld.py:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Lib_ctypes_macholib_dyld.py      Wed Jun 23 18:30:24 2021
@@ -0,0 +1,32 @@
+$NetBSD: patch-Lib_ctypes_macholib_dyld.py,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+darwin20 support, via MacPorts.
+
+--- Lib/ctypes/macholib/dyld.py.orig   2021-06-22 19:20:28.000000000 +0000
++++ Lib/ctypes/macholib/dyld.py
+@@ -7,6 +7,12 @@ from framework import framework_info
+ from dylib import dylib_info
+ from itertools import *
+ 
++try:
++    from _ctypes import _dyld_shared_cache_contains_path
++except ImportError:
++    def _dyld_shared_cache_contains_path(*args):
++        raise NotImplementedError
++
+ __all__ = [
+     'dyld_find', 'framework_find',
+     'framework_info', 'dylib_info',
+@@ -132,6 +138,12 @@ def dyld_find(name, executable_path=None
+             ), env):
+         if os.path.isfile(path):
+             return path
++        try:
++            if _dyld_shared_cache_contains_path(path):
++                return path
++        except NotImplementedError:
++            pass
++
+     raise ValueError("dylib %s could not be found" % (name,))
+ 
+ def framework_find(fn, executable_path=None, env=None):
Index: pkgsrc/lang/python27/patches/patch-Lib_ctypes_test_test__macholib.py
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Lib_ctypes_test_test__macholib.py:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Lib_ctypes_test_test__macholib.py        Wed Jun 23 18:30:24 2021
@@ -0,0 +1,34 @@
+$NetBSD: patch-Lib_ctypes_test_test__macholib.py,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+darwin20 support, via MacPorts.
+
+--- Lib/ctypes/test/test_macholib.py.orig      2021-06-22 19:20:28.000000000 +0000
++++ Lib/ctypes/test/test_macholib.py
+@@ -48,18 +48,22 @@ class MachOTest(unittest.TestCase):
+     @unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test')
+     def test_find(self):
+ 
+-        self.assertEqual(find_lib('pthread'),
+-                             '/usr/lib/libSystem.B.dylib')
++        # On macOS 11, system dylibs are only present in the shared cache,
++        # so symlinks like libpthread.dylib -> libSystem.B.dylib will not
++        # be resolved by dyld_find
++        self.assertIn(find_lib('pthread'),
++            ('/usr/lib/libSystem.B.dylib', '/usr/lib/libpthread.dylib'))
+ 
+         result = find_lib('z')
+         # Issue #21093: dyld default search path includes $HOME/lib and
+         # /usr/local/lib before /usr/lib, which caused test failures if
+         # a local copy of libz exists in one of them. Now ignore the head
+         # of the path.
+-        self.assertRegexpMatches(result, r".*/lib/libz\..*.*\.dylib")
++        self.assertRegexpMatches(result, r".*/lib/libz.*\.dylib")
+ 
+-        self.assertEqual(find_lib('IOKit'),
+-                             '/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit')
++        self.assertIn(find_lib('IOKit'),
++            ('/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit',
++             '/System/Library/Frameworks/IOKit.framework/IOKit'))
+ 
+ if __name__ == "__main__":
+     unittest.main()
Index: pkgsrc/lang/python27/patches/patch-Lib_distutils_tests_test__build__ext.py
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Lib_distutils_tests_test__build__ext.py:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Lib_distutils_tests_test__build__ext.py  Wed Jun 23 18:30:24 2021
@@ -0,0 +1,15 @@
+$NetBSD: patch-Lib_distutils_tests_test__build__ext.py,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+darwin20 support, via MacPorts.
+
+--- Lib/distutils/tests/test_build_ext.py.orig 2021-06-22 19:20:28.000000000 +0000
++++ Lib/distutils/tests/test_build_ext.py
+@@ -491,7 +491,7 @@ class BuildExtTestCase(support.TempdirMa
+         # format the target value as defined in the Apple
+         # Availability Macros.  We can't use the macro names since
+         # at least one value we test with will not exist yet.
+-        if target[1] < 10:
++        if target[:2] < (10, 10):
+             # for 10.1 through 10.9.x -> "10n0"
+             target = '%02d%01d0' % target
+         else:
Index: pkgsrc/lang/python27/patches/patch-Lib_test_test__platform.py
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Lib_test_test__platform.py:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Lib_test_test__platform.py       Wed Jun 23 18:30:24 2021
@@ -0,0 +1,27 @@
+$NetBSD: patch-Lib_test_test__platform.py,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+darwin20 support, via MacPorts.
+
+--- Lib/test/test_platform.py.orig     2021-06-22 19:20:28.000000000 +0000
++++ Lib/test/test_platform.py
+@@ -207,6 +207,11 @@ class PlatformTest(unittest.TestCase):
+             fd.close()
+             self.assertFalse(real_ver is None)
+             result_list = res[0].split('.')
++            # macOS 11.0 (Big Sur) may report its version number
++            # as 10.16 if the executable is built with an older
++            # SDK target but sw_vers reports 11.0.
++            if result_list == ['10', '16']:
++                result_list = ['11', '0']
+             expect_list = real_ver.split('.')
+             len_diff = len(result_list) - len(expect_list)
+             # On Snow Leopard, sw_vers reports 10.6.0 as 10.6
+@@ -220,7 +225,7 @@ class PlatformTest(unittest.TestCase):
+             self.assertEqual(res[1], ('', '', ''))
+ 
+             if sys.byteorder == 'little':
+-                self.assertIn(res[2], ('i386', 'x86_64'))
++                self.assertIn(res[2], ('i386', 'x86_64', 'arm64'))
+             else:
+                 self.assertEqual(res[2], 'PowerPC')
+ 
Index: pkgsrc/lang/python27/patches/patch-Lib_test_test__unicode.py
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Lib_test_test__unicode.py:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Lib_test_test__unicode.py        Wed Jun 23 18:30:24 2021
@@ -0,0 +1,22 @@
+$NetBSD: patch-Lib_test_test__unicode.py,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+macOS arm64 support, via MacPorts.
+
+--- Lib/test/test_unicode.py.orig      2021-06-22 19:20:03.000000000 +0000
++++ Lib/test/test_unicode.py
+@@ -1676,6 +1676,7 @@ class CAPITest(unittest.TestCase):
+     def test_from_format(self):
+         test_support.import_module('ctypes')
+         from ctypes import (
++            c_char_p,
+             pythonapi, py_object, sizeof,
+             c_int, c_long, c_longlong, c_ssize_t,
+             c_uint, c_ulong, c_ulonglong, c_size_t, c_void_p)
+@@ -1684,6 +1685,7 @@ class CAPITest(unittest.TestCase):
+         else:
+             name = "PyUnicodeUCS4_FromFormat"
+         _PyUnicode_FromFormat = getattr(pythonapi, name)
++        _PyUnicode_FromFormat.argtypes = (c_char_p,)
+         _PyUnicode_FromFormat.restype = py_object
+ 
+         def PyUnicode_FromFormat(format, *args):
Index: pkgsrc/lang/python27/patches/patch-Mac_Tools_pythonw.c
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Mac_Tools_pythonw.c:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Mac_Tools_pythonw.c      Wed Jun 23 18:30:24 2021
@@ -0,0 +1,16 @@
+$NetBSD: patch-Mac_Tools_pythonw.c,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+macOS arm64 support, via MacPorts.
+
+--- Mac/Tools/pythonw.c.orig   2021-06-22 19:20:03.000000000 +0000
++++ Mac/Tools/pythonw.c
+@@ -114,6 +114,9 @@ setup_spawnattr(posix_spawnattr_t* spawn
+ #elif defined(__x86_64__)
+     cpu_types[0] = CPU_TYPE_X86_64;
+ 
++#elif defined(__arm64__)
++    cpu_types[0] = CPU_TYPE_ARM64;
++
+ #elif defined(__ppc__)
+     cpu_types[0] = CPU_TYPE_POWERPC;
+ #elif defined(__i386__)
Index: pkgsrc/lang/python27/patches/patch-Modules___ctypes_callbacks.c
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Modules___ctypes_callbacks.c:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Modules___ctypes_callbacks.c     Wed Jun 23 18:30:24 2021
@@ -0,0 +1,43 @@
+$NetBSD: patch-Modules___ctypes_callbacks.c,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+macOS arm64 support, via MacPorts.
+
+--- Modules/_ctypes/callbacks.c.orig   2021-06-22 19:20:03.000000000 +0000
++++ Modules/_ctypes/callbacks.c
+@@ -24,7 +24,7 @@ CThunkObject_dealloc(PyObject *_self)
+     Py_XDECREF(self->callable);
+     Py_XDECREF(self->restype);
+     if (self->pcl_write)
+-        ffi_closure_free(self->pcl_write);
++        Py_ffi_closure_free(self->pcl_write);
+     PyObject_GC_Del(self);
+ }
+ 
+@@ -426,7 +426,7 @@ CThunkObject *_ctypes_alloc_callback(PyO
+ 
+     assert(CThunk_CheckExact(p));
+ 
+-    p->pcl_write = ffi_closure_alloc(sizeof(ffi_closure),
++    p->pcl_write = Py_ffi_closure_alloc(sizeof(ffi_closure),
+                                    &p->pcl_exec);
+     if (p->pcl_write == NULL) {
+         PyErr_NoMemory();
+@@ -473,12 +473,15 @@ CThunkObject *_ctypes_alloc_callback(PyO
+                      "ffi_prep_cif failed with %d", result);
+         goto error;
+     }
+-#if defined(X86_DARWIN) || defined(POWERPC_DARWIN)
+-    result = ffi_prep_closure(p->pcl_write, &p->cif, closure_fcn, p);
+-#else
++#if HAVE_FFI_PREP_CLOSURE_LOC
+     result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn,
+                                 p,
+                                 p->pcl_exec);
++#elif defined(__APPLE__) && defined(__arm64__)
++    PyErr_Format(PyExc_NotImplementedError, "ffi_prep_closure_loc() is missing");
++    goto error;
++#else
++    result = ffi_prep_closure(p->pcl_write, &p->cif, closure_fcn, p);
+ #endif
+     if (result != FFI_OK) {
+         PyErr_Format(PyExc_RuntimeError,
Index: pkgsrc/lang/python27/patches/patch-Modules___ctypes_callproc.c
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Modules___ctypes_callproc.c:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Modules___ctypes_callproc.c      Wed Jun 23 18:30:24 2021
@@ -0,0 +1,119 @@
+$NetBSD: patch-Modules___ctypes_callproc.c,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+macOS arm64 support, via MacPorts.
+
+--- Modules/_ctypes/callproc.c.orig    2021-06-22 19:20:28.000000000 +0000
++++ Modules/_ctypes/callproc.c
+@@ -74,6 +74,10 @@
+ #include <malloc.h>
+ #endif
+ 
++#if __APPLE__ && HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
++#include <mach-o/dyld.h>
++#endif
++
+ #include <ffi.h>
+ #include "ctypes.h"
+ #ifdef HAVE_ALLOCA_H
+@@ -773,7 +777,8 @@ static int _call_function_pointer(int fl
+                                   ffi_type **atypes,
+                                   ffi_type *restype,
+                                   void *resmem,
+-                                  int argcount)
++                                  int argcount,
++                                  int argtypecount)
+ {
+ #ifdef WITH_THREAD
+     PyThreadState *_save = NULL; /* For Py_BLOCK_THREADS and Py_UNBLOCK_THREADS */
+@@ -801,6 +806,37 @@ static int _call_function_pointer(int fl
+     if ((flags & FUNCFLAG_CDECL) == 0)
+         cc = FFI_STDCALL;
+ #endif
++
++    /* Even on Apple-arm64 the calling convention for variadic functions conincides
++    * with the standard calling convention in the case that the function called
++    * only with its fixed arguments.   Thus, we do not need a special flag to be
++    * set on variadic functions.   We treat a function as variadic if it is called
++    * with a nonzero number of variadic arguments */
++    int is_variadic = (argtypecount != 0 && argcount > argtypecount);
++    (void) is_variadic;
++
++#if defined(__APPLE__) && defined(__arm64__) && !defined(HAVE_FFI_PREP_CIF_VAR)
++    if (is_variadic) {
++        PyErr_SetString(PyExc_NotImplementedError, "ffi_prep_cif_var() is missing");
++        return -1;
++    }
++#endif
++
++#if HAVE_FFI_PREP_CIF_VAR
++    if (is_variadic) {
++        if (FFI_OK != ffi_prep_cif_var(&cif,
++                                        cc,
++                                        argtypecount,
++                                        argcount,
++                                        restype,
++                                        atypes)) {
++            PyErr_SetString(PyExc_RuntimeError,
++                            "ffi_prep_cif_var failed");
++            return -1;
++        }
++    } else
++ #endif
++    {
+     if (FFI_OK != ffi_prep_cif(&cif,
+                                cc,
+                                argcount,
+@@ -810,6 +846,7 @@ static int _call_function_pointer(int fl
+                         "ffi_prep_cif failed");
+         return -1;
+     }
++    }
+ 
+     if (flags & (FUNCFLAG_USE_ERRNO | FUNCFLAG_USE_LASTERROR)) {
+         error_object = _ctypes_get_errobj(&space);
+@@ -1183,6 +1220,9 @@ PyObject *_ctypes_callproc(PPROC pProc,
+                                      rtype, resbuf,
+                                      Py_SAFE_DOWNCAST(argcount,
+                                                       Py_ssize_t,
++                                                      int),
++                                     Py_SAFE_DOWNCAST(argtype_count,
++                                                      Py_ssize_t,
+                                                       int)))
+         goto cleanup;
+ 
+@@ -1416,6 +1456,25 @@ copy_com_pointer(PyObject *self, PyObjec
+ }
+ #else
+ 
++#if __APPLE__ && HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
++static PyObject *py_dyld_shared_cache_contains_path(PyObject *self, PyObject *args)
++{
++    if (__builtin_available(macos 11, ios 14, watchos 7, tvos 14, *)) {
++        char *name_str;
++        if (!PyArg_ParseTuple(args, "z", &name_str))
++            return NULL;
++
++        if(_dyld_shared_cache_contains_path(name_str))
++            Py_RETURN_TRUE;
++        else
++            Py_RETURN_FALSE;
++    } else {
++        PyErr_SetString(PyExc_NotImplementedError, "_dyld_shared_cache_contains_path symbol is missing");
++        return NULL;
++    }
++}
++#endif
++
+ static PyObject *py_dl_open(PyObject *self, PyObject *args)
+ {
+     char *name;
+@@ -1940,6 +1999,9 @@ PyMethodDef _ctypes_module_methods[] = {
+      "dlopen(name, flag={RTLD_GLOBAL|RTLD_LOCAL}) open a shared library"},
+     {"dlclose", py_dl_close, METH_VARARGS, "dlclose a library"},
+     {"dlsym", py_dl_sym, METH_VARARGS, "find symbol in shared library"},
++#if __APPLE__ && HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
++    {"_dyld_shared_cache_contains_path", py_dyld_shared_cache_contains_path, METH_VARARGS, "check if path is in the shared cache"},
++#endif
+ #endif
+     {"alignment", align_func, METH_O, alignment_doc},
+     {"sizeof", sizeof_func, METH_O, sizeof_doc},
Index: pkgsrc/lang/python27/patches/patch-Modules___ctypes_ctypes.h
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Modules___ctypes_ctypes.h:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Modules___ctypes_ctypes.h        Wed Jun 23 18:30:24 2021
@@ -0,0 +1,20 @@
+$NetBSD: patch-Modules___ctypes_ctypes.h,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+macOS arm64 support, via MacPorts.
+
+--- Modules/_ctypes/ctypes.h.orig      2021-06-22 19:20:03.000000000 +0000
++++ Modules/_ctypes/ctypes.h
+@@ -481,6 +481,13 @@ static void capsule_destructor_ ## name(
+ 
+ #endif /* PY_VERSION_HEX >= 0x020700A4 */
+ 
++#if USING_MALLOC_CLOSURE_DOT_C
++void Py_ffi_closure_free(void *p);
++void *Py_ffi_closure_alloc(size_t size, void** codeloc);
++#else
++#define Py_ffi_closure_free ffi_closure_free
++#define Py_ffi_closure_alloc ffi_closure_alloc
++#endif
+ 
+ /*
+  Local Variables:
Index: pkgsrc/lang/python27/patches/patch-Modules___ctypes_malloc__closure.c
diff -u /dev/null pkgsrc/lang/python27/patches/patch-Modules___ctypes_malloc__closure.c:1.1
--- /dev/null   Wed Jun 23 18:30:24 2021
+++ pkgsrc/lang/python27/patches/patch-Modules___ctypes_malloc__closure.c       Wed Jun 23 18:30:24 2021
@@ -0,0 +1,39 @@
+$NetBSD: patch-Modules___ctypes_malloc__closure.c,v 1.1 2021/06/23 18:30:24 schmonz Exp $
+
+macOS arm64 support, via MacPorts.
+
+--- Modules/_ctypes/malloc_closure.c.orig      2021-06-22 19:20:03.000000000 +0000
++++ Modules/_ctypes/malloc_closure.c
+@@ -89,16 +89,24 @@ static void more_core(void)
+ /******************************************************************/
+ 
+ /* put the item back into the free list */
+-void ffi_closure_free(void *p)
++void Py_ffi_closure_free(void *p)
+ {
++#if HAVE_FFI_CLOSURE_ALLOC
++    ffi_closure_free(p);
++    return;
++#else
+     ITEM *item = (ITEM *)p;
+     item->next = free_list;
+     free_list = item;
++#endif
+ }
+ 
+ /* return one item from the free list, allocating more if needed */
+-void *ffi_closure_alloc(size_t ignored, void** codeloc)
++void *Py_ffi_closure_alloc(size_t size, void** codeloc)
+ {
++#if HAVE_FFI_CLOSURE_ALLOC
++    return ffi_closure_alloc(size, codeloc);
++#else
+     ITEM *item;
+     if (!free_list)
+         more_core();
+@@ -108,4 +116,5 @@ void *ffi_closure_alloc(size_t ignored, 
+     free_list = item->next;
+     *codeloc = (void *)item;
+     return (void *)item;
++#endif
+ }



Home | Main Index | Thread Index | Old Index