Skip to content

Commit b8c3814

Browse files
committed
[GR-76116] Remove Truffle NFI dependency and references.
PullRequest: graalpython/4647
2 parents 2497003 + 3249c75 commit b8c3814

103 files changed

Lines changed: 865 additions & 1307 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.

docs/contributor/IMPLEMENTATION_DETAILS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ When a managed object is passed to a native extension code:
276276
accessed any primitive elements are (like the previous step) boxed into a
277277
`PythonAbstractObject`.
278278

279-
* When NFI calls `toNative`/`asPointer`, we:
279+
* When a C API transition needs a native pointer for a managed object, we:
280280
* Allocate a native stub that will represent the object on the native side.
281281
We allocate room for the `refcount` and type pointer to avoid upcalls for
282282
reading those. For some types such as floats, we also store the

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ endif()
5050
require_var(GRAALPY_PARENT_DIR)
5151
require_var(CAPI_INC_DIR)
5252
require_var(PYCONFIG_INCLUDE_DIR)
53-
require_var(TRUFFLE_NFI_H_INC)
5453
require_var(GRAALPY_EXT)
5554

5655
if(NOT DEFINED SRC_DIR)
@@ -200,7 +199,6 @@ include_directories(
200199
"${SRC_DIR}/include"
201200
"${CAPI_INC_DIR}"
202201
"${PYCONFIG_INCLUDE_DIR}"
203-
"${TRUFFLE_NFI_H_INC}"
204202
)
205203

206204
function(native_module name core src_files)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "capi.h"
4242
#include <stdio.h>
4343
#include <time.h>
44-
#include <trufflenfi.h>
4544

4645
#include "pycore_gc.h" // _PyGC_InitState
4746

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#endif // GraalPy change
3030

3131
#include "capi.h"
32-
#include <trufflenfi.h>
3332

3433
static THREAD_LOCAL int graalpy_attached_thread = 0;
3534
static THREAD_LOCAL int graalpy_gilstate_counter = 0;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -128,7 +128,6 @@ def test_buffer(self):
128128
assert struct.Struct(buffer.format).size == int_format.size
129129
assert buffer.shape == (2, 2)
130130

131-
# TODO: GR-60735, we cannot support this without NFI struct by value support
132131
def ignore_test_custom_libs():
133132
# 16B: returned in registers on System V AMD64 ABI
134133
class MySmallStruct1(ctypes.Structure):

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -101,6 +101,22 @@ def test_member(self):
101101
return Py_None;
102102
}
103103
104+
PyObject* set_string_inplace(PyObject *self, PyObject *arg) {
105+
TestMemberObject *tmo = (TestMemberObject *)self;
106+
Py_ssize_t len;
107+
const char *utf8 = PyUnicode_AsUTF8AndSize(arg, &len);
108+
if (utf8 == NULL)
109+
return NULL;
110+
if (len >= (Py_ssize_t)sizeof(tmo->member_string_inplace)) {
111+
PyErr_SetString(PyExc_ValueError, "string too long");
112+
return NULL;
113+
}
114+
memcpy(tmo->member_string_inplace, utf8, len);
115+
tmo->member_string_inplace[len] = 0;
116+
Py_INCREF(Py_None);
117+
return Py_None;
118+
}
119+
104120
PyObject* get_min_values(PyObject *self) {
105121
PyObject *result = PyTuple_New(9);
106122
PyTuple_SetItem(result, 0, PyLong_FromSsize_t(CHAR_MIN));
@@ -138,6 +154,7 @@ def test_member(self):
138154
float member_float;
139155
double member_double;
140156
char *member_string;
157+
char member_string_inplace[8];
141158
char member_char;
142159
char member_byte;
143160
unsigned char member_ubyte;
@@ -159,6 +176,7 @@ def test_member(self):
159176
{"member_float", T_FLOAT, offsetof(TestMemberObject, member_float), 0, "float member"},
160177
{"member_double", T_DOUBLE, offsetof(TestMemberObject, member_double), 0, "double member"},
161178
{"member_string", T_STRING, offsetof(TestMemberObject, member_string), 0, "string member"},
179+
{"member_string_inplace", T_STRING_INPLACE, offsetof(TestMemberObject, member_string_inplace), 0, "string inplace member"},
162180
{"member_char", T_CHAR, offsetof(TestMemberObject, member_char), 0, "char member"},
163181
{"member_byte", T_BYTE, offsetof(TestMemberObject, member_byte), 0, "byte member"},
164182
{"member_ubyte", T_UBYTE, offsetof(TestMemberObject, member_ubyte), 0, "ubyte member"},
@@ -172,6 +190,7 @@ def test_member(self):
172190
""",
173191
tp_methods='''
174192
{"set_string", (PyCFunction)set_string, METH_O, ""},
193+
{"set_string_inplace", (PyCFunction)set_string_inplace, METH_O, ""},
175194
{"get_min_values", (PyCFunction)get_min_values, METH_NOARGS, ""},
176195
{"get_max_values", (PyCFunction)get_max_values, METH_NOARGS, ""}
177196
''',
@@ -277,6 +296,19 @@ def test_member(self):
277296
assert type(obj.member_string) is str
278297
assert obj.member_string == "hello"
279298

299+
# T_STRING_INPLACE
300+
assert type(obj.member_string_inplace) is str
301+
assert obj.member_string_inplace == ""
302+
assert_raises(TypeError, delattr, obj, "member_string_inplace")
303+
assert_raises(TypeError, setattr, obj, "member_string_inplace", "hello")
304+
obj.set_string_inplace("hello")
305+
assert type(obj.member_string_inplace) is str
306+
assert obj.member_string_inplace == "hello"
307+
obj.set_string_inplace("hi")
308+
assert obj.member_string_inplace == "hi"
309+
assert_raises(ValueError, obj.set_string_inplace, "too long")
310+
assert obj.member_string_inplace == "hi"
311+
280312
# T_CHAR
281313
assert type(obj.member_char) is str
282314
assert obj.member_char == "\x00", "was: %r" % obj.member_char

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -514,14 +514,6 @@ def test_host_lookup(self):
514514
else:
515515
assert False, "requesting a non-existing host symbol should raise KeyError"
516516

517-
def test_internal_languages_dont_eval(self):
518-
try:
519-
polyglot.eval(language="nfi", string="default")
520-
except ValueError as e:
521-
assert str(e) == "polyglot language 'nfi' not found"
522-
523-
assert polyglot.eval(language="python", string="21 * 2") == 42
524-
525517
def test_module_eval_returns_last_expr(self):
526518
assert polyglot.eval(language="python", string="x = 2; x") == 2
527519

graalpython/com.oracle.graal.python/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ SOFTWARE.
6767
<groupId>org.graalvm.truffle</groupId>
6868
<artifactId>truffle-api</artifactId>
6969
</dependency>
70-
<dependency>
71-
<groupId>org.graalvm.truffle</groupId>
72-
<artifactId>truffle-nfi</artifactId>
73-
</dependency>
7470
<dependency>
7571
<groupId>org.graalvm.tools</groupId>
7672
<artifactId>profiler-tool</artifactId>

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@
157157
version = PythonLanguage.VERSION, //
158158
characterMimeTypes = {PythonLanguage.MIME_TYPE}, //
159159
defaultMimeType = PythonLanguage.MIME_TYPE, //
160-
dependentLanguages = "nfi", //
161160
interactive = true, internal = false, //
162161
contextPolicy = TruffleLanguage.ContextPolicy.SHARED, //
163162
fileTypeDetectors = PythonFileDetector.class, //
@@ -371,7 +370,7 @@ public boolean isSingleContext() {
371370

372371
/**
373372
* A generic source cache for all kinds of {@link Source} objects. For example, this should be
374-
* used to cache the sources created from NFI signature strings to ensure code sharing.
373+
* used to cache synthetic sources to ensure code sharing.
375374
*/
376375
private final ConcurrentHashMap<Object, Source> sourceCache = new ConcurrentHashMap<>();
377376

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker;
5454
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
5555
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming;
56-
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode;
56+
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode;
5757
import com.oracle.graal.python.builtins.objects.mmap.PMMap;
5858
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5959
import com.oracle.graal.python.runtime.PosixConstants;
@@ -112,7 +112,7 @@ public void postInitialize(Python3Core core) {
112112
ExternalFunctionInvoker.invokeMMAP_INIT_BUFFERPROTOCOL(
113113
TIMING_MMAP_INIT_BUFFERPROTOCOL,
114114
CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_MMAP_INIT_BUFFERPROTOCOL),
115-
PythonToNativeNode.executeLongUncached(promoted));
115+
PythonToNativeInternalNode.executeUncached(promoted, false));
116116
});
117117
}
118118
}

0 commit comments

Comments
 (0)