changeset 17898:8c33abdd2f9a

maint: Avoid using NULL in C++ code. * qtinfo/parser.cc, profiler.cc, profiler.h, txt-eng-ft.cc, __init_fltk__.cc, ov-fcn-handle.cc, ov-java.cc, mkoctfile.in.cc: Avoid using NULL in C++ code.
author John W. Eaton <jwe@octave.org>
date Mon, 11 Nov 2013 01:49:57 -0500
parents 185038fe7a16
children 14c427b5c5c1
files libgui/src/qtinfo/parser.cc libinterp/corefcn/profiler.cc libinterp/corefcn/profiler.h libinterp/corefcn/txt-eng-ft.cc libinterp/dldfcn/__init_fltk__.cc libinterp/octave-value/ov-fcn-handle.cc libinterp/octave-value/ov-java.cc src/mkoctfile.in.cc
diffstat 8 files changed, 54 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/qtinfo/parser.cc	Sun Nov 10 21:10:41 2013 +0100
+++ b/libgui/src/qtinfo/parser.cc	Mon Nov 11 01:49:57 2013 -0500
@@ -76,14 +76,14 @@
 QIODevice *
 parser::open_file (QFileInfo & file_info)
 {
-  QIODevice *iodevice=NULL;
+  QIODevice *iodevice = 0;
   if ( _compressors_map.contains(file_info.suffix ()))
     {
       QProcess gzip;
       gzip.start (_compressors_map.value (file_info.suffix ()).arg (file_info.absoluteFilePath ()));
 
       if (!gzip.waitForFinished ())
-        return NULL;
+        return 0;
 
       QByteArray result = gzip.readAll ();
 
@@ -91,7 +91,7 @@
       io->setData (result);
 
       if (!io->open (QIODevice::ReadOnly | QIODevice::Text))
-        return NULL;
+        return 0;
 
       iodevice = io;
     }
@@ -99,7 +99,7 @@
     {
       QFile *io = new QFile (file_info.absoluteFilePath ());
       if (!io->open (QIODevice::ReadOnly | QIODevice::Text))
-        return NULL;
+        return 0;
       iodevice = io;
     }
 
@@ -140,7 +140,7 @@
       real_position (pos, file_info, realPos);
 
       QIODevice *io = open_file (file_info);
-      if (io == NULL)
+      if (! io)
         {
           return QString ();
         }
@@ -427,7 +427,7 @@
       QFileInfo fileInfo = _info_files.at (i);
 
       QIODevice *io = open_file (fileInfo);
-      if (io == NULL)
+      if (! io)
         {
           continue;
         }
@@ -572,7 +572,7 @@
     {
       QFileInfo file_info = _info_files.at (i);
       QIODevice *io = open_file (file_info);
-      if (io == NULL)
+      if (! io)
         {
           continue;
         }
--- a/libinterp/corefcn/profiler.cc	Sun Nov 10 21:10:41 2013 +0100
+++ b/libinterp/corefcn/profiler.cc	Mon Nov 11 01:49:57 2013 -0500
@@ -192,7 +192,7 @@
 
 profile_data_accumulator::profile_data_accumulator ()
   : known_functions (), fcn_index (),
-    enabled (false), call_tree (NULL), last_time (-1.0)
+    enabled (false), call_tree (0), last_time (-1.0)
 {}
 
 profile_data_accumulator::~profile_data_accumulator ()
@@ -208,7 +208,7 @@
     {
       // Create a call-tree top-node if there isn't yet one.
       if (!call_tree)
-        call_tree = new tree_node (NULL, 0);
+        call_tree = new tree_node (0, 0);
 
       // Let the top-node be the active one.  This ensures we have a clean
       // fresh start collecting times.
@@ -287,7 +287,7 @@
   if (call_tree)
     {
       delete call_tree;
-      call_tree = NULL;
+      call_tree = 0;
     }
 
   last_time = -1.0;
--- a/libinterp/corefcn/profiler.h	Sun Nov 10 21:10:41 2013 +0100
+++ b/libinterp/corefcn/profiler.h	Mon Nov 11 01:49:57 2013 -0500
@@ -118,7 +118,7 @@
     // Get the hierarchical profile for this node and its children.  If total
     // is set, accumulate total time of the subtree in that variable as
     // additional return value.
-    octave_value get_hierarchical (double* total = NULL) const;
+    octave_value get_hierarchical (double* total = 0) const;
 
   private:
 
--- a/libinterp/corefcn/txt-eng-ft.cc	Sun Nov 10 21:10:41 2013 +0100
+++ b/libinterp/corefcn/txt-eng-ft.cc	Mon Nov 11 01:49:57 2013 -0500
@@ -663,7 +663,7 @@
               if (r != 0)
                 ::warning ("ft_render: failed to decode string `%s' with "
                            "locale `%s'", str.c_str (),
-                           std::setlocale (LC_CTYPE, NULL));
+                           std::setlocale (LC_CTYPE, 0));
               break;
             }
         }
--- a/libinterp/dldfcn/__init_fltk__.cc	Sun Nov 10 21:10:41 2013 +0100
+++ b/libinterp/dldfcn/__init_fltk__.cc	Mon Nov 11 01:49:57 2013 -0500
@@ -290,7 +290,7 @@
       {
         const Fl_Menu_Item *m = static_cast<const Fl_Menu_Item*> (&
                                 (menubar->menu ()[t]));
-        if ((m->label () != NULL) && m->visible ())
+        if (m->label () && m->visible ())
           n++;
       }
 
@@ -337,7 +337,7 @@
         else
           {
             // End of submenu? Pop back one level.
-            if (m->label () == NULL)
+            if (m->label ())
               {
                 std::size_t idx = menupath.find_last_of ("/");
                 if (idx != std::string::npos)
@@ -421,7 +421,7 @@
       {
         Fl_Menu_Item* item = const_cast<Fl_Menu_Item*> (menubar->find_item (
                                fltk_label.c_str ()));
-        if (item != NULL)
+        if (item)
           {
             std::string acc = uimenup.get_accelerator ();
             if (acc.length () > 0)
@@ -440,13 +440,13 @@
       {
         Fl_Menu_Item* item = const_cast<Fl_Menu_Item*> (menubar->find_item (
                                fltk_label.c_str ()));
-        if (item != NULL)
+        if (item)
           {
             if (!uimenup.get_callback ().is_empty ())
               item->callback (static_cast<Fl_Callback*> (script_cb),
                               static_cast<void*> (&uimenup));
             else
-              item->callback (NULL, static_cast<void*> (0));
+              item->callback (0, static_cast<void*> (0));
           }
       }
   }
@@ -458,7 +458,7 @@
       {
         Fl_Menu_Item* item = const_cast<Fl_Menu_Item*> (menubar->find_item (
                                fltk_label.c_str ()));
-        if (item != NULL)
+        if (item)
           {
             if (uimenup.is_enable ())
               item->activate ();
@@ -475,7 +475,7 @@
       {
         Fl_Menu_Item* item = const_cast<Fl_Menu_Item*> (menubar->find_item (
                                fltk_label.c_str ()));
-        if (item != NULL)
+        if (item)
           {
             Matrix rgb = uimenup.get_foregroundcolor_rgb ();
 
@@ -504,7 +504,7 @@
             Fl_Menu_Item* item
               = const_cast<Fl_Menu_Item*> (&menubar->menu () [idx]);
             itemflags = item->flags;
-            if (item->label () != NULL)
+            if (item->label ())
               break;
           }
 
@@ -528,7 +528,7 @@
       {
         Fl_Menu_Item* item
           = const_cast<Fl_Menu_Item*> (menubar->find_item (fltk_label.c_str ()));
-        if (item != NULL)
+        if (item)
           {
             if (uimenup.is_visible ())
               item->show ();
@@ -551,19 +551,7 @@
             const Fl_Menu_Item* item
               = menubar->find_item (fltk_label.c_str ());
 
-            if (item == NULL)
-              {
-                Matrix uimenu_ch = find_uimenu_children (uimenup);
-                int len = uimenu_ch.numel ();
-                int flags = 0;
-                if (len > 0)
-                  flags = FL_SUBMENU;
-                if (len == 0 && uimenup.is_checked ())
-                  flags += FL_MENU_TOGGLE + FL_MENU_VALUE;
-                menubar->add (fltk_label.c_str (), 0, 0, 0, flags);
-                item_added = true;
-              }
-            else
+            if (item)
               {
                 //avoid duplicate menulabels
                 std::size_t idx1 = fltk_label.find_last_of ("(");
@@ -582,6 +570,18 @@
                 valstream << val;
                 fltk_label += "(" + valstream.str () + ")";
               }
+            else
+              {
+                Matrix uimenu_ch = find_uimenu_children (uimenup);
+                int len = uimenu_ch.numel ();
+                int flags = 0;
+                if (len > 0)
+                  flags = FL_SUBMENU;
+                if (len == 0 && uimenup.is_checked ())
+                  flags += FL_MENU_TOGGLE + FL_MENU_VALUE;
+                menubar->add (fltk_label.c_str (), 0, 0, 0, flags);
+                item_added = true;
+              }
           }
         while (!item_added);
         uimenup.set_fltk_label (fltk_label);
--- a/libinterp/octave-value/ov-fcn-handle.cc	Sun Nov 10 21:10:41 2013 +0100
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Mon Nov 11 01:49:57 2013 -0500
@@ -1884,8 +1884,8 @@
   octave_user_function *usr_fcn = f.user_function_value (false);
   tree_parameter_list *param_list = usr_fcn ? usr_fcn->parameter_list () : 0;
 
-  tree_statement_list *cmd_list = NULL;
-  tree_expression *body_expr = NULL;
+  tree_statement_list *cmd_list = 0;
+  tree_expression *body_expr = 0;
 
   if (usr_fcn)
     {
--- a/libinterp/octave-value/ov-java.cc	Sun Nov 10 21:10:41 2013 +0100
+++ b/libinterp/octave-value/ov-java.cc	Mon Nov 11 01:49:57 2013 -0500
@@ -241,7 +241,7 @@
 {
   typedef BOOL (WINAPI *dllfcn_t) (LPCTSTR path);
 
-  static dllfcn_t dllfcn = NULL;
+  static dllfcn_t dllfcn = 0;
   static bool first = true;
 
   if (! dllfcn && first)
@@ -253,7 +253,7 @@
     }
 
   if (dllfcn)
-    dllfcn (dir.empty () ? NULL : dir.c_str ());
+    dllfcn (dir.empty () ? 0 : dir.c_str ());
 }
 #endif
 
@@ -424,7 +424,7 @@
     return;
 
   JNIEnv *current_env;
-  const char *static_locale = setlocale (LC_ALL, NULL);
+  const char *static_locale = setlocale (LC_ALL, 0);
   const std::string locale (static_locale);
 
 #if defined (__WIN32__)
@@ -433,7 +433,16 @@
   std::string jvm_lib_path;
   std::string old_cwd;
 
-  if (hMod == NULL)
+  if (hMod)
+    {
+      // JVM seems to be already loaded, better to use that DLL instead
+      // of looking in the registry, to avoid opening a different JVM.
+      jvm_lib_path = get_module_filename (hMod);
+
+      if (jvm_lib_path.empty ())
+        throw std::string ("unable to find Java Runtime Environment");
+    }
+  else
     {
       // In windows, find the location of the JRE from the registry
       // and load the symbol from the dll.
@@ -472,15 +481,6 @@
           octave_env::chdir (jvm_bin_path);
         }
     }
-  else
-    {
-      // JVM seems to be already loaded, better to use that DLL instead
-      // of looking in the registry, to avoid opening a different JVM.
-      jvm_lib_path = get_module_filename (hMod);
-
-      if (jvm_lib_path.empty ())
-        throw std::string ("unable to find Java Runtime Environment");
-    }
 
 #else  // Not Win32 system
 
@@ -544,7 +544,7 @@
           JavaVMAttachArgs vm_args;
           vm_args.version = JNI_VERSION_1_2;
           vm_args.name = const_cast<char *> ("octave");
-          vm_args.group = NULL;
+          vm_args.group = 0;
           if (jvm->AttachCurrentThread (reinterpret_cast<void **> (&current_env),
                                         &vm_args) < 0)
             throw std::string ("JVM internal error, unable to attach octave to existing JVM");
@@ -1595,7 +1595,7 @@
 JNIEnv *
 octave_java::thread_jni_env (void)
 {
-  JNIEnv *env = NULL;
+  JNIEnv *env = 0;
 
   if (jvm)
     jvm->GetEnv (reinterpret_cast<void **> (&env), JNI_VERSION_1_2);
--- a/src/mkoctfile.in.cc	Sun Nov 10 21:10:41 2013 +0100
+++ b/src/mkoctfile.in.cc	Mon Nov 11 01:49:57 2013 -0500
@@ -96,10 +96,10 @@
 get_variable (const char *name, const string& defval)
 {
   const char *val = getenv (name);
-  if (val == NULL || val[0] == '\0')
+  if (val && *val)
+    return string (val);
+  else
     return defval;
-  else
-    return string (val);
 }
 
 static string