Skip to content

Commit 3852160

Browse files
committed
[GR-60098] Add GRAALPY_VERSION, generate pyconfig.h
PullRequest: graalpython/3593
2 parents 3af7519 + fe50c75 commit 3852160

File tree

12 files changed

+176
-43
lines changed

12 files changed

+176
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
1616
* Rewrite wheelbuilder to be easier to use and contribute to. This version is now the same we run internally to build publishable wheels for some platforms we support, so the community can build the same wheels on their own hardware easily if desired.
1717
* `pip` is now able to fetch newer versions of GraalPy patches for third-party packages from `graalpython` GitHub repository, allowing us to add new patches to released versions.
1818
* The patch repository can be overridden using `PIP_GRAALPY_PATCHES_URL` environment variable, which can point to a local path or a URL. It can be disabled by setting it to an empty string.
19+
* Added `GRAALPY_VERSION` and `GRAALPY_VERSION_NUM` C macros
1920

2021
## Version 24.1.0
2122
* GraalPy is now considered stable for pure Python workloads. While many workloads involving native extension modules work, we continue to consider them experimental. You can use the command-line option `--python.WarnExperimentalFeatures` to enable warnings for such modules at runtime. In Java embeddings the warnings are enabled by default and you can suppress them by setting the context option 'python.WarnExperimentalFeatures' to 'false'.

graalpython/com.oracle.graal.python.benchmarks/python/host_interop/java-register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class JList:
5151
def append(self, value):
5252
self.add(value)
5353

54-
def __getitem__(self, item):
55-
return self.get(item)
54+
# def __getitem__(self, item):
55+
# return self.get(item)
5656

5757
def get_value(self):
5858
return sum(self)

graalpython/com.oracle.graal.python.cext/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if(WIN32)
4545
require_var(GRAALVM_LLVM_LIB_DIR)
4646
endif()
4747
require_var(CAPI_INC_DIR)
48+
require_var(PYCONFIG_INCLUDE_DIR)
4849
require_var(TRUFFLE_H_INC)
4950
require_var(TRUFFLE_NFI_H_INC)
5051
require_var(GRAALPY_EXT)
@@ -150,6 +151,7 @@ include_directories(
150151
${CAPI_SRC}
151152
"${SRC_DIR}/include"
152153
"${CAPI_INC_DIR}"
154+
"${PYCONFIG_INCLUDE_DIR}"
153155
"${TRUFFLE_H_INC}"
154156
"${TRUFFLE_NFI_H_INC}"
155157
)

graalpython/com.oracle.graal.python.hpy.llvm/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
4747

4848
require_var(GRAALVM_HPY_INCLUDE_DIR)
4949
require_var(GRAALVM_PYTHON_INCLUDE_DIR)
50+
require_var(PYCONFIG_INCLUDE_DIR)
5051
require_var(TRUFFLE_H_INC)
5152

5253
set(HPY_SRC "${SRC_DIR}/src")
@@ -91,6 +92,7 @@ target_sources(${TARGET_LIB} PRIVATE ${SRC_FILES} ${HPY_HEADERS})
9192
target_include_directories(${TARGET_LIB} PRIVATE
9293
"${GRAALVM_HPY_INCLUDE_DIR}"
9394
"${GRAALVM_PYTHON_INCLUDE_DIR}"
95+
"${PYCONFIG_INCLUDE_DIR}"
9496
"${TRUFFLE_H_INC}"
9597
)
9698

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_misc.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
import os
4242
import pathlib
4343
import sys
44+
import unittest
4445

45-
from . import CPyExtTestCase, CPyExtFunction, unhandled_error_compare
46-
46+
from . import CPyExtTestCase, CPyExtFunction, unhandled_error_compare, CPyExtType
4747

4848
__global_builtins_dict = builtins.__dict__
4949

@@ -370,3 +370,30 @@ class TestMisc(CPyExtTestCase):
370370
arguments=["PyObject* value"],
371371
cmpfunc=unhandled_error_compare
372372
)
373+
374+
375+
@unittest.skipUnless(sys.implementation.name == 'graalpy', "GraalPy-only")
376+
def test_graalpy_version():
377+
tester = CPyExtType(
378+
"VersionTester",
379+
code='''
380+
static PyObject* get_version_str(PyObject* unused) {
381+
return PyUnicode_FromString(GRAALPY_VERSION);
382+
}
383+
static PyObject* get_version_num(PyObject* unused) {
384+
return PyLong_FromLong(GRAALPY_VERSION_NUM);
385+
}
386+
''',
387+
tp_methods='''
388+
{"get_version_str", (PyCFunction)get_version_str, METH_NOARGS | METH_STATIC, ""},
389+
{"get_version_num", (PyCFunction)get_version_num, METH_NOARGS | METH_STATIC, ""}
390+
''',
391+
)
392+
expected_version = __graalpython__.get_graalvm_version().removesuffix('-dev')
393+
assert tester.get_version_str() == expected_version
394+
parts = [int(v) for v in expected_version.split('.')] + [0]
395+
expected_num = 0
396+
for i in range(3):
397+
expected_num <<= 8
398+
expected_num |= parts[i]
399+
assert tester.get_version_num() == expected_num

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_asyncio.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ test.test_asyncio.test_subprocess.SubprocessSafeWatcherTests.test_create_subproc
726726
test.test_asyncio.test_subprocess.SubprocessSafeWatcherTests.test_popen_error @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64
727727
test.test_asyncio.test_subprocess.SubprocessSafeWatcherTests.test_popen_error_with_stdin_pipe @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64
728728
test.test_asyncio.test_subprocess.SubprocessSafeWatcherTests.test_read_stdout_after_process_exit @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64
729-
test.test_asyncio.test_subprocess.SubprocessSafeWatcherTests.test_start_new_session @ darwin-x86_64
729+
!test.test_asyncio.test_subprocess.SubprocessSafeWatcherTests.test_start_new_session
730730
test.test_asyncio.test_subprocess.SubprocessThreadedWatcherTests.test_cancel_make_subprocess_transport_exec @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64
731731
test.test_asyncio.test_subprocess.SubprocessThreadedWatcherTests.test_cancel_post_init @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64
732732
test.test_asyncio.test_subprocess.SubprocessThreadedWatcherTests.test_cancel_process_wait @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_xml_etree.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test.test_xml_etree.BasicElementTest.test___deepcopy__ @ darwin-arm64,darwin-x86
2121
test.test_xml_etree.BasicElementTest.test___init__ @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2222
test.test_xml_etree.BasicElementTest.test_augmentation_type_errors @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2323
test.test_xml_etree.BasicElementTest.test_copy @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
24-
test.test_xml_etree.BasicElementTest.test_cyclic_gc @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
24+
!test.test_xml_etree.BasicElementTest.test_cyclic_gc @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2525
test.test_xml_etree.BasicElementTest.test_get_keyword_args @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2626
test.test_xml_etree.BasicElementTest.test_pickle @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2727
test.test_xml_etree.BasicElementTest.test_pickle_issue18997 @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_xml_etree_c.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test.test_xml_etree_c.BasicElementTest.test___deepcopy__ @ darwin-arm64,darwin-x
2121
test.test_xml_etree_c.BasicElementTest.test___init__ @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2222
test.test_xml_etree_c.BasicElementTest.test_augmentation_type_errors @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2323
test.test_xml_etree_c.BasicElementTest.test_copy @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
24-
test.test_xml_etree_c.BasicElementTest.test_cyclic_gc @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
24+
!test.test_xml_etree_c.BasicElementTest.test_cyclic_gc @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2525
test.test_xml_etree_c.BasicElementTest.test_get_keyword_args @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2626
test.test_xml_etree_c.BasicElementTest.test_pickle @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64,win32-AMD64
2727
test.test_xml_etree_c.BasicElementTest.test_pickle_issue18997 @ darwin-arm64,darwin-x86_64,linux-aarch64,linux-x86_64
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#
2+
# Copyright (c) 2024, Oracle and/or its affiliates.
3+
#
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without modification, are
7+
# permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice, this list of
10+
# conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
# conditions and the following disclaimer in the documentation and/or other materials provided
14+
# with the distribution.
15+
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to
16+
# endorse or promote products derived from this software without specific prior written
17+
# permission.
18+
#
19+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
20+
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21+
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22+
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24+
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25+
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27+
# OF THE POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
cmake_minimum_required(VERSION 3.22)
30+
project(graalpy-pyconfig)
31+
32+
include(CheckSymbolExists)
33+
include(CheckIncludeFile)
34+
include (TestBigEndian)
35+
36+
test_big_endian(IS_BIG_ENDIAN)
37+
38+
set(CMAKE_REQUIRED_LINK_OPTIONS "-lm")
39+
40+
check_include_file("dirent.h" HAVE_DIRENT_H)
41+
check_include_file("errno.h" HAVE_ERRNO_H)
42+
check_include_file("utime.h" HAVE_UTIME_H)
43+
check_include_file("signal.h" HAVE_SIGNAL_H)
44+
check_include_file("fcntl.h" HAVE_FCNTL_H)
45+
check_include_file("wchar.h" HAVE_WCHAR_H)
46+
check_include_file("unistd.h" HAVE_UNISTD_H)
47+
check_include_file("pthread.h" HAVE_PTHREAD_H)
48+
check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
49+
check_include_file("sys/wait.h" HAVE_SYS_WAIT_H)
50+
check_include_file("sys/time.h" HAVE_SYS_TIME_H)
51+
52+
check_symbol_exists(acosh "math.h" HAVE_ACOSH)
53+
check_symbol_exists(asinh "math.h" HAVE_ASINH)
54+
check_symbol_exists(atanh "math.h" HAVE_ATANH)
55+
check_symbol_exists(copysign "math.h" HAVE_COPYSIGN)
56+
check_symbol_exists(round "math.h" HAVE_ROUND)
57+
check_symbol_exists(hypot "math.h" HAVE_HYPOT)
58+
check_symbol_exists(clock "time.h" HAVE_CLOCK)
59+
check_symbol_exists(sendfile "sys/sendfile.h" HAVE_SENDFILE)
60+
61+
if(HAVE_SYS_TIME_H)
62+
set(TIME_WITH_SYS_TIME 1)
63+
endif()
64+
if(WIN32)
65+
set(NT_THREADS 1)
66+
endif()
67+
if(IS_BIG_ENDIAN)
68+
set(DOUBLE_IS_BIG_ENDIAN_IEEE754 1)
69+
else()
70+
set(DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1)
71+
endif()
72+
73+
configure_file("pyconfig_template.h" "pyconfig.h" @ONLY)

graalpython/com.oracle.graal.python.cext/include/pyconfig.h renamed to graalpython/graalpy-pyconfig/pyconfig_template.h

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#define Py_PYCONFIG_H
4343

4444
#define GRAALVM_PYTHON 1
45+
#cmakedefine GRAALPY_VERSION "@GRAALPY_VERSION@"
46+
#cmakedefine GRAALPY_VERSION_NUM @GRAALPY_VERSION_NUM@
4547

4648
// The graalpy build always sets MS_WINDOWS, so when this is not set, we are
4749
// dealing with an extension build. In that case, if we're on Windows, we need
@@ -148,44 +150,37 @@
148150
// #define Py_LIMITED_API 1
149151
// END TRUFFLE DEFS
150152

151-
#define HAVE_ACOSH 1
152-
#define HAVE_ASINH 1
153-
#define HAVE_ATANH 1
154-
#define HAVE_CLOCK 1
155-
#define HAVE_DIRENT_H 1
156-
#define HAVE_SENDFILE 1
157-
#define HAVE_SYS_STAT_H 1
158-
#define HAVE_ERRNO_H 1
159-
#define HAVE_UTIME_H
160-
#define HAVE_SIGNAL_H
161-
#define HAVE_FCNTL_H
162-
163-
#define HAVE_STDARG_PROTOTYPES
164-
165-
#define HAVE_WCHAR_H 1
166-
153+
#cmakedefine HAVE_ACOSH 1
154+
#cmakedefine HAVE_ASINH 1
155+
#cmakedefine HAVE_ATANH 1
156+
#cmakedefine HAVE_COPYSIGN 1
157+
#cmakedefine HAVE_ROUND 1
158+
#cmakedefine HAVE_HYPOT 1
159+
#cmakedefine HAVE_CLOCK 1
160+
#cmakedefine HAVE_SENDFILE 1
161+
#cmakedefine HAVE_DIRENT_H 1
162+
#cmakedefine HAVE_ERRNO_H 1
163+
#cmakedefine HAVE_UTIME_H 1
164+
#cmakedefine HAVE_SIGNAL_H 1
165+
#cmakedefine HAVE_FCNTL_H 1
166+
#cmakedefine HAVE_WCHAR_H 1
167+
#cmakedefine HAVE_UNISTD_H 1
168+
#cmakedefine HAVE_PTHREAD_H 1
169+
#cmakedefine HAVE_SYS_WAIT_H 1
170+
#cmakedefine HAVE_SYS_TIME_H 1
171+
#cmakedefine HAVE_SYS_STAT_H 1
172+
173+
#cmakedefine TIME_WITH_SYS_TIME 1
174+
#cmakedefine NT_THREADS 1
175+
176+
#define HAVE_STDARG_PROTOTYPES 1
167177
#define WITH_THREAD 1
168178
#define WITH_DOC_STRINGS 1
169179

170-
#ifndef MS_WINDOWS
171-
#define HAVE_UNISTD_H
172-
#define HAVE_PTHREAD_H
173-
#define HAVE_SYS_WAIT_H
174-
#define HAVE_SYS_TIME_H
175-
#define TIME_WITH_SYS_TIME 1
176-
#else
177-
#define HAVE_COPYSIGN 1
178-
#define HAVE_ROUND 1
179-
#define HAVE_HYPOT 1
180-
#define NT_THREADS 1
181-
#endif
182-
183-
// The following should have been generated using `configure` command,
184-
// but instead, are set manully for the time being.
185-
186180
/* Define if C doubles are 64-bit IEEE 754 binary format, stored with the
187181
least significant byte first */
188-
#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1
182+
#cmakedefine DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1
183+
#cmakedefine DOUBLE_IS_BIG_ENDIAN_IEEE754 1
189184

190185

191186
#endif /*Py_PYCONFIG_H*/

0 commit comments

Comments
 (0)