Skip to content

Commit 334e2bf

Browse files
committed
Fix ctypes long format string on windows
1 parent c551b37 commit 334e2bf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/PyCSimpleTypeBuiltins.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -67,6 +67,7 @@
6767
import com.oracle.graal.python.builtins.CoreFunctions;
6868
import com.oracle.graal.python.builtins.Python3Core;
6969
import com.oracle.graal.python.builtins.PythonBuiltins;
70+
import com.oracle.graal.python.builtins.PythonOS;
7071
import com.oracle.graal.python.builtins.modules.BuiltinConstructors.TypeNode;
7172
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.IsInstanceNode;
7273
import com.oracle.graal.python.builtins.modules.ctypes.CFieldBuiltins.SetFuncNode;
@@ -368,6 +369,8 @@ static TruffleString ctypesAllocFormatStringForType(char code, boolean big_endia
368369
/* The standard-size code is the same as the ctypes one */
369370
char pep_code = code;
370371

372+
boolean longIs32Bit = PythonOS.getPythonOS() == PythonOS.PLATFORM_WIN32;
373+
371374
switch (code) {
372375
// #if SIZEOF_INT == 2
373376
// case 'i': pep_code = 'h'; break;
@@ -387,10 +390,10 @@ static TruffleString ctypesAllocFormatStringForType(char code, boolean big_endia
387390
// case 'L': pep_code = 'L'; break;
388391
// #elif SIZEOF_LONG == 8
389392
case 'l':
390-
pep_code = 'q';
393+
pep_code = longIs32Bit ? 'l' : 'q';
391394
break;
392395
case 'L':
393-
pep_code = 'Q';
396+
pep_code = longIs32Bit ? 'L' : 'Q';
394397
break;
395398
// #if SIZEOF__BOOL == 1
396399
case '?':

0 commit comments

Comments
 (0)