Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 110b863

Browse files
author
Paul Monson
committed
rebase PR on libffi PR
only use optimizer workaround on old compilers enable ctypes for ARM in configuration manager
1 parent 23a683a commit 110b863

File tree

9 files changed

+42
-22
lines changed

9 files changed

+42
-22
lines changed

Include/pyport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ extern "C" {
406406
#endif
407407

408408
/* get and set x87 control word for VisualStudio/x86 */
409-
#if defined(_MSC_VER) && defined(_M_IX86) /* x87 only supported in x86 */
409+
#if defined(_MSC_VER) && !defined(_WIN64) && !defined(_M_ARM) /* x87 not supported in 64-bit or ARM */
410410
#define HAVE_PY_SET_53BIT_PRECISION 1
411411
#define _Py_SET_53BIT_PRECISION_HEADER \
412412
unsigned int old_387controlword, new_387controlword, out_387controlword

Include/pythonrun.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ PyAPI_DATA(PyThreadState*) _PyOS_ReadlineTState;
165165
to an 8k margin. */
166166
#define PYOS_STACK_MARGIN 2048
167167

168-
#if defined(WIN32) && !defined(MS_WIN64) && defined(_MSC_VER) && _MSC_VER >= 1300
168+
#if defined(WIN32) && !defined(MS_WIN64) && !defined(_M_ARM) && defined(_MSC_VER) && _MSC_VER >= 1300
169169
/* Enable stack checking under Microsoft C */
170170
#define USE_STACKCHECK
171171
#endif

Modules/_ctypes/callbacks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
380380
}
381381

382382
cc = FFI_DEFAULT_ABI;
383-
#if defined(MS_WIN32) && !defined(_WIN32_WCE) && !defined(MS_WIN64)
383+
#if defined(MS_WIN32) && !defined(_WIN32_WCE) && !defined(MS_WIN64) && !defined(_M_ARM)
384384
if ((flags & FUNCFLAG_CDECL) == 0)
385385
cc = FFI_STDCALL;
386386
#endif

Modules/_ctypes/callproc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,17 @@ of 1, 2, 4, 8, 16, 32, or 64 bits
737737
*/
738738
int can_return_struct_as_int(size_t s)
739739
{
740-
return s == 1 || s == 2 || s == 4;
740+
return s == 1 || s == 2 || s == 4;
741741
}
742742

743743
int can_return_struct_as_sint64(size_t s)
744744
{
745-
return s == 8;
745+
#ifdef _M_ARM
746+
// 8 byte structs cannot be returned in a register on ARM32
747+
return 0;
748+
#else
749+
return s == 8;
750+
#endif
746751
}
747752
#endif
748753

@@ -807,7 +812,7 @@ static int _call_function_pointer(int flags,
807812
}
808813

809814
cc = FFI_DEFAULT_ABI;
810-
#if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(_WIN32_WCE)
815+
#if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(_WIN32_WCE) && !defined(_M_ARM)
811816
if ((flags & FUNCFLAG_CDECL) == 0)
812817
cc = FFI_STDCALL;
813818
#endif

Modules/_ctypes/malloc_closure.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ void *ffi_closure_alloc(size_t ignored, void** codeloc)
106106
return NULL;
107107
item = free_list;
108108
free_list = item->next;
109+
#ifdef _M_ARM
110+
// set Thumb bit so that blx is called correctly
111+
*codeloc = (ITEM*)((uintptr_t)item | 1);
112+
#else
109113
*codeloc = (void *)item;
114+
#endif
110115
return (void *)item;
111116
}

PC/layout/main.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,6 @@
6666
TOOLS_DIRS = FileNameSet("scripts", "i18n", "pynche", "demo", "parser")
6767
TOOLS_FILES = FileSuffixSet(".py", ".pyw", ".txt")
6868

69-
def copy_if_modified(src, dest):
70-
try:
71-
dest_stat = os.stat(dest)
72-
except FileNotFoundError:
73-
do_copy = True
74-
else:
75-
src_stat = os.stat(src)
76-
do_copy = (src_stat.st_mtime != dest_stat.st_mtime or
77-
src_stat.st_size != dest_stat.st_size)
78-
79-
if do_copy:
80-
shutil.copy2(src, dest)
8169

8270
def get_lib_layout(ns):
8371
def _c(f):
@@ -438,7 +426,7 @@ def copy_files(files, ns):
438426
need_compile.append((dest, ns.copy / dest))
439427
else:
440428
(ns.temp / "Lib" / dest).parent.mkdir(parents=True, exist_ok=True)
441-
copy_if_modified(src, ns.temp / "Lib" / dest)
429+
shutil.copy2(src, ns.temp / "Lib" / dest)
442430
need_compile.append((dest, ns.temp / "Lib" / dest))
443431

444432
if src not in EXCLUDE_FROM_CATALOG:
@@ -448,7 +436,7 @@ def copy_files(files, ns):
448436
log_debug("Copy {} -> {}", src, ns.copy / dest)
449437
(ns.copy / dest).parent.mkdir(parents=True, exist_ok=True)
450438
try:
451-
copy_if_modified(src, ns.copy / dest)
439+
shutil.copy2(src, ns.copy / dest)
452440
except shutil.SameFileError:
453441
pass
454442

PCbuild/pcbuild.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ Global
238238
{0E9791DB-593A-465F-98BC-681011311617}.Release|x64.ActiveCfg = Release|x64
239239
{0E9791DB-593A-465F-98BC-681011311617}.Release|x64.Build.0 = Release|x64
240240
{0E9791DB-593A-465F-98BC-681011311618}.Debug|ARM.ActiveCfg = Debug|ARM
241+
{0E9791DB-593A-465F-98BC-681011311618}.Debug|ARM.Build.0 = Debug|ARM
241242
{0E9791DB-593A-465F-98BC-681011311618}.Debug|Win32.ActiveCfg = Debug|Win32
242243
{0E9791DB-593A-465F-98BC-681011311618}.Debug|Win32.Build.0 = Debug|Win32
243244
{0E9791DB-593A-465F-98BC-681011311618}.Debug|x64.ActiveCfg = Debug|x64
@@ -255,6 +256,7 @@ Global
255256
{0E9791DB-593A-465F-98BC-681011311618}.PGUpdate|x64.ActiveCfg = PGUpdate|x64
256257
{0E9791DB-593A-465F-98BC-681011311618}.PGUpdate|x64.Build.0 = PGUpdate|x64
257258
{0E9791DB-593A-465F-98BC-681011311618}.Release|ARM.ActiveCfg = Release|ARM
259+
{0E9791DB-593A-465F-98BC-681011311618}.Release|ARM.Build.0 = Release|ARM
258260
{0E9791DB-593A-465F-98BC-681011311618}.Release|Win32.ActiveCfg = Release|Win32
259261
{0E9791DB-593A-465F-98BC-681011311618}.Release|Win32.Build.0 = Release|Win32
260262
{0E9791DB-593A-465F-98BC-681011311618}.Release|x64.ActiveCfg = Release|x64

PCbuild/prepare_libffi.bat

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ echo.
2424
echo.Available flags:
2525
echo. -x64 build for x64
2626
echo. -x86 build for x86
27+
echo. -arm32 build for arm32
2728
echo. -? this help
2829
echo. --install-cygwin install cygwin to c:\cygwin
2930
exit /b 127
@@ -32,12 +33,14 @@ exit /b 127
3233

3334
set BUILD_X64=
3435
set BUILD_X86=
36+
set BUILD_ARM32=
3537
set INSTALL_CYGWIN=
3638

3739
:CheckOpts
3840
if "%1"=="" goto :CheckOptsDone
3941
if /I "%1"=="-x64" (set BUILD_X64=1) & shift & goto :CheckOpts
4042
if /I "%1"=="-x86" (set BUILD_X86=1) & shift & goto :CheckOpts
43+
if /I "%1"=="-arm32" (set BUILD_ARM32=1) & shift & goto :CheckOpts
4144
if /I "%1"=="-?" goto :Usage
4245
if /I "%1"=="--install-cygwin" (set INSTALL_CYGWIN=1) & shift & goto :CheckOpts
4346
goto :Usage
@@ -47,6 +50,7 @@ goto :Usage
4750
if NOT DEFINED BUILD_X64 if NOT DEFINED BUILD_X86 if NOT DEFINED BUILD_ARM32 (
4851
set BUILD_X64=1
4952
set BUILD_X86=1
53+
set BUILD_ARM32=1
5054
)
5155

5256
if "%INSTALL_CYGWIN%"=="1" call :InstallCygwin
@@ -83,8 +87,9 @@ echo.
8387

8488
if not exist Makefile.in (%SH% -lc "(cd $LIBFFI_SOURCE; ./autogen.sh;)")
8589

86-
call :BuildOne x86 i686-pc-cygwin i686-pc-cygwin
87-
call :BuildOne x64 x86_64-w64-cygwin x86_64-w64-cygwin
90+
if "%BUILD_X64%"=="1" call :BuildOne x64 x86_64-w64-cygwin x86_64-w64-cygwin
91+
if "%BUILD_X86%"=="1" call :BuildOne x86 i686-pc-cygwin i686-pc-cygwin
92+
if "%BUILD_ARM32%"=="1" call :BuildOne x86_arm i686-pc-cygwin arm-w32-cygwin
8893

8994
popd
9095
endlocal
@@ -118,6 +123,12 @@ if /I "%VCVARS_PLATFORM%" EQU "x86" (
118123
set ASSEMBLER=
119124
set SRC_ARCHITECTURE=x86
120125
)
126+
if /I "%VCVARS_PLATFORM%" EQU "x86_arm" (
127+
set ARCH=arm32
128+
set ARTIFACTS=%LIBFFI_SOURCE%\arm-w32-cygwin
129+
set ASSEMBLER=-marm
130+
set SRC_ARCHITECTURE=ARM
131+
)
121132

122133
if NOT DEFINED LIBFFI_OUT set LIBFFI_OUT=%~dp0\..\externals\libffi
123134
set _LIBFFI_OUT=%LIBFFI_OUT%\%ARCH%

Python/ceval.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,15 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
17331733
exc = POP(); /* exc */
17341734
/* fall through */
17351735
case 0:
1736+
#if defined(_M_ARM) && !defined(DEBUG) && (_MSC_VER < 1915)
1737+
// Workaround only required before version 15.8 of Visual Studio
1738+
// work around optimizer problem on windows arm32
1739+
if (oparg == 2)
1740+
{
1741+
exc = stack_pointer[0];
1742+
cause = stack_pointer[1];
1743+
}
1744+
#endif
17361745
if (do_raise(exc, cause)) {
17371746
goto exception_unwind;
17381747
}

0 commit comments

Comments
 (0)