diff --git a/common/enumerable.h b/common/enumerable.h index 0445128f8..461e38196 100644 --- a/common/enumerable.h +++ b/common/enumerable.h @@ -17,6 +17,7 @@ limitations under the License. #pragma once #include #include +#include // If class A can be enumerable with A::get() and A::next(), // then objects of A can be enumerated by the `for` statement diff --git a/fs/cache/cache.h b/fs/cache/cache.h index 9a0df879b..97b1a8970 100644 --- a/fs/cache/cache.h +++ b/fs/cache/cache.h @@ -19,6 +19,7 @@ limitations under the License. #include #include #include +#include #include #include diff --git a/fs/cache/forwardcfs.h b/fs/cache/forwardcfs.h index 584ae4687..009f2bc53 100644 --- a/fs/cache/forwardcfs.h +++ b/fs/cache/forwardcfs.h @@ -20,6 +20,8 @@ limitations under the License. namespace photon { namespace fs{ +class ICacheStore; +class ICachePool; template class ForwardCachedFileBase : public IForwardCachedFile { protected: @@ -38,6 +40,8 @@ class ForwardCachedFileBase : public IForwardCachedFile { return Base::m_file->query(offset, count); } }; + +class ICachedFile; using ForwardCachedFile = ForwardCachedFileBase>; using ForwardCachedFile_Ownership = ForwardCachedFileBase>; @@ -60,6 +64,9 @@ class ForwardCachedFSBase : public IForwardCachedFS { return Base::m_fs->set_pool(pool); } }; + +class ICachedFileSystem; + using ForwardCachedFS = ForwardCachedFSBase>; using ForwardCachedFS_Ownership = ForwardCachedFSBase>; diff --git a/include/fcntl.h b/include/fcntl.h index 263d6bc96..8f28dd302 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -37,9 +37,20 @@ limitations under the License. #define O_NONBLOCK 0x4000 #endif -// Windows/MinGW lacks posix_fadvise() and its POSIX_FADV_* constants. The -// fadvise() override on Windows is a no-op, so any integer value is safe; -// using 0 for all of them keeps the shim minimal and call sites unchanged. +#else +// Non-Windows: forward to the real libc . +#include_next +#endif + +// posix_fadvise() and its POSIX_FADV_* constants are Linux-only: neither MinGW +// nor Darwin has them (Darwin's SDK defines no POSIX_FADV_* and declares no +// posix_fadvise at all). Every platform that lacks them also lacks the +// fadvise() override -- fs/localfs.cpp puts it under #ifdef __linux__, so the +// base UNIMPLEMENTED(int fadvise(...)) in fs/filesystem.h handles the call and +// the advice value never reaches a syscall. Any integer is therefore safe; 0 +// for all of them keeps the shim minimal and call sites unchanged. These are +// outside the _WIN32 branch above and #ifndef-guarded, so Linux, whose +// does define them, keeps the real values. #ifndef POSIX_FADV_NORMAL #define POSIX_FADV_NORMAL 0 #endif @@ -58,8 +69,3 @@ limitations under the License. #ifndef POSIX_FADV_NOREUSE #define POSIX_FADV_NOREUSE 0 #endif - -#else -// Non-Windows: forward to the real libc . -#include_next -#endif diff --git a/io/iocp.h b/io/iocp.h index b46c4dea9..4137cba15 100644 --- a/io/iocp.h +++ b/io/iocp.h @@ -16,6 +16,7 @@ limitations under the License. #pragma once +#include #include #include #include diff --git a/test/test-includes.sh b/test/test-includes.sh new file mode 100644 index 000000000..bfb21b913 --- /dev/null +++ b/test/test-includes.sh @@ -0,0 +1,74 @@ +# Compile every header under include/photon/ on its own, so a header that is not +# self-contained fails here instead of in whichever .cpp happens to include it +# second. Up to JOBS compilations run at once, defaulting to the number of +# online CPUs; JOBS=1 gives the old serial behaviour. +# +# Extra arguments are passed through to gcc, which is how you supply a dependency +# this machine keeps somewhere off the default search path: +# test/test-includes.sh -I/opt/homebrew/include +# +# Exits non-zero if any header failed. +cd `dirname $0`/../include || exit 1 + +# getconf rather than nproc: nproc is GNU coreutils and macOS does not have it. +# The case arm catches both a machine where getconf is missing and a JOBS that +# was set to something xargs -P would reject. +JOBS=${JOBS:-`getconf _NPROCESSORS_ONLN 2>/dev/null`} +case $JOBS in ('' | *[!0-9]*) JOBS=1 ;; esac + +# Force colour ONLY when this script's own stdout is a terminal; into a +# redirected log the escape bytes are just noise, so COLOR stays empty and gcc is +# invoked exactly as before. +# +# Why forcing is needed at all: gcc and clang colour diagnostics only when their +# own output is a TTY, and this script captures them through a pipe so each can +# be attributed to its header -- which silently drops the colour. Which flag +# forces it back on is not portable: gcc 15 ignores -fcolor-diagnostics and clang +# older than 17 does not know -fdiagnostics-color, so probe for the flag that +# actually puts an escape byte into a pipe rather than guessing from a version +# number. +COLOR= +if [ -t 1 ]; then + esc=`printf '\033'` + for f in -fdiagnostics-color=always -fcolor-diagnostics; do + if printf 'int x = "s";\n' | gcc -x c - -c -o /dev/null "$f" 2>&1 | grep -q "$esc"; then + COLOR=$f + break + fi + done +fi + +# xargs appends its own items after the command, so the gcc flags cannot be +# handed to `sh -c` as leading arguments; they travel in the environment instead. +# The worker expands this unquoted on purpose -- it is a flag list, not one +# argument. $COLOR goes first so that passing -fdiagnostics-color=never on the +# command line still turns the colour back off. That spelling, not clang's +# -fno-color-diagnostics: gcc rejects the latter outright with "unrecognized +# command-line option". +PHOTON_HDR_FLAGS="$COLOR $*" +export PHOTON_HDR_FLAGS + +result=`mktemp` +trap 'rm -f "$result"' EXIT + +# Each header's diagnostics are captured and then printed under its own FAIL +# line. Letting gcc write straight to the terminal was fine serially, but with +# -P 8 the streams interleave and an error can no longer be attributed to the +# header that produced it. +find photon -name "*.h" -print0 | + xargs -0 -P "$JOBS" -n1 sh -c ' + h=$1 + if err=`printf "#include <%s>\n" "$h" | + gcc -x c++ - -std=c++20 -c -I . -o /dev/null $PHOTON_HDR_FLAGS 2>&1`; then + printf "PASS %s\n" "$h" + else + printf "FAIL %s\n" "$h" + printf "%s\n" "$err" | sed "s/^/ /" + fi + ' _ | tee "$result" + +pass=`grep -c "^PASS " "$result"` +fail=`grep -c "^FAIL " "$result"` +printf "\n%d headers: %d passed, %d failed (JOBS=%d)\n" \ + "$((pass + fail))" "$pass" "$fail" "$JOBS" +[ "$fail" -eq 0 ] diff --git a/thread/coro20.h b/thread/coro20.h index d3c42febe..d8ef0318f 100644 --- a/thread/coro20.h +++ b/thread/coro20.h @@ -302,7 +302,8 @@ auto run(F &&f, Args &&... args) { } inline auto usleep(uint64_t time) { - return wrapper(photon::thread_usleep, time); + int (*f)(Timeout) = &photon::thread_usleep; + return wrapper(f, Timeout(time)); } inline auto sleep(uint64_t time) { return wrapper(photon::thread_sleep, time); }