Commit eb319ef3 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

WTF: Remove WTF::PrintStream.

It is only used to printf to a FILE*, which <cstdio> already does.

Change-Id: I05965cafca27d918858716ed624358a506119b96
Reviewed-on: https://chromium-review.googlesource.com/965383Reviewed-by: default avatarYuta Kitamura <yutak@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543694}
parent d7df60b2
...@@ -73,8 +73,6 @@ jumbo_component("wtf") { ...@@ -73,8 +73,6 @@ jumbo_component("wtf") {
"DoublyLinkedList.h", "DoublyLinkedList.h",
"DynamicAnnotations.cpp", "DynamicAnnotations.cpp",
"DynamicAnnotations.h", "DynamicAnnotations.h",
"FilePrintStream.cpp",
"FilePrintStream.h",
"Forward.h", "Forward.h",
"Functional.h", "Functional.h",
"GetPtr.h", "GetPtr.h",
...@@ -96,8 +94,6 @@ jumbo_component("wtf") { ...@@ -96,8 +94,6 @@ jumbo_component("wtf") {
"Noncopyable.h", "Noncopyable.h",
"NotFound.h", "NotFound.h",
"Optional.h", "Optional.h",
"PrintStream.cpp",
"PrintStream.h",
"ProcessMetrics.h", "ProcessMetrics.h",
"RefCounted.h", "RefCounted.h",
"RefVector.h", "RefVector.h",
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "platform/wtf/BitVector.h" #include "platform/wtf/BitVector.h"
#include "platform/wtf/LeakAnnotations.h" #include "platform/wtf/LeakAnnotations.h"
#include "platform/wtf/PrintStream.h"
#include "platform/wtf/allocator/Partitions.h" #include "platform/wtf/allocator/Partitions.h"
#include <algorithm> #include <algorithm>
#include <string.h> #include <string.h>
...@@ -112,13 +111,4 @@ void BitVector::ResizeOutOfLine(size_t num_bits) { ...@@ -112,13 +111,4 @@ void BitVector::ResizeOutOfLine(size_t num_bits) {
bits_or_pointer_ = BitwiseCast<uintptr_t>(new_out_of_line_bits) >> 1; bits_or_pointer_ = BitwiseCast<uintptr_t>(new_out_of_line_bits) >> 1;
} }
void BitVector::Dump(PrintStream& out) {
for (size_t i = 0; i < size(); ++i) {
if (Get(i))
out.Printf("1");
else
out.Printf("-");
}
}
} // namespace WTF } // namespace WTF
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
namespace WTF { namespace WTF {
class PrintStream;
// This is a space-efficient, resizeable bitvector class. In the common case it // This is a space-efficient, resizeable bitvector class. In the common case it
// occupies one word, but if necessary, it will inflate this one word to point // occupies one word, but if necessary, it will inflate this one word to point
// to a single chunk of out-of-line allocated storage to store an arbitrary // to a single chunk of out-of-line allocated storage to store an arbitrary
...@@ -156,8 +154,6 @@ class WTF_EXPORT BitVector { ...@@ -156,8 +154,6 @@ class WTF_EXPORT BitVector {
Clear(bit); Clear(bit);
} }
void Dump(PrintStream& out);
private: private:
static unsigned BitsInPointer() { return sizeof(void*) << 3; } static unsigned BitsInPointer() { return sizeof(void*) << 3; }
......
...@@ -25,13 +25,11 @@ ...@@ -25,13 +25,11 @@
#include "platform/wtf/DataLog.h" #include "platform/wtf/DataLog.h"
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include "build/build_config.h" #include "build/build_config.h"
#if defined(OS_POSIX)
#include <pthread.h>
#include <unistd.h>
#endif
#define DATA_LOG_TO_FILE 0 #define DATA_LOG_TO_FILE 0
// Uncomment to force logging to the given file regardless of what the // Uncomment to force logging to the given file regardless of what the
...@@ -44,61 +42,42 @@ ...@@ -44,61 +42,42 @@
namespace WTF { namespace WTF {
#if defined(OS_POSIX) static FILE* OpenLogFile() {
static pthread_once_t g_initialize_log_file_once_key = PTHREAD_ONCE_INIT; FILE* file = nullptr;
#endif
static FilePrintStream* g_file;
static void InitializeLogFileOnce() {
#if DATA_LOG_TO_FILE #if DATA_LOG_TO_FILE
#ifdef DATA_LOG_FILENAME #ifdef DATA_LOG_FILENAME
const char* filename = DATA_LOG_FILENAME; const char* filename = DATA_LOG_FILENAME;
#else #else
const char* filename = getenv("WTF_DATA_LOG_FILENAME"); const char* filename = getenv("WTF_DATA_LOG_FILENAME");
#endif #endif
char actualFilename[1024]; char actual_filename[1024];
snprintf(actualFilename, sizeof(actualFilename), "%s.%d.txt", filename, snprintf(actual_filename, sizeof(actual_filename), "%s.%d.txt", filename,
getpid()); getpid());
if (filename) { if (filename) {
file = FilePrintStream::open(actualFilename, "w").release(); file = fopen(actual_filename, "w");
if (!file) if (!file) {
fprintf(stderr, "Warning: Could not open log file %s for writing.\n", fprintf(stderr, "Warning: Could not open log file %s for writing.\n",
actualFilename); actual_filename);
}
} }
#endif // DATA_LOG_TO_FILE #endif // DATA_LOG_TO_FILE
if (!g_file) if (!file)
g_file = new FilePrintStream(stderr, FilePrintStream::kBorrow); file = stderr;
// Prefer unbuffered output, so that we get a full log upon crash or // Prefer unbuffered output, so that we get a full log upon crash or
// deadlock. // deadlock.
setvbuf(g_file->File(), nullptr, _IONBF, 0); setvbuf(file, nullptr, _IONBF, 0);
}
static void InitializeLogFile() {
#if defined(OS_POSIX)
pthread_once(&g_initialize_log_file_once_key, InitializeLogFileOnce);
#else
if (!g_file)
InitializeLogFileOnce();
#endif
}
FilePrintStream& DataFile() {
InitializeLogFile();
return *g_file;
}
void DataLogFV(const char* format, va_list arg_list) { return file;
DataFile().Vprintf(format, arg_list);
} }
void DataLogF(const char* format, ...) { void DataLogF(const char* format, ...) {
static FILE* file = OpenLogFile();
va_list arg_list; va_list arg_list;
va_start(arg_list, format); va_start(arg_list, format);
DataLogFV(format, arg_list); vfprintf(file, format, arg_list);
va_end(arg_list); va_end(arg_list);
} }
......
...@@ -26,29 +26,15 @@ ...@@ -26,29 +26,15 @@
#ifndef DataLog_h #ifndef DataLog_h
#define DataLog_h #define DataLog_h
#include "platform/wtf/Assertions.h" #include "base/compiler_specific.h"
#include "platform/wtf/Compiler.h"
#include "platform/wtf/FilePrintStream.h"
#include "platform/wtf/WTFExport.h" #include "platform/wtf/WTFExport.h"
#include <stdarg.h>
#include <stdio.h>
namespace WTF { namespace WTF {
FilePrintStream& DataFile();
WTF_EXPORT PRINTF_FORMAT(1, 0) void DataLogFV(const char* format, va_list);
WTF_EXPORT PRINTF_FORMAT(1, 2) void DataLogF(const char* format, ...); WTF_EXPORT PRINTF_FORMAT(1, 2) void DataLogF(const char* format, ...);
template <typename... T>
void DataLog(const T&... values) {
DataFile().Print(values...);
}
} // namespace WTF } // namespace WTF
using WTF::DataLog;
using WTF::DataLogF; using WTF::DataLogF;
#endif // DataLog_h #endif // DataLog_h
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform/wtf/FilePrintStream.h"
#include <memory>
namespace WTF {
FilePrintStream::FilePrintStream(FILE* file, AdoptionMode adoption_mode)
: file_(file), adoption_mode_(adoption_mode) {}
FilePrintStream::~FilePrintStream() {
if (adoption_mode_ == kBorrow)
return;
fclose(file_);
}
std::unique_ptr<FilePrintStream> FilePrintStream::Open(const char* filename,
const char* mode) {
FILE* file = fopen(filename, mode);
if (!file)
return std::unique_ptr<FilePrintStream>();
return std::make_unique<FilePrintStream>(file);
}
void FilePrintStream::Vprintf(const char* format, va_list arg_list) {
vfprintf(file_, format, arg_list);
}
void FilePrintStream::Flush() {
fflush(file_);
}
} // namespace WTF
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef FilePrintStream_h
#define FilePrintStream_h
#include "platform/wtf/Compiler.h"
#include "platform/wtf/PrintStream.h"
#include <memory>
#include <stdio.h>
namespace WTF {
class WTF_EXPORT FilePrintStream final : public PrintStream {
public:
enum AdoptionMode { kAdopt, kBorrow };
FilePrintStream(FILE*, AdoptionMode = kAdopt);
~FilePrintStream() override;
static std::unique_ptr<FilePrintStream> Open(const char* filename,
const char* mode);
FILE* File() { return file_; }
PRINTF_FORMAT(2, 0) void Vprintf(const char* format, va_list) override;
void Flush() override;
private:
FILE* file_;
AdoptionMode adoption_mode_;
};
} // namespace WTF
using WTF::FilePrintStream;
#endif // FilePrintStream_h
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform/wtf/PrintStream.h"
#include "platform/wtf/text/CString.h"
#include "platform/wtf/text/WTFString.h"
#include <stdio.h>
namespace WTF {
PrintStream::PrintStream() = default;
PrintStream::~PrintStream() = default; // Force the vtable to be in this module
void PrintStream::Printf(const char* format, ...) {
va_list arg_list;
va_start(arg_list, format);
Vprintf(format, arg_list);
va_end(arg_list);
}
void PrintStream::Flush() {}
void PrintInternal(PrintStream& out, const char* string) {
out.Printf("%s", string);
}
void PrintInternal(PrintStream& out, const CString& string) {
out.Print(string.data());
}
void PrintInternal(PrintStream& out, const String& string) {
out.Print(string.Utf8());
}
void PrintInternal(PrintStream& out, bool value) {
if (value)
out.Print("true");
else
out.Print("false");
}
void PrintInternal(PrintStream& out, int value) {
out.Printf("%d", value);
}
void PrintInternal(PrintStream& out, unsigned value) {
out.Printf("%u", value);
}
void PrintInternal(PrintStream& out, long value) {
out.Printf("%ld", value);
}
void PrintInternal(PrintStream& out, unsigned long value) {
out.Printf("%lu", value);
}
void PrintInternal(PrintStream& out, long long value) {
out.Printf("%lld", value);
}
void PrintInternal(PrintStream& out, unsigned long long value) {
out.Printf("%llu", value);
}
void PrintInternal(PrintStream& out, float value) {
out.Print(static_cast<double>(value));
}
void PrintInternal(PrintStream& out, double value) {
out.Printf("%lf", value);
}
void DumpCharacter(PrintStream& out, char value) {
out.Printf("%c", value);
}
} // namespace WTF
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PrintStream_h
#define PrintStream_h
#include <stdarg.h>
#include "base/macros.h"
#include "platform/wtf/Allocator.h"
#include "platform/wtf/Compiler.h"
#include "platform/wtf/StdLibExtras.h"
#include "platform/wtf/WTFExport.h"
namespace WTF {
class CString;
class String;
class WTF_EXPORT PrintStream {
USING_FAST_MALLOC(PrintStream);
public:
PrintStream();
virtual ~PrintStream();
PRINTF_FORMAT(2, 3) void Printf(const char* format, ...);
PRINTF_FORMAT(2, 0) virtual void Vprintf(const char* format, va_list) = 0;
// Typically a no-op for many subclasses of PrintStream, this is a hint that
// the implementation should flush its buffers if it had not done so already.
virtual void Flush();
template <typename T>
void Print(const T& value) {
PrintInternal(*this, value);
}
template <typename T1, typename... RemainingTypes>
void Print(const T1& value1, const RemainingTypes&... values) {
Print(value1);
Print(values...);
}
DISALLOW_COPY_AND_ASSIGN(PrintStream);
};
WTF_EXPORT void PrintInternal(PrintStream&, const char*);
WTF_EXPORT void PrintInternal(PrintStream&, const CString&);
WTF_EXPORT void PrintInternal(PrintStream&, const String&);
inline void PrintInternal(PrintStream& out, char* value) {
PrintInternal(out, static_cast<const char*>(value));
}
inline void PrintInternal(PrintStream& out, CString& value) {
PrintInternal(out, static_cast<const CString&>(value));
}
inline void PrintInternal(PrintStream& out, String& value) {
PrintInternal(out, static_cast<const String&>(value));
}
WTF_EXPORT void PrintInternal(PrintStream&, bool);
WTF_EXPORT void PrintInternal(PrintStream&, int);
WTF_EXPORT void PrintInternal(PrintStream&, unsigned);
WTF_EXPORT void PrintInternal(PrintStream&, long);
WTF_EXPORT void PrintInternal(PrintStream&, unsigned long);
WTF_EXPORT void PrintInternal(PrintStream&, long long);
WTF_EXPORT void PrintInternal(PrintStream&, unsigned long long);
WTF_EXPORT void PrintInternal(PrintStream&, float);
WTF_EXPORT void PrintInternal(PrintStream&, double);
template <typename T>
void PrintInternal(PrintStream& out, const T& value) {
value.Dump(out);
}
} // namespace WTF
using WTF::PrintStream;
#endif // PrintStream_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment