Skip to content

Commit 94ea8d9

Browse files
committed
[GR-46618] Avoid hard dependency on Sulong in Python native extensions
PullRequest: graalpython/2829
2 parents a249a82 + 18f1ee4 commit 94ea8d9

File tree

193 files changed

+11933
-24774
lines changed

Some content is hidden

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

193 files changed

+11933
-24774
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "722a2918fe02527be69d3a59e042ef76d6f8333c" }
1+
{ "overlay": "76e256d73bf17fe1760a898d46482c4ed79ba96d" }

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ if(WIN32)
4343
require_var(GRAALVM_LLVM_LIB_DIR)
4444
endif()
4545
require_var(TRUFFLE_H_INC)
46+
require_var(TRUFFLE_NFI_H_INC)
4647
require_var(LLVM_MODE)
4748
require_var(GRAALPY_EXT)
4849

@@ -91,17 +92,17 @@ set(SRC_FILES ${CAPI_SRC}/codecs.c ${CAPI_SRC}/setobject.c ${CAPI_SRC}/compile.c
9192
${CAPI_SRC}/memoryobject.c ${CAPI_SRC}/traceback.c ${CAPI_SRC}/unicodeobject.c ${CAPI_SRC}/pythonrun.c
9293
${CAPI_SRC}/funcobject.c ${CAPI_SRC}/codeobject.c ${CAPI_SRC}/unicodectype.c ${CAPI_SRC}/structseq.c
9394
${CAPI_SRC}/import.c ${CAPI_SRC}/pytime.c ${CAPI_SRC}/bytearrayobject.c ${CAPI_SRC}/listobject.c
94-
${CAPI_SRC}/bytesobject.c ${CAPI_SRC}/object_shared.c ${CAPI_SRC}/longobject.c ${CAPI_SRC}/sysmodule.c
95+
${CAPI_SRC}/bytesobject.c ${CAPI_SRC}/longobject.c ${CAPI_SRC}/sysmodule.c
9596
${CAPI_SRC}/pystrtod.c ${CAPI_SRC}/tupleobject.c ${CAPI_SRC}/iterobject.c ${CAPI_SRC}/sliceobject.c
9697
${CAPI_SRC}/classobject.c ${CAPI_SRC}/floatobject.c ${CAPI_SRC}/namespaceobject.c ${CAPI_SRC}/_warnings.c
9798
${CAPI_SRC}/dictobject.c ${CAPI_SRC}/pystate.c ${CAPI_SRC}/mysnprintf.c ${CAPI_SRC}/ceval.c
98-
${CAPI_SRC}/getcompiler.c ${CAPI_SRC}/pyhash.c ${CAPI_SRC}/fileutils.c ${CAPI_SRC}/descrobject_shared.c
99+
${CAPI_SRC}/getcompiler.c ${CAPI_SRC}/pyhash.c ${CAPI_SRC}/fileutils.c
99100
${CAPI_SRC}/modsupport.c ${CAPI_SRC}/context.c ${CAPI_SRC}/abstract.c ${CAPI_SRC}/frameobject.c
100-
${CAPI_SRC}/posixmodule.c ${CAPI_SRC}/longobject_shared.c ${CAPI_SRC}/exceptions.c ${CAPI_SRC}/pyctype.c
101-
${CAPI_SRC}/typeobject_shared.c ${CAPI_SRC}/mystrtoul.c ${CAPI_SRC}/weakrefobject.c
101+
${CAPI_SRC}/posixmodule.c ${CAPI_SRC}/exceptions.c ${CAPI_SRC}/pyctype.c
102+
${CAPI_SRC}/mystrtoul.c ${CAPI_SRC}/weakrefobject.c
102103
${CAPI_SRC}/modsupport_shared.c ${CAPI_SRC}/fileobject.c ${CAPI_SRC}/pystrcmp.c ${CAPI_SRC}/getversion.c
103104
${CAPI_SRC}/genobject.c ${CAPI_SRC}/methodobject.c ${CAPI_SRC}/boolobject.c ${CAPI_SRC}/pylifecycle.c
104-
${CAPI_SRC}/errors.c ${CAPI_SRC}/signals.c ${CAPI_SRC}/datetime.c ${CAPI_SRC}/bytearrayobject_shared.c
105+
${CAPI_SRC}/errors.c ${CAPI_SRC}/signals.c ${CAPI_SRC}/datetime.c
105106
)
106107

107108
file(GLOB_RECURSE ACTUAL_SRC_FILES
@@ -138,6 +139,7 @@ include_directories(
138139
${CAPI_SRC}
139140
"${SRC_DIR}/include"
140141
"${TRUFFLE_H_INC}"
142+
"${TRUFFLE_NFI_H_INC}"
141143
)
142144

143145
function(native_module name core src_files)
@@ -170,7 +172,6 @@ endfunction()
170172
######################################################################
171173

172174
add_library(${TARGET_LIBPYTHON} SHARED)
173-
simple_native_module("_mmap")
174175
simple_native_module("_cpython_sre")
175176
simple_native_module("_cpython_unicodedata")
176177
simple_native_module("_cpython_struct")
@@ -228,6 +229,9 @@ target_compile_options(${TARGET_LIBPYTHON} PRIVATE ${CFLAGS_WARNINGS})
228229
if(WIN32)
229230
target_link_directories(${TARGET_LIBPYTHON} PRIVATE ${GRAALVM_LLVM_LIB_DIR})
230231
target_link_libraries(${TARGET_LIBPYTHON} sulong-native graalvm-llvm)
232+
else()
233+
# Link to math library; required for functions like 'hypot' or similar
234+
target_link_libraries(${TARGET_LIBPYTHON} m)
231235
endif()
232236

233237
install(TARGETS ${TARGET_LIBPYTHON} DESTINATION bin)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#include "pyframe.h"
112112
#include "traceback.h"
113113
#include "sliceobject.h"
114+
#include "cellobject.h"
114115
#include "iterobject.h"
115116
#include "cpython/initconfig.h"
116117
#include "genobject.h"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* Copyright (c) 2018, 2023, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2020 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
/* Cell object interface */
7+
#ifndef Py_LIMITED_API
8+
#ifndef Py_CELLOBJECT_H
9+
#define Py_CELLOBJECT_H
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
typedef struct {
15+
PyObject_HEAD
16+
PyObject *ob_ref; /* Content of the cell or NULL when empty */
17+
} PyCellObject;
18+
19+
PyAPI_DATA(PyTypeObject) PyCell_Type;
20+
21+
#define PyCell_Check(op) Py_IS_TYPE(op, &PyCell_Type)
22+
23+
PyAPI_FUNC(PyObject *) PyCell_New(PyObject *);
24+
PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);
25+
PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);
26+
27+
#define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref)
28+
#define PyCell_SET(op, v) ((void)(((PyCellObject *)(op))->ob_ref = v))
29+
30+
#ifdef __cplusplus
31+
}
32+
#endif
33+
#endif /* !Py_TUPLEOBJECT_H */
34+
#endif /* Py_LIMITED_API */
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* Copyright (c) 2023, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2022 Python Software Foundation
3+
*
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
5+
*/
6+
#ifndef Py_INTERNAL_PYERRORS_H
7+
#define Py_INTERNAL_PYERRORS_H
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#ifndef Py_BUILD_CORE
13+
# error "this header requires Py_BUILD_CORE define"
14+
#endif
15+
16+
PyAPI_FUNC(PyObject*) _PyErr_Occurred(PyThreadState *tstate);
17+
18+
PyAPI_FUNC(void) _PyErr_ClearExcState(_PyErr_StackItem *exc_state);
19+
20+
PyAPI_FUNC(void) _PyErr_Fetch(
21+
PyThreadState *tstate,
22+
PyObject **type,
23+
PyObject **value,
24+
PyObject **traceback);
25+
26+
PyAPI_FUNC(int) _PyErr_ExceptionMatches(
27+
PyThreadState *tstate,
28+
PyObject *exc);
29+
30+
PyAPI_FUNC(void) _PyErr_Restore(
31+
PyThreadState *tstate,
32+
PyObject *type,
33+
PyObject *value,
34+
PyObject *traceback);
35+
36+
PyAPI_FUNC(void) _PyErr_SetObject(
37+
PyThreadState *tstate,
38+
PyObject *type,
39+
PyObject *value);
40+
41+
PyAPI_FUNC(void) _PyErr_ChainStackItem(
42+
_PyErr_StackItem *exc_info);
43+
44+
PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate);
45+
46+
PyAPI_FUNC(void) _PyErr_SetNone(PyThreadState *tstate, PyObject *exception);
47+
48+
PyAPI_FUNC(PyObject *) _PyErr_NoMemory(PyThreadState *tstate);
49+
50+
PyAPI_FUNC(void) _PyErr_SetString(
51+
PyThreadState *tstate,
52+
PyObject *exception,
53+
const char *string);
54+
55+
PyAPI_FUNC(PyObject *) _PyErr_Format(
56+
PyThreadState *tstate,
57+
PyObject *exception,
58+
const char *format,
59+
...);
60+
61+
PyAPI_FUNC(void) _PyErr_NormalizeException(
62+
PyThreadState *tstate,
63+
PyObject **exc,
64+
PyObject **val,
65+
PyObject **tb);
66+
67+
PyAPI_FUNC(PyObject *) _PyErr_FormatFromCauseTstate(
68+
PyThreadState *tstate,
69+
PyObject *exception,
70+
const char *format,
71+
...);
72+
73+
PyAPI_FUNC(int) _PyErr_CheckSignalsTstate(PyThreadState *tstate);
74+
75+
PyAPI_FUNC(void) _Py_DumpExtensionModules(int fd, PyInterpreterState *interp);
76+
77+
extern PyObject* _Py_Offer_Suggestions(PyObject* exception);
78+
PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b,
79+
Py_ssize_t max_cost);
80+
81+
#ifdef __cplusplus
82+
}
83+
#endif
84+
#endif /* !Py_INTERNAL_PYERRORS_H */

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

Lines changed: 1 addition & 1 deletion
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, "pythonjni.lib")
58+
# pragma comment(lib, "python-native.lib")
5959
# endif
6060
#endif
6161

graalpython/com.oracle.graal.python.cext/modules/_mmap.c

Lines changed: 0 additions & 101 deletions
This file was deleted.

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ int PyErr_WarnExplicitFormat(PyObject *category,
176176
return ret;
177177
}
178178

179-
void _PyErr_ChainExceptions(PyObject* a, PyObject* b, PyObject* c) {
180-
// empty dummy implementation
181-
}
182-
183179
PyObject* _PyErr_FormatFromCause(PyObject *exception, const char *format, ...) {
184180
// dummy implementation that ignores the cause
185181
va_list args;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ PyObject * PySequence_Fast(PyObject *v, const char *m) {
295295
}
296296

297297
PyObject * PyMapping_GetItemString(PyObject *o, const char *key) {
298-
return GraalPyTruffleObject_GetItemString(o, truffleString(key));
298+
return GraalPyTruffleObject_GetItemString(o, key);
299299
}
300300

301301
// downcall for native python objects
@@ -332,7 +332,7 @@ int PyObject_CheckBuffer(PyObject *obj) {
332332

333333
// taken from CPython "Objects/abstract.c"
334334
int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
335-
PyBufferProcs *pb = PyTypeObject_tp_as_buffer(Py_TYPE(obj));
335+
PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer;
336336

337337
if (pb == NULL || pb->bf_getbuffer == NULL) {
338338
PyErr_Format(PyExc_TypeError,
@@ -499,7 +499,7 @@ PyObject ** _PySequence_Fast_ITEMS(PyObject *o) {
499499
}
500500

501501
PyObject* _PySequence_ITEM(PyObject* obj, Py_ssize_t index) {
502-
PySequenceMethods* methods = PyTypeObject_tp_as_sequence(Py_TYPE(obj));
503-
return PySequenceMethods_sq_item(methods)(obj, index);
502+
PySequenceMethods* methods = Py_TYPE(obj)->tp_as_sequence;
503+
return methods->sq_item(obj, index);
504504
}
505505

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,11 @@ int bytearray_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags) {
6565
void bytearray_releasebuffer(PyByteArrayObject *obj, Py_buffer *view) {
6666
set_PyByteArrayObject_ob_exports(obj, PyByteArrayObject_ob_exports(obj) - 1);
6767
}
68+
69+
char* PyByteArray_AsString(PyObject* obj) {
70+
return PyByteArray_AS_STRING(obj);
71+
}
72+
73+
Py_ssize_t PyByteArray_Size(PyObject *self) {
74+
return PyByteArray_GET_SIZE(self);
75+
}

0 commit comments

Comments
 (0)