From 4401039fdc12b3bf8c155057019ce6d924d43465 Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Fri, 18 Sep 2015 01:37:13 -0700 Subject: [PATCH] Support MSVC, which does not have VLAs, in folly/io/async/AsyncSocket.cpp Summary: [Folly] Support MSVC, which does not have VLAs, in `folly/io/async/AsyncSocket.cpp`. We use VLAs in compilers that have them, and fixed-size arrays in compilers that do not. Reviewed By: @JoelMarcey Differential Revision: D2450689 --- folly/configure.ac | 27 ++++++++++++++++++++++++--- folly/io/async/AsyncSocket.cpp | 6 ++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/folly/configure.ac b/folly/configure.ac index 538d8108..8d4b07a4 100644 --- a/folly/configure.ac +++ b/folly/configure.ac @@ -365,6 +365,10 @@ AC_CACHE_CHECK( [folly_cv_prog_cc_xsi_strerror_r=yes], [folly_cv_prog_cc_xsi_strerror_r=no])]) +if test "$folly_cv_prog_cc_xsi_strerror_r" = "yes"; then + AC_DEFINE([HAVE_XSI_STRERROR_R], [1], [Define to 1 if the runtime supports XSI-style strerror_r]) +fi + AC_CACHE_CHECK( [for ext/random and __gnu_cxx::sfmt19937], [folly_cv_prog_cc_have_extrandom_sfmt19937], @@ -379,9 +383,26 @@ AC_CACHE_CHECK( [folly_cv_prog_cc_have_extrandom_sfmt19937=yes], [folly_cv_prog_cc_have_extrandom_sfmt19937=no])]) -if test "$folly_cv_prog_cc_xsi_strerror_r" = "yes"; then - AC_DEFINE([HAVE_XSI_STRERROR_R], [1], [Define to 1 if the runtime supports XSI-style strerror_r]) -fi +AC_CACHE_CHECK( + [for VLA (variable-length array) support], + [folly_cv_prog_cc_have_vla], + [AC_COMPILE_IFELSE( + [AC_LANG_SOURCE[ + int main(int argc, char** argv) { + unsigned size = argc; + char data[size]; + return 0; + } + ]], + [folly_cv_prog_cc_have_vla=yes], + [folly_cv_prog_cc_have_vla=no])]) + +test "$folly_cv_prog_cc_have_vla" = yes && have_vla=1 || have_vla=0 +AC_DEFINE_UNQUOTED( + [HAVE_VLA], + [$have_vla], + [Define to 1 if the compiler has VLA (variable-length array) support, + otherwise define to 0]) # Checks for library functions. AC_CHECK_FUNCS([getdelim \ diff --git a/folly/io/async/AsyncSocket.cpp b/folly/io/async/AsyncSocket.cpp index e7c9c451..a603e709 100644 --- a/folly/io/async/AsyncSocket.cpp +++ b/folly/io/async/AsyncSocket.cpp @@ -31,6 +31,7 @@ #include #include #include +#include using std::string; using std::unique_ptr; @@ -622,9 +623,10 @@ void AsyncSocket::writev(WriteCallback* callback, void AsyncSocket::writeChain(WriteCallback* callback, unique_ptr&& buf, WriteFlags flags) { + constexpr size_t kSmallSizeMax = 64; size_t count = buf->countChainElements(); - if (count <= 64) { - iovec vec[count]; + if (count <= kSmallSizeMax) { + iovec vec[BOOST_PP_IF(FOLLY_HAVE_VLA, count, kSmallSizeMax)]; writeChainImpl(callback, vec, count, std::move(buf), flags); } else { iovec* vec = new iovec[count]; -- 2.34.1