Skip to content

Commit

Permalink
GCC/MSVC fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
snej committed Sep 29, 2023
1 parent 9eb10ba commit 880e08a
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 23 deletions.
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # For JetBrains IDE


Expand Down Expand Up @@ -49,11 +52,12 @@ if (MSVC)
# MSVC:
add_definitions(-DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0A00 -DNOMINMAX)
add_compile_options(
/W4 # I think this means 'turn on lots of warnings'
/wd4068 # ignore unknown pragma
/wd4100 # ignore unused fn parameters
/wd4244 # ignore implicit sign conversion
/wd4267 # ignore implicit integer truncation
"/wd4068;/wd4100;/wd4244;/wd4267"
# /W4 # I think this means 'turn on lots of warnings'
# /wd4068 # ignore unknown pragma
# /wd4100 # ignore unused fn parameters
# /wd4244 # ignore implicit sign conversion
# /wd4267 # ignore implicit integer truncation
)
else()
# Clang & GCC:
Expand All @@ -76,7 +80,8 @@ else()
add_compile_options(
-Wno-gnu-zero-variadic-macro-arguments
-Wno-gnu-conditional-omitted-operand # Allow `x ?: y`
-Wno-gnu-statement-expression-from-macro-expansion # Allow `({...})`
-Wno-gnu-statement-expression # Allow `({...})`
-Wno-gnu-statement-expression-from-macro-expansion
)
endif()
endif()
Expand Down
2 changes: 2 additions & 0 deletions include/Awaitable.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#pragma once
#include "Result.hh"

#include <functional>

namespace crouton {

/** Pure-virtual interface declaring the coroutine methods needed to support `co_await`
Expand Down
17 changes: 17 additions & 0 deletions include/Base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@
#endif


#ifndef __has_attribute
#define __has_attribute(x) 0
#endif

#if __has_attribute(__unused__)
#define __unused __attribute__((__unused__))
#else
#define __unused
#endif

#if __has_attribute(__pure__)
#define pure __attribute__((__pure__))
#else
#define pure
#endif


// Synonyms for coroutine primitives. Optional, but they're more visible in the code.
#define AWAIT co_await
#define YIELD co_yield
Expand Down
4 changes: 2 additions & 2 deletions include/Error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <array>
#include <concepts>
#include <exception>
#include <stdexcept>
#include <type_traits>
#include <typeinfo>

Expand Down Expand Up @@ -51,7 +51,7 @@ namespace crouton {
template <typename T>
concept ErrorDomain = requires {
std::is_enum_v<T>;
std::same_as<std::underlying_type_t<T>, errorcode_t>;
requires std::same_as<std::underlying_type_t<T>, errorcode_t>;
{ErrorDomainInfo<T>::name} -> std::convertible_to<string_view>;
{ErrorDomainInfo<T>::description} -> std::convertible_to<ErrorDescriptionFunc>;
};
Expand Down
1 change: 1 addition & 0 deletions include/EventLoop.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Future.hh"

#include <functional>
#include <optional>

struct uv_timer_s;

Expand Down
4 changes: 2 additions & 2 deletions include/Future.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace crouton {
template <typename T>
class Future : public Coroutine<FutureImpl<T>>, public ISelectable {
public:
using nonvoidT = std::conditional<std::is_void_v<T>, std::byte, T>::type;
using nonvoidT = typename std::conditional<std::is_void_v<T>, std::byte, T>::type;

/// Creates a Future from a FutureProvider.
explicit Future(FutureProvider<T> state) :_state(std::move(state)) {assert(_state);}
Expand Down Expand Up @@ -260,7 +260,7 @@ namespace crouton {
public:
using super = CoroutineImpl<FutureImpl<T>, true>;
using handle_type = typename super::handle_type;
using nonvoidT = std::conditional<std::is_void_v<T>, std::byte, T>::type;
using nonvoidT = typename std::conditional<std::is_void_v<T>, std::byte, T>::type;

FutureImpl() = default;

Expand Down
2 changes: 2 additions & 0 deletions include/LinkedList.hh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ namespace crouton::util {
protected:
Link* _begin() {return _head._next;}
Link* _end() {return &_head;}
Link const* _begin() const {return _head._next;}
Link const* _end() const {return &_head;}

template <class LINK>
static LINK& downcast(Link& link) {return static_cast<LINK&>(link);}
Expand Down
4 changes: 4 additions & 0 deletions include/PubSub.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "Select.hh"
#include "Task.hh"

#include <functional>
#include <optional>
#include <vector>

namespace crouton::ps {

/** Type-erasing wrapper around any Series implementation. */
Expand Down
10 changes: 5 additions & 5 deletions include/Queue.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ namespace crouton {
size_t size() const {return _queue.size();}
Error error() const {return empty() ? _closeError : noerror;}

using iterator = std::deque<T>::iterator;
using const_iterator = std::deque<T>::const_iterator;
using iterator = typename std::deque<T>::iterator;
using const_iterator = typename std::deque<T>::const_iterator;

iterator begin() {return _queue.begin();}
iterator end() {return _queue.end();}
Expand Down Expand Up @@ -120,7 +120,7 @@ namespace crouton {
}

/// Adds an item at the position of the iterator, i.e. before whatever's at the iterator.
virtual bool pushBefore(std::deque<T>::iterator i, T item) {
virtual bool pushBefore(typename std::deque<T>::iterator i, T item) {
if (_state != Open)
return false;
_queue.emplace(i, std::move(item));
Expand Down Expand Up @@ -245,7 +245,7 @@ namespace crouton {
this->closeWhenEmpty();
break;
}
if (!(YIELD 0))
if (bool ok = YIELD 0; !ok)
break;
}
}
Expand All @@ -266,7 +266,7 @@ namespace crouton {
return !full() && super::push(std::move(t));
}

[[nodiscard]] bool pushBefore(std::deque<T>::iterator i, T item) override {
[[nodiscard]] bool pushBefore(typename std::deque<T>::iterator i, T item) override {
return !full() && super::pushBefore(i, std::move(item));
}

Expand Down
2 changes: 2 additions & 0 deletions include/Result.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace crouton {



#if 0
/// Syntactic sugar to handle a `Result<T>`, similar to Swift's `try`.
/// - If R has a value, evaluates to its value.
/// - If R has an error, `co_return`s the error from the current coroutine.
Expand All @@ -148,4 +149,5 @@ namespace crouton {
/// - If the future returns a value, evaluates to that value.
/// - If the future returns an error, `co_return`s the error.
#define TRY_AWAIT(F) UNWRAP(AWAIT NoThrow(F))
#endif
}
7 changes: 4 additions & 3 deletions src/io/FileStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ namespace crouton::io {
_readBuf = make_unique<Buffer>();
assert(_readBuf->empty());
MutableBytes buf(_readBuf->data, Buffer::kCapacity);
size_t n = TRY_AWAIT(_preadv(&buf, 1, -1));

_readBuf->size = uint32_t(n);
Result<size_t> n = AWAIT _preadv(&buf, 1, -1);
if (auto err = n.error())
RETURN err;
_readBuf->size = uint32_t(n.value());
_readBuf->used = 0;
RETURN _readBuf->bytes();
}
Expand Down
4 changes: 4 additions & 0 deletions src/io/blip/BLIPConnection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "Message.hh"
#include "Task.hh"

#include <functional>
#include <optional>
#include <unordered_map>

namespace crouton::io::blip {
class MessageBuilder;

Expand Down
2 changes: 2 additions & 0 deletions src/io/blip/BLIPIO.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "Message.hh"
#include "MessageOut.hh"
#include "Queue.hh"

#include <algorithm>
#include <unordered_map>
#include <vector>

namespace crouton::io::blip {
Expand Down
4 changes: 2 additions & 2 deletions src/io/blip/Message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ namespace crouton::io::blip {
_unackedBytes += frameSize;
if (_unackedBytes >= kIncomingAckThreshold) {
// Send an ACK after enough data has been received of this message:
MessageType msgType = isResponse() ? kAckResponseType : kAckRequestType;
auto msgType = FrameFlags(isResponse() ? kAckResponseType : kAckRequestType);
char buf[10];
string payload(buf, putUVarint(_rawBytesReceived, buf));
_connection->send(make_shared<MessageOut>(_connection,
(FrameFlags)(msgType|kUrgent|kNoReply),
FrameFlags(msgType|kUrgent|kNoReply),
payload, _number));
_unackedBytes = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/io/blip/MessageBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace crouton::io::blip {


FrameFlags MessageBuilder::flags() const {
int flags = type & kTypeMask;
int flags = FrameFlags(type) & kTypeMask;
if (urgent) flags |= kUrgent;
if (compressed) flags |= kCompressed;
if (noreply) flags |= kNoReply;
Expand Down
2 changes: 1 addition & 1 deletion src/io/blip/MessageOut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace crouton::io::blip {
// Note: The MessageIn's flags will be updated when the 1st frame of the response arrives;
// the type might become kErrorType, and kUrgent or kCompressed might be set.
return new MessageIn(_connection,
(FrameFlags)kResponseType,
FrameFlags(kResponseType),
_number,
_uncompressedBytesSent,
std::move(_onResponse));
Expand Down
2 changes: 2 additions & 0 deletions src/support/StringUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#pragma once
#include "Base.hh"

#include <cstring>
#include <cassert>

namespace crouton {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ TEST_CASE("Select Future and Generator", "[generator]") {
int64_t expectedCount = 1;
bool done = false;
while (!done) {
switch (int which = AWAIT select) {
switch (AWAIT select) {
case 0: {
Result<int64_t> r = AWAIT count;
cerr << r << ", ";
Expand Down

0 comments on commit 880e08a

Please sign in to comment.