From: Adam Simpkins Date: Thu, 26 May 2016 22:38:13 +0000 (-0700) Subject: move io/Cursor-defs.h to io/Cursor.cpp X-Git-Tag: 2016.07.26~198 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1fa49a2e4b15c727fdb0715545c44f3aa1108193;p=folly.git move io/Cursor-defs.h to io/Cursor.cpp Summary: The two function definitions in this file are both normal function definitions, not template functions. Therefore this should be just a normal .cpp file, and not a -defs.h header file. Reviewed By: igorsugak Differential Revision: D3348439 fbshipit-source-id: 3ebe49c84493f5aab06c568d9df15a37c2c48836 --- diff --git a/folly/Makefile.am b/folly/Makefile.am index 1b28ff7f..275d2477 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -401,6 +401,7 @@ libfolly_la_SOURCES = \ IPAddressV6.cpp \ LifoSem.cpp \ io/Compression.cpp \ + io/Cursor.cpp \ io/IOBuf.cpp \ io/IOBufQueue.cpp \ io/RecordIO.cpp \ diff --git a/folly/io/Cursor-defs.h b/folly/io/Cursor-defs.h deleted file mode 100644 index 078c4297..00000000 --- a/folly/io/Cursor-defs.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2016 Facebook, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include - -#include -#include - -namespace folly { namespace io { - -void Appender::printf(const char* fmt, ...) { - va_list ap; - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); -} - -void Appender::vprintf(const char* fmt, va_list ap) { - // Make a copy of ap in case we need to retry. - // We use ap on the first attempt, so it always gets advanced - // passed the used arguments. We'll only use apCopy if we need to retry. - va_list apCopy; - va_copy(apCopy, ap); - SCOPE_EXIT { - va_end(apCopy); - }; - - // First try writing into our available data space. - int ret = vsnprintf(reinterpret_cast(writableData()), length(), - fmt, ap); - if (ret < 0) { - throw std::runtime_error("error formatting printf() data"); - } - // vsnprintf() returns the number of characters that would be printed, - // not including the terminating nul. - if (size_t(ret) < length()) { - // All of the data was successfully written. - append(ret); - return; - } - - // There wasn't enough room for the data. - // Allocate more room, and then retry. - ensure(ret + 1); - ret = vsnprintf(reinterpret_cast(writableData()), length(), - fmt, apCopy); - if (ret < 0) { - throw std::runtime_error("error formatting printf() data"); - } - if (size_t(ret) >= length()) { - // This shouldn't ever happen. - throw std::runtime_error("unexpectedly out of buffer space on second " - "vsnprintf() attmept"); - } - append(ret); -} - -}} // folly::io diff --git a/folly/io/Cursor.cpp b/folly/io/Cursor.cpp new file mode 100644 index 00000000..fe478403 --- /dev/null +++ b/folly/io/Cursor.cpp @@ -0,0 +1,70 @@ +/* + * Copyright 2016 Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include +#include + +namespace folly { namespace io { + +void Appender::printf(const char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); +} + +void Appender::vprintf(const char* fmt, va_list ap) { + // Make a copy of ap in case we need to retry. + // We use ap on the first attempt, so it always gets advanced + // passed the used arguments. We'll only use apCopy if we need to retry. + va_list apCopy; + va_copy(apCopy, ap); + SCOPE_EXIT { + va_end(apCopy); + }; + + // First try writing into our available data space. + int ret = vsnprintf(reinterpret_cast(writableData()), length(), + fmt, ap); + if (ret < 0) { + throw std::runtime_error("error formatting printf() data"); + } + // vsnprintf() returns the number of characters that would be printed, + // not including the terminating nul. + if (size_t(ret) < length()) { + // All of the data was successfully written. + append(ret); + return; + } + + // There wasn't enough room for the data. + // Allocate more room, and then retry. + ensure(ret + 1); + ret = vsnprintf(reinterpret_cast(writableData()), length(), + fmt, apCopy); + if (ret < 0) { + throw std::runtime_error("error formatting printf() data"); + } + if (size_t(ret) >= length()) { + // This shouldn't ever happen. + throw std::runtime_error("unexpectedly out of buffer space on second " + "vsnprintf() attmept"); + } + append(ret); +} + +}} // folly::io diff --git a/folly/io/test/IOBufCursorBenchmark.cpp b/folly/io/test/IOBufCursorBenchmark.cpp index 559f7a3e..465691c0 100644 --- a/folly/io/test/IOBufCursorBenchmark.cpp +++ b/folly/io/test/IOBufCursorBenchmark.cpp @@ -20,7 +20,6 @@ #include #include #include -#include DECLARE_bool(benchmark); diff --git a/folly/io/test/IOBufCursorTest.cpp b/folly/io/test/IOBufCursorTest.cpp index 958f6d45..a5bc4eb9 100644 --- a/folly/io/test/IOBufCursorTest.cpp +++ b/folly/io/test/IOBufCursorTest.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include