mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 23:30:30 +00:00
Add source_file_line_basename()
This commit is contained in:
parent
0feb0be8c2
commit
47c4e7939e
@ -65,30 +65,40 @@ inline const char *cpp_version_in_use() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const char *source_file_line_basename(const char *sfl) {
|
||||||
|
unsigned i_sep = 0;
|
||||||
|
for (unsigned i = 0; sfl[i]; i++) {
|
||||||
|
if (sfl[i] == '/' || sfl[i] == '\\') {
|
||||||
|
i_sep = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sfl + i_sep;
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template <typename IntrinsicType>
|
template <typename IntrinsicType>
|
||||||
bool odr_guard_impl(const std::type_index &it_ti, const char *tc_id) {
|
bool odr_guard_impl(const std::type_index &it_ti, const char *source_file_line) {
|
||||||
// std::cout cannot be used here: static initialization could be incomplete.
|
// std::cout cannot be used here: static initialization could be incomplete.
|
||||||
#define PYBIND11_DETAIL_ODR_GUARD_IMPL_PRINTF_OFF
|
#define PYBIND11_DETAIL_ODR_GUARD_IMPL_PRINTF_OFF
|
||||||
#ifdef PYBIND11_DETAIL_ODR_GUARD_IMPL_PRINTF_ON
|
#ifdef PYBIND11_DETAIL_ODR_GUARD_IMPL_PRINTF_ON
|
||||||
fprintf(stdout, "\nODR_GUARD_IMPL %s %s\n", type_id<IntrinsicType>().c_str(), tc_id);
|
fprintf(
|
||||||
|
stdout, "\nODR_GUARD_IMPL %s %s\n", type_id<IntrinsicType>().c_str(), source_file_line);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
std::string tc_id_str{tc_id};
|
std::string sflbn_str{source_file_line_basename(source_file_line)};
|
||||||
if (tc_id_str.size() > 2 && tc_id_str[0] == '.'
|
auto ins = odr_guard_registry().insert({it_ti, source_file_line});
|
||||||
&& (tc_id_str[1] == '/' || tc_id_str[1] == '\\')) {
|
|
||||||
tc_id_str = tc_id_str.substr(2);
|
|
||||||
}
|
|
||||||
auto ins = odr_guard_registry().insert({it_ti, tc_id_str});
|
|
||||||
auto reg_iter = ins.first;
|
auto reg_iter = ins.first;
|
||||||
auto added = ins.second;
|
auto added = ins.second;
|
||||||
if (!added && reg_iter->second != tc_id_str) {
|
if (!added
|
||||||
|
&& strcmp(source_file_line_basename(reg_iter->second.c_str()),
|
||||||
|
source_file_line_basename(source_file_line))
|
||||||
|
!= 0) {
|
||||||
std::system_error err(std::make_error_code(std::errc::state_not_recoverable),
|
std::system_error err(std::make_error_code(std::errc::state_not_recoverable),
|
||||||
"ODR VIOLATION DETECTED (" + std::string(cpp_version_in_use())
|
"ODR VIOLATION DETECTED (" + std::string(cpp_version_in_use())
|
||||||
+ "): pybind11::detail::type_caster<" + type_id<IntrinsicType>()
|
+ "): pybind11::detail::type_caster<" + type_id<IntrinsicType>()
|
||||||
+ ">: SourceLocation1=\"" + reg_iter->second
|
+ ">: SourceLocation1=\"" + reg_iter->second
|
||||||
+ "\", SourceLocation2=\"" + tc_id_str + "\"");
|
+ "\", SourceLocation2=\"" + source_file_line + "\"");
|
||||||
#define PYBIND11_TYPE_CASTER_ODR_GUARD_THROW_OFF
|
#define PYBIND11_TYPE_CASTER_ODR_GUARD_THROW_OFF
|
||||||
#ifdef PYBIND11_TYPE_CASTER_ODR_GUARD_THROW_ON
|
#ifdef PYBIND11_TYPE_CASTER_ODR_GUARD_THROW_ON
|
||||||
throw err;
|
throw err;
|
||||||
|
Loading…
Reference in New Issue
Block a user