Bug 784739 - Switch from NULL to nullptr in js/src/devtools/vprof/ and tools/{jprof,trace-malloc}/; r=ehsan
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Mon, 06 Jan 2014 10:07:38 -0500
changeset 162189 5954f2857de4a9d9d39f147279e33b9691da3051
parent 162188 7ebd1e1a81978681ebe38d5af517b568e4b46aee
child 162190 6c4c65228af1b71e1daa3ae3c737957836d693d2
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs784739
milestone29.0a1
Bug 784739 - Switch from NULL to nullptr in js/src/devtools/vprof/ and tools/{jprof,trace-malloc}/; r=ehsan
js/src/devtools/vprof/vprof.cpp
tools/jprof/bfd.cpp
tools/jprof/coff.cpp
tools/jprof/leaky.cpp
tools/jprof/stub/libmalloc.cpp
tools/trace-malloc/leaksoup.cpp
--- a/js/src/devtools/vprof/vprof.cpp
+++ b/js/src/devtools/vprof/vprof.cpp
@@ -48,17 +48,17 @@
 #if THREAD_SAFE
 #define LOCK(lock) DO_LOCK(lock)
 #define UNLOCK(lock) DO_UNLOCK(lock)
 #else
 #define LOCK(lock) { (void)(lock);
 #define UNLOCK(lock) }
 #endif
 
-static entry* entries = NULL;
+static entry* entries = nullptr;
 static bool notInitialized = true;
 static long glock = LOCK_IS_FREE;
 
 #define Lock(lock) while (_InterlockedCompareExchange(lock, LOCK_IS_TAKEN, LOCK_IS_FREE) == LOCK_IS_TAKEN){};
 #define Unlock(lock) _InterlockedCompareExchange(lock, LOCK_IS_FREE, LOCK_IS_TAKEN);
 
 #if defined(WIN32)
 	static void vprof_printf(const char* format, ...)
@@ -77,17 +77,17 @@ static long glock = LOCK_IS_FREE;
 #else
 	#define vprof_printf printf
 #endif
 
 static inline entry* reverse (entry* s)
 {
     entry_t e, n, p;
 
-    p = NULL;
+    p = nullptr;
     for (e = s; e; e = n) {
         n = e->next;
         e->next = p;
         p = e;
     }
 
     return p;
 }
@@ -153,56 +153,56 @@ static void dumpProfile (void)
 
 static inline entry_t findEntry (char* file, int line)
 {
     for (entry_t e =  entries; e; e = e->next) {
         if ((e->line == line) && (VMPI_strcmp (e->file, file) == 0)) {
             return e;
         }
     }
-    return NULL;
+    return nullptr;
 }
 
 // Initialize the location pointed to by 'id' to a new value profile entry
 // associated with 'file' and 'line', or do nothing if already initialized.
 // An optional final argument provides a user-defined probe function.
 
 int initValueProfile(void** id, char* file, int line, ...)
 {
     DO_LOCK (&glock);
         entry_t e = (entry_t) *id;
         if (notInitialized) {
             atexit (dumpProfile);
             notInitialized = false;
         }
 
-        if (e == NULL) {
+        if (e == nullptr) {
             e = findEntry (file, line);
             if (e) {
                 *id = e;
             }
         }
 
-        if (e == NULL) {
+        if (e == nullptr) {
             va_list va;
             e = (entry_t) malloc (sizeof(entry));
             e->lock = LOCK_IS_FREE;
             e->file = file;
             e->line = line;
             e->value = 0;
             e->sum = 0;
             e->count = 0;
             e->min = 0;
             e->max = 0;
             // optional probe function argument
             va_start (va, line);
             e->func = (void (__cdecl*)(void*)) va_arg (va, void*);
             va_end (va);
-            e->h = NULL;
-            e->genptr = NULL;
+            e->h = nullptr;
+            e->genptr = nullptr;
             VMPI_memset (&e->ivar,   0, sizeof(e->ivar));
             VMPI_memset (&e->i64var, 0, sizeof(e->i64var));
             VMPI_memset (&e->dvar,   0, sizeof(e->dvar));
             e->next = entries;
             entries = e;
             *id = e;
         }
     DO_UNLOCK (&glock);
@@ -242,39 +242,39 @@ int initHistProfile(void** id, char* fil
 {
     DO_LOCK (&glock);
         entry_t e = (entry_t) *id;
         if (notInitialized) {
             atexit (dumpProfile);
             notInitialized = false;
         }
 
-        if (e == NULL) {
+        if (e == nullptr) {
             e = findEntry (file, line);
             if (e) {
                 *id = e;
             }
         }
 
-        if (e == NULL) {
+        if (e == nullptr) {
             va_list va;
             hist_t h;
             int b, n, s;
             int64_t* lb;
 
             e = (entry_t) malloc (sizeof(entry));
             e->lock = LOCK_IS_FREE;
             e->file = file;
             e->line = line;
             e->value = 0;
             e->sum = 0;
             e->count = 0;
             e->min = 0;
             e->max = 0;
-            e->func = NULL;
+            e->func = nullptr;
             e->h = h = (hist_t) malloc (sizeof(hist));
             n = 1+MAX(nbins,0);
             h->nbins = n-1;
             s = n*sizeof(int64_t);
             lb = (int64_t*) malloc (s);
             h->lb = lb;
             VMPI_memset (h->lb, 0, s);
             h->count = (int64_t*) malloc (s);
@@ -283,17 +283,17 @@ int initHistProfile(void** id, char* fil
             va_start (va, nbins);
             for (b = 0; b < nbins; b++) {
                 //lb[b] = va_arg (va, int64_t);
                 lb[b] = va_arg (va, int);
             }
             lb[b] = MAXINT64;
             va_end (va);
 
-            e->genptr = NULL;
+            e->genptr = nullptr;
             VMPI_memset (&e->ivar,   0, sizeof(e->ivar));
             VMPI_memset (&e->i64var, 0, sizeof(e->i64var));
             VMPI_memset (&e->dvar,   0, sizeof(e->dvar));
             e->next = entries;
             entries = e;
             *id = e;
         }
     DO_UNLOCK (&glock);
--- a/tools/jprof/bfd.cpp
+++ b/tools/jprof/bfd.cpp
@@ -13,50 +13,50 @@
 #include <libgen.h>
 #include <bfd.h>
 #include <cxxabi.h>
 
 static bfd *try_debug_file(const char *filename, unsigned long crc32)
 {
   int fd = open(filename, O_RDONLY);
   if (fd < 0)
-    return NULL;
+    return nullptr;
 
   unsigned char buf[4*1024];
   unsigned long crc = 0;
 
   while (1) {
     ssize_t count = read(fd, buf, sizeof(buf));
     if (count <= 0)
       break;
 
     crc = bfd_calc_gnu_debuglink_crc32(crc, buf, count);
   }
 
   close(fd);
 
   if (crc != crc32)
-    return NULL;
+    return nullptr;
 
-  bfd *object = bfd_openr(filename, NULL);
+  bfd *object = bfd_openr(filename, nullptr);
   if (!bfd_check_format(object, bfd_object)) {
     bfd_close(object);
-    return NULL;
+    return nullptr;
   }
 
   return object;
 }
 
 static bfd *find_debug_file(bfd *lib, const char *aFileName)
 {
   // check for a separate debug file with symbols
   asection *sect = bfd_get_section_by_name(lib, ".gnu_debuglink");
 
   if (!sect)
-    return NULL;
+    return nullptr;
 
   bfd_size_type debuglinkSize = bfd_section_size (objfile->obfd, sect);
 
   char *debuglink = new char[debuglinkSize];
   bfd_get_section_contents(lib, sect, debuglink, 0, debuglinkSize);
 
   // crc checksum is aligned to 4 bytes, and after the NUL.
   int crc_offset = (int(strlen(debuglink)) & ~3) + 4;
@@ -120,17 +120,17 @@ Symbol ** leaky::ExtendSymbols(int num)
                          if (sp >= lastSymbol) { \
                            sp = ExtendSymbols(16384); \
                          } \
                        } while (0)
 
 void leaky::ReadSymbols(const char *aFileName, u_long aBaseAddress)
 {
   int initialSymbols = usefulSymbols;
-  if (NULL == externalSymbols) {
+  if (nullptr == externalSymbols) {
     externalSymbols = (Symbol**) calloc(sizeof(Symbol*),10000);
     Symbol *new_array = new Symbol[10000];
     for (int i = 0; i < 10000; i++) {
       externalSymbols[i] = &new_array[i];
     }
     numExternalSymbols = 10000;
   }
   Symbol** sp = externalSymbols + usefulSymbols;
@@ -144,18 +144,18 @@ void leaky::ReadSymbols(const char *aFil
   bfd_boolean kDynamic = (bfd_boolean) false;
 
   static int firstTime = 1;
   if (firstTime) {
     firstTime = 0;
     bfd_init ();
   }
 
-  bfd* lib = bfd_openr(aFileName, NULL);
-  if (NULL == lib) {
+  bfd* lib = bfd_openr(aFileName, nullptr);
+  if (nullptr == lib) {
     return;
   }
   if (!bfd_check_format(lib, bfd_object)) {
     bfd_close(lib);
     return;
   }
 
   bfd *symbolFile = find_debug_file(lib, aFileName);
@@ -194,17 +194,17 @@ void leaky::ReadSymbols(const char *aFil
     sym = bfd_minisymbol_to_symbol(symbolFile, kDynamic, (const PTR) from, store);
 
     symbol_info syminfo;
     bfd_get_symbol_info (symbolFile, sym, &syminfo);
 
 //    if ((syminfo.type == 'T') || (syminfo.type == 't')) {
       const char* nm = bfd_asymbol_name(sym);
       if (nm && nm[0]) {
-        char* dnm = NULL;
+        char* dnm = nullptr;
         if (strncmp("__thunk", nm, 7)) {
           dnm = abi::__cxa_demangle(nm, 0, 0, 0);
         }
         (*sp)->Init(dnm ? dnm : nm, syminfo.value + aBaseAddress);
         if (dnm) {
           free(dnm);
         }
         NEXT_SYMBOL;
--- a/tools/jprof/coff.cpp
+++ b/tools/jprof/coff.cpp
@@ -33,17 +33,17 @@ static char *Demangle(char *rawName)
     return strdup(namebuf);
 #endif
 }
 
 void leaky::readSymbols(const char *fileName)
 {
     LDFILE *ldptr;
 
-    ldptr = ldopen(fileName, NULL);
+    ldptr = ldopen(fileName, nullptr);
     if (!ldptr) {
 	fprintf(stderr, "%s: unable to open \"%s\"\n", applicationName,
 		fileName);
 	exit(-1);
     }
     if (PSYMTAB(ldptr) == 0) {
 	fprintf(stderr, "%s: \"%s\": has no symbol table\n", applicationName,
 		fileName);
--- a/tools/jprof/leaky.cpp
+++ b/tools/jprof/leaky.cpp
@@ -54,17 +54,17 @@ int main(int argc, char** argv)
       l->outputfd = fopen(name,"w");
       // if an error we won't process the file
     }
     if (l->outputfd) { // paranoia
       l->open(argv[l->logFileIndex + i]);
 
       if (l->outputfd != stderr) {
         fclose(l->outputfd);
-        l->outputfd = NULL;
+        l->outputfd = nullptr;
       }
     }
   }
 
   return 0;
 }
 
 char *
@@ -110,18 +110,18 @@ htmlify(const char *in)
   } while (*p);
   *q = '\0';
 
   return out;
 }
 
 leaky::leaky()
 {
-  applicationName = NULL;
-  progFile = NULL;
+  applicationName = nullptr;
+  progFile = nullptr;
 
   quiet = true;
   showAddress = false;
   showThreads = false;
   stackDepth = 100000;
   onlyThread = 0;
   cleo = false;
 
@@ -130,17 +130,17 @@ leaky::leaky()
 
   sfd = -1;
   externalSymbols = 0;
   usefulSymbols = 0;
   numExternalSymbols = 0;
   lowestSymbolAddr = 0;
   highestSymbolAddr = 0;
 
-  loadMap = NULL;
+  loadMap = nullptr;
 
   collect_last  = false;
   collect_start = -1;
   collect_end   = -1;
 }
 
 leaky::~leaky()
 {
@@ -162,24 +162,24 @@ void leaky::usageError()
           "\t--output-dir dir: write output files to dir\n"
           "\tIf there's one log, output goes to stdout unless --output-dir is set\n"
           "\tIf there are more than one log, output files will be named with .html added\n"
           );
   exit(-1);
 }
 
 static struct option longopts[] = {
-    { "threads", 0, NULL, 't' },
-    { "only-thread", 1, NULL, 'T' },
-    { "last", 0, NULL, 'l' },
-    { "start", 1, NULL, 'x' },
-    { "end", 1, NULL, 'n' },
-    { "cleo",0, NULL, 'c' },
-    { "output-dir", 1, NULL, 'd' },
-    { NULL, 0, NULL, 0 },
+    { "threads", 0, nullptr, 't' },
+    { "only-thread", 1, nullptr, 'T' },
+    { "last", 0, nullptr, 'l' },
+    { "start", 1, nullptr, 'x' },
+    { "end", 1, nullptr, 'n' },
+    { "cleo",0, nullptr, 'c' },
+    { "output-dir", 1, nullptr, 'd' },
+    { nullptr, 0, nullptr, 0 },
 };
 
 void leaky::initialize(int argc, char** argv)
 {
   applicationName = argv[0];
   applicationName = strrchr(applicationName, '/');
   if (!applicationName) {
     applicationName = argv[0];
@@ -187,17 +187,17 @@ void leaky::initialize(int argc, char** 
     applicationName++;
   }
 
   int arg;
   int errflg = 0;
   int longindex = 0;
 
   onlyThread = 0;
-  output_dir = NULL;
+  output_dir = nullptr;
   cleo = false;
 
   // XXX tons of cruft here left over from tracemalloc
   // XXX The -- options shouldn't need short versions, or they should be documented
   while (((arg = getopt_long(argc, argv, "adEe:gh:i:r:Rs:tT:qvx:ln:",longopts,&longindex)) != -1)) {
     switch (arg) {
       case '?':
       default:
@@ -459,17 +459,17 @@ static int symbolOrder(void const* a, vo
   Symbol const** bp = (Symbol const **)b;
   return (*ap)->address == (*bp)->address ? 0 :
     ((*ap)->address > (*bp)->address ? 1 : -1);
 }
 
 void leaky::ReadSharedLibrarySymbols()
 {
   LoadMapEntry* lme = loadMap;
-  while (NULL != lme) {
+  while (nullptr != lme) {
     ReadSymbols(lme->name, lme->address);
     lme = lme->next;
   }
 }
 
 void leaky::setupSymbols(const char *fileName)
 {
   if (usefulSymbols == 0) {
@@ -521,17 +521,17 @@ int leaky::findSymbolIndex(u_long addr)
   return -1;
 }
 
 Symbol* leaky::findSymbol(u_long addr)
 {
   int idx = findSymbolIndex(addr);
 
   if(idx<0) {
-    return NULL;
+    return nullptr;
   } else {
     return externalSymbols[idx];
   }
 }
 
 //----------------------------------------------------------------------
 
 bool leaky::excluded(malloc_log_entry* lep)
--- a/tools/jprof/stub/libmalloc.cpp
+++ b/tools/jprof/stub/libmalloc.cpp
@@ -166,17 +166,17 @@ static void DumpAddressMap()
   {
     startSignalCounter(0);
   }
 
   int mfd = open(M_MAPFILE, O_CREAT|O_WRONLY|O_TRUNC, 0666);
   if (mfd >= 0) {
     malloc_map_entry mme;
     link_map* map = _r_debug.r_map;
-    while (NULL != map) {
+    while (nullptr != map) {
       if (map->l_name && *map->l_name) {
 	mme.nameLen = strlen(map->l_name);
 	mme.address = map->l_addr;
 	write(mfd, &mme, sizeof(mme));
 	write(mfd, map->l_name, mme.nameLen);
 #if 0
 	write(1, map->l_name, mme.nameLen);
 	write(1, "\n", 1);
@@ -434,34 +434,34 @@ static void startSignalCounter(unsigned 
     struct itimerval tvalue;
 
     tvalue.it_interval.tv_sec = 0;
     tvalue.it_interval.tv_usec = 0;
     tvalue.it_value.tv_sec = millisec/1000;
     tvalue.it_value.tv_usec = (millisec%1000)*1000;
 
     if (realTime) {
-	setitimer(ITIMER_REAL, &tvalue, NULL);
+        setitimer(ITIMER_REAL, &tvalue, nullptr);
     } else {
-    	setitimer(ITIMER_PROF, &tvalue, NULL);
+        setitimer(ITIMER_PROF, &tvalue, nullptr);
     }
 }
 
 static long timerMilliSec = 50;
 
 #if defined(linux)
 static int setupRTCSignals(int hz, struct sigaction *sap)
 {
     /* global */ rtcFD = open("/dev/rtc", O_RDONLY);
     if (rtcFD < 0) {
         perror("JPROF_RTC setup: open(\"/dev/rtc\", O_RDONLY)");
         return 0;
     }
 
-    if (sigaction(SIGIO, sap, NULL) == -1) {
+    if (sigaction(SIGIO, sap, nullptr) == -1) {
         perror("JPROF_RTC setup: sigaction(SIGIO)");
         return 0;
     }
 
     if (ioctl(rtcFD, RTC_IRQP_SET, hz) == -1) {
         perror("JPROF_RTC setup: ioctl(/dev/rtc, RTC_IRQP_SET, $JPROF_RTC_HZ)");
         return 0;
     }
@@ -612,17 +612,17 @@ NS_EXPORT_(void) setupProfilingStuff(voi
 		startTimer = 0;
 	    }
 	    if(strstr(tst, "JP_START")) doNotStart = 0;
 	    if(strstr(tst, "JP_REALTIME")) realTime = 1;
 	    if(strstr(tst, "JP_APPEND")) append = O_APPEND;
 
 	    char *delay = strstr(tst,"JP_PERIOD=");
 	    if(delay) {
-                double tmp = strtod(delay+strlen("JP_PERIOD="), NULL);
+                double tmp = strtod(delay+strlen("JP_PERIOD="), nullptr);
                 if (tmp>=1e-3) {
 		    timerMilliSec = static_cast<unsigned long>(1000 * tmp);
                 } else {
                     fprintf(stderr,
                             "JP_PERIOD of %g less than 0.001 (1ms), using 1ms\n",
                             tmp);
                     timerMilliSec = 1;
                 }
@@ -703,56 +703,56 @@ NS_EXPORT_(void) setupProfilingStuff(voi
 
 		    main_thread = pthread_self();
                     //fprintf(stderr,"jprof: main_thread = %u\n",
                     //        (unsigned int)main_thread);
 
                     // FIX!  probably should block these against each other
                     // Very unlikely.
 		    sigemptyset(&mset);
-		    action.sa_handler = NULL;
+		    action.sa_handler = nullptr;
 		    action.sa_sigaction = StackHook;
 		    action.sa_mask  = mset;
 		    action.sa_flags = SA_RESTART | SA_SIGINFO;
 #if defined(linux)
                     if (rtcHz) {
                         if (!setupRTCSignals(rtcHz, &action)) {
                             fputs("jprof: Error initializing RTC, NOT "
                                   "profiling\n", stderr);
                             return;
                         }
                     }
 
                     if (!rtcHz || firstDelay != 0)
 #endif
                     {
                         if (realTime) {
-                            sigaction(SIGALRM, &action, NULL);
+                            sigaction(SIGALRM, &action, nullptr);
                         }
                     }
                     // enable PROF in all cases to simplify JP_DEFER/pause/restart
-                    sigaction(SIGPROF, &action, NULL);
+                    sigaction(SIGPROF, &action, nullptr);
 
 		    // make it so a SIGUSR1 will stop the profiling
 		    // Note:  It currently does not close the logfile.
 		    // This could be configurable (so that it could
 		    // later be reopened).
 
 		    struct sigaction stop_action;
 		    stop_action.sa_handler = EndProfilingHook;
 		    stop_action.sa_mask  = mset;
 		    stop_action.sa_flags = SA_RESTART;
-		    sigaction(SIGUSR1, &stop_action, NULL);
+		    sigaction(SIGUSR1, &stop_action, nullptr);
 
 		    // make it so a SIGUSR2 will clear the circular buffer
 
 		    stop_action.sa_handler = ClearProfilingHook;
 		    stop_action.sa_mask  = mset;
 		    stop_action.sa_flags = SA_RESTART;
-		    sigaction(SIGUSR2, &stop_action, NULL);
+		    sigaction(SIGUSR2, &stop_action, nullptr);
 
                     printf("Jprof: Initialized signal handler and set "
                            "timer for %lu %s, %d s "
                            "initial delay\n",
                            rtcHz ? rtcHz : timerMilliSec, 
                            rtcHz ? "Hz" : "ms",
                            firstDelay);
 
--- a/tools/trace-malloc/leaksoup.cpp
+++ b/tools/trace-malloc/leaksoup.cpp
@@ -97,17 +97,17 @@ int main(int argc, char **argv)
     if (argc != 2) {
         fprintf(stderr,
                 "Expected usage:  %s <sd-leak-file>\n"
                 "  sd-leak-file: Output of --shutdown-leaks=<file> option.\n",
                 argv[0]);
         return 1;
     }
 
-    NS_InitXPCOM2(NULL, NULL, NULL);
+    NS_InitXPCOM2(nullptr, nullptr, nullptr);
 
     ADLog log;
     if (!log.Read(argv[1])) {
         fprintf(stderr,
                 "%s: Error reading input file %s.\n", argv[0], argv[1]);
     }
 
     const size_t count = log.count();
@@ -396,12 +396,12 @@ int main(int argc, char **argv)
         }
         printf("</body>\n"
                "</html>\n");
     }
 
     delete [] sorted_nodes;
     delete [] nodes;
 
-    NS_ShutdownXPCOM(NULL);
+    NS_ShutdownXPCOM(nullptr);
 
     return 0;
 }