Skip to content

Commit 41cc531

Browse files
committed
[GR-54235] Get pip install numpy to work windows again
PullRequest: graalpython/3344
2 parents 4e6c0ae + 15fdd62 commit 41cc531

File tree

13 files changed

+226
-28
lines changed

13 files changed

+226
-28
lines changed

graalpython/com.oracle.graal.python.cext/include/pyconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
// relevant for code that is compiled without bitcode and will run only
5656
// natively. Since the pythonjni library contains all the trampolines to call
5757
// into the python-native.dll in this case, we must only depend on that.
58-
# pragma comment(lib, "python-native.lib")
58+
# pragma comment(lib, "python311.lib")
5959
# endif
6060
#endif
6161

@@ -157,7 +157,6 @@
157157
#define HAVE_SYS_STAT_H 1
158158
#define HAVE_ERRNO_H 1
159159
#define HAVE_UTIME_H
160-
#define HAVE_UNISTD_H
161160
#define HAVE_SIGNAL_H
162161
#define HAVE_FCNTL_H
163162

@@ -168,6 +167,7 @@
168167
#define WITH_THREAD 1
169168

170169
#ifndef MS_WINDOWS
170+
#define HAVE_UNISTD_H
171171
#define HAVE_PTHREAD_H
172172
#define HAVE_SYS_WAIT_H
173173
#define HAVE_SYS_TIME_H

graalpython/com.oracle.graal.python.cext/src/errors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,6 @@ PyErr_SetFromErrno(PyObject *exc)
754754
return PyErr_SetFromErrnoWithFilenameObjects(exc, NULL, NULL);
755755
}
756756

757-
#if 0 // GraalPy change
758757
#ifdef MS_WINDOWS
759758
/* Windows specific error code handling */
760759
PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject(
@@ -892,6 +891,7 @@ PyObject *PyErr_SetFromWindowsErrWithFilename(
892891

893892
#endif /* MS_WINDOWS */
894893

894+
#if 0 // GraalPy change
895895
PyObject *
896896
PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
897897
PyObject *name, PyObject *path)

graalpython/com.oracle.graal.python.test/src/tests/test_tagged_unittests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class TestTaggedUnittests(unittest.TestCase):
182182
working_tests = [x for x in working_tests if x[0] in selection]
183183

184184
this_os = sys.platform
185-
this_machine = os.uname().machine
185+
this_machine = os.uname().machine if hasattr(os, "uname") else ""
186186
for idx, working_test in enumerate(working_tests):
187187
if os.environ.get("CI", None) and any(
188188
(os is None or os in this_os)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import com.oracle.graal.python.builtins.modules.MMapModuleBuiltins;
9090
import com.oracle.graal.python.builtins.modules.MarshalModuleBuiltins;
9191
import com.oracle.graal.python.builtins.modules.MathModuleBuiltins;
92+
import com.oracle.graal.python.builtins.modules.MsvcrtModuleBuiltins;
9293
import com.oracle.graal.python.builtins.modules.NtModuleBuiltins;
9394
import com.oracle.graal.python.builtins.modules.OperatorModuleBuiltins;
9495
import com.oracle.graal.python.builtins.modules.PolyglotModuleBuiltins;
@@ -525,6 +526,7 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed,
525526
new PosixModuleBuiltins(),
526527
new NtModuleBuiltins(),
527528
new WinregModuleBuiltins(),
529+
new MsvcrtModuleBuiltins(),
528530
new WinapiModuleBuiltins(),
529531
new CryptModuleBuiltins(),
530532
new ScandirIteratorBuiltins(),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/PythonBuiltinClassType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public enum PythonBuiltinClassType implements TruffleObject {
333333
PStructPasswd("struct_passwd", "pwd", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
334334
PStructRusage("struct_rusage", "resource", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
335335
PVersionInfo("version_info", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
336+
PWindowsVersion("windowsversion", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
336337
PFlags("flags", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
337338
PFloatInfo("float_info", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
338339
PIntInfo("int_info", "sys", Flags.PUBLIC_DERIVED_WODICT, TUPLE_M_FLAGS),
@@ -811,6 +812,7 @@ public final Shape getInstanceShape(PythonLanguage lang) {
811812
PStatvfsResult.redefinedSlots = repr;
812813
PFloatInfo.redefinedSlots = reprAndNew;
813814
PVersionInfo.redefinedSlots = repr;
815+
PWindowsVersion.redefinedSlots = repr;
814816
PFlags.redefinedSlots = repr;
815817
PTerminalSize.redefinedSlots = reprAndNew;
816818

@@ -921,6 +923,7 @@ public final Shape getInstanceShape(PythonLanguage lang) {
921923
PStructPasswd.base = PTuple;
922924
PStructRusage.base = PTuple;
923925
PVersionInfo.base = PTuple;
926+
PWindowsVersion.base = PTuple;
924927
PFlags.base = PTuple;
925928
PFloatInfo.base = PTuple;
926929
PIntInfo.base = PTuple;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.builtins.modules;
42+
43+
import java.util.List;
44+
45+
import com.oracle.graal.python.builtins.Builtin;
46+
import com.oracle.graal.python.builtins.CoreFunctions;
47+
import com.oracle.graal.python.builtins.Python3Core;
48+
import com.oracle.graal.python.builtins.PythonBuiltins;
49+
import com.oracle.graal.python.builtins.PythonOS;
50+
import com.oracle.graal.python.builtins.objects.PNone;
51+
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
52+
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
53+
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
54+
import com.oracle.truffle.api.dsl.NodeFactory;
55+
import com.oracle.truffle.api.dsl.Specialization;
56+
import com.oracle.truffle.api.frame.VirtualFrame;
57+
58+
@CoreFunctions(defineModule = "msvcrt", os = PythonOS.PLATFORM_WIN32)
59+
public final class MsvcrtModuleBuiltins extends PythonBuiltins {
60+
@Override
61+
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
62+
return MsvcrtModuleBuiltinsFactory.getFactories();
63+
}
64+
65+
@Override
66+
public void initialize(Python3Core core) {
67+
super.initialize(core);
68+
addBuiltinConstant("LK_NBLCK", 0);
69+
addBuiltinConstant("LK_UNLCK", 0);
70+
}
71+
72+
@Builtin(name = "locking", minNumOfPositionalArgs = 3)
73+
@GenerateNodeFactory
74+
public abstract static class EnumKeyNode extends PythonTernaryBuiltinNode {
75+
@SuppressWarnings("unused")
76+
@Specialization
77+
static Object locking(VirtualFrame frame, Object file, Object operation, Object arg) {
78+
// TODO: implement on windows, this is just here to make mesonbuild work
79+
return PNone.NONE;
80+
}
81+
}
82+
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ public abstract static class GetLoadAvgNode extends PythonBuiltinNode {
645645

646646
/*
647647
* Return average recent system load information.
648-
*
648+
*
649649
* Return the number of processes in the system run queue averaged over the last 1, 5, and
650650
* 15 minutes as a tuple of three floats. Raises OSError if the load average was
651651
* unobtainable.
@@ -1564,7 +1564,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
15641564
}
15651565
}
15661566

1567-
@Builtin(name = "uname", minNumOfPositionalArgs = 0)
1567+
@Builtin(name = "uname", minNumOfPositionalArgs = 0, os = PythonOS.PLATFORM_LINUX)
1568+
@Builtin(name = "uname", minNumOfPositionalArgs = 0, os = PythonOS.PLATFORM_DARWIN)
15681569
@GenerateNodeFactory
15691570
abstract static class UnameNode extends PythonBuiltinNode {
15701571

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,27 @@ public final class SysModuleBuiltins extends PythonBuiltins {
302302
"'alpha', 'beta', 'candidate', or 'final'", "Serial release number"},
303303
false);
304304

305+
static final StructSequence.BuiltinTypeDescriptor WINDOWS_VER_DESC = new StructSequence.BuiltinTypeDescriptor(
306+
PythonBuiltinClassType.PWindowsVersion,
307+
// @formatter:off The formatter joins these lines making it less readable
308+
"sys.getwindowsversion\n" +
309+
"\n" +
310+
"Return info about the running version of Windows as a named tuple.",
311+
// @formatter:on
312+
5,
313+
new String[]{
314+
"major", "minor", "build",
315+
"platform", "service_pack",
316+
"service_pack_major", "service_pack_minor",
317+
"suite_mask", "product_type", "platform_version"},
318+
new String[]{
319+
"Major version number", "Minor version number", "Build number",
320+
"Operating system platform", "Latest Service Pack installed on the system",
321+
"Service Pack major version number", "Service Pack minor version number",
322+
"Bit mask identifying available product suites",
323+
"System product type", "Diagnostic version number"},
324+
false);
325+
305326
static final StructSequence.BuiltinTypeDescriptor FLAGS_DESC = new StructSequence.BuiltinTypeDescriptor(
306327
PythonBuiltinClassType.PFlags,
307328
// @formatter:off The formatter joins these lines making it less readable
@@ -499,6 +520,9 @@ protected static PSimpleNamespace makeImplementation(PythonObjectFactory factory
499520
@Override
500521
public void initialize(Python3Core core) {
501522
StructSequence.initType(core, VERSION_INFO_DESC);
523+
if (PythonOS.getPythonOS() == PLATFORM_WIN32) {
524+
StructSequence.initType(core, WINDOWS_VER_DESC);
525+
}
502526
StructSequence.initType(core, FLAGS_DESC);
503527
StructSequence.initType(core, FLOAT_INFO_DESC);
504528
StructSequence.initType(core, INT_INFO_DESC);
@@ -520,7 +544,7 @@ public void initialize(Python3Core core) {
520544
addBuiltinConstant("api_version", PythonLanguage.API_VERSION);
521545
addBuiltinConstant("version", toTruffleStringUncached(PythonLanguage.VERSION +
522546
" (" + COMPILE_TIME + ")" +
523-
"\n[Graal, " + Truffle.getRuntime().getName() + ", Java " + System.getProperty("java.version") + "]"));
547+
"\n[Graal, " + Truffle.getRuntime().getName() + ", Java " + System.getProperty("java.version") + " (" + System.getProperty("os.arch") + ")]"));
524548
addBuiltinConstant("float_info", factory.createStructSeq(FLOAT_INFO_DESC,
525549
Double.MAX_VALUE, // DBL_MAX
526550
Double.MAX_EXPONENT + 1, // DBL_MAX_EXP
@@ -2012,4 +2036,52 @@ protected ArgumentClinicProvider getArgumentClinic() {
20122036
return SetDlopenFlagsClinicProviderGen.INSTANCE;
20132037
}
20142038
}
2039+
2040+
@Builtin(name = "getwindowsversion", minNumOfPositionalArgs = 0, os = PLATFORM_WIN32)
2041+
@GenerateNodeFactory
2042+
abstract static class Getwindowsversion extends PythonBuiltinNode {
2043+
static int[] CACHED_VERSION_INFO = null;
2044+
static int PLATFORM = 2;
2045+
2046+
@Specialization
2047+
PTuple getVersion(@Cached PythonObjectFactory factory) {
2048+
if (CACHED_VERSION_INFO == null) {
2049+
cacheVersion();
2050+
}
2051+
return factory.createStructSeq(WINDOWS_VER_DESC,
2052+
CACHED_VERSION_INFO[0], CACHED_VERSION_INFO[1], CACHED_VERSION_INFO[2],
2053+
PLATFORM, T_EMPTY_STRING, 0, 0, 0, 1,
2054+
factory.createTuple(CACHED_VERSION_INFO));
2055+
}
2056+
2057+
@TruffleBoundary
2058+
static void cacheVersion() {
2059+
String[] winvers = System.getProperty("os.version", "10.0.20000").split("\\.");
2060+
int major = 0;
2061+
int minor = 0;
2062+
int build = 0;
2063+
if (winvers.length > 0) {
2064+
try {
2065+
major = Integer.parseInt(winvers[0]);
2066+
} catch (NumberFormatException e) {
2067+
// use default
2068+
}
2069+
}
2070+
if (winvers.length > 1) {
2071+
try {
2072+
minor = Integer.parseInt(winvers[1]);
2073+
} catch (NumberFormatException e) {
2074+
// use default
2075+
}
2076+
}
2077+
if (winvers.length > 2) {
2078+
try {
2079+
build = Integer.parseInt(winvers[2]);
2080+
} catch (NumberFormatException e) {
2081+
// use default
2082+
}
2083+
}
2084+
CACHED_VERSION_INFO = new int[]{major, minor, build};
2085+
}
2086+
}
20152087
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WinregModuleBuiltins.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 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
@@ -86,7 +86,6 @@ public void initialize(Python3Core core) {
8686
// stubs to just have msvc9compiler import
8787
addBuiltinConstant("error", PNone.NONE);
8888
addBuiltinConstant("EnumValue", PNone.NONE);
89-
addBuiltinConstant("OpenKeyEx", PNone.NONE);
9089
}
9190

9291
@Builtin(name = "OpenKey", minNumOfPositionalArgs = 2, parameterNames = {"key", "sub_key", "reserved", "access"})
@@ -125,4 +124,16 @@ static Object enumKey(VirtualFrame frame, Object key, Object index,
125124
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, OSErrorEnum.ENOENT);
126125
}
127126
}
127+
128+
@Builtin(name = "OpenKeyEx", minNumOfPositionalArgs = 2, parameterNames = {"key", "index"})
129+
@GenerateNodeFactory
130+
public abstract static class OpenKeyExNode extends PythonBinaryBuiltinNode {
131+
@SuppressWarnings("unused")
132+
@Specialization
133+
static Object enumKey(VirtualFrame frame, Object key, Object index,
134+
@Bind("this") Node inliningTarget,
135+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
136+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, OSErrorEnum.ENOENT);
137+
}
138+
}
128139
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2573,7 +2573,7 @@ private static int getBuiltinTypeItemsize(PythonBuiltinClassType cls) {
25732573
PIntInfo, PHashInfo, PThreadInfo, PUnraisableHookArgs, PIOBase, PFileIO, PBufferedIOBase,
25742574
PBufferedReader, PBufferedWriter, PBufferedRWPair, PBufferedRandom, PIncrementalNewlineDecoder,
25752575
PTextIOWrapper, CArgObject, CThunkObject, StgDict, Structure, Union, PyCPointer, PyCArray,
2576-
PyCData, SimpleCData, PyCFuncPtr, CField, DictRemover, StructParam -> 8;
2576+
PWindowsVersion, PyCData, SimpleCData, PyCFuncPtr, CField, DictRemover, StructParam -> 8;
25772577
case PythonClass -> 40;
25782578
default -> 0;
25792579
};

0 commit comments

Comments
 (0)