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

Skip to content

Commit 11efd79

Browse files
paulmonzooba
authored andcommitted
bpo-36071 Add support for Windows ARM32 in ctypes/libffi (GH-12059)
1 parent 264a0b4 commit 11efd79

File tree

7 files changed

+31
-8
lines changed

7 files changed

+31
-8
lines changed

Include/pyport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ extern "C" {
427427
#endif
428428

429429
/* get and set x87 control word for VisualStudio/x86 */
430-
#if defined(_MSC_VER) && defined(_M_IX86) /* x87 only supported in x86 */
430+
#if defined(_MSC_VER) && !defined(_WIN64) && !defined(_M_ARM) /* x87 not supported in 64-bit or ARM */
431431
#define HAVE_PY_SET_53BIT_PRECISION 1
432432
#define _Py_SET_53BIT_PRECISION_HEADER \
433433
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
}

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%

0 commit comments

Comments
 (0)