Bug 1350500 - Allow passing nullptr for aLog in AutoObjectMapperPOSIX. r?jseward
MozReview-Commit-ID: q4AOPRsBee
--- a/tools/profiler/lul/AutoObjectMapper.cpp
+++ b/tools/profiler/lul/AutoObjectMapper.cpp
@@ -38,16 +38,20 @@
// A helper function for creating failure error messages in
// AutoObjectMapper*::Map.
static void
failedToMessage(void(*aLog)(const char*),
const char* aHowFailed, std::string aFileName)
{
+ if (!aLog) {
+ return;
+ }
+
char buf[300];
SprintfLiteral(buf, "AutoObjectMapper::Map: Failed to %s \'%s\'",
aHowFailed, aFileName.c_str());
buf[sizeof(buf)-1] = 0;
aLog(buf);
}
--- a/tools/profiler/lul/AutoObjectMapper.h
+++ b/tools/profiler/lul/AutoObjectMapper.h
@@ -17,17 +17,17 @@
// functions: open, fstat, close, mmap, munmap.
class MOZ_STACK_CLASS AutoObjectMapperPOSIX {
public:
// The constructor does not attempt to map the file, because that
// might fail. Instead, once the object has been constructed,
// call Map() to attempt the mapping. There is no corresponding
// Unmap() since the unmapping is done in the destructor. Failure
- // messages are sent to |aLog|.
+ // messages are sent to |aLog|, if |aLog| is non-null.
explicit AutoObjectMapperPOSIX(void(*aLog)(const char*));
// Unmap the file on destruction of this object.
~AutoObjectMapperPOSIX();
// Map |fileName| into the address space and return the mapping
// extents. If the file is zero sized this will fail. The file is
// mapped read-only and private. Returns true iff the mapping
@@ -37,17 +37,17 @@ public:
bool Map(/*OUT*/void** start, /*OUT*/size_t* length, std::string fileName);
protected:
// If we are currently holding a mapped object, these record the
// mapped address range.
void* mImage;
size_t mSize;
- // A logging sink, for complaining about mapping failures.
+ // A logging sink, for complaining about mapping failures. Can be null.
void (*mLog)(const char*);
private:
// Are we currently holding a mapped object? This is private to
// the base class. Derived classes need to have their own way to
// track whether they are holding a mapped object.
bool mIsMapped;