diff --git a/hphp/compiler/analysis/control_flow.cpp b/hphp/compiler/analysis/control_flow.cpp index 3acd9487a..15590ec7d 100644 --- a/hphp/compiler/analysis/control_flow.cpp +++ b/hphp/compiler/analysis/control_flow.cpp @@ -868,7 +868,7 @@ ControlFlowGraph *ControlFlowGraph::buildControlFlow(MethodStatementPtr m) { ControlFlowGraph *graph = new ControlFlowGraph; graph->m_stmt = m; - ControlFlowBuilder cfb(graph, m->getOrigGeneratorFunc()); + ControlFlowBuilder cfb(graph, !!m->getOrigGeneratorFunc()); cfb.run(m->getStmts()); graph->m_nextDfn = 1; depth_first_visit(*graph, cfb.head(), diff --git a/hphp/compiler/analysis/emitter.cpp b/hphp/compiler/analysis/emitter.cpp index 0c1a17ba8..7520dcbe1 100644 --- a/hphp/compiler/analysis/emitter.cpp +++ b/hphp/compiler/analysis/emitter.cpp @@ -14,6 +14,13 @@ +----------------------------------------------------------------------+ */ +#include "folly/ScopeGuard.h" + +#include +#include +#include +#include + #include #include #include @@ -96,11 +103,6 @@ #include -#include -#include -#include -#include - namespace HPHP { namespace Compiler { /////////////////////////////////////////////////////////////////////////////// @@ -3826,7 +3828,7 @@ bool EmitterVisitor::visitImpl(ConstructPtr node) { pce->addMethod(invoke); MethodStatementPtr body( static_pointer_cast(ce->getClosureFunction())); - invoke->setHasGeneratorAsBody(body->getGeneratorFunc()); + invoke->setHasGeneratorAsBody(!!body->getGeneratorFunc()); postponeMeth(body, invoke, false, new ClosureUseVarVec(useVars)); return true; @@ -5173,7 +5175,7 @@ void EmitterVisitor::emitPostponedMeths() { fe = new FuncEmitter(m_ue, -1, -1, methName); fe->setIsGenerator(funcScope->isGenerator()); fe->setIsGeneratorFromClosure(funcScope->isGeneratorFromClosure()); - fe->setHasGeneratorAsBody(p.m_meth->getGeneratorFunc()); + fe->setHasGeneratorAsBody(!!p.m_meth->getGeneratorFunc()); p.m_fe = fe; top_fes.push_back(fe); } @@ -7459,7 +7461,7 @@ Unit* hphp_compiler_parse(const char* code, int codeLen, const MD5& md5, filename = ""; unitOrigin = UnitOriginEval; } - ScopeGuard sg(SymbolTable::Purge); + SCOPE_EXIT { SymbolTable::Purge(); }; // Check if this file contains raw hip hop bytecode instead of php. // For now this is just dictated by file extension, and doesn't ever diff --git a/hphp/compiler/analysis/function_scope.cpp b/hphp/compiler/analysis/function_scope.cpp index 4cd90f24b..c5eb2e5dd 100644 --- a/hphp/compiler/analysis/function_scope.cpp +++ b/hphp/compiler/analysis/function_scope.cpp @@ -342,12 +342,12 @@ bool FunctionScope::isGenerator() const { (ParserBase::IsContinuationName(name()) && m_paramNames.size() == 1 && m_paramNames[0] == CONTINUATION_OBJECT_NAME)); - return getOrigGenStmt(); + return !!getOrigGenStmt(); } bool FunctionScope::hasGeneratorAsBody() const { MethodStatementPtr stmt = dynamic_pointer_cast(getStmt()); - return stmt ? stmt->getGeneratorFunc() : false; + return stmt ? !!stmt->getGeneratorFunc() : false; } bool FunctionScope::isGeneratorFromClosure() const { diff --git a/hphp/compiler/analysis/variable_table.cpp b/hphp/compiler/analysis/variable_table.cpp index 208fd9c13..6ce3f3376 100644 --- a/hphp/compiler/analysis/variable_table.cpp +++ b/hphp/compiler/analysis/variable_table.cpp @@ -744,7 +744,7 @@ static bool by_location(const VariableTable::StaticGlobalInfoPtr &p1, const VariableTable::StaticGlobalInfoPtr &p2) { ConstructRawPtr d1 = p1->sym->getDeclaration(); ConstructRawPtr d2 = p2->sym->getDeclaration(); - if (!d1) return d2; + if (!d1) return !!d2; if (!d2) return false; return d1->getLocation()->compare(d2->getLocation().get()) < 0; } diff --git a/hphp/runtime/base/program_functions.cpp b/hphp/runtime/base/program_functions.cpp index c08886d6a..1589e484d 100644 --- a/hphp/runtime/base/program_functions.cpp +++ b/hphp/runtime/base/program_functions.cpp @@ -13,9 +13,9 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ +#include "runtime/base/program_functions.h" #include "runtime/base/types.h" -#include "runtime/base/program_functions.h" #include "runtime/base/type_conversions.h" #include "runtime/base/builtin_functions.h" #include "runtime/base/execution_context.h" @@ -618,7 +618,7 @@ static int start_server(const std::string &username) { Logger::Info("Replaying warmup request %s", file.c_str()); try { rt.onRequestStart(start); - rt.replayInput(file); + rt.replayInput(Hdf(file)); handler.handleRequest(&rt); Logger::Info("Finished successfully"); } catch (std::exception& e) { diff --git a/hphp/runtime/base/server/satellite_server.cpp b/hphp/runtime/base/server/satellite_server.cpp index 670376736..e57c2f8fb 100644 --- a/hphp/runtime/base/server/satellite_server.cpp +++ b/hphp/runtime/base/server/satellite_server.cpp @@ -45,7 +45,7 @@ SatelliteServerInfo::SatelliteServerInfo(Hdf hdf) { hdf["Passwords"].get(m_passwords); m_alwaysReset = hdf["AlwaysReset"].getBool(false); - string type = hdf["Type"]; + string type = hdf["Type"].getString(); if (type == "InternalPageServer") { m_type = SatelliteServer::KindOfInternalPageServer; vector urls; @@ -99,7 +99,7 @@ private: class InternalPageServer : public SatelliteServer { public: - InternalPageServer(SatelliteServerInfoPtr info) { + explicit InternalPageServer(SatelliteServerInfoPtr info) { InternalPageServerImplPtr server (new TypedServer (RuntimeOption::ServerIP, info->getPort(), info->getThreadCount(), @@ -124,7 +124,7 @@ private: class DanglingPageServer : public SatelliteServer { public: - DanglingPageServer(SatelliteServerInfoPtr info) { + explicit DanglingPageServer(SatelliteServerInfoPtr info) { m_server = ServerPtr (new TypedServer (RuntimeOption::ServerIP, info->getPort(), info->getThreadCount(), @@ -185,7 +185,7 @@ private: class RPCServer : public SatelliteServer { public: - RPCServer(SatelliteServerInfoPtr info) { + explicit RPCServer(SatelliteServerInfoPtr info) { m_server = ServerPtr(new RPCServerImpl(RuntimeOption::ServerIP, info)); } diff --git a/hphp/runtime/ext/ext_mysql.cpp b/hphp/runtime/ext/ext_mysql.cpp index 59d6195de..aed19c9f3 100644 --- a/hphp/runtime/ext/ext_mysql.cpp +++ b/hphp/runtime/ext/ext_mysql.cpp @@ -15,6 +15,8 @@ +----------------------------------------------------------------------+ */ +#include "folly/ScopeGuard.h" + #include #include #include @@ -1443,7 +1445,7 @@ Variant f_mysql_async_wait_actionable(CVarRef items, double timeout) { } struct pollfd* fds = (struct pollfd*)calloc(count, sizeof(struct pollfd)); - ScopeGuard fds_free([fds]() { free(fds); }); + SCOPE_EXIT { free(fds); }; // Walk our input, determine what kind of poll() operation is // necessary for the descriptor in question, and put an entry into diff --git a/hphp/util/alloc.cpp b/hphp/util/alloc.cpp index 17563dc59..29e0aee89 100644 --- a/hphp/util/alloc.cpp +++ b/hphp/util/alloc.cpp @@ -13,15 +13,15 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ +#include "util/alloc.h" #include -#include "alloc.h" #include #include #include -#include "util.h" -#include "logger.h" +#include "util/util.h" +#include "util/logger.h" namespace HPHP { namespace Util { /////////////////////////////////////////////////////////////////////////////// diff --git a/hphp/util/alloc.h b/hphp/util/alloc.h index f8d2595d7..436ce06ce 100644 --- a/hphp/util/alloc.h +++ b/hphp/util/alloc.h @@ -65,8 +65,8 @@ namespace HPHP { class OutOfMemoryException : public Exception { public: - OutOfMemoryException(size_t size) - : Exception("Unable to allocate %zu bytes of memory", size) {} + explicit OutOfMemoryException(size_t size) + : Exception("Unable to allocate %zu bytes of memory", size) {} virtual ~OutOfMemoryException() throw() {} EXCEPTION_COMMON_IMPL(OutOfMemoryException); }; diff --git a/hphp/util/asm-x64.cpp b/hphp/util/asm-x64.cpp index ab58f3f4a..994511522 100644 --- a/hphp/util/asm-x64.cpp +++ b/hphp/util/asm-x64.cpp @@ -13,6 +13,8 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ +#include "util/asm-x64.h" + #include #include #include @@ -24,7 +26,6 @@ #include #include "util/assertions.h" -#include "util/asm-x64.h" #include "util/maphuge.h" #include "runtime/base/runtime_option.h" diff --git a/hphp/util/asm-x64.h b/hphp/util/asm-x64.h index bf978bd31..99ca32d94 100644 --- a/hphp/util/asm-x64.h +++ b/hphp/util/asm-x64.h @@ -79,7 +79,7 @@ struct Reg64 { // Implicit conversion for backward compatability only. This is // needed to keep the store_reg##_disp_reg## style apis working. - constexpr operator RegNumber() const { return RegNumber(rn); } + constexpr /* implicit */ operator RegNumber() const { return RegNumber(rn); } // Integer conversion is allowed but only explicitly. (It's not // unusual to want to printf registers, etc. Just cast it first.) @@ -101,7 +101,7 @@ private: #define SIMPLE_REGTYPE(What) \ struct What { \ explicit constexpr What(int rn) : rn(rn) {} \ - explicit constexpr operator RegNumber() const { \ + explicit constexpr /* implicit */ operator RegNumber() const { \ return RegNumber(rn); \ } \ explicit constexpr operator int() const { return rn; } \ @@ -440,14 +440,6 @@ namespace reg { ////////////////////////////////////////////////////////////////////// -static inline void -atomic_store64(volatile uint64_t* dest, uint64_t value) { - // gcc on x64 will implement this with a 64-bit store, and - // normal 64-bit stores don't tear across instruction boundaries - // assuming all 8 bytes of dest are on the same cacheline. - *dest = value; -} - /* * Note that CodeAddresses are not const; the whole point is that we intend * to mutate them. uint8_t is as good a type as any: instructions are @@ -574,7 +566,12 @@ struct DataBlock { for (size_t i = 0; i < n; ++i) { u.bytes[i] = bs[i]; } - atomic_store64((uint64_t*)frontier, u.qword); + + // If this address doesn't span cache lines, on x64 this is an + // atomic store. We're not using atomic_release_store() because + // this code path occurs even when it may span cache lines, and + // that function asserts about this. + *reinterpret_cast(frontier) = u.qword; } else { memcpy(frontier, bs, n); } diff --git a/hphp/util/async_job.h b/hphp/util/async_job.h index ab9879498..7c67a3f01 100644 --- a/hphp/util/async_job.h +++ b/hphp/util/async_job.h @@ -39,9 +39,10 @@ class WorkerInfo { template class WorkerWrapper { public: - WorkerWrapper(JobDispatcher &dispatcher) - : m_dispatcher(dispatcher), - m_func(this, &WorkerWrapper::doJob) { + explicit WorkerWrapper(JobDispatcher &dispatcher) + : m_dispatcher(dispatcher) + , m_func(this, &WorkerWrapper::doJob) + { if (!WorkerInfo::DoInit) { m_func.setNoInit(); } diff --git a/hphp/util/base.h b/hphp/util/base.h index 52f646c3d..2fbf43060 100644 --- a/hphp/util/base.h +++ b/hphp/util/base.h @@ -263,14 +263,18 @@ public: hphp_raw_ptr() : px(0) {} explicit hphp_raw_ptr(T *p) : px(p) {} - hphp_raw_ptr(const boost::weak_ptr &p) : px(p.lock().get()) {} + /* implicit */ hphp_raw_ptr(const boost::weak_ptr &p) + : px(p.lock().get()) + {} template - hphp_raw_ptr(const boost::shared_ptr &p) : px(p.get()) {} + /* implicit */ hphp_raw_ptr(const boost::shared_ptr &p) : px(p.get()) {} template - hphp_raw_ptr(const boost::weak_ptr &p) : px(p.lock().get()) {} + /* implicit */ hphp_raw_ptr(const boost::weak_ptr &p) + : px(p.lock().get()) + {} template - hphp_raw_ptr(const hphp_raw_ptr &p) : px(p.get()) {} + /* implicit */ hphp_raw_ptr(const hphp_raw_ptr &p) : px(p.get()) {} boost::shared_ptr lock() const { return px ? boost::static_pointer_cast(px->shared_from_this()) : @@ -281,7 +285,7 @@ public: } template - operator boost::shared_ptr() const { + /* implicit */ operator boost::shared_ptr() const { S *s = px; // just to verify the implicit conversion T->S return s ? boost::static_pointer_cast(px->shared_from_this()) : boost::shared_ptr(); @@ -289,7 +293,7 @@ public: T *operator->() const { assert(px); return px; } T *get() const { return px; } - operator bool() const { return !expired(); } + explicit operator bool() const { return !expired(); } void reset() { px = 0; } private: T *px; @@ -448,18 +452,6 @@ destroyMapValues(Container& c) { } } -// Arbitrary callback when a scope exits. -struct ScopeGuard { - typedef std::tr1::function Callback; - - ScopeGuard(void(*cbFptr)()) : m_cb(Callback(cbFptr)) { } - ScopeGuard(Callback cb) : m_cb(cb) { } - ~ScopeGuard() { m_cb(); } -private: - Callback m_cb; -}; - - /////////////////////////////////////////////////////////////////////////////// // boost diff --git a/hphp/util/biased_coin.h b/hphp/util/biased_coin.h index dd4682075..699c85d14 100644 --- a/hphp/util/biased_coin.h +++ b/hphp/util/biased_coin.h @@ -28,7 +28,10 @@ class BiasedCoin { unsigned m_state; public: - BiasedCoin(double pct, unsigned seed = -1u) : m_seed(seed), m_pct(pct) { + explicit BiasedCoin(double pct, unsigned seed = -1u) + : m_seed(seed) + , m_pct(pct) + { assert(pct <= 100.0); if (seed == -1u) { seed = getpid(); diff --git a/hphp/util/cronoutils.h b/hphp/util/cronoutils.h index 23e9a75b9..2c1a1fdd8 100644 --- a/hphp/util/cronoutils.h +++ b/hphp/util/cronoutils.h @@ -71,7 +71,8 @@ * NEED_GETOPT_DEFS can be defined and declarations are provided here. */ -#if !defined(_CRONOUTILS_H_) +#ifndef incl_HPHP_CRONOUTILS_H_ +#define incl_HPHP_CRONOUTILS_H_ /* Header files */ diff --git a/hphp/util/db_conn.h b/hphp/util/db_conn.h index 001facbd0..8af101e07 100644 --- a/hphp/util/db_conn.h +++ b/hphp/util/db_conn.h @@ -110,7 +110,7 @@ class DBConn { static unsigned int DefaultReadTimeout; public: - DBConn(int maxRetryOpenOnFail = 0, int maxRetryQueryOnFail = 1); + explicit DBConn(int maxRetryOpenOnFail = 0, int maxRetryQueryOnFail = 1); ~DBConn(); /** diff --git a/hphp/util/db_dataset.h b/hphp/util/db_dataset.h index 6098b92aa..85b5bb12b 100644 --- a/hphp/util/db_dataset.h +++ b/hphp/util/db_dataset.h @@ -57,7 +57,8 @@ class DBDataSet : public DataSet { virtual int getFieldLength(int field) const; private: - DBDataSet(DBDataSet &ds) { assert(false);} // no copy constructor + DBDataSet(const DBDataSet &ds) = delete; + DBDataSet& operator=(const DBDataSet&) = delete; typedef std::list ResultList; ResultList m_results; diff --git a/hphp/util/db_filter.h b/hphp/util/db_filter.h index 8c8c781c3..ab66c7bc5 100644 --- a/hphp/util/db_filter.h +++ b/hphp/util/db_filter.h @@ -91,7 +91,7 @@ class DBInStringFilter : public DBQueryFilter { /** * We need a connection object to escape strings. */ - DBInStringFilter(DBConn *conn); + explicit DBInStringFilter(DBConn *conn); /** * Just keep adding strings to the filter. diff --git a/hphp/util/disasm.cpp b/hphp/util/disasm.cpp index a6bd4e349..63783a143 100644 --- a/hphp/util/disasm.cpp +++ b/hphp/util/disasm.cpp @@ -13,6 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ +#include "util/disasm.h" #include #include @@ -22,7 +23,6 @@ #include "folly/Format.h" #include "folly/ScopeGuard.h" -#include "util/disasm.h" #include "util/base.h" #include "util/text_color.h" diff --git a/hphp/util/disasm.h b/hphp/util/disasm.h index c6356d2e1..6f331da2c 100644 --- a/hphp/util/disasm.h +++ b/hphp/util/disasm.h @@ -13,7 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ -#ifndef incl_HPHP_UTIL_DISAASM_H_ +#ifndef incl_HPHP_UTIL_DISASM_H_ #define incl_HPHP_UTIL_DISASM_H_ #ifdef HAVE_LIBXED diff --git a/hphp/util/embedded_vfs.cpp b/hphp/util/embedded_vfs.cpp index b4530a939..71ac6e686 100644 --- a/hphp/util/embedded_vfs.cpp +++ b/hphp/util/embedded_vfs.cpp @@ -13,6 +13,7 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ +#include "util/embedded_vfs.h" /* * based on test_demovfs.c and test_multiplex.c in sqlite3 @@ -28,7 +29,6 @@ #include #include -#include "embedded_vfs.h" #ifndef SQLITE_CORE #define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */ diff --git a/hphp/util/exception.h b/hphp/util/exception.h index 4c7d073aa..2e4ffda92 100644 --- a/hphp/util/exception.h +++ b/hphp/util/exception.h @@ -61,7 +61,7 @@ public: struct Deleter { Exception* m_e; Deleter() : m_e(nullptr) {} - Deleter(Exception* e) : m_e(e) {} + explicit Deleter(Exception* e) : m_e(e) {} ~Deleter() { delete m_e; } }; @@ -82,7 +82,7 @@ protected: class FileOpenException : public Exception { public: - FileOpenException(const char *filename) + explicit FileOpenException(const char *filename) : Exception("Unable to open file %s", filename) { } @@ -95,8 +95,8 @@ class VMSwitchModeException : public Exception { private: bool m_unwindBuiltin; public: - VMSwitchModeException(bool m_unwindBuiltin) - : m_unwindBuiltin(m_unwindBuiltin) {} + explicit VMSwitchModeException(bool unwindBuiltin) + : m_unwindBuiltin(unwindBuiltin) {} bool unwindBuiltin() const { return m_unwindBuiltin; } EXCEPTION_COMMON_IMPL(VMSwitchModeException); diff --git a/hphp/util/hdf.h b/hphp/util/hdf.h index a41dbcc0b..cac7fc189 100644 --- a/hphp/util/hdf.h +++ b/hphp/util/hdf.h @@ -46,12 +46,12 @@ public: /** * Constructors. */ - Hdf(); // create an empty HDF tree - Hdf(const char *filename); // open the specified file - Hdf(const std::string &filename); // open the specified file - Hdf(const Hdf *hdf, const char *name); // constructing a sub-node (internal) - Hdf(const Hdf &hdf); // make a copy by reference (internal) - Hdf(HDF *hdf); // attaching a raw pointer (internal) + Hdf(); // create an empty HDF tree + explicit Hdf(const char *filename); // open the specified file + explicit Hdf(const std::string &filename); // open the specified file + explicit Hdf(const Hdf *hdf, const char *name); // constructing a sub-node + Hdf(const Hdf &hdf); // make a copy by reference + explicit Hdf(HDF *hdf); // attaching a raw pointer ~Hdf(); /** @@ -135,19 +135,6 @@ public: void get(std::map &values) const; void get(hphp_string_imap &values) const; - operator const char *() const { return get();} - operator std::string() const { return getString();} - operator bool () const { return getBool() ;} - operator char () const { return getByte() ;} - operator uchar () const { return getUByte() ;} - operator int16_t () const { return getInt16() ;} - operator uint16_t () const { return getUInt16();} - operator int32_t () const { return getInt32() ;} - operator uint32_t () const { return getUInt32();} - operator int64_t () const { return getInt64() ;} - operator uint64_t () const { return getUInt64();} - operator double () const { return getDouble();} - /** * Set this node's value. */ @@ -396,7 +383,7 @@ public: */ class HdfDataValueException : public HdfException { public: - HdfDataValueException(const Hdf *hdf, const char *expected = "") + explicit HdfDataValueException(const Hdf *hdf, const char *expected = "") : HdfException("HDF node [%s]'s value \"%s\" is not expected %s", hdf->getFullPath().c_str(), hdf->get(""), expected) { } @@ -408,7 +395,7 @@ public: */ class HdfInvalidOperation : public HdfException { public: - HdfInvalidOperation(const char *operation) + explicit HdfInvalidOperation(const char *operation) : HdfException("Invalid operation: %s", operation) { } EXCEPTION_COMMON_IMPL(HdfInvalidOperation); diff --git a/hphp/util/json.h b/hphp/util/json.h index 4a2440966..b5b8eb247 100644 --- a/hphp/util/json.h +++ b/hphp/util/json.h @@ -55,11 +55,11 @@ public: class Name { public: - Name(const char *name) { + explicit Name(const char *name) { assert(name && *name); m_name = name; } - Name(const std::string &name) { + explicit Name(const std::string &name) { assert(!name.empty()); m_name = name; } @@ -193,7 +193,7 @@ private: template class _MapStream { public: - _MapStream(_OutputStream &jout) + explicit _MapStream(_OutputStream &jout) : m_out(jout.raw()), m_jout(jout), m_first(true) {} template @@ -234,7 +234,7 @@ private: template class _ListStream { public: - _ListStream(_OutputStream &jout) + explicit _ListStream(_OutputStream &jout) : m_out(jout.raw()), m_jout(jout), m_first(true) {} void next() { diff --git a/hphp/util/kernel_version.h b/hphp/util/kernel_version.h index 81339101c..10ffbd2a7 100644 --- a/hphp/util/kernel_version.h +++ b/hphp/util/kernel_version.h @@ -26,7 +26,7 @@ struct KernelVersion { int m_dash; int m_fbk; KernelVersion(); // Use uname - KernelVersion(const char*); // A known kernel version for cmp. + explicit KernelVersion(const char*); // A known kernel version for cmp. static int cmp(const KernelVersion& l, const KernelVersion& r) { #define C(field) if (l.field != r.field) return l.field - r.field; C(m_major); diff --git a/hphp/util/lock.h b/hphp/util/lock.h index feaf1b282..2d7919b0f 100644 --- a/hphp/util/lock.h +++ b/hphp/util/lock.h @@ -34,7 +34,7 @@ public: static bool s_profile; static int s_profile_sampling; - LockProfiler(bool profile); + explicit LockProfiler(bool profile); ~LockProfiler(); private: @@ -96,23 +96,23 @@ public: */ class Lock : public ConditionalLock { public: - Lock(Mutex &mutex, bool profile = true) + explicit Lock(Mutex &mutex, bool profile = true) : ConditionalLock(mutex, true, profile) {} - Lock(Synchronizable *obj, bool profile = true) + explicit Lock(Synchronizable *obj, bool profile = true) : ConditionalLock(obj, true, profile) {} - Lock(SynchronizableMulti *obj, bool profile = true) + explicit Lock(SynchronizableMulti *obj, bool profile = true) : ConditionalLock(obj, true, profile) {} }; class ScopedUnlock { public: - ScopedUnlock(Mutex &mutex) : m_mutex(mutex) { + explicit ScopedUnlock(Mutex &mutex) : m_mutex(mutex) { m_mutex.unlock(); } - ScopedUnlock(Synchronizable *obj) : m_mutex(obj->getMutex()) { + explicit ScopedUnlock(Synchronizable *obj) : m_mutex(obj->getMutex()) { m_mutex.unlock(); } - ScopedUnlock(SynchronizableMulti *obj) : m_mutex(obj->getMutex()) { + explicit ScopedUnlock(SynchronizableMulti *obj) : m_mutex(obj->getMutex()) { m_mutex.unlock(); } @@ -138,7 +138,7 @@ public: class SimpleLock : public SimpleConditionalLock { public: - SimpleLock(SimpleMutex &mutex, bool profile = true) + explicit SimpleLock(SimpleMutex &mutex, bool profile = true) : SimpleConditionalLock(mutex, true, profile) {} }; @@ -169,13 +169,13 @@ private: class ReadLock : public ConditionalReadLock { public: - ReadLock(ReadWriteMutex &mutex, bool profile = true) + explicit ReadLock(ReadWriteMutex &mutex, bool profile = true) : ConditionalReadLock(mutex, true, profile) {} }; class WriteLock { public: - WriteLock(ReadWriteMutex &mutex, bool profile = true) + explicit WriteLock(ReadWriteMutex &mutex, bool profile = true) : m_profiler(profile), m_mutex(mutex) { m_mutex.acquireWrite(); } diff --git a/hphp/util/logger.h b/hphp/util/logger.h index 8cf4f914a..aa8315d9b 100644 --- a/hphp/util/logger.h +++ b/hphp/util/logger.h @@ -32,7 +32,11 @@ class Exception; class LogFileData { public: LogFileData() : log(nullptr), bytesWritten(0), prevBytesWritten(0) {} - LogFileData(FILE *f) : log(f), bytesWritten(0), prevBytesWritten(0) {} + explicit LogFileData(FILE *f) + : log(f) + , bytesWritten(0) + , prevBytesWritten(0) + {} LogFileData(const LogFileData& rhs) : log(rhs.log), prevBytesWritten(rhs.prevBytesWritten) { bytesWritten.store(rhs.bytesWritten.load()); diff --git a/hphp/util/maphuge.h b/hphp/util/maphuge.h index b47e0bf71..71c8384bc 100644 --- a/hphp/util/maphuge.h +++ b/hphp/util/maphuge.h @@ -13,6 +13,11 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ +#ifndef incl_HPHP_MAPHUGE_H_ +#define incl_HPHP_MAPHUGE_H_ + namespace HPHP { void hintHuge(void* mem, size_t length); } + +#endif diff --git a/hphp/util/mutex.h b/hphp/util/mutex.h index 5f4e58f8c..e3654a7d3 100644 --- a/hphp/util/mutex.h +++ b/hphp/util/mutex.h @@ -95,7 +95,7 @@ public: #endif } public: - BaseMutex(bool recursive = true, Rank r = RankUnranked) { + explicit BaseMutex(bool recursive = true, Rank r = RankUnranked) { pthread_mutexattr_init(&m_mutexattr); if (recursive) { pthread_mutexattr_settype(&m_mutexattr, PTHREAD_MUTEX_RECURSIVE); @@ -189,7 +189,7 @@ protected: */ class Mutex : public BaseMutex { public: - Mutex(bool recursive = true, Rank rank = RankUnranked) : + explicit Mutex(bool recursive = true, Rank rank = RankUnranked) : BaseMutex(recursive, rank) {} pthread_mutex_t &getRaw() { return m_mutex; } }; @@ -200,7 +200,7 @@ public: */ class SimpleMutex : public BaseMutex { public: - SimpleMutex(bool recursive = true, Rank rank = RankUnranked) : + explicit SimpleMutex(bool recursive = true, Rank rank = RankUnranked) : BaseMutex(recursive, rank) {} }; @@ -211,7 +211,7 @@ class SpinLock { Rank m_rank; #endif public: - SpinLock(Rank rank = RankUnranked) + explicit SpinLock(Rank rank = RankUnranked) #ifdef DEBUG : m_rank(rank) #endif @@ -283,7 +283,7 @@ class ReadWriteMutex { } public: - ReadWriteMutex(Rank rank = RankUnranked) + explicit ReadWriteMutex(Rank rank = RankUnranked) #ifdef DEBUG : m_rank(rank) #endif diff --git a/hphp/util/repo_schema.h b/hphp/util/repo_schema.h index 52a6cb690..e3dd3d797 100644 --- a/hphp/util/repo_schema.h +++ b/hphp/util/repo_schema.h @@ -13,6 +13,8 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ +#ifndef incl_HPHP_REPO_SCHEMA_H_ +#define incl_HPHP_REPO_SCHEMA_H_ namespace HPHP { @@ -25,3 +27,5 @@ extern const char* kRepoSchemaId; ////////////////////////////////////////////////////////////////////// } + +#endif diff --git a/hphp/util/shared_memory_allocator.h b/hphp/util/shared_memory_allocator.h index 6a7077704..082ed8e69 100644 --- a/hphp/util/shared_memory_allocator.h +++ b/hphp/util/shared_memory_allocator.h @@ -220,7 +220,7 @@ public: return boost::interprocess::named_mutex::remove(name); } - SharedMemoryLock(const char *name) { + explicit SharedMemoryLock(const char *name) { assert(name && *name); m_mutex = new boost::interprocess::named_mutex (boost::interprocess::open_or_create, name); diff --git a/hphp/util/shm_counter.h b/hphp/util/shm_counter.h index 0fde23d2b..f62d9fdc5 100644 --- a/hphp/util/shm_counter.h +++ b/hphp/util/shm_counter.h @@ -32,7 +32,7 @@ namespace HPHP { class ShmCounter { public: ShmCounter() {} - ShmCounter(const char *n) : count(0) { + explicit ShmCounter(const char *n) : count(0) { size_t size = sizeof(name); strncpy(name, n, size); name[size - 1] = '\0'; diff --git a/hphp/util/stack_trace.h b/hphp/util/stack_trace.h index d332f17ee..893d6fc05 100644 --- a/hphp/util/stack_trace.h +++ b/hphp/util/stack_trace.h @@ -31,7 +31,7 @@ public: DECLARE_BOOST_TYPES(Frame); class Frame { public: - Frame(void *_bt) : bt(_bt), lineno(0), offset(0) {} + explicit Frame(void *_bt) : bt(_bt), lineno(0), offset(0) {} void *bt; int lineno; @@ -71,7 +71,7 @@ public: DECLARE_BOOST_TYPES(Frame); class Frame : public StackTraceBase::Frame { public: - Frame(void *_bt) : StackTraceBase::Frame(_bt) {} + explicit Frame(void *_bt) : StackTraceBase::Frame(_bt) {} std::string filename; std::string funcname; std::string toString() const; @@ -79,7 +79,7 @@ public: public: - StackTrace(bool trace = true) ; + explicit StackTrace(bool trace = true) ; /** * Translate a frame pointer to file name and line number pair. @@ -100,9 +100,8 @@ public: /** * Constructing from hexEncode() results. */ - StackTrace(const std::string &hexEncoded); - - StackTrace(const char *hexEncoded); + explicit StackTrace(const std::string &hexEncoded); + explicit StackTrace(const char *hexEncoded); /** * Generate an output of the written stack trace. @@ -138,7 +137,7 @@ public: * Constructor, and this will save current stack trace if trace is true. * It can be false for an empty stacktrace. */ - StackTraceNoHeap(bool trace = true) ; + explicit StackTraceNoHeap(bool trace = true); /** * Log stacktrace into a file under /tmp. If "out" is not null, diff --git a/hphp/util/string_bag.h b/hphp/util/string_bag.h index 2c5c61d64..d9be37e91 100644 --- a/hphp/util/string_bag.h +++ b/hphp/util/string_bag.h @@ -28,7 +28,7 @@ namespace HPHP { */ class StringBag { public: - StringBag(int reserve_count = 0); + explicit StringBag(int reserve_count = 0); ~StringBag(); const char *add(const char *s); diff --git a/hphp/util/synchronizable.cpp b/hphp/util/synchronizable.cpp index bed6eeed1..2d6ace280 100644 --- a/hphp/util/synchronizable.cpp +++ b/hphp/util/synchronizable.cpp @@ -13,10 +13,10 @@ | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ */ +#include "util/synchronizable.h" -#include "compatibility.h" -#include "rank.h" -#include "synchronizable.h" +#include "util/compatibility.h" +#include "util/rank.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// diff --git a/hphp/util/synchronizable_multi.h b/hphp/util/synchronizable_multi.h index 1cd74542c..d5362266e 100644 --- a/hphp/util/synchronizable_multi.h +++ b/hphp/util/synchronizable_multi.h @@ -17,9 +17,9 @@ #ifndef incl_HPHP_SYNCHRONIZABLE_MULTI_H_ #define incl_HPHP_SYNCHRONIZABLE_MULTI_H_ -#include "base.h" -#include "mutex.h" -#include "rank.h" +#include "util/base.h" +#include "util/mutex.h" +#include "util/rank.h" namespace HPHP { /////////////////////////////////////////////////////////////////////////////// @@ -32,7 +32,7 @@ namespace HPHP { */ class SynchronizableMulti { public: - SynchronizableMulti(int size); + explicit SynchronizableMulti(int size); virtual ~SynchronizableMulti(); /**