Skip to content

Commit 3c6c612

Browse files
committed
[GR-50133] Make numpy install and some basic examples work on Windows
PullRequest: graalpython/3062
2 parents 9524f75 + 9412262 commit 3c6c612

File tree

13 files changed

+77
-16
lines changed

13 files changed

+77
-16
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
#define __SIZEOF_SHORT__ 2
9797
#define __SIZEOF_LONG__ 4
9898
#define __SIZEOF_LONG_LONG__ 8
99-
#define __SIZEOF_INT128__ 16
10099
#define __SIZEOF_FLOAT__ 4
101100
#define __SIZEOF_DOUBLE__ 8
102101
#define __SIZEOF_LONG_DOUBLE__ 8

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Py_ssize_t PyNumber_AsSsize_t(PyObject *item, PyObject *err) {
221221

222222
// downcall for native python objects
223223
// taken from CPython "Objects/abstract.c PySequence_Check()"
224-
int PyTruffle_PySequence_Check(PyObject *s) {
224+
PyAPI_FUNC(int) PyTruffle_PySequence_Check(PyObject *s) {
225225
if (PyDict_Check(s))
226226
return 0;
227227
PySequenceMethods* seq = Py_TYPE(s)->tp_as_sequence;
@@ -230,7 +230,7 @@ int PyTruffle_PySequence_Check(PyObject *s) {
230230

231231
// downcall for native python objects
232232
// partially taken from CPython "Objects/abstract.c/PySequence_GetItem"
233-
PyObject* PyTruffle_PySequence_GetItem(PyObject *s, Py_ssize_t i)
233+
PyAPI_FUNC(PyObject*) PyTruffle_PySequence_GetItem(PyObject *s, Py_ssize_t i)
234234
{
235235
PySequenceMethods *m = Py_TYPE(s)->tp_as_sequence;
236236
if (m && m->sq_item) {
@@ -255,7 +255,7 @@ PyObject* PyTruffle_PySequence_GetItem(PyObject *s, Py_ssize_t i)
255255

256256
// downcall for native python objects
257257
// taken from CPython "Objects/abstract.c/Py_Sequence_Size"
258-
Py_ssize_t PyTruffle_PySequence_Size(PyObject *s) {
258+
PyAPI_FUNC(Py_ssize_t) PyTruffle_PySequence_Size(PyObject *s) {
259259
PySequenceMethods *seq;
260260
PyMappingMethods *m;
261261

@@ -300,7 +300,7 @@ PyObject * PyMapping_GetItemString(PyObject *o, const char *key) {
300300

301301
// downcall for native python objects
302302
// taken from CPython "Objects/abstract.c/PyObject_Size"
303-
Py_ssize_t PyTruffle_PyObject_Size(PyObject *o) {
303+
PyAPI_FUNC(Py_ssize_t) PyTruffle_PyObject_Size(PyObject *o) {
304304
PySequenceMethods *m;
305305

306306
if (o == NULL) {
@@ -320,7 +320,7 @@ Py_ssize_t PyTruffle_PyObject_Size(PyObject *o) {
320320

321321
// downcall for native python objects
322322
// taken from CPython "Objects/abstract.c PyMapping_Check"
323-
int PyTruffle_PyMapping_Check(PyObject *o) {
323+
PyAPI_FUNC(int) PyTruffle_PyMapping_Check(PyObject *o) {
324324
return o && Py_TYPE(o)->tp_as_mapping && Py_TYPE(o)->tp_as_mapping->mp_subscript;
325325
}
326326

@@ -475,7 +475,7 @@ int PyBuffer_IsContiguous(const Py_buffer *view, char order) {
475475

476476
// PyMapping_Size downcall for native python objects
477477
// partially taken from CPython "Objects/abstract.c/Py_Mapping_Size"
478-
Py_ssize_t PyTruffle_PyMapping_Size(PyObject *o) {
478+
PyAPI_FUNC(Py_ssize_t) PyTruffle_PyMapping_Size(PyObject *o) {
479479
PyMappingMethods *m;
480480

481481
if (o == NULL) {

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
@@ -116,6 +116,7 @@
116116
import com.oracle.graal.python.builtins.modules.UnicodeDataModuleBuiltins;
117117
import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins;
118118
import com.oracle.graal.python.builtins.modules.WeakRefModuleBuiltins;
119+
import com.oracle.graal.python.builtins.modules.WinapiModuleBuiltins;
119120
import com.oracle.graal.python.builtins.modules.WinregModuleBuiltins;
120121
import com.oracle.graal.python.builtins.modules.ast.AstBuiltins;
121122
import com.oracle.graal.python.builtins.modules.ast.AstModuleBuiltins;
@@ -510,6 +511,7 @@ private static PythonBuiltins[] initializeBuiltins(boolean nativeAccessAllowed,
510511
new PosixModuleBuiltins(),
511512
new NtModuleBuiltins(),
512513
new WinregModuleBuiltins(),
514+
new WinapiModuleBuiltins(),
513515
new CryptModuleBuiltins(),
514516
new ScandirIteratorBuiltins(),
515517
new DirEntryBuiltins(),
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2022, 2023, 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.CoreFunctions;
46+
import com.oracle.graal.python.builtins.PythonBuiltins;
47+
import com.oracle.graal.python.builtins.PythonOS;
48+
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
49+
import com.oracle.truffle.api.dsl.NodeFactory;
50+
51+
@CoreFunctions(defineModule = "_winapi", os = PythonOS.PLATFORM_WIN32)
52+
public final class WinapiModuleBuiltins extends PythonBuiltins {
53+
@Override
54+
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
55+
return List.of();
56+
}
57+
}

graalpython/lib-graalpython/patches/numpy/numpy-1.23.5.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,11 @@ index f959162..2ef579b 100644
566566
return multiiter_wrong_number_of_args();
567567
}
568568
- ret = multiiter_new_impl(n, PySequence_Fast_ITEMS(fast_seq));
569-
+ PyObject* seq[n];
569+
+ PyObject** seq = (PyObject **)malloc(n, sizeof(PyObject *));
570570
+ for (int i = 0; i < n; i++) {
571571
+ seq[i] = PySequence_Fast_GET_ITEM(fast_seq, i);
572572
+ }
573-
+ ret = multiiter_new_impl(n, seq);
573+
+ ret = multiiter_new_impl(n, seq); free(seq);
574574
Py_DECREF(fast_seq);
575575
return ret;
576576
}

graalpython/lib-graalpython/patches/pip/pip-22.2.2.patch

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ new file mode 100644
9595
index 0000000..b8a506c
9696
--- /dev/null
9797
+++ b/pip/_internal/utils/graalpy.py
98-
@@ -0,0 +1,194 @@
98+
@@ -0,0 +1,195 @@
9999
+# ATTENTION: GraalPy uses existence of this module to verify that it is
100100
+# running a patched pip in pip_hook.py
101101
+import os
@@ -243,8 +243,9 @@ index 0000000..b8a506c
243243
+ if rule:
244244
+ if patch := rule.get('patch'):
245245
+ print(f"Patching package {name} using {patch}")
246+
+ exe = '.exe' if os.name == 'nt' else ''
246247
+ try:
247-
+ subprocess.run(["patch", "-f", "-d", location, "-p1", "-i", str(patch)], check=True)
248+
+ subprocess.run([f"patch{exe}", "-f", "-d", location, "-p1", "-i", str(patch)], check=True)
248249
+ except FileNotFoundError:
249250
+ print(
250251
+ "WARNING: GraalPy needs the 'patch' utility to apply compatibility patches. Please install it using your system's package manager.")

graalpython/lib-graalpython/patches/pip/pip-23.0.1.patch

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ new file mode 100644
9595
index 0000000..b8a506c
9696
--- /dev/null
9797
+++ b/pip/_internal/utils/graalpy.py
98-
@@ -0,0 +1,194 @@
98+
@@ -0,0 +1,195 @@
9999
+# ATTENTION: GraalPy uses existence of this module to verify that it is
100100
+# running a patched pip in pip_hook.py
101101
+import os
@@ -243,8 +243,9 @@ index 0000000..b8a506c
243243
+ if rule:
244244
+ if patch := rule.get('patch'):
245245
+ print(f"Patching package {name} using {patch}")
246+
+ exe = '.exe' if os.name == 'nt' else ''
246247
+ try:
247-
+ subprocess.run(["patch", "-f", "-d", location, "-p1", "-i", str(patch)], check=True)
248+
+ subprocess.run([f"patch{exe}", "-f", "-d", location, "-p1", "-i", str(patch)], check=True)
248249
+ except FileNotFoundError:
249250
+ print(
250251
+ "WARNING: GraalPy needs the 'patch' utility to apply compatibility patches. Please install it using your system's package manager.")

graalpython/lib-python/3/distutils/msvc9compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def get_build_version():
173173
prefix = "MSC v."
174174
i = sys.version.find(prefix)
175175
if i == -1:
176-
return 6
176+
return 14 # Truffle change to 14
177177
i = i + len(prefix)
178178
s, rest = sys.version[i:].split(" ", 1)
179179
majorVersion = int(s[:-2]) - 6

graalpython/lib-python/3/distutils/msvccompiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def get_build_version():
153153
prefix = "MSC v."
154154
i = sys.version.find(prefix)
155155
if i == -1:
156-
return 6
156+
return 14 # Truffle change to 14
157157
i = i + len(prefix)
158158
s, rest = sys.version[i:].split(" ", 1)
159159
majorVersion = int(s[:-2]) - 6

graalpython/lib-python/3/encodings/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def search_function(encoding):
159159
def _alias_mbcs(encoding):
160160
try:
161161
import _winapi
162+
return None # Truffle change: we don't support this method yet
162163
ansi_code_page = "cp%s" % _winapi.GetACP()
163164
if encoding == ansi_code_page:
164165
import encodings.mbcs

0 commit comments

Comments
 (0)