|
| 1 | +diff --git a/pybind11/include/pybind11/cast.h b/pybind11/include/pybind11/cast.h |
| 2 | +index 6f0a75a..173a3d9 100644 |
| 3 | +--- a/pybind11/include/pybind11/cast.h |
| 4 | ++++ b/pybind11/include/pybind11/cast.h |
| 5 | +@@ -132,7 +132,7 @@ public: |
| 6 | + return false; |
| 7 | + } |
| 8 | + |
| 9 | +-#if !defined(PYPY_VERSION) |
| 10 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 11 | + auto index_check = [](PyObject *o) { return PyIndex_Check(o); }; |
| 12 | + #else |
| 13 | + // In PyPy 7.3.3, `PyIndex_Check` is implemented by calling `__index__`, |
| 14 | +@@ -328,7 +328,7 @@ public: |
| 15 | + if (src.is_none()) { |
| 16 | + res = 0; // None is implicitly converted to False |
| 17 | + } |
| 18 | +-#if defined(PYPY_VERSION) |
| 19 | ++#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON) |
| 20 | + // On PyPy, check that "__bool__" attr exists |
| 21 | + else if (hasattr(src, PYBIND11_BOOL_ATTR)) { |
| 22 | + res = PyObject_IsTrue(src.ptr()); |
| 23 | +@@ -445,7 +445,7 @@ struct string_caster { |
| 24 | + |
| 25 | + private: |
| 26 | + static handle decode_utfN(const char *buffer, ssize_t nbytes) { |
| 27 | +-#if !defined(PYPY_VERSION) |
| 28 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 29 | + return UTF_N == 8 ? PyUnicode_DecodeUTF8(buffer, nbytes, nullptr) |
| 30 | + : UTF_N == 16 ? PyUnicode_DecodeUTF16(buffer, nbytes, nullptr, nullptr) |
| 31 | + : PyUnicode_DecodeUTF32(buffer, nbytes, nullptr, nullptr); |
| 32 | +diff --git a/pybind11/include/pybind11/detail/class.h b/pybind11/include/pybind11/detail/class.h |
| 33 | +index 528e716..352f686 100644 |
| 34 | +--- a/pybind11/include/pybind11/detail/class.h |
| 35 | ++++ b/pybind11/include/pybind11/detail/class.h |
| 36 | +@@ -26,7 +26,7 @@ PYBIND11_NAMESPACE_BEGIN(detail) |
| 37 | + #endif |
| 38 | + |
| 39 | + inline std::string get_fully_qualified_tp_name(PyTypeObject *type) { |
| 40 | +-#if !defined(PYPY_VERSION) |
| 41 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 42 | + return type->tp_name; |
| 43 | + #else |
| 44 | + auto module_name = handle((PyObject *) type).attr("__module__").cast<std::string>(); |
| 45 | +@@ -42,7 +42,7 @@ inline PyTypeObject *type_incref(PyTypeObject *type) { |
| 46 | + return type; |
| 47 | + } |
| 48 | + |
| 49 | +-#if !defined(PYPY_VERSION) |
| 50 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 51 | + |
| 52 | + /// `pybind11_static_property.__get__()`: Always pass the class instead of the instance. |
| 53 | + extern "C" inline PyObject *pybind11_static_get(PyObject *self, PyObject * /*ob*/, PyObject *cls) { |
| 54 | +@@ -149,7 +149,7 @@ extern "C" inline int pybind11_meta_setattro(PyObject *obj, PyObject *name, PyOb |
| 55 | + && (PyObject_IsInstance(value, static_prop) == 0); |
| 56 | + if (call_descr_set) { |
| 57 | + // Call `static_property.__set__()` instead of replacing the `static_property`. |
| 58 | +-#if !defined(PYPY_VERSION) |
| 59 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 60 | + return Py_TYPE(descr)->tp_descr_set(descr, obj, value); |
| 61 | + #else |
| 62 | + if (PyObject *result = PyObject_CallMethod(descr, "__set__", "OO", obj, value)) { |
| 63 | +@@ -347,7 +347,7 @@ inline bool deregister_instance(instance *self, void *valptr, const type_info *t |
| 64 | + /// for holding C++ objects and holders. Allocation is done lazily (the first time the instance is |
| 65 | + /// cast to a reference or pointer), and initialization is done by an `__init__` function. |
| 66 | + inline PyObject *make_new_instance(PyTypeObject *type) { |
| 67 | +-#if defined(PYPY_VERSION) |
| 68 | ++#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON) |
| 69 | + // PyPy gets tp_basicsize wrong (issue 2482) under multiple inheritance when the first |
| 70 | + // inherited object is a plain Python type (i.e. not derived from an extension type). Fix it. |
| 71 | + ssize_t instance_size = static_cast<ssize_t>(sizeof(instance)); |
| 72 | +@@ -638,7 +638,7 @@ inline PyObject *make_new_python_type(const type_record &rec) { |
| 73 | + } |
| 74 | + |
| 75 | + const auto *full_name = c_str( |
| 76 | +-#if !defined(PYPY_VERSION) |
| 77 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 78 | + module_ ? str(module_).cast<std::string>() + "." + rec.name : |
| 79 | + #endif |
| 80 | + rec.name); |
| 81 | +diff --git a/pybind11/include/pybind11/detail/common.h b/pybind11/include/pybind11/detail/common.h |
| 82 | +index f34fd27..f1681b7 100644 |
| 83 | +--- a/pybind11/include/pybind11/detail/common.h |
| 84 | ++++ b/pybind11/include/pybind11/detail/common.h |
| 85 | +@@ -233,6 +233,9 @@ |
| 86 | + #if defined(PYPY_VERSION) && !defined(PYBIND11_SIMPLE_GIL_MANAGEMENT) |
| 87 | + # define PYBIND11_SIMPLE_GIL_MANAGEMENT |
| 88 | + #endif |
| 89 | ++#ifdef GRAALVM_PYTHON |
| 90 | ++# define PYBIND11_SIMPLE_GIL_MANAGEMENT |
| 91 | ++#endif |
| 92 | + |
| 93 | + #if defined(_MSC_VER) |
| 94 | + # if defined(PYBIND11_DEBUG_MARKER) |
| 95 | +diff --git a/pybind11/include/pybind11/detail/internals.h b/pybind11/include/pybind11/detail/internals.h |
| 96 | +index 7de7794..146b084 100644 |
| 97 | +--- a/pybind11/include/pybind11/detail/internals.h |
| 98 | ++++ b/pybind11/include/pybind11/detail/internals.h |
| 99 | +@@ -174,7 +174,7 @@ struct internals { |
| 100 | + PyTypeObject *static_property_type; |
| 101 | + PyTypeObject *default_metaclass; |
| 102 | + PyObject *instance_base; |
| 103 | +-#if defined(WITH_THREAD) |
| 104 | ++#if defined(WITH_THREAD) && !defined(GRAALVM_PYTHON) |
| 105 | + // Unused if PYBIND11_SIMPLE_GIL_MANAGEMENT is defined: |
| 106 | + PYBIND11_TLS_KEY_INIT(tstate) |
| 107 | + # if PYBIND11_INTERNALS_VERSION > 4 |
| 108 | +@@ -278,7 +278,7 @@ struct type_info { |
| 109 | + #endif |
| 110 | + |
| 111 | + #ifndef PYBIND11_INTERNALS_KIND |
| 112 | +-# if defined(WITH_THREAD) |
| 113 | ++# if defined(WITH_THREAD) && !defined(GRAALVM_PYTHON) |
| 114 | + # define PYBIND11_INTERNALS_KIND "" |
| 115 | + # else |
| 116 | + # define PYBIND11_INTERNALS_KIND "_without_thread" |
| 117 | +@@ -454,7 +454,7 @@ PYBIND11_NOINLINE internals &get_internals() { |
| 118 | + } |
| 119 | + auto *&internals_ptr = *internals_pp; |
| 120 | + internals_ptr = new internals(); |
| 121 | +-#if defined(WITH_THREAD) |
| 122 | ++#if defined(WITH_THREAD) && !defined(GRAALVM_PYTHON) |
| 123 | + |
| 124 | + # if PY_VERSION_HEX < 0x03090000 |
| 125 | + PyEval_InitThreads(); |
| 126 | +@@ -491,7 +491,7 @@ PYBIND11_NOINLINE internals &get_internals() { |
| 127 | + struct local_internals { |
| 128 | + type_map<type_info *> registered_types_cpp; |
| 129 | + std::forward_list<ExceptionTranslator> registered_exception_translators; |
| 130 | +-#if defined(WITH_THREAD) && PYBIND11_INTERNALS_VERSION == 4 |
| 131 | ++#if defined(WITH_THREAD) && !defined(GRAALVM_PYTHON) && PYBIND11_INTERNALS_VERSION == 4 |
| 132 | + |
| 133 | + // For ABI compatibility, we can't store the loader_life_support TLS key in |
| 134 | + // the `internals` struct directly. Instead, we store it in `shared_data` and |
| 135 | +diff --git a/pybind11/include/pybind11/detail/type_caster_base.h b/pybind11/include/pybind11/detail/type_caster_base.h |
| 136 | +index 21f69c2..0b853f0 100644 |
| 137 | +--- a/pybind11/include/pybind11/detail/type_caster_base.h |
| 138 | ++++ b/pybind11/include/pybind11/detail/type_caster_base.h |
| 139 | +@@ -36,7 +36,7 @@ private: |
| 140 | + loader_life_support *parent = nullptr; |
| 141 | + std::unordered_set<PyObject *> keep_alive; |
| 142 | + |
| 143 | +-#if defined(WITH_THREAD) |
| 144 | ++#if defined(WITH_THREAD) && !defined(GRAALVM_PYTHON) |
| 145 | + // Store stack pointer in thread-local storage. |
| 146 | + static PYBIND11_TLS_KEY_REF get_stack_tls_key() { |
| 147 | + # if PYBIND11_INTERNALS_VERSION == 4 |
| 148 | +@@ -55,7 +55,7 @@ private: |
| 149 | + // Use single global variable for stack. |
| 150 | + static loader_life_support **get_stack_pp() { |
| 151 | + static loader_life_support *global_stack = nullptr; |
| 152 | +- return global_stack; |
| 153 | ++ return &global_stack; |
| 154 | + } |
| 155 | + static loader_life_support *get_stack_top() { return *get_stack_pp(); } |
| 156 | + static void set_stack_top(loader_life_support *value) { *get_stack_pp() = value; } |
| 157 | +@@ -484,7 +484,7 @@ PYBIND11_NOINLINE handle get_object_handle(const void *ptr, const detail::type_i |
| 158 | + } |
| 159 | + |
| 160 | + inline PyThreadState *get_thread_state_unchecked() { |
| 161 | +-#if defined(PYPY_VERSION) |
| 162 | ++#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON) |
| 163 | + return PyThreadState_GET(); |
| 164 | + #else |
| 165 | + return _PyThreadState_UncheckedGet(); |
| 166 | +diff --git a/pybind11/include/pybind11/eval.h b/pybind11/include/pybind11/eval.h |
| 167 | +index bd5f981..c25f036 100644 |
| 168 | +--- a/pybind11/include/pybind11/eval.h |
| 169 | ++++ b/pybind11/include/pybind11/eval.h |
| 170 | +@@ -94,7 +94,7 @@ void exec(const char (&s)[N], object global = globals(), object local = object() |
| 171 | + eval<eval_statements>(s, std::move(global), std::move(local)); |
| 172 | + } |
| 173 | + |
| 174 | +-#if defined(PYPY_VERSION) |
| 175 | ++#if defined(PYPY_VERSION) || defined(GRAALVM_PYTHON) |
| 176 | + template <eval_mode mode = eval_statements> |
| 177 | + object eval_file(str, object, object) { |
| 178 | + pybind11_fail("eval_file not supported in PyPy3. Use eval"); |
| 179 | +diff --git a/pybind11/include/pybind11/gil.h b/pybind11/include/pybind11/gil.h |
| 180 | +index cb0028d..6435226 100644 |
| 181 | +--- a/pybind11/include/pybind11/gil.h |
| 182 | ++++ b/pybind11/include/pybind11/gil.h |
| 183 | +@@ -173,8 +173,8 @@ public: |
| 184 | + if (disassoc) { |
| 185 | + // Python >= 3.7 can remove this, it's an int before 3.7 |
| 186 | + // NOLINTNEXTLINE(readability-qualified-auto) |
| 187 | +- auto key = detail::get_internals().tstate; |
| 188 | +- PYBIND11_TLS_REPLACE_VALUE(key, tstate); |
| 189 | ++ // auto key = detail::get_internals().tstate; |
| 190 | ++ // PYBIND11_TLS_REPLACE_VALUE(key, tstate); |
| 191 | + } |
| 192 | + } |
| 193 | + |
| 194 | +diff --git a/pybind11/include/pybind11/pybind11.h b/pybind11/include/pybind11/pybind11.h |
| 195 | +index 42d432a..2e12a93 100644 |
| 196 | +--- a/pybind11/include/pybind11/pybind11.h |
| 197 | ++++ b/pybind11/include/pybind11/pybind11.h |
| 198 | +@@ -537,7 +537,7 @@ protected: |
| 199 | + chain_start = rec; |
| 200 | + rec->next = chain; |
| 201 | + auto rec_capsule |
| 202 | +- = reinterpret_borrow<capsule>(((PyCFunctionObject *) m_ptr)->m_self); |
| 203 | ++ = reinterpret_borrow<capsule>(PyCFunction_GetSelf(m_ptr)); |
| 204 | + rec_capsule.set_pointer(unique_rec.release()); |
| 205 | + guarded_strdup.release(); |
| 206 | + } else { |
| 207 | +@@ -2657,7 +2657,7 @@ get_type_override(const void *this_ptr, const type_info *this_type, const char * |
| 208 | + |
| 209 | + /* Don't call dispatch code if invoked from overridden function. |
| 210 | + Unfortunately this doesn't work on PyPy. */ |
| 211 | +-#if !defined(PYPY_VERSION) |
| 212 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 213 | + # if PY_VERSION_HEX >= 0x03090000 |
| 214 | + PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get()); |
| 215 | + if (frame != nullptr) { |
| 216 | +diff --git a/pybind11/include/pybind11/pytypes.h b/pybind11/include/pybind11/pytypes.h |
| 217 | +index d21fc89..70cf72a 100644 |
| 218 | +--- a/pybind11/include/pybind11/pytypes.h |
| 219 | ++++ b/pybind11/include/pybind11/pytypes.h |
| 220 | +@@ -534,7 +534,7 @@ struct error_fetch_and_normalize { |
| 221 | + |
| 222 | + bool have_trace = false; |
| 223 | + if (m_trace) { |
| 224 | +-#if !defined(PYPY_VERSION) |
| 225 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 226 | + auto *tb = reinterpret_cast<PyTracebackObject *>(m_trace.ptr()); |
| 227 | + |
| 228 | + // Get the deepest trace possible. |
| 229 | +@@ -1208,7 +1208,7 @@ private: |
| 230 | + }; |
| 231 | + PYBIND11_NAMESPACE_END(iterator_policies) |
| 232 | + |
| 233 | +-#if !defined(PYPY_VERSION) |
| 234 | ++#if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 235 | + using tuple_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>; |
| 236 | + using list_iterator = generic_iterator<iterator_policies::sequence_fast_readonly>; |
| 237 | + #else |
| 238 | +diff --git a/pybind11/include/pybind11/stl/filesystem.h b/pybind11/include/pybind11/stl/filesystem.h |
| 239 | +index e26f421..a221955 100644 |
| 240 | +--- a/pybind11/include/pybind11/stl/filesystem.h |
| 241 | ++++ b/pybind11/include/pybind11/stl/filesystem.h |
| 242 | +@@ -40,7 +40,7 @@ struct path_caster { |
| 243 | + |
| 244 | + private: |
| 245 | + static PyObject *unicode_from_fs_native(const std::string &w) { |
| 246 | +-# if !defined(PYPY_VERSION) |
| 247 | ++# if !defined(PYPY_VERSION) && !defined(GRAALVM_PYTHON) |
| 248 | + return PyUnicode_DecodeFSDefaultAndSize(w.c_str(), ssize_t(w.size())); |
| 249 | + # else |
| 250 | + // PyPy mistakenly declares the first parameter as non-const. |
0 commit comments