Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/contributor/IMPLEMENTATION_DETAILS.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ When a managed object is passed to a native extension code:
accessed any primitive elements are (like the previous step) boxed into a
`PythonAbstractObject`.

* When NFI calls `toNative`/`asPointer`, we:
* When a C API transition needs a native pointer for a managed object, we:
* Allocate a native stub that will represent the object on the native side.
We allocate room for the `refcount` and type pointer to avoid upcalls for
reading those. For some types such as floats, we also store the
Expand Down
2 changes: 0 additions & 2 deletions graalpython/com.oracle.graal.python.cext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ endif()
require_var(GRAALPY_PARENT_DIR)
require_var(CAPI_INC_DIR)
require_var(PYCONFIG_INCLUDE_DIR)
require_var(TRUFFLE_NFI_H_INC)
require_var(GRAALPY_EXT)

if(NOT DEFINED SRC_DIR)
Expand Down Expand Up @@ -200,7 +199,6 @@ include_directories(
"${SRC_DIR}/include"
"${CAPI_INC_DIR}"
"${PYCONFIG_INCLUDE_DIR}"
"${TRUFFLE_NFI_H_INC}"
)

function(native_module name core src_files)
Expand Down
1 change: 0 additions & 1 deletion graalpython/com.oracle.graal.python.cext/src/capi.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "capi.h"
#include <stdio.h>
#include <time.h>
#include <trufflenfi.h>

#include "pycore_gc.h" // _PyGC_InitState

Expand Down
1 change: 0 additions & 1 deletion graalpython/com.oracle.graal.python.cext/src/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#endif // GraalPy change

#include "capi.h"
#include <trufflenfi.h>

static THREAD_LOCAL int graalpy_attached_thread = 0;
static THREAD_LOCAL int graalpy_gilstate_counter = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2024, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -128,7 +128,6 @@ def test_buffer(self):
assert struct.Struct(buffer.format).size == int_format.size
assert buffer.shape == (2, 2)

# TODO: GR-60735, we cannot support this without NFI struct by value support
def ignore_test_custom_libs():
# 16B: returned in registers on System V AMD64 ABI
class MySmallStruct1(ctypes.Structure):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -101,6 +101,22 @@ def test_member(self):
return Py_None;
}

PyObject* set_string_inplace(PyObject *self, PyObject *arg) {
TestMemberObject *tmo = (TestMemberObject *)self;
Py_ssize_t len;
const char *utf8 = PyUnicode_AsUTF8AndSize(arg, &len);
if (utf8 == NULL)
return NULL;
if (len >= (Py_ssize_t)sizeof(tmo->member_string_inplace)) {
PyErr_SetString(PyExc_ValueError, "string too long");
return NULL;
}
memcpy(tmo->member_string_inplace, utf8, len);
tmo->member_string_inplace[len] = 0;
Py_INCREF(Py_None);
return Py_None;
}

PyObject* get_min_values(PyObject *self) {
PyObject *result = PyTuple_New(9);
PyTuple_SetItem(result, 0, PyLong_FromSsize_t(CHAR_MIN));
Expand Down Expand Up @@ -138,6 +154,7 @@ def test_member(self):
float member_float;
double member_double;
char *member_string;
char member_string_inplace[8];
char member_char;
char member_byte;
unsigned char member_ubyte;
Expand All @@ -159,6 +176,7 @@ def test_member(self):
{"member_float", T_FLOAT, offsetof(TestMemberObject, member_float), 0, "float member"},
{"member_double", T_DOUBLE, offsetof(TestMemberObject, member_double), 0, "double member"},
{"member_string", T_STRING, offsetof(TestMemberObject, member_string), 0, "string member"},
{"member_string_inplace", T_STRING_INPLACE, offsetof(TestMemberObject, member_string_inplace), 0, "string inplace member"},
{"member_char", T_CHAR, offsetof(TestMemberObject, member_char), 0, "char member"},
{"member_byte", T_BYTE, offsetof(TestMemberObject, member_byte), 0, "byte member"},
{"member_ubyte", T_UBYTE, offsetof(TestMemberObject, member_ubyte), 0, "ubyte member"},
Expand All @@ -172,6 +190,7 @@ def test_member(self):
""",
tp_methods='''
{"set_string", (PyCFunction)set_string, METH_O, ""},
{"set_string_inplace", (PyCFunction)set_string_inplace, METH_O, ""},
{"get_min_values", (PyCFunction)get_min_values, METH_NOARGS, ""},
{"get_max_values", (PyCFunction)get_max_values, METH_NOARGS, ""}
''',
Expand Down Expand Up @@ -277,6 +296,19 @@ def test_member(self):
assert type(obj.member_string) is str
assert obj.member_string == "hello"

# T_STRING_INPLACE
assert type(obj.member_string_inplace) is str
assert obj.member_string_inplace == ""
assert_raises(TypeError, delattr, obj, "member_string_inplace")
assert_raises(TypeError, setattr, obj, "member_string_inplace", "hello")
obj.set_string_inplace("hello")
assert type(obj.member_string_inplace) is str
assert obj.member_string_inplace == "hello"
obj.set_string_inplace("hi")
assert obj.member_string_inplace == "hi"
assert_raises(ValueError, obj.set_string_inplace, "too long")
assert obj.member_string_inplace == "hi"

# T_CHAR
assert type(obj.member_char) is str
assert obj.member_char == "\x00", "was: %r" % obj.member_char
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,14 +514,6 @@ def test_host_lookup(self):
else:
assert False, "requesting a non-existing host symbol should raise KeyError"

def test_internal_languages_dont_eval(self):
try:
polyglot.eval(language="nfi", string="default")
except ValueError as e:
assert str(e) == "polyglot language 'nfi' not found"

assert polyglot.eval(language="python", string="21 * 2") == 42

def test_module_eval_returns_last_expr(self):
assert polyglot.eval(language="python", string="x = 2; x") == 2

Expand Down
4 changes: 0 additions & 4 deletions graalpython/com.oracle.graal.python/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ SOFTWARE.
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-nfi</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.tools</groupId>
<artifactId>profiler-tool</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
version = PythonLanguage.VERSION, //
characterMimeTypes = {PythonLanguage.MIME_TYPE}, //
defaultMimeType = PythonLanguage.MIME_TYPE, //
dependentLanguages = "nfi", //
interactive = true, internal = false, //
contextPolicy = TruffleLanguage.ContextPolicy.SHARED, //
fileTypeDetectors = PythonFileDetector.class, //
Expand Down Expand Up @@ -371,7 +370,7 @@ public boolean isSingleContext() {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import com.oracle.graal.python.builtins.objects.cext.capi.ExternalFunctionInvoker;
import com.oracle.graal.python.builtins.objects.cext.capi.NativeCAPISymbol;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTiming;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode;
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeInternalNode;
import com.oracle.graal.python.builtins.objects.mmap.PMMap;
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
import com.oracle.graal.python.runtime.PosixConstants;
Expand Down Expand Up @@ -112,7 +112,7 @@ public void postInitialize(Python3Core core) {
ExternalFunctionInvoker.invokeMMAP_INIT_BUFFERPROTOCOL(
TIMING_MMAP_INIT_BUFFERPROTOCOL,
CApiContext.getNativeSymbol(null, NativeCAPISymbol.FUN_MMAP_INIT_BUFFERPROTOCOL),
PythonToNativeNode.executeLongUncached(promoted));
PythonToNativeInternalNode.executeUncached(promoted, false));
});
}
}
Loading
Loading