Skip to content

Commit 4e2e149

Browse files
committed
util, gen: undef Windows COM macros and rename interface identifier
<winsock2.h> transitively pulls in <windows.h> and <commdlg.h>, which #define INTERFACE, interface, and ERROR. These collide with capnp's Kind::INTERFACE enumerator, the gen.cpp parameter named 'interface', and KJ_LOG(ERROR, ...) in proxy.cpp. Undef the macros right after the winsock2.h include in util.h, and rename gen.cpp's 'interface' locals to 'schema' / 'node_interface'.
1 parent 67e5833 commit 4e2e149

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

include/mp/util.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@
2525

2626
#ifdef WIN32
2727
#include <winsock2.h>
28+
// <winsock2.h> transitively includes <windows.h>, which pulls in
29+
// <commdlg.h> and other COM headers that #define INTERFACE, interface
30+
// and ERROR. These collide with capnp's Kind::INTERFACE enumerator,
31+
// identifiers named `interface`, and KJ_LOG(ERROR, ...).
32+
#ifdef INTERFACE
33+
#undef INTERFACE
34+
#endif
35+
#ifdef interface
36+
#undef interface
37+
#endif
38+
#ifdef ERROR
39+
#undef ERROR
40+
#endif
2841
#endif
2942

3043
namespace mp {

src/mp/gen.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ static bool GetAnnotationInt32(const Reader& reader, uint64_t id, int32_t* resul
7777
return false;
7878
}
7979

80-
static void ForEachMethod(const capnp::InterfaceSchema& interface, const std::function<void(const capnp::InterfaceSchema& interface, const capnp::InterfaceSchema::Method)>& callback) // NOLINT(misc-no-recursion)
80+
static void ForEachMethod(const capnp::InterfaceSchema& schema, const std::function<void(const capnp::InterfaceSchema& schema, const capnp::InterfaceSchema::Method)>& callback) // NOLINT(misc-no-recursion)
8181
{
82-
for (const auto super : interface.getSuperclasses()) {
82+
for (const auto super : schema.getSuperclasses()) {
8383
ForEachMethod(super, callback);
8484
}
85-
for (const auto method : interface.getMethods()) {
86-
callback(interface, method);
85+
for (const auto method : schema.getMethods()) {
86+
callback(schema, method);
8787
}
8888
}
8989

@@ -389,7 +389,7 @@ static void Generate(kj::StringPtr src_prefix,
389389
}
390390

391391
if (proxied_class_type.size() && node.getProto().isInterface()) {
392-
const auto& interface = node.asInterface();
392+
const auto& node_interface = node.asInterface();
393393

394394
std::ostringstream client;
395395
client << "template<>\nstruct ProxyClient<" << message_namespace << "::" << node_name << "> final : ";
@@ -411,7 +411,7 @@ static void Generate(kj::StringPtr src_prefix,
411411
const std::ostringstream client_destroy;
412412

413413
int method_ordinal = 0;
414-
ForEachMethod(interface, [&] (const capnp::InterfaceSchema& method_interface, const capnp::InterfaceSchema::Method& method) {
414+
ForEachMethod(node_interface, [&] (const capnp::InterfaceSchema& method_interface, const capnp::InterfaceSchema::Method& method) {
415415
const kj::StringPtr method_name = method.getProto().getName();
416416
kj::StringPtr proxied_method_name = method_name;
417417
GetAnnotationText(method.getProto(), NAME_ANNOTATION_ID, &proxied_method_name);
@@ -501,7 +501,7 @@ static void Generate(kj::StringPtr src_prefix,
501501
}
502502
}
503503

504-
if (!is_construct && !is_destroy && (&method_interface == &interface)) {
504+
if (!is_construct && !is_destroy && (&method_interface == &node_interface)) {
505505
methods << "template<>\n";
506506
methods << "struct ProxyMethod<" << method_prefix << "Params>\n";
507507
methods << "{\n";

0 commit comments

Comments
 (0)