diff --git a/graalpython/com.oracle.graal.python.cext/include/Python.h b/graalpython/com.oracle.graal.python.cext/include/Python.h index a653aa8ea2..00e286ff9e 100644 --- a/graalpython/com.oracle.graal.python.cext/include/Python.h +++ b/graalpython/com.oracle.graal.python.cext/include/Python.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2022, 2024, Oracle and/or its affiliates. +/* Copyright (c) 2022, 2026, Oracle and/or its affiliates. * Copyright (C) 1996-2022 Python Software Foundation * * Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 @@ -100,6 +100,7 @@ struct timeval; #include "pythonrun.h" #include "pylifecycle.h" #include "ceval.h" +#include "intrcheck.h" #include "sysmodule.h" #include "osmodule.h" #include "import.h" diff --git a/graalpython/com.oracle.graal.python.cext/include/intrcheck.h b/graalpython/com.oracle.graal.python.cext/include/intrcheck.h new file mode 100644 index 0000000000..2c940799b2 --- /dev/null +++ b/graalpython/com.oracle.graal.python.cext/include/intrcheck.h @@ -0,0 +1,34 @@ +/* Copyright (c) 2026, Oracle and/or its affiliates. + * Copyright (C) 1996-2020 Python Software Foundation + * + * Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 + */ + +#ifndef Py_INTRCHECK_H +#define Py_INTRCHECK_H +#ifdef __cplusplus +extern "C" { +#endif + +PyAPI_FUNC(int) PyOS_InterruptOccurred(void); +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03070000 +PyAPI_FUNC(void) PyOS_BeforeFork(void); +PyAPI_FUNC(void) PyOS_AfterFork_Parent(void); +PyAPI_FUNC(void) PyOS_AfterFork_Child(void); +#endif +/* Deprecated, please use PyOS_AfterFork_Child() instead */ +Py_DEPRECATED(3.7) PyAPI_FUNC(void) PyOS_AfterFork(void); + +#ifndef Py_LIMITED_API +PyAPI_FUNC(int) _PyOS_IsMainThread(void); + +#ifdef MS_WINDOWS +/* windows.h is not included by Python.h so use void* instead of HANDLE */ +PyAPI_FUNC(void*) _PyOS_SigintEvent(void); +#endif +#endif /* !Py_LIMITED_API */ + +#ifdef __cplusplus +} +#endif +#endif /* !Py_INTRCHECK_H */ diff --git a/graalpython/com.oracle.graal.python.cext/src/pylifecycle.c b/graalpython/com.oracle.graal.python.cext/src/pylifecycle.c index 77e295c1fc..16f474b73d 100644 --- a/graalpython/com.oracle.graal.python.cext/src/pylifecycle.c +++ b/graalpython/com.oracle.graal.python.cext/src/pylifecycle.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -73,6 +73,36 @@ _Py_IsFinalizing(void) return graalpy_finalizing; } +static void +graalpy_fork_not_supported(void) +{ + PyErr_SetString(PyExc_SystemError, "fork is not supported by GraalPy"); +} + +void +PyOS_BeforeFork(void) +{ + graalpy_fork_not_supported(); +} + +void +PyOS_AfterFork_Parent(void) +{ + graalpy_fork_not_supported(); +} + +void +PyOS_AfterFork_Child(void) +{ + graalpy_fork_not_supported(); +} + +void +PyOS_AfterFork(void) +{ + PyOS_AfterFork_Child(); +} + void _Py_NO_RETURN _Py_FatalErrorFunc(const char *func, const char *msg) { const char *prefix1 = "", *prefix2 = ""; if (func) { diff --git a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java index b1442d8123..12a452f965 100644 --- a/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java +++ b/graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiFunction.java @@ -855,10 +855,10 @@ public final class CApiFunction { @CApiBuiltin(name = "PyODict_DelItem", ret = Int, args = {PyObject, PyObject}, call = NotImplemented) @CApiBuiltin(name = "PyODict_New", ret = PyObject, args = {}, call = NotImplemented) @CApiBuiltin(name = "PyODict_SetItem", ret = Int, args = {PyObject, PyObject, PyObject}, call = NotImplemented) - @CApiBuiltin(name = "PyOS_AfterFork", ret = Void, args = {}, call = NotImplemented) - @CApiBuiltin(name = "PyOS_AfterFork_Child", ret = Void, args = {}, call = NotImplemented) - @CApiBuiltin(name = "PyOS_AfterFork_Parent", ret = Void, args = {}, call = NotImplemented) - @CApiBuiltin(name = "PyOS_BeforeFork", ret = Void, args = {}, call = NotImplemented) + @CApiBuiltin(name = "PyOS_AfterFork", ret = Void, args = {}, call = CImpl) + @CApiBuiltin(name = "PyOS_AfterFork_Child", ret = Void, args = {}, call = CImpl) + @CApiBuiltin(name = "PyOS_AfterFork_Parent", ret = Void, args = {}, call = CImpl) + @CApiBuiltin(name = "PyOS_BeforeFork", ret = Void, args = {}, call = CImpl) @CApiBuiltin(name = "PyOS_InterruptOccurred", ret = Int, args = {}, call = NotImplemented) @CApiBuiltin(name = "PyOS_Readline", ret = CHAR_PTR, args = {FILE_PTR, FILE_PTR, ConstCharPtrAsTruffleString}, call = NotImplemented) @CApiBuiltin(name = "PyOS_getsig", ret = PY_OS_SIGHANDLER, args = {Int}, call = NotImplemented) diff --git a/mx.graalpython/copyrights/overrides b/mx.graalpython/copyrights/overrides index 24cdf56daf..89a9959ddd 100644 --- a/mx.graalpython/copyrights/overrides +++ b/mx.graalpython/copyrights/overrides @@ -182,6 +182,7 @@ graalpython/com.oracle.graal.python.cext/include/internal/pycore_typeobject.h,py graalpython/com.oracle.graal.python.cext/include/internal/pycore_ucnhash.h,python.copyright graalpython/com.oracle.graal.python.cext/include/internal/pycore_unicodeobject.h,python.copyright graalpython/com.oracle.graal.python.cext/include/internal/pycore_warnings.h,python.copyright +graalpython/com.oracle.graal.python.cext/include/intrcheck.h,python.copyright graalpython/com.oracle.graal.python.cext/include/iterobject.h,python.copyright graalpython/com.oracle.graal.python.cext/include/listobject.h,python.copyright graalpython/com.oracle.graal.python.cext/include/longobject.h,python.copyright