Skip to content

Commit c7d1d03

Browse files
committed
Workaround build failure on MSVC
It seems that MSVC doesn't expand `__VA_ARGS__` in a macro call, so the introspection of `P11X_ENUM_TYPE` doesn't work. Instead, just pass the type we want manually.
1 parent 7fd09b7 commit c7d1d03

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/_enums.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
//
2121
// Place this in PYBIND11_MODULE to register the enums declared by P11X_DECLARE_ENUM.
2222

23-
// a1 includes the opening brace and a2 the closing brace.
24-
// This definition is compatible with older compiler versions compared to
25-
// #define P11X_ENUM_TYPE(...) decltype(std::map{std::pair __VA_ARGS__})::mapped_type
26-
#define P11X_ENUM_TYPE(a1, a2, ...) decltype(std::pair a1, a2)::second_type
27-
2823
#define P11X_CAT2(a, b) a##b
2924
#define P11X_CAT(a, b) P11X_CAT2(a, b)
3025

@@ -51,7 +46,7 @@ namespace p11x {
5146

5247
// Immediately converting the args to a vector outside of the lambda avoids
5348
// name collisions.
54-
#define P11X_DECLARE_ENUM(py_name, py_base_cls, ...) \
49+
#define P11X_DECLARE_ENUM(py_name, py_base_cls, cpp_type, ...) \
5550
namespace p11x { \
5651
namespace { \
5752
[[maybe_unused]] auto const P11X_CAT(enum_placeholder_, __COUNTER__) = \
@@ -68,10 +63,9 @@ namespace p11x {
6863
} \
6964
} \
7065
namespace pybind11::detail { \
71-
template<> struct type_caster<P11X_ENUM_TYPE(__VA_ARGS__)> { \
72-
using type = P11X_ENUM_TYPE(__VA_ARGS__); \
73-
static_assert(std::is_enum_v<type>, "Not an enum"); \
74-
PYBIND11_TYPE_CASTER(type, _(py_name)); \
66+
template<> struct type_caster<cpp_type> { \
67+
static_assert(std::is_enum_v<cpp_type>, "Not an enum"); \
68+
PYBIND11_TYPE_CASTER(cpp_type, _(py_name)); \
7569
bool load(handle src, bool) { \
7670
auto cls = p11x::enums.at(py_name); \
7771
PyObject* tmp = nullptr; \
@@ -87,7 +81,7 @@ namespace p11x {
8781
} \
8882
static handle cast(decltype(value) obj, return_value_policy, handle) { \
8983
auto cls = p11x::enums.at(py_name); \
90-
return cls(std::underlying_type_t<type>(obj)).inc_ref(); \
84+
return cls(std::underlying_type_t<cpp_type>(obj)).inc_ref(); \
9185
} \
9286
}; \
9387
}

src/ft2font_wrapper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const char *Kerning__doc__ = R"""(
2828
)""";
2929

3030
P11X_DECLARE_ENUM(
31-
"Kerning", "Enum",
31+
"Kerning", "Enum", FT_Kerning_Mode,
3232
{"DEFAULT", FT_KERNING_DEFAULT},
3333
{"UNFITTED", FT_KERNING_UNFITTED},
3434
{"UNSCALED", FT_KERNING_UNSCALED},
@@ -76,7 +76,7 @@ enum class FaceFlags : FT_Long {
7676
};
7777

7878
P11X_DECLARE_ENUM(
79-
"FaceFlags", "Flag",
79+
"FaceFlags", "Flag", FaceFlags,
8080
{"SCALABLE", FaceFlags::SCALABLE},
8181
{"FIXED_SIZES", FaceFlags::FIXED_SIZES},
8282
{"FIXED_WIDTH", FaceFlags::FIXED_WIDTH},
@@ -147,7 +147,7 @@ enum class LoadFlags : FT_Int32 {
147147
};
148148

149149
P11X_DECLARE_ENUM(
150-
"LoadFlags", "Flag",
150+
"LoadFlags", "Flag", LoadFlags,
151151
{"DEFAULT", LoadFlags::DEFAULT},
152152
{"NO_SCALE", LoadFlags::NO_SCALE},
153153
{"NO_HINTING", LoadFlags::NO_HINTING},
@@ -197,7 +197,7 @@ enum class StyleFlags : FT_Long {
197197
};
198198

199199
P11X_DECLARE_ENUM(
200-
"StyleFlags", "Flag",
200+
"StyleFlags", "Flag", StyleFlags,
201201
{"NORMAL", StyleFlags::NORMAL},
202202
{"ITALIC", StyleFlags::ITALIC},
203203
{"BOLD", StyleFlags::BOLD},

0 commit comments

Comments
 (0)