Skip to content

Commit c6a9d2b

Browse files
committed
hg merge default to release-1.15
2 parents b8c1bdd + 0af040c commit c6a9d2b

31 files changed

+424
-84
lines changed

.github/workflows/ci.yaml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- spec: cp38-manylinux_x86_64
3434
- spec: cp39-manylinux_x86_64
3535
- spec: cp310-manylinux_x86_64
36+
- spec: cp311-manylinux_x86_64
3637
- spec: cp27-manylinux_i686
3738
cibw_version: cibuildwheel<2.0 # py2.7 is not supported on CIBW 2.0+
3839
manylinux_img: manylinux1 # build really old Pythons on manylinux1
@@ -42,32 +43,41 @@ jobs:
4243
- spec: cp38-manylinux_i686
4344
- spec: cp39-manylinux_i686
4445
- spec: cp310-manylinux_i686
46+
- spec: cp311-manylinux_i686
47+
- spec: cp39-musllinux_x86_64
48+
- spec: cp310-musllinux_x86_64
49+
- spec: cp311-musllinux_x86_64
50+
- spec: cp39-musllinux_i686
51+
- spec: cp310-musllinux_i686
52+
- spec: cp311-musllinux_i686
4553
steps:
4654
- name: clone repo
4755
uses: actions/checkout@v2
4856

4957
- name: build/test wheels
5058
env:
59+
CFLAGS: -Dffi_call=cffistatic_ffi_call # override name for ffi_call to break hard if we linked against someone else's libffi
5160
CIBW_ARCHS_LINUX: auto
5261
CIBW_BUILD: ${{ matrix.spec }}
5362
CIBW_BEFORE_BUILD: |
5463
set -eux && \
5564
curl -L -O https://github.com/libffi/libffi/archive/v3.4.2.tar.gz && \
5665
tar zxf v3.4.2.tar.gz && cd libffi-3.4.2 && \
5766
./autogen.sh && \
58-
./configure --without-gcc-arch --disable-docs && \
67+
./configure --without-gcc-arch --disable-docs --with-pic --enable-shared=no && \
5968
make && \
6069
make install && \
61-
ldconfig
62-
# TODO: update default to '' once CIBW 2.1.3 ships: https://github.com/pypa/cibuildwheel/pull/829
63-
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_img || 'manylinux2010' }}
64-
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_img || 'manylinux2010' }}
70+
ldconfig || true
71+
CIBW_ENVIRONMENT_PASS_LINUX: CFLAGS # ensure that the build container can see our overridden build config
72+
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_img || '' }}
73+
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.manylinux_img || '' }}
74+
CIBW_PRERELEASE_PYTHONS: 'True'
6575
CIBW_TEST_REQUIRES: pytest
66-
CIBW_TEST_COMMAND: python -m pytest {project}/c {project}/testing
76+
CIBW_TEST_COMMAND: PYTHONUNBUFFERED=1 python -m pytest {project}
6777
run: |
6878
python -m pip install --upgrade "${{ matrix.cibw_version || 'cibuildwheel' }}"
6979
70-
# actually build libyaml + wheel (using env tweaks above)
80+
# actually build libffi + wheel (using env tweaks above)
7181
python -m cibuildwheel --output-dir dist .
7282
7383
@@ -94,6 +104,7 @@ jobs:
94104
- spec: cp38-macosx_x86_64
95105
- spec: cp39-macosx_x86_64
96106
- spec: cp310-macosx_x86_64
107+
- spec: cp311-macosx_x86_64
97108
# build for arm64 under a hacked macOS 12 self-hosted x86_64-on-arm64 runner until arm64 is fully supported
98109
# FIXME: ? cp38-macosx_arm64 requires special handling and fails some test_zdist tests under cibw 2.1.2, skip it (so Apple's XCode python3 won't have a wheel)
99110
- spec: cp39-macosx_arm64
@@ -107,6 +118,14 @@ jobs:
107118
runs_on: [self-hosted, macOS]
108119
run_wrapper: arch -arm64 bash --noprofile --norc -eo pipefail {0}
109120
sdkroot: macosx11.3
121+
122+
- spec: cp311-macosx_arm64
123+
deployment_target: '11.0'
124+
runs_on: [self-hosted, macOS]
125+
run_wrapper: arch -arm64 bash --noprofile --norc -eo pipefail {0}
126+
sdkroot: macosx11.3
127+
128+
110129
steps:
111130
- name: clone repo
112131
uses: actions/checkout@v2
@@ -119,8 +138,9 @@ jobs:
119138
- name: build/test wheels
120139
env:
121140
CIBW_BUILD: ${{ matrix.spec }}
141+
CIBW_PRERELEASE_PYTHONS: 'True'
122142
CIBW_TEST_REQUIRES: pytest
123-
CIBW_TEST_COMMAND: pip install pip --upgrade; cd {project}; pytest
143+
CIBW_TEST_COMMAND: pip install pip --upgrade; cd {project}; PYTHONUNBUFFERED=1 pytest
124144
run: |
125145
if [[ -n "${{ matrix.deployment_target || '' }}" ]]
126146
then
@@ -141,7 +161,7 @@ jobs:
141161
if-no-files-found: error
142162

143163
windows:
144-
runs-on: windows-2016
164+
runs-on: windows-2019
145165
strategy:
146166
matrix:
147167
include:
@@ -152,13 +172,15 @@ jobs:
152172
- spec: cp38-win_amd64
153173
- spec: cp39-win_amd64
154174
- spec: cp310-win_amd64
175+
- spec: cp311-win_amd64
155176
- spec: cp27-win32
156177
cibw_version: cibuildwheel==1.10 # last release with proper py2.7 Windows support
157178
- spec: cp36-win32
158179
- spec: cp37-win32
159180
- spec: cp38-win32
160181
- spec: cp39-win32
161182
- spec: cp310-win32
183+
- spec: cp311-win32
162184
steps:
163185
- name: clone repo
164186
uses: actions/checkout@v2
@@ -180,6 +202,7 @@ jobs:
180202
- name: build/test wheels
181203
env:
182204
CIBW_BUILD: ${{ matrix.spec }}
205+
CIBW_PRERELEASE_PYTHONS: 'True'
183206
run: |
184207
python -m pip install --upgrade pip
185208
pip install "${{ matrix.cibw_version || 'cibuildwheel'}}"

c/_cffi_backend.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <Python.h>
33
#include "structmember.h"
44

5-
#define CFFI_VERSION "1.15.0"
5+
#define CFFI_VERSION "1.15.1"
66

77
#ifdef MS_WIN32
88
#include <windows.h>
@@ -2197,7 +2197,7 @@ static PyObject *_frombuf_repr(CDataObject *cd, const char *cd_type_name)
21972197
}
21982198
}
21992199

2200-
static PyObject *cdataowning_repr(CDataObject *cd)
2200+
static Py_ssize_t cdataowning_size_bytes(CDataObject *cd)
22012201
{
22022202
Py_ssize_t size = _cdata_var_byte_size(cd);
22032203
if (size < 0) {
@@ -2208,6 +2208,12 @@ static PyObject *cdataowning_repr(CDataObject *cd)
22082208
else
22092209
size = cd->c_type->ct_size;
22102210
}
2211+
return size;
2212+
}
2213+
2214+
static PyObject *cdataowning_repr(CDataObject *cd)
2215+
{
2216+
Py_ssize_t size = cdataowning_size_bytes(cd);
22112217
return PyText_FromFormat("<cdata '%s' owning %zd bytes>",
22122218
cd->c_type->ct_name, size);
22132219
}
@@ -4603,7 +4609,7 @@ static PyObject *get_unique_type(CTypeDescrObject *x,
46034609
array [ctype, length]
46044610
funcptr [ctresult, ellipsis+abi, num_args, ctargs...]
46054611
*/
4606-
PyObject *key, *y;
4612+
PyObject *key, *y, *res;
46074613
void *pkey;
46084614

46094615
key = PyBytes_FromStringAndSize(NULL, keylength * sizeof(void *));
@@ -4635,8 +4641,9 @@ static PyObject *get_unique_type(CTypeDescrObject *x,
46354641
/* the 'value' in unique_cache doesn't count as 1, but don't use
46364642
Py_DECREF(x) here because it will confuse debug builds into thinking
46374643
there was an extra DECREF in total. */
4638-
((PyObject *)x)->ob_refcnt--;
4639-
return (PyObject *)x;
4644+
res = (PyObject *)x;
4645+
Py_SET_REFCNT(res, Py_REFCNT(res) - 1);
4646+
return res;
46404647

46414648
error:
46424649
Py_DECREF(x);
@@ -5665,7 +5672,8 @@ static ffi_type *fb_fill_type(struct funcbuilder_s *fb, CTypeDescrObject *ct,
56655672
}
56665673
}
56675674

5668-
#define ALIGN_ARG(n) ((n) + 7) & ~7
5675+
#define ALIGN_TO(n, a) ((n) + ((a)-1)) & ~((a)-1)
5676+
#define ALIGN_ARG(n) ALIGN_TO(n, 8)
56695677

56705678
static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,
56715679
CTypeDescrObject *fresult)
@@ -5690,10 +5698,12 @@ static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,
56905698
/* exchange data size */
56915699
/* first, enough room for an array of 'nargs' pointers */
56925700
exchange_offset = nargs * sizeof(void*);
5701+
/* then enough room for the result --- which means at least
5702+
sizeof(ffi_arg), according to the ffi docs, but we also
5703+
align according to the result type, for issue #531 */
5704+
exchange_offset = ALIGN_TO(exchange_offset, fb->rtype->alignment);
56935705
exchange_offset = ALIGN_ARG(exchange_offset);
56945706
cif_descr->exchange_offset_arg[0] = exchange_offset;
5695-
/* then enough room for the result --- which means at least
5696-
sizeof(ffi_arg), according to the ffi docs */
56975707
i = fb->rtype->size;
56985708
if (i < (Py_ssize_t)sizeof(ffi_arg))
56995709
i = sizeof(ffi_arg);
@@ -5721,6 +5731,7 @@ static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,
57215731
if (fb->atypes != NULL) {
57225732
fb->atypes[i] = atype;
57235733
/* exchange data size */
5734+
exchange_offset = ALIGN_TO(exchange_offset, atype->alignment);
57245735
exchange_offset = ALIGN_ARG(exchange_offset);
57255736
cif_descr->exchange_offset_arg[1 + i] = exchange_offset;
57265737
exchange_offset += atype->size;
@@ -5737,6 +5748,7 @@ static int fb_build(struct funcbuilder_s *fb, PyObject *fargs,
57375748
}
57385749

57395750
#undef ALIGN_ARG
5751+
#undef ALIGN_TO
57405752

57415753
static void fb_cat_name(struct funcbuilder_s *fb, const char *piece,
57425754
int piecelen)
@@ -7010,12 +7022,14 @@ b_buffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
70107022
/* this is the constructor of the type implemented in minibuffer.h */
70117023
CDataObject *cd;
70127024
Py_ssize_t size = -1;
7025+
int explicit_size;
70137026
static char *keywords[] = {"cdata", "size", NULL};
70147027

70157028
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|n:buffer", keywords,
70167029
&CData_Type, &cd, &size))
70177030
return NULL;
70187031

7032+
explicit_size = size >= 0;
70197033
if (size < 0)
70207034
size = _cdata_var_byte_size(cd);
70217035

@@ -7039,6 +7053,20 @@ b_buffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
70397053
cd->c_type->ct_name);
70407054
return NULL;
70417055
}
7056+
7057+
if (explicit_size && CDataOwn_Check(cd)) {
7058+
Py_ssize_t size_max = cdataowning_size_bytes(cd);
7059+
if (size > size_max) {
7060+
char msg[256];
7061+
sprintf(msg, "ffi.buffer(cdata, bytes): creating a buffer of %llu "
7062+
"bytes over a cdata that owns only %llu bytes. This "
7063+
"will crash if you access the extra memory",
7064+
(unsigned PY_LONG_LONG)size,
7065+
(unsigned PY_LONG_LONG)size_max);
7066+
if (PyErr_WarnEx(PyExc_UserWarning, msg, 1))
7067+
return NULL;
7068+
}
7069+
}
70427070
/*WRITE(cd->c_data, size)*/
70437071
return minibuffer_new(cd->c_data, size, (PyObject *)cd);
70447072
}

c/libffi_arm64/README

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Libffi package for ARM64 is copied from cpython binary dependencies
1+
Please run build_libffi.bat to generate the libffi static library and header files
22

3-
https://github.com/python/cpython-bin-deps/archive/libffi.zip
3+
Environment variable LIBFFI_SOURCE needs to be set to libffi source before invoking the script.
44

5-
The library file has been renamed from libffi-7.lib to ffi.lib to avoid special casing
5+
Libffi source can be downloaded from https://github.com/libffi/libffi

c/libffi_arm64/build_libffi.bat

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
@echo off
2+
goto :Run
3+
4+
:Usage
5+
echo.
6+
echo Before running prepare_libffi.bat
7+
echo .
8+
echo LIBFFI_SOURCE environment variable must be set to the location of libffi source
9+
echo Source can be checked out from https://github.com/libffi/libffi
10+
echo.
11+
echo Cygwin needs to be installed (Invoke with --install-cygwin to install)
12+
echo.
13+
echo. Visual Studio 2017 or newer with ARM64 toolchain needs to be installed
14+
:Run
15+
set INSTALL_CYGWIN=
16+
17+
:CheckOpts
18+
if "%1"=="" goto :CheckOptsDone
19+
if /I "%1"=="-?" goto :Usage
20+
if /I "%1"=="--install-cygwin" (set INSTALL_CYGWIN=1) & shift & goto :CheckOpts
21+
goto :Usage
22+
23+
:CheckOptsDone
24+
25+
if "%INSTALL_CYGWIN%"=="1" call :InstallCygwin
26+
27+
REM Set build variables
28+
29+
set BUILD=i686-pc-cygwin
30+
set HOST=aarch64-w64-cygwin
31+
if NOT DEFINED SH if exist c:\cygwin\bin\sh.exe set SH=c:\cygwin\bin\sh.exe
32+
33+
REM Initialise ARM64 build environment
34+
35+
if NOT DEFINED VCVARSALL (
36+
for /F "tokens=*" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -property installationPath -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64') DO @(set VCVARSALL="%%i\VC\Auxiliary\Build\vcvarsall.bat")
37+
)
38+
if ^%VCVARSALL:~0,1% NEQ ^" SET VCVARSALL="%VCVARSALL%"
39+
call %VCVARSALL% x86_arm64
40+
pushd %LIBFFI_SOURCE%
41+
%SH% --login -lc "cygcheck -dc cygwin"
42+
set GET_MSVCC=%SH% -lc "cd $LIBFFI_SOURCE; export MSVCC=`/usr/bin/find $PWD -name msvcc.sh`; echo ${MSVCC};"
43+
FOR /F "usebackq delims==" %%i IN (`%GET_MSVCC%`) do @set MSVCC=%%i
44+
set MSVCC=%MSVCC% -marm64
45+
46+
echo Configuring and building libffi for ARM64
47+
48+
%SH% -lc "(cd $LIBFFI_SOURCE; ./autogen.sh)"
49+
%SH% -lc "(cd $LIBFFI_SOURCE; ./configure CC='%MSVCC%' CXX='%MSVCC%' LD='link' CPP='cl -nologo -EP' CXXCPP='cl -nologo -EP' CPPFLAGS='-DFFI_BUILDING_DLL' NM='dumpbin -symbols' STRIP=':' --build=$BUILD --host=$HOST --enable-static --disable-shared)"
50+
%SH% -lc "(cd $LIBFFI_SOURCE; cp src/aarch64/ffitarget.h include)"
51+
%SH% -lc "(cd $LIBFFI_SOURCE; make)"
52+
53+
set LIBFFI_OUT=%~dp0
54+
55+
echo copying files to %LIBFFI_OUT%
56+
if not exist %LIBFFI_OUT%\include (md %LIBFFI_OUT%\include)
57+
copy %LIBFFI_SOURCE%\%HOST%\.libs\libffi.lib %LIBFFI_OUT%\ffi.lib || exit /B 1
58+
copy %LIBFFI_SOURCE%\%HOST%\fficonfig.h %LIBFFI_OUT%\include || exit /B 1
59+
copy %LIBFFI_SOURCE%\%HOST%\include\*.h %LIBFFI_OUT%\include || exit /B 1
60+
popd
61+
exit /B
62+
63+
:InstallCygwin
64+
setlocal
65+
set CYG_ROOT=C:/cygwin
66+
set CYG_CACHE=C:/cygwin/var/cache/setup
67+
set CYG_MIRROR=http://mirrors.kernel.org/sourceware/cygwin/
68+
powershell -c "Invoke-WebRequest https://cygwin.com/setup-x86.exe -OutFile setup.exe"
69+
setup.exe -qgnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P dejagnu -P autoconf -P automake -P libtool -P make
70+
endlocal
71+
exit /B

c/libffi_arm64/ffi.lib

56.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)