Skip to content

Commit b25409f

Browse files
Windows compatibility, part 2.
1 parent 08ae485 commit b25409f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

include/pybind11/detail/non_limited_api.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ typedef void Py_buffer_;
5656

5757
using namespace detail;
5858

59-
#ifdef __clang__
60-
// warning: 'pybind11NLA_error_fetch_and_normalize_format_value_and_trace' has C-linkage specified, but returns user-defined type 'std::string' (aka 'basic_string<char>') which is incompatible with C [-Wreturn-type-c-linkage]
59+
#if defined(__clang__)
60+
// warning: 'X' has C-linkage specified, but returns user-defined type 'std::string' (aka 'basic_string<char>') which is incompatible with C [-Wreturn-type-c-linkage]
6161
#define PYBIND11_NONLIMITEDAPI_SILENCE_EXTERN_C_WARNING(...) _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wreturn-type-c-linkage\"") __VA_ARGS__ _Pragma("clang diagnostic pop")
62+
#elif defined(_MSC_VER)
63+
// 'X' has C-linkage specified, but returns UDT 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' which is incompatible with C
64+
#define PYBIND11_NONLIMITEDAPI_SILENCE_EXTERN_C_WARNING(...) _Pragma("warning(push)") _Pragma("warning(disable: 4190)") __VA_ARGS__ _Pragma("warning(pop)")
6265
#else
6366
#define PYBIND11_NONLIMITEDAPI_SILENCE_EXTERN_C_WARNING(...) __VA_ARGS__
6467
#endif
@@ -186,7 +189,7 @@ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
186189
HMODULE module_handle = NULL; \
187190
if (!GetModuleHandleExW( \
188191
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, \
189-
(LPCTSTR)MR::SystemPath::getLibraryPath, \
192+
(LPCTSTR)PYBIND11_CONCAT(PyInit_, module_), \
190193
&module_handle \
191194
)) \
192195
{ \
@@ -200,7 +203,7 @@ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
200203
throw std::runtime_error( "pybind11 non-limited-api: The self library path is too long." ); \
201204
\
202205
return std::filesystem::path(path).parent_path() PYBIND11_NONLIMITEDAPI_LIB_PATH_RELATIVE_TO_PARENT_LIB_WITH_SLASH; \
203-
}();
206+
}()
204207
#else
205208
#define PYBIND11_NONLIMITEDAPI_GET_SHARED_LIBRARY_DIR(module_) \
206209
[]{ \

source/non_limited_api/non_limited_api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static PyThreadState *get_thread_state_unchecked() {
384384

385385
static int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int flags) {
386386
// Look for a `get_buffer` implementation in this type's info or any bases (following MRO).
387-
type_info *tinfo = nullptr;
387+
detail::type_info *tinfo = nullptr;
388388
for (auto type : reinterpret_borrow<tuple>(Py_TYPE(obj)->tp_mro)) {
389389
tinfo = get_type_info((PyTypeObject *) type.ptr());
390390
if (tinfo && tinfo->get_buffer) {
@@ -1675,7 +1675,7 @@ self.m_base.attr(op) = cpp_function(
16751675
void pybind11::non_limited_api::pybind11NLA_get_type_override(function &ret, const void *this_ptr, const type_info *this_type, const char *name) {
16761676
handle self = get_object_handle(this_ptr, this_type);
16771677
if (!self) {
1678-
return function();
1678+
return;
16791679
}
16801680
handle type = type::handle_of(self);
16811681
auto key = std::make_pair(type.ptr(), name);

0 commit comments

Comments
 (0)