Skip to content

Commit a78c4d4

Browse files
committed
Merge branch 'master'
2 parents 39dc4f1 + 47e380d commit a78c4d4

769 files changed

Lines changed: 6928 additions & 2670 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ci.jsonnet‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ overlay: "41b5d34c082c57db236d3a620b1dc1d367537fac" }
1+
{ overlay: "573cc70d2151ae3fdbf52a1e36265ebf4de69369" }

‎graalpython/com.oracle.graal.python.cext/include/Python.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#include "weakrefobject.h"
123123
#include "sysmodule.h"
124124
#include "fileutils.h"
125+
#include "pystrtod.h"
125126

126127
// TODO: we must extend the refcounting behavior to support handles to managed objects
127128
#undef Py_DECREF
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Copyright (c) 2019, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2017 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
7+
#ifndef Py_STRTOD_H
8+
#define Py_STRTOD_H
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
15+
PyAPI_FUNC(double) PyOS_string_to_double(const char *str,
16+
char **endptr,
17+
PyObject *overflow_exception);
18+
19+
/* The caller is responsible for calling PyMem_Free to free the buffer
20+
that's is returned. */
21+
PyAPI_FUNC(char *) PyOS_double_to_string(double val,
22+
char format_code,
23+
int precision,
24+
int flags,
25+
int *type);
26+
27+
#ifndef Py_LIMITED_API
28+
PyAPI_FUNC(PyObject *) _Py_string_to_number_with_underscores(
29+
const char *str, Py_ssize_t len, const char *what, PyObject *obj, void *arg,
30+
PyObject *(*innerfunc)(const char *, Py_ssize_t, void *));
31+
32+
PyAPI_FUNC(double) _Py_parse_inf_or_nan(const char *p, char **endptr);
33+
#endif
34+
35+
36+
/* PyOS_double_to_string's "flags" parameter can be set to 0 or more of: */
37+
#define Py_DTSF_SIGN 0x01 /* always add the sign */
38+
#define Py_DTSF_ADD_DOT_0 0x02 /* if the result is an integer add ".0" */
39+
#define Py_DTSF_ALT 0x04 /* "alternate" formatting. it's format_code
40+
specific */
41+
42+
/* PyOS_double_to_string's "type", if non-NULL, will be set to one of: */
43+
#define Py_DTST_FINITE 0
44+
#define Py_DTST_INFINITE 1
45+
#define Py_DTST_NAN 2
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#endif /* !Py_STRTOD_H */

‎graalpython/com.oracle.graal.python.cext/setup.py‎

Lines changed: 21 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@
5757
so_ext = get_config_var("EXT_SUFFIX")
5858

5959

60-
if darwin_native:
61-
get_config_vars()["LDSHARED"] = get_config_vars()['LDSHARED_LINUX'] + " -L" + sys.graal_python_capi_home + " -lpython." + get_config_vars()["SOABI"] + " -rpath '@loader_path/../'"
62-
63-
6460
def system(cmd, msg=""):
6561
logger.debug("Running command: " + cmd)
6662
status = os.system(cmd)
@@ -70,58 +66,35 @@ def system(cmd, msg=""):
7066

7167
def xit(msg, status=-1):
7268
print(msg)
73-
exit(-1)
69+
sys.exit(-1)
7470

7571

7672
class CAPIDependency:
7773
_lib_install_dir = os.path.join(site.getuserbase(), "lib", get_config_var("SOABI"))
7874
_include_install_dir = os.path.join(site.getuserbase(), "include")
7975

80-
def __init__(self, lib_name, package_spec, url):
76+
def __init__(self, lib_name, package_spec, src_var):
8177
self.lib_name = lib_name
8278
if "==" in package_spec:
8379
self.package_name, _, self.version = package_spec.rpartition("==")
8480
else:
8581
self.package_name = self.package_spec
8682
self.version = None
87-
self.url = url
83+
self.src_var = src_var
8884

8985
def download(self):
9086
import tempfile
91-
package_pattern = os.environ.get("GINSTALL_PACKAGE_PATTERN", None)
92-
package_version_pattern = os.environ.get("GINSTALL_PACKAGE_VERSION_PATTERN", None)
93-
tempdir = tempfile.mkdtemp()
94-
package_name = self.package_name
95-
96-
if package_pattern and package_version_pattern:
97-
if self.version:
98-
url = package_version_pattern % (package_name, self.version)
99-
else:
100-
url = package_pattern % package_name
101-
else:
102-
url = self.url
103-
104-
logger.info("Downloading dependency %s from %s to %s" % (package_name, url, tempdir))
105-
106-
# honor env var 'HTTP_PROXY' and 'HTTPS_PROXY'
107-
os_env = os.environ
108-
curl_opts = []
109-
if url.startswith("http://") and "HTTP_PROXY" in os_env:
110-
curl_opts += ["--proxy", os_env["HTTP_PROXY"]]
111-
elif url.startswith("https://") and "HTTPS_PROXY" in os_env:
112-
curl_opts += ["--proxy", os_env["HTTPS_PROXY"]]
113-
114-
system("curl -L %s -o %s/%s %s" % (" ".join(curl_opts), tempdir, package_name, url), msg="Download error")
115-
if url.endswith(".tar.gz"):
116-
system("tar xzf %s/%s -C %s" % (tempdir, package_name, tempdir), msg="Error extracting tar.gz")
117-
elif url.endswith(".tar.bz2"):
118-
system("tar xjf %s/%s -C %s" % (tempdir, package_name, tempdir), msg="Error extracting tar.bz2")
119-
elif url.endswith(".zip"):
120-
system("unzip -u %s/%s -d %s" % (tempdir, package_name, tempdir), msg="Error extracting zip")
87+
tempdir = tempfile.mktemp()
88+
src_archive = os.environ.get(self.src_var, None)
89+
if src_archive:
90+
shutil.copytree(src_archive, tempdir)
12191
else:
122-
xit("Unknown file type: %s" % package_name)
92+
xit("FATAL: Please set the environment variable %s to the location of the source archive of %s" % (src_archive_var, lib_name))
12393
return tempdir
12494

95+
def conftest(self):
96+
return False
97+
12598
@staticmethod
12699
def _ensure_dir(dir):
127100
if not (os.path.isdir(dir) and os.path.exists(dir)):
@@ -230,7 +203,7 @@ def __init__(self, name, subdir="modules", files=None, deps=[]):
230203
self.files = [name + ".c"]
231204

232205
def __call__(self):
233-
libs = ["polyglot-mock"] if darwin_native else []
206+
libs = []
234207
library_dirs = []
235208
include_dirs = []
236209
runtime_library_dirs = []
@@ -247,8 +220,6 @@ def __call__(self):
247220
if dep.lib_install_dir:
248221
libs.append(dep.lib_name)
249222
library_dirs.append(dep.lib_install_dir)
250-
#runtime_library_dirs.append(dep.lib_install_dir)
251-
extra_link_args.append("-Wl,-rpath," + dep.lib_install_dir)
252223

253224
# If the dependency provides a header file, add the include path
254225
if dep.include_install_dir:
@@ -272,44 +243,26 @@ def __call__(self):
272243
NativeBuiltinModule("_mmap"),
273244
NativeBuiltinModule("_struct"),
274245
# the above modules are more core, we need them first to deal with later, more complex modules with dependencies
275-
NativeBuiltinModule("_bz2", deps=[Bzip2Depedency("bz2", "bzip2==1.0.8", "https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz")]),
246+
NativeBuiltinModule("_bz2", deps=[Bzip2Depedency("bz2", "bzip2==1.0.8", "BZIP2")]),
276247
)
277248

278249

279-
class BootstrapContextManager:
280-
def __enter__(self):
281-
# Very special case on Darwin native: for building 'libpython*.dylib' we must not try to link against i
282-
# 'libpython', of course. It is special for Darwin because we don't link against it on Linux.
283-
if darwin_native:
284-
self.default_link_args = get_config_var("LDSHARED")
285-
assert get_config_vars()["LDSHARED"] == get_config_var("LDSHARED")
286-
get_config_vars()["LDSHARED"] = get_config_vars()["LDSHARED_LINUX"]
287-
288-
def __exit__(self, typ=None, val=None, tb=None):
289-
if darwin_native:
290-
get_config_vars()["LDSHARED"] = self.default_link_args
291-
292-
293250
def build_libpython(capi_home):
294251
src_dir = os.path.join(__dir__, "src")
295252
files = [os.path.abspath(os.path.join(src_dir, f)) for f in os.listdir(src_dir) if f.endswith(".c")]
296253
module = Extension(libpython_name,
297254
sources=files,
298255
extra_compile_args=cflags_warnings,
299-
# Darwin's linker is pretty pedantic so we need to avoid any unresolved syms. To do so, we use
300-
# 'libpolyglot-mock' that provides definitions for polyglot functions and we define an install name for this lib.
301-
extra_link_args=["-lpolyglot-mock", "-Wl,-install_name,@rpath/" + libpython_name + so_ext] if darwin_native else [],
302256
)
303257
args = [verbosity, 'build', 'install_lib', '-f', '--install-dir=%s' % capi_home, "clean"]
304-
with BootstrapContextManager():
305-
setup(
306-
script_name='setup' + libpython_name,
307-
script_args=args,
308-
name=libpython_name,
309-
version='1.0',
310-
description="Graal Python's C API",
311-
ext_modules=[module],
312-
)
258+
setup(
259+
script_name='setup' + libpython_name,
260+
script_args=args,
261+
name=libpython_name,
262+
version='1.0',
263+
description="Graal Python's C API",
264+
ext_modules=[module],
265+
)
313266

314267
def build_builtin_exts(capi_home):
315268
args = [verbosity, 'build', 'install_lib', '-f', '--install-dir=%s/modules' % capi_home, "clean"]

‎graalpython/com.oracle.graal.python.cext/src/pystrtod.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,19 @@ double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_ex
5353
}
5454
return result;
5555
}
56+
57+
/* translation macro to be independent of changes in 'pystrtod.h' */
58+
#define TRANSLATE_TYPE(__tc__) ((__tc__) == 0 ? Py_DTST_FINITE : ((__tc__) == 1 ? Py_DTST_INFINITE : Py_DTST_NAN))
59+
60+
UPCALL_ID(PyTruffle_OS_DoubleToString);
61+
char * PyOS_double_to_string(double val, char format_code, int precision, int flags, int *type) {
62+
char* result = NULL;
63+
PyObject* resultTuple = UPCALL_CEXT_O(_jls_PyTruffle_OS_DoubleToString, val, (int32_t)format_code, precision, flags);
64+
if (resultTuple != NULL) {
65+
result = (char *) PyTuple_GetItem(resultTuple, 0);
66+
if (type != NULL) {
67+
*type = TRANSLATE_TYPE(as_int(PyTuple_GetItem(resultTuple, 1)));
68+
}
69+
}
70+
return result;
71+
}

‎graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Map;
3939
import java.util.Set;
4040

41+
import com.oracle.truffle.llvm.toolchain.launchers.common.Driver;
4142
import org.graalvm.launcher.AbstractLanguageLauncher;
4243
import org.graalvm.nativeimage.ImageInfo;
4344
import org.graalvm.nativeimage.ProcessProperties;
@@ -203,6 +204,10 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
203204
unrecognized.add(arg);
204205
}
205206
break;
207+
case "-llvm-path":
208+
print(new Driver("llvm-ar").getLLVMBinDir().toString());
209+
System.exit(0);
210+
break;
206211
case "-u":
207212
unbufferedIO = true;
208213
break;

‎graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/PythonTests.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ private static String getFileContent(File file) {
285285

286286
public static RootNode getParseResult(com.oracle.truffle.api.source.Source source, PrintStream out, PrintStream err) {
287287
PythonTests.enterContext();
288-
PythonContext ctx = PythonLanguage.getContextRef().get();
288+
PythonContext ctx = PythonLanguage.getContext();
289289
ctx.setOut(out);
290290
ctx.setErr(err);
291291
return (RootNode) ctx.getCore().getParser().parse(ParserMode.File, ctx.getCore(), source, null);

‎graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/TestParserTranslator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public class TestParserTranslator {
129129

130130
public TestParserTranslator() {
131131
PythonTests.enterContext();
132-
context = PythonLanguage.getContextRef().get();
132+
context = PythonLanguage.getContext();
133133
}
134134

135135
private static class JUnitRootNode extends PRootNode {

‎graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/AssignmentTests.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,19 @@ public void nonLocal01() throws Exception {
208208
" inner()\n",
209209
"SyntaxError: name 'x' is assigned to before nonlocal declaration");
210210
}
211+
212+
@Test
213+
public void annotationType01() throws Exception {
214+
checkTreeResult("j: int");
215+
}
216+
217+
@Test
218+
public void annotationType02() throws Exception {
219+
checkScopeAndTree("def fn():\n" + " index : int = 0\n");
220+
}
221+
222+
@Test
223+
public void annotationType03() throws Exception {
224+
checkTreeResult("j = 1\n" + "ahoj.__annotations__['j'] = float");
225+
}
211226
}

‎graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/BasicTests.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,6 @@ public void not01() throws Exception {
522522
checkTreeResult("not a");
523523
}
524524

525-
@Test
526-
public void star01() throws Exception {
527-
checkTreeResult("*a");
528-
}
529-
530525
@Test
531526
public void nonlocal02() throws Exception {
532527
checkTreeResult("nonlocal x");

0 commit comments

Comments
 (0)