aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-09-29 14:56:34 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-09-29 15:07:41 +0300
commit879a377a0a58f7bf1b0c55ea8c0f525e33f35b53 (patch)
treee641b8333a1bfaba647b06775c352f4315f26ee5 /contrib/libs
parentd33d1897c75f511aed6d7a35b51fa4647cfd5fd4 (diff)
downloadydb-879a377a0a58f7bf1b0c55ea8c0f525e33f35b53.tar.gz
Intermediate changes
commit_hash:02eb31a2fa9b8a7459367d02598ccdfb6d69f271
Diffstat (limited to 'contrib/libs')
-rw-r--r--contrib/libs/pybind11/include/pybind11/detail/class.h17
-rw-r--r--contrib/libs/pybind11/include/pybind11/detail/common.h4
-rw-r--r--contrib/libs/pybind11/include/pybind11/detail/cpp_conduit.h77
-rw-r--r--contrib/libs/pybind11/include/pybind11/detail/exception_translation.h71
-rw-r--r--contrib/libs/pybind11/include/pybind11/detail/internals.h10
-rw-r--r--contrib/libs/pybind11/include/pybind11/detail/type_caster_base.h46
-rw-r--r--contrib/libs/pybind11/include/pybind11/pybind11.h62
-rw-r--r--contrib/libs/pybind11/include/pybind11/typing.h4
-rw-r--r--contrib/libs/pybind11/ya.make4
9 files changed, 229 insertions, 66 deletions
diff --git a/contrib/libs/pybind11/include/pybind11/detail/class.h b/contrib/libs/pybind11/include/pybind11/detail/class.h
index 790afe52ca..9559b97cba 100644
--- a/contrib/libs/pybind11/include/pybind11/detail/class.h
+++ b/contrib/libs/pybind11/include/pybind11/detail/class.h
@@ -12,6 +12,8 @@
#include <pybind11/attr.h>
#include <pybind11/options.h>
+#include "exception_translation.h"
+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
@@ -626,7 +628,22 @@ extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int fla
return -1;
}
std::memset(view, 0, sizeof(Py_buffer));
+#if PY_MAJOR_VERSION < 3
buffer_info *info = tinfo->get_buffer(obj, tinfo->get_buffer_data);
+#else
+ buffer_info *info = nullptr;
+ try {
+ info = tinfo->get_buffer(obj, tinfo->get_buffer_data);
+ } catch (...) {
+ try_translate_exceptions();
+ raise_from(PyExc_BufferError, "Error getting buffer");
+ return -1;
+ }
+ if (info == nullptr) {
+ pybind11_fail("FATAL UNEXPECTED SITUATION: tinfo->get_buffer() returned nullptr.");
+ }
+#endif
+
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE && info->readonly) {
delete info;
// view->obj = nullptr; // Was just memset to 0, so not necessary
diff --git a/contrib/libs/pybind11/include/pybind11/detail/common.h b/contrib/libs/pybind11/include/pybind11/detail/common.h
index 1f97eea91c..93eafe7828 100644
--- a/contrib/libs/pybind11/include/pybind11/detail/common.h
+++ b/contrib/libs/pybind11/include/pybind11/detail/common.h
@@ -11,11 +11,11 @@
#define PYBIND11_VERSION_MAJOR 2
#define PYBIND11_VERSION_MINOR 13
-#define PYBIND11_VERSION_PATCH 5
+#define PYBIND11_VERSION_PATCH 6
// Similar to Python's convention: https://docs.python.org/3/c-api/apiabiversion.html
// Additional convention: 0xD = dev
-#define PYBIND11_VERSION_HEX 0x020D0500
+#define PYBIND11_VERSION_HEX 0x020D0600
// Define some generic pybind11 helper macros for warning management.
//
diff --git a/contrib/libs/pybind11/include/pybind11/detail/cpp_conduit.h b/contrib/libs/pybind11/include/pybind11/detail/cpp_conduit.h
new file mode 100644
index 0000000000..b66c2d39c0
--- /dev/null
+++ b/contrib/libs/pybind11/include/pybind11/detail/cpp_conduit.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2024 The pybind Community.
+
+#pragma once
+
+#include <pybind11/pytypes.h>
+
+#include "common.h"
+#include "internals.h"
+
+#include <typeinfo>
+
+PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
+PYBIND11_NAMESPACE_BEGIN(detail)
+
+// Forward declaration needed here: Refactoring opportunity.
+extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, PyObject *);
+
+inline bool type_is_managed_by_our_internals(PyTypeObject *type_obj) {
+#if defined(PYPY_VERSION)
+ auto &internals = get_internals();
+ return bool(internals.registered_types_py.find(type_obj)
+ != internals.registered_types_py.end());
+#else
+ return bool(type_obj->tp_new == pybind11_object_new);
+#endif
+}
+
+inline bool is_instance_method_of_type(PyTypeObject *type_obj, PyObject *attr_name) {
+ PyObject *descr = _PyType_Lookup(type_obj, attr_name);
+ return bool((descr != nullptr) && PyInstanceMethod_Check(descr));
+}
+
+inline object try_get_cpp_conduit_method(PyObject *obj) {
+ if (PyType_Check(obj)) {
+ return object();
+ }
+ PyTypeObject *type_obj = Py_TYPE(obj);
+ str attr_name("_pybind11_conduit_v1_");
+ bool assumed_to_be_callable = false;
+ if (type_is_managed_by_our_internals(type_obj)) {
+ if (!is_instance_method_of_type(type_obj, attr_name.ptr())) {
+ return object();
+ }
+ assumed_to_be_callable = true;
+ }
+ PyObject *method = PyObject_GetAttr(obj, attr_name.ptr());
+ if (method == nullptr) {
+ PyErr_Clear();
+ return object();
+ }
+ if (!assumed_to_be_callable && PyCallable_Check(method) == 0) {
+ Py_DECREF(method);
+ return object();
+ }
+ return reinterpret_steal<object>(method);
+}
+
+inline void *try_raw_pointer_ephemeral_from_cpp_conduit(handle src,
+ const std::type_info *cpp_type_info) {
+ object method = try_get_cpp_conduit_method(src.ptr());
+ if (method) {
+ capsule cpp_type_info_capsule(const_cast<void *>(static_cast<const void *>(cpp_type_info)),
+ typeid(std::type_info).name());
+ object cpp_conduit = method(bytes(PYBIND11_PLATFORM_ABI_ID),
+ cpp_type_info_capsule,
+ bytes("raw_pointer_ephemeral"));
+ if (isinstance<capsule>(cpp_conduit)) {
+ return reinterpret_borrow<capsule>(cpp_conduit).get_pointer();
+ }
+ }
+ return nullptr;
+}
+
+#define PYBIND11_HAS_CPP_CONDUIT 1
+
+PYBIND11_NAMESPACE_END(detail)
+PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
diff --git a/contrib/libs/pybind11/include/pybind11/detail/exception_translation.h b/contrib/libs/pybind11/include/pybind11/detail/exception_translation.h
new file mode 100644
index 0000000000..2764180bb0
--- /dev/null
+++ b/contrib/libs/pybind11/include/pybind11/detail/exception_translation.h
@@ -0,0 +1,71 @@
+/*
+ pybind11/detail/exception_translation.h: means to translate C++ exceptions to Python exceptions
+
+ Copyright (c) 2024 The Pybind Development Team.
+
+ All rights reserved. Use of this source code is governed by a
+ BSD-style license that can be found in the LICENSE file.
+*/
+
+#pragma once
+
+#include "common.h"
+#include "internals.h"
+
+PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
+PYBIND11_NAMESPACE_BEGIN(detail)
+
+// Apply all the extensions translators from a list
+// Return true if one of the translators completed without raising an exception
+// itself. Return of false indicates that if there are other translators
+// available, they should be tried.
+inline bool apply_exception_translators(std::forward_list<ExceptionTranslator> &translators) {
+ auto last_exception = std::current_exception();
+
+ for (auto &translator : translators) {
+ try {
+ translator(last_exception);
+ return true;
+ } catch (...) {
+ last_exception = std::current_exception();
+ }
+ }
+ return false;
+}
+
+inline void try_translate_exceptions() {
+ /* When an exception is caught, give each registered exception
+ translator a chance to translate it to a Python exception. First
+ all module-local translators will be tried in reverse order of
+ registration. If none of the module-locale translators handle
+ the exception (or there are no module-locale translators) then
+ the global translators will be tried, also in reverse order of
+ registration.
+
+ A translator may choose to do one of the following:
+
+ - catch the exception and call py::set_error()
+ to set a standard (or custom) Python exception, or
+ - do nothing and let the exception fall through to the next translator, or
+ - delegate translation to the next translator by throwing a new type of exception.
+ */
+
+ bool handled = with_internals([&](internals &internals) {
+ auto &local_exception_translators = get_local_internals().registered_exception_translators;
+ if (detail::apply_exception_translators(local_exception_translators)) {
+ return true;
+ }
+ auto &exception_translators = internals.registered_exception_translators;
+ if (detail::apply_exception_translators(exception_translators)) {
+ return true;
+ }
+ return false;
+ });
+
+ if (!handled) {
+ set_error(PyExc_SystemError, "Exception escaped from default exception translator!");
+ }
+}
+
+PYBIND11_NAMESPACE_END(detail)
+PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
diff --git a/contrib/libs/pybind11/include/pybind11/detail/internals.h b/contrib/libs/pybind11/include/pybind11/detail/internals.h
index 7d846e40e4..85002f708b 100644
--- a/contrib/libs/pybind11/include/pybind11/detail/internals.h
+++ b/contrib/libs/pybind11/include/pybind11/detail/internals.h
@@ -341,15 +341,17 @@ struct type_info {
# define PYBIND11_INTERNALS_KIND ""
#endif
+#define PYBIND11_PLATFORM_ABI_ID \
+ PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB PYBIND11_BUILD_ABI \
+ PYBIND11_BUILD_TYPE
+
#define PYBIND11_INTERNALS_ID \
"__pybind11_internals_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
- PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \
- PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
+ PYBIND11_PLATFORM_ABI_ID "__"
#define PYBIND11_MODULE_LOCAL_ID \
"__pybind11_module_local_v" PYBIND11_TOSTRING(PYBIND11_INTERNALS_VERSION) \
- PYBIND11_INTERNALS_KIND PYBIND11_COMPILER_TYPE PYBIND11_STDLIB \
- PYBIND11_BUILD_ABI PYBIND11_BUILD_TYPE "__"
+ PYBIND11_PLATFORM_ABI_ID "__"
/// Each module locally stores a pointer to the `internals` data. The data
/// itself is shared among modules with the same `PYBIND11_INTERNALS_ID`.
diff --git a/contrib/libs/pybind11/include/pybind11/detail/type_caster_base.h b/contrib/libs/pybind11/include/pybind11/detail/type_caster_base.h
index 188d6458b3..d228e8f46a 100644
--- a/contrib/libs/pybind11/include/pybind11/detail/type_caster_base.h
+++ b/contrib/libs/pybind11/include/pybind11/detail/type_caster_base.h
@@ -12,14 +12,19 @@
#include <pybind11/pytypes.h>
#include "common.h"
+#if PY_MAJOR_VERSION >= 3
+#include "cpp_conduit.h"
+#endif
#include "descr.h"
#include "internals.h"
#include "typeid.h"
#include "value_and_holder.h"
#include <cstdint>
+#include <cstring>
#include <iterator>
#include <new>
+#include <stdexcept>
#include <string>
#include <type_traits>
#include <typeindex>
@@ -621,6 +626,15 @@ public:
}
return false;
}
+#if PY_MAJOR_VERSION >= 3
+ bool try_cpp_conduit(handle src) {
+ value = try_raw_pointer_ephemeral_from_cpp_conduit(src, cpptype);
+ if (value != nullptr) {
+ return true;
+ }
+ return false;
+ }
+#endif
void check_holder_compat() {}
PYBIND11_NOINLINE static void *local_load(PyObject *src, const type_info *ti) {
@@ -752,6 +766,12 @@ public:
return true;
}
+#if PY_MAJOR_VERSION >= 3
+ if (convert && cpptype && this_.try_cpp_conduit(src)) {
+ return true;
+ }
+#endif
+
return false;
}
@@ -779,6 +799,32 @@ public:
void *value = nullptr;
};
+inline object cpp_conduit_method(handle self,
+ const bytes &pybind11_platform_abi_id,
+ const capsule &cpp_type_info_capsule,
+ const bytes &pointer_kind) {
+#ifdef PYBIND11_HAS_STRING_VIEW
+ using cpp_str = std::string_view;
+#else
+ using cpp_str = std::string;
+#endif
+ if (cpp_str(pybind11_platform_abi_id) != PYBIND11_PLATFORM_ABI_ID) {
+ return none();
+ }
+ if (std::strcmp(cpp_type_info_capsule.name(), typeid(std::type_info).name()) != 0) {
+ return none();
+ }
+ if (cpp_str(pointer_kind) != "raw_pointer_ephemeral") {
+ throw std::runtime_error("Invalid pointer_kind: \"" + std::string(pointer_kind) + "\"");
+ }
+ const auto *cpp_type_info = cpp_type_info_capsule.get_pointer<const std::type_info>();
+ type_caster_generic caster(*cpp_type_info);
+ if (!caster.load(self, false)) {
+ return none();
+ }
+ return capsule(caster.value, cpp_type_info->name());
+}
+
/**
* Determine suitable casting operator for pointer-or-lvalue-casting type casters. The type caster
* needs to provide `operator T*()` and `operator T&()` operators.
diff --git a/contrib/libs/pybind11/include/pybind11/pybind11.h b/contrib/libs/pybind11/include/pybind11/pybind11.h
index a1b8e478d1..0c6d61a258 100644
--- a/contrib/libs/pybind11/include/pybind11/pybind11.h
+++ b/contrib/libs/pybind11/include/pybind11/pybind11.h
@@ -9,8 +9,8 @@
*/
#pragma once
-
#include "detail/class.h"
+#include "detail/exception_translation.h"
#include "detail/init.h"
#include "attr.h"
#include "gil.h"
@@ -95,24 +95,6 @@ inline std::string replace_newlines_and_squash(const char *text) {
return result.substr(str_begin, str_range);
}
-// Apply all the extensions translators from a list
-// Return true if one of the translators completed without raising an exception
-// itself. Return of false indicates that if there are other translators
-// available, they should be tried.
-inline bool apply_exception_translators(std::forward_list<ExceptionTranslator> &translators) {
- auto last_exception = std::current_exception();
-
- for (auto &translator : translators) {
- try {
- translator(last_exception);
- return true;
- } catch (...) {
- last_exception = std::current_exception();
- }
- }
- return false;
-}
-
#if defined(_MSC_VER)
# define PYBIND11_COMPAT_STRDUP _strdup
#else
@@ -619,7 +601,8 @@ protected:
int index = 0;
/* Create a nice pydoc rec including all signatures and
docstrings of the functions in the overload chain */
- if (chain && options::show_function_signatures()) {
+ if (chain && options::show_function_signatures()
+ && std::strcmp(rec->name, "_pybind11_conduit_v1_") != 0) {
// First a generic signature
signatures += rec->name;
signatures += "(*args, **kwargs)\n";
@@ -628,7 +611,8 @@ protected:
// Then specific overload signatures
bool first_user_def = true;
for (auto *it = chain_start; it != nullptr; it = it->next) {
- if (options::show_function_signatures()) {
+ if (options::show_function_signatures()
+ && std::strcmp(rec->name, "_pybind11_conduit_v1_") != 0) {
if (index > 0) {
signatures += '\n';
}
@@ -1047,40 +1031,7 @@ protected:
throw;
#endif
} catch (...) {
- /* When an exception is caught, give each registered exception
- translator a chance to translate it to a Python exception. First
- all module-local translators will be tried in reverse order of
- registration. If none of the module-locale translators handle
- the exception (or there are no module-locale translators) then
- the global translators will be tried, also in reverse order of
- registration.
-
- A translator may choose to do one of the following:
-
- - catch the exception and call py::set_error()
- to set a standard (or custom) Python exception, or
- - do nothing and let the exception fall through to the next translator, or
- - delegate translation to the next translator by throwing a new type of exception.
- */
-
- bool handled = with_internals([&](internals &internals) {
- auto &local_exception_translators
- = get_local_internals().registered_exception_translators;
- if (detail::apply_exception_translators(local_exception_translators)) {
- return true;
- }
- auto &exception_translators = internals.registered_exception_translators;
- if (detail::apply_exception_translators(exception_translators)) {
- return true;
- }
- return false;
- });
-
- if (handled) {
- return nullptr;
- }
-
- set_error(PyExc_SystemError, "Exception escaped from default exception translator!");
+ try_translate_exceptions();
return nullptr;
}
@@ -1683,6 +1634,7 @@ public:
= instances[std::type_index(typeid(type))];
});
}
+ def("_pybind11_conduit_v1_", cpp_conduit_method);
}
template <typename Base, detail::enable_if_t<is_base<Base>::value, int> = 0>
diff --git a/contrib/libs/pybind11/include/pybind11/typing.h b/contrib/libs/pybind11/include/pybind11/typing.h
index b0feb9464a..84aaf9f702 100644
--- a/contrib/libs/pybind11/include/pybind11/typing.h
+++ b/contrib/libs/pybind11/include/pybind11/typing.h
@@ -100,9 +100,7 @@ class Never : public none {
using none::none;
};
-#if defined(__cpp_nontype_template_parameter_class) \
- && (/* See #5201 */ !defined(__GNUC__) \
- || (__GNUC__ > 10 || (__GNUC__ == 10 && __GNUC_MINOR__ >= 3)))
+#if defined(__cpp_nontype_template_args) && __cpp_nontype_template_args >= 201911L
# define PYBIND11_TYPING_H_HAS_STRING_LITERAL
template <size_t N>
struct StringLiteral {
diff --git a/contrib/libs/pybind11/ya.make b/contrib/libs/pybind11/ya.make
index 54b64a24c0..287765493d 100644
--- a/contrib/libs/pybind11/ya.make
+++ b/contrib/libs/pybind11/ya.make
@@ -6,9 +6,9 @@ LICENSE(BSD-3-Clause)
LICENSE_TEXTS(.yandex_meta/licenses.list.txt)
-VERSION(2.13.5)
+VERSION(2.13.6)
-ORIGINAL_SOURCE(https://github.com/pybind/pybind11/archive/v2.13.5.tar.gz)
+ORIGINAL_SOURCE(https://github.com/pybind/pybind11/archive/v2.13.6.tar.gz)
ADDINCL(
GLOBAL contrib/libs/pybind11/include