Bug 1350500 - Allow passing nullptr for aLog in AutoObjectMapperPOSIX. r?jseward draft
authorMarkus Stange <mstange@themasta.com>
Wed, 10 May 2017 15:30:46 -0400
changeset 575778 446db90c41bd7c0fd640bcebca3aeb9084072b58
parent 575474 ebbcdaa5b5802ecd39624dd2acbdda8547b8384d
child 575779 81b3327241c778fbdc1b5cf9903015281073d31d
push id58162
push userbmo:mstange@themasta.com
push dateWed, 10 May 2017 21:00:27 +0000
reviewersjseward
bugs1350500
milestone55.0a1
Bug 1350500 - Allow passing nullptr for aLog in AutoObjectMapperPOSIX. r?jseward MozReview-Commit-ID: q4AOPRsBee
tools/profiler/lul/AutoObjectMapper.cpp
tools/profiler/lul/AutoObjectMapper.h
--- 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;