Просмотр исходного кода

dselect: Use C++11 nullptr instead of 0 or NULL

It is way more descriptive, and has a better type. Check for C++11
compiler support and fallback nullptr to 0 if unavailable.
Guillem Jover лет назад: 12
Родитель
Сommit
80cc83904a

+ 1 - 0
configure.ac

@@ -38,6 +38,7 @@ DPKG_DEB_COMPRESSOR([xz])
 AC_PROG_CC
 DPKG_C_C99
 AC_PROG_CXX
+DPKG_CXX_CXX11
 AC_PROG_LEX
 DPKG_DIST_CHECK([test "$LEX" = ":"], [lex program required])
 AC_PROG_RANLIB

+ 3 - 0
debian/changelog

@@ -5,6 +5,9 @@ dpkg (1.17.3) UNRELEASED; urgency=low
   * Move DPKG_C_C99 call just after AC_PROG_CC, so that subsequent checks
     can take advantage of the possibly set flags to enable C99 features.
   * Improve configure C99 compiler check output.
+  * Use C++11 nullptr instead of 0 or NULL, which is way more descriptive
+    and has a better type. Check for C++11 compiler support, and fallback
+    nullptr to 0 if unavailable.
 
  -- Guillem Jover <guillem@debian.org>  Thu, 05 Dec 2013 06:50:31 +0100
 

+ 18 - 11
dselect/baselist.cc

@@ -49,7 +49,7 @@ void mywerase(WINDOW *win) {
   wmove(win,0,0);
 }
 
-baselist *baselist::signallist= 0;
+baselist *baselist::signallist = nullptr;
 void baselist::sigwinchhandler(int) {
   int save_errno = errno;
   struct winsize size;
@@ -68,9 +68,11 @@ static void cu_sigwinch(int, void **argv) {
   struct sigaction *osigactp= (struct sigaction*)argv[0];
   sigset_t *oblockedp= (sigset_t*)argv[1];
 
-  if (sigaction(SIGWINCH,osigactp,0)) ohshite(_("failed to restore old SIGWINCH sigact"));
+  if (sigaction(SIGWINCH, osigactp, nullptr))
+    ohshite(_("failed to restore old SIGWINCH sigact"));
   delete osigactp;
-  if (sigprocmask(SIG_SETMASK,oblockedp,0)) ohshite(_("failed to restore old signal mask"));
+  if (sigprocmask(SIG_SETMASK, oblockedp, nullptr))
+    ohshite(_("failed to restore old signal mask"));
   delete oblockedp;
 }
 
@@ -80,17 +82,21 @@ void baselist::setupsigwinch() {
 
   osigactp= new(struct sigaction);
   oblockedp= new(sigset_t);
-  if (sigprocmask(0,0,oblockedp)) ohshite(_("failed to get old signal mask"));
-  if (sigaction(SIGWINCH,0,osigactp)) ohshite(_("failed to get old SIGWINCH sigact"));
+  if (sigprocmask(0, nullptr, oblockedp))
+    ohshite(_("failed to get old signal mask"));
+  if (sigaction(SIGWINCH, nullptr, osigactp))
+    ohshite(_("failed to get old SIGWINCH sigact"));
 
-  push_cleanup(cu_sigwinch,~0, 0,0, 2,(void*)osigactp,(void*)oblockedp);
+  push_cleanup(cu_sigwinch, ~0, nullptr, 0, 2, osigactp, oblockedp);
 
-  if (sigprocmask(SIG_BLOCK,&sigwinchset,0)) ohshite(_("failed to block SIGWINCH"));
+  if (sigprocmask(SIG_BLOCK, &sigwinchset, nullptr))
+    ohshite(_("failed to block SIGWINCH"));
   memset(&nsigact,0,sizeof(nsigact));
   nsigact.sa_handler= sigwinchhandler;
   sigemptyset(&nsigact.sa_mask);
 //nsigact.sa_flags= SA_INTERRUPT;
-  if (sigaction(SIGWINCH,&nsigact,0)) ohshite(_("failed to set new SIGWINCH sigact"));
+  if (sigaction(SIGWINCH, &nsigact, nullptr))
+    ohshite(_("failed to set new SIGWINCH sigact"));
 }
 
 void baselist::setheights() {
@@ -211,7 +217,7 @@ void baselist::enddisplay() {
   delwin(thisstatepad);
   delwin(infopad);
   wmove(stdscr,ymax,0); wclrtoeol(stdscr);
-  listpad= 0;
+  listpad = nullptr;
 }
 
 void baselist::redrawall() {
@@ -241,7 +247,8 @@ baselist::baselist(keybindings *kb) {
   xmax= -1;
   list_height=0; info_height=0;
   topofscreen= 0; leftofscreen= 0;
-  listpad= 0; cursorline= -1;
+  listpad = nullptr;
+  cursorline = -1;
   showinfo= 1;
 
   searchstring[0]= 0;
@@ -253,7 +260,7 @@ void baselist::itd_keys() {
   const int givek= xmax/3;
   bindings->describestart();
   const char **ta;
-  while ((ta= bindings->describenext()) != 0) {
+  while ((ta = bindings->describenext()) != nullptr) {
     const char **tap= ta+1;
     for (;;) {
       waddstr(infopad, gettext(*tap));

+ 8 - 6
dselect/bindings.cc

@@ -33,7 +33,7 @@
 
 keybindings::keybindings(const interpretation *ints, const orgbinding *orgbindings) {
   interps= ints;
-  bindings=0;
+  bindings = nullptr;
   const orgbinding *b= orgbindings;
   while (b->action) { bind(b->key,b->action); b++; }
   describestart();
@@ -66,7 +66,7 @@ keybindings::bind(int key, const char *action)
     bindings = b;
   }
   b->interp = interp;
-  b->desc = desc ? desc->desc : 0;
+  b->desc = desc ? desc->desc : nullptr;
 
   return true;
 }
@@ -87,7 +87,8 @@ const keybindings::interpretation *keybindings::operator()(int key) {
   binding *b = bindings;
   while (b && b->key != key)
     b = b->next;
-  if (!b) return 0;
+  if (!b)
+    return nullptr;
   return b->interp;
 }
 
@@ -95,7 +96,8 @@ const char **keybindings::describenext() {
   binding *search;
   int count;
   for (;;) {
-    if (!iterate->action) return 0;
+    if (!iterate->action)
+      return nullptr;
     for (count=0, search=bindings; search; search=search->next)
       if (strcmp(search->interp->action, iterate->action) == 0)
         count++;
@@ -107,7 +109,7 @@ const char **keybindings::describenext() {
   for (count=1, search=bindings; search; search=search->next)
     if (strcmp(search->interp->action, iterate->action) == 0)
       retarray[count++]= key2name(search->key);
-  retarray[count]= 0;
+  retarray[count] = nullptr;
   iterate++;
   return retarray;
 }
@@ -173,5 +175,5 @@ const keybindings::description keybindings::descriptions[]= {
   // Actions which apply only to lists of methods.
   { "select-and-quit", N_("Select currently-highlighted access method")          },
   { "abort",           N_("Quit without changing selected access method")        },
-  {  0,                0                                                         }
+  { nullptr,           nullptr                                                   }
 };

+ 27 - 27
dselect/main.cc

@@ -82,7 +82,7 @@ static const struct table_t colourtable[]= {
   {"magenta",	COLOR_MAGENTA	},
   {"cyan",	COLOR_CYAN	},
   {"white",	COLOR_WHITE	},
-  {NULL, 0},
+  {nullptr, 0},
 };
 
 static const struct table_t attrtable[]= {
@@ -94,7 +94,7 @@ static const struct table_t attrtable[]= {
   {"bright",	A_BLINK		}, // on some terminals
   {"dim",	A_DIM		},
   {"bold",	A_BOLD		},
-  {NULL, 0},
+  {nullptr, 0},
 };
 
 /* A slightly confusing mapping from dselect's internal names to
@@ -112,7 +112,7 @@ static const struct table_t screenparttable[]= {
   {"infodesc",		info_head	},
   {"infofoot",		whatinfo	},
   {"helpscreen",	helpscreen	},
-  {NULL, 0},
+  {nullptr, 0},
 };
 
 /* Historical (patriotic?) colours. */
@@ -149,8 +149,8 @@ static const menuentry menuentries[]= {
   { "config",	N_("c"),	N_("[C]onfig"),	N_("Configure any packages that are unconfigured."),	&urq_config  },
   { "remove",	N_("r"),	N_("[R]emove"),	N_("Remove unwanted software."),			&urq_remove  },
   { "quit",	N_("q"),	N_("[Q]uit"),	N_("Quit dselect."),					&urq_quit    },
-  { 0,		0,  		N_("menu"),	0,							&urq_menu    },
-  { 0 }
+  { nullptr,	nullptr,	N_("menu"),	nullptr,						&urq_menu    },
+  { nullptr }
 };
 
 static const char programdesc[]=
@@ -247,7 +247,7 @@ extern "C" {
   {
     int i;
 
-    for (i= 0;  item && (table[i].name!=NULL); i++)
+    for (i = 0; item && (table[i].name != nullptr); i++)
       if (strcasecmp(item, table[i].name) == 0)
         return table[i].num;
 
@@ -271,32 +271,32 @@ extern "C" {
 
     s = m_strdup(string); // strtok modifies strings, keep string const
     screenpart= findintable(screenparttable, strtok(s, ":"), _("screen part"));
-    colours= strtok(NULL, ":");
-    attributes= strtok(NULL, ":");
+    colours = strtok(nullptr, ":");
+    attributes = strtok(nullptr, ":");
 
-    if ((colours == NULL || ! strlen(colours)) &&
-        (attributes == NULL || ! strlen(attributes))) {
+    if ((colours == nullptr || ! strlen(colours)) &&
+        (attributes == nullptr || ! strlen(attributes))) {
        ohshit(_("null colour specification"));
     }
 
-    if (colours != NULL && strlen(colours)) {
+    if (colours != nullptr && strlen(colours)) {
       colourname= strtok(colours, ",");
-      if (colourname != NULL && strlen(colourname)) {
+      if (colourname != nullptr && strlen(colourname)) {
         // normalize attributes to prevent confusion
         color[screenpart].attr= A_NORMAL;
        color[screenpart].fore=findintable(colourtable, colourname, _("colour"));
       }
-      colourname= strtok(NULL, ",");
-      if (colourname != NULL && strlen(colourname)) {
+      colourname = strtok(nullptr, ",");
+      if (colourname != nullptr && strlen(colourname)) {
         color[screenpart].attr= A_NORMAL;
         color[screenpart].back=findintable(colourtable, colourname, _("colour"));
       }
     }
 
-    if (attributes != NULL && strlen(attributes)) {
+    if (attributes != nullptr && strlen(attributes)) {
       for (attrib= strtok(attributes, "+");
-           attrib != NULL && strlen(attrib);
-          attrib= strtok(NULL, "+")) {
+           attrib != nullptr && strlen(attrib);
+           attrib = strtok(nullptr, "+")) {
                aval=findintable(attrtable, attrib, _("colour attribute"));
                if (aval == A_NORMAL) // set to normal
                        color[screenpart].attr= aval;
@@ -309,14 +309,14 @@ extern "C" {
 } /* End of extern "C" */
 
 static const struct cmdinfo cmdinfos[]= {
-  { "admindir",     0,   1,  0,  &admindir,  0               },
-  { "debug",       'D',  1,  0,  0,          set_debug       },
-  { "expert",      'E',  0,  0,  0,          set_expert      },
-  { "help",        '?',  0,  0,  0,          usage           },
-  { "version",      0,   0,  0,  0,          printversion    },
-  { "color",        0,   1,  0,  0,          set_color       }, /* US spelling */
-  { "colour",       0,   1,  0,  0,          set_color       }, /* UK spelling */
-  { 0,              0,   0,  0,  0,          0               }
+  { "admindir",     0,  1, nullptr,  &admindir, nullptr      },
+  { "debug",       'D', 1, nullptr,  nullptr,   set_debug    },
+  { "expert",      'E', 0, nullptr,  nullptr,   set_expert   },
+  { "help",        '?', 0, nullptr,  nullptr,   usage        },
+  { "version",      0,  0, nullptr,  nullptr,   printversion },
+  { "color",        0,  1, nullptr,  nullptr,   set_color    }, /* US spelling */
+  { "colour",       0,  1, nullptr,  nullptr,   set_color    }, /* UK spelling */
+  { nullptr,        0,  0, nullptr,  nullptr,   nullptr      }
 };
 
 static bool cursesareon = false;
@@ -517,7 +517,7 @@ main(int, const char *const *argv)
   dpkg_locales_init(DSELECT);
   dpkg_set_progname(DSELECT);
 
-  push_error_context_func(dselect_catch_fatal_error, print_fatal_error, 0);
+  push_error_context_func(dselect_catch_fatal_error, print_fatal_error, nullptr);
 
   dpkg_options_load(DSELECT, cmdinfos);
   dpkg_options_parse(&argv, cmdinfos, printforhelp);
@@ -526,7 +526,7 @@ main(int, const char *const *argv)
 
   if (*argv) {
     const char *a;
-    while ((a= *argv++) != 0) {
+    while ((a = *argv++) != nullptr) {
       const menuentry *me = menuentries;
       while (me->command && strcmp(me->command, a))
         me++;

+ 24 - 24
dselect/methkeys.cc

@@ -27,29 +27,29 @@
 #include "bindings.h"
 
 const keybindings::interpretation methodlist_kinterps[] = {
-  { "up",              &methodlist::kd_up,             0,    qa_noquit           },
-  { "down",            &methodlist::kd_down,           0,    qa_noquit           },
-  { "top",             &methodlist::kd_top,            0,    qa_noquit           },
-  { "bottom",          &methodlist::kd_bottom,         0,    qa_noquit           },
-  { "scrollon",        &methodlist::kd_scrollon,       0,    qa_noquit           },
-  { "scrollback",      &methodlist::kd_scrollback,     0,    qa_noquit           },
-  { "iscrollon",       &methodlist::kd_iscrollon,      0,    qa_noquit           },
-  { "iscrollback",     &methodlist::kd_iscrollback,    0,    qa_noquit           },
-  { "scrollon1",       &methodlist::kd_scrollon1,      0,    qa_noquit           },
-  { "scrollback1",     &methodlist::kd_scrollback1,    0,    qa_noquit           },
-  { "iscrollon1",      &methodlist::kd_iscrollon1,     0,    qa_noquit           },
-  { "iscrollback1",    &methodlist::kd_iscrollback1,   0,    qa_noquit           },
-  { "panon",           &methodlist::kd_panon,          0,    qa_noquit           },
-  { "panback",         &methodlist::kd_panback,        0,    qa_noquit           },
-  { "panon1",          &methodlist::kd_panon1,         0,    qa_noquit           },
-  { "panback1",        &methodlist::kd_panback1,       0,    qa_noquit           },
-  { "help",            &methodlist::kd_help,           0,    qa_noquit           },
-  { "search",          &methodlist::kd_search,         0,    qa_noquit           },
-  { "searchagain",     &methodlist::kd_searchagain,    0,    qa_noquit           },
-  { "redraw",          &methodlist::kd_redraw,         0,    qa_noquit           },
-  { "select-and-quit", &methodlist::kd_quit,           0,    qa_quitchecksave    },
-  { "abort",           &methodlist::kd_abort,          0,    qa_quitnochecksave  },
-  {  0,                0,                             0,    qa_noquit           }
+  { "up",              &methodlist::kd_up,           nullptr, qa_noquit           },
+  { "down",            &methodlist::kd_down,         nullptr, qa_noquit           },
+  { "top",             &methodlist::kd_top,          nullptr, qa_noquit           },
+  { "bottom",          &methodlist::kd_bottom,       nullptr, qa_noquit           },
+  { "scrollon",        &methodlist::kd_scrollon,     nullptr, qa_noquit           },
+  { "scrollback",      &methodlist::kd_scrollback,   nullptr, qa_noquit           },
+  { "iscrollon",       &methodlist::kd_iscrollon,    nullptr, qa_noquit           },
+  { "iscrollback",     &methodlist::kd_iscrollback,  nullptr, qa_noquit           },
+  { "scrollon1",       &methodlist::kd_scrollon1,    nullptr, qa_noquit           },
+  { "scrollback1",     &methodlist::kd_scrollback1,  nullptr, qa_noquit           },
+  { "iscrollon1",      &methodlist::kd_iscrollon1,   nullptr, qa_noquit           },
+  { "iscrollback1",    &methodlist::kd_iscrollback1, nullptr, qa_noquit           },
+  { "panon",           &methodlist::kd_panon,        nullptr, qa_noquit           },
+  { "panback",         &methodlist::kd_panback,      nullptr, qa_noquit           },
+  { "panon1",          &methodlist::kd_panon1,       nullptr, qa_noquit           },
+  { "panback1",        &methodlist::kd_panback1,     nullptr, qa_noquit           },
+  { "help",            &methodlist::kd_help,         nullptr, qa_noquit           },
+  { "search",          &methodlist::kd_search,       nullptr, qa_noquit           },
+  { "searchagain",     &methodlist::kd_searchagain,  nullptr, qa_noquit           },
+  { "redraw",          &methodlist::kd_redraw,       nullptr, qa_noquit           },
+  { "select-and-quit", &methodlist::kd_quit,         nullptr, qa_quitchecksave    },
+  { "abort",           &methodlist::kd_abort,        nullptr, qa_quitnochecksave  },
+  { nullptr,           nullptr,                      nullptr, qa_noquit           }
 };
 
 const keybindings::orgbinding methodlist_korgbindings[]= {
@@ -105,5 +105,5 @@ const keybindings::orgbinding methodlist_korgbindings[]= {
   { 'X',            "abort"            },
   { 'Q',            "abort"            },
 
-  {  -1,             0                 }
+  {  -1,            nullptr            }
 };

+ 4 - 2
dselect/methlist.cc

@@ -159,11 +159,13 @@ quitaction methodlist::display() {
     if (whatinfo_height) wcursyncup(whatinfowin);
     if (doupdate() == ERR) ohshite(_("doupdate failed"));
     signallist= this;
-    if (sigprocmask(SIG_UNBLOCK,&sigwinchset,0)) ohshite(_("failed to unblock SIGWINCH"));
+    if (sigprocmask(SIG_UNBLOCK, &sigwinchset, nullptr))
+      ohshite(_("failed to unblock SIGWINCH"));
     do
     response= getch();
     while (response == ERR && errno == EINTR);
-    if (sigprocmask(SIG_BLOCK,&sigwinchset,0)) ohshite(_("failed to re-block SIGWINCH"));
+    if (sigprocmask(SIG_BLOCK, &sigwinchset, nullptr))
+      ohshite(_("failed to re-block SIGWINCH"));
     if (response == ERR) ohshite(_("getch failed"));
     interp= (*bindings)(response);
     debug(dbg_general, "methodlist[%p]::display() response=%d interp=%s",

+ 9 - 9
dselect/method.cc

@@ -51,10 +51,10 @@
 static const char *const methoddirectories[]= {
   LIBDIR "/" METHODSDIR,
   LOCALLIBDIR "/" METHODSDIR,
-  0
+  nullptr
 };
 
-static char *methodlockfile= 0;
+static char *methodlockfile = nullptr;
 static int methlockfd= -1;
 
 static void
@@ -88,7 +88,7 @@ static enum urqresult ensureoptions(void) {
   int nread;
 
   if (!options) {
-    newoptions= 0;
+    newoptions = nullptr;
     nread= 0;
     for (ccpp= methoddirectories; *ccpp; ccpp++)
       readmethods(*ccpp, &newoptions, &nread);
@@ -105,7 +105,7 @@ static enum urqresult ensureoptions(void) {
 static enum urqresult lockmethod(void) {
   struct flock fl;
 
-  if (methodlockfile == NULL)
+  if (methodlockfile == nullptr)
     methodlockfile = dpkg_db_get_path(METHLOCKFILE);
 
   if (methlockfd == -1) {
@@ -128,7 +128,7 @@ static enum urqresult lockmethod(void) {
     sthfailed("unable to lock access method area");
     return urqr_fail;
   }
-  push_cleanup(cu_unlockmethod,~0, 0,0, 0);
+  push_cleanup(cu_unlockmethod, ~0, nullptr, 0, 0);
   return urqr_normal;
 }
 
@@ -144,7 +144,7 @@ falliblesubprocess(struct command *cmd)
 
   pid = subproc_fork();
   if (pid == 0) {
-    subproc_signals_cleanup(0, 0);
+    subproc_signals_cleanup(0, nullptr);
     command_exec(cmd);
   }
 
@@ -180,7 +180,7 @@ static urqresult runscript(const char *exepath, const char *name) {
 
     command_init(&cmd, coption->meth->path, name);
     command_add_args(&cmd, exepath, dpkg_db_get_dir(),
-                     coption->meth->name, coption->name, NULL);
+                     coption->meth->name, coption->name, nullptr);
     ur = falliblesubprocess(&cmd);
     command_destroy(&cmd);
   } else {
@@ -206,7 +206,7 @@ static urqresult rundpkgauto(const char *name, const char *dpkgmode) {
 
   command_init(&cmd, DPKG, name);
   command_add_args(&cmd, DPKG, "--admindir", dpkg_db_get_dir(), "--pending",
-                   dpkgmode, NULL);
+                   dpkgmode, nullptr);
 
   cursesoff();
   printf("running dpkg --pending %s ...\n",dpkgmode);
@@ -245,7 +245,7 @@ urqresult urq_setup(void) {
 
     command_init(&cmd, coption->meth->path, _("query/setup script"));
     command_add_args(&cmd, METHODSETUPSCRIPT, dpkg_db_get_dir(),
-                     coption->meth->name, coption->name, NULL);
+                     coption->meth->name, coption->name, nullptr);
     ur = falliblesubprocess(&cmd);
     command_destroy(&cmd);
     if (ur == urqr_normal) writecurrentopt();

+ 12 - 9
dselect/methparse.cc

@@ -44,8 +44,8 @@
 #include "method.h"
 
 int noptions=0;
-struct dselect_option *options=0, *coption=0;
-struct method *methods=0;
+struct dselect_option *options = nullptr, *coption = nullptr;
+struct method *methods = nullptr;
 
 static void DPKG_ATTR_NORET
 badmethod(const char *pathname, const char *why)
@@ -62,7 +62,10 @@ eofmethod(const char *pathname, FILE *f, const char *why)
 
 void readmethods(const char *pathbase, dselect_option **optionspp, int *nread) {
   static const char *const methodprograms[]= {
-    METHODSETUPSCRIPT, METHODUPDATESCRIPT, METHODINSTALLSCRIPT, 0
+    METHODSETUPSCRIPT,
+    METHODUPDATESCRIPT,
+    METHODINSTALLSCRIPT,
+    nullptr
   };
   const char *const *ccpp;
   int methodlen, c, baselen;
@@ -92,7 +95,7 @@ void readmethods(const char *pathbase, dselect_option **optionspp, int *nread) {
 
   debug(dbg_general, "readmethods('%s',...) directory open", pathbase);
 
-  while ((dent= readdir(dir)) != 0) {
+  while ((dent = readdir(dir)) != nullptr) {
     c= dent->d_name[0];
     debug(dbg_general, "readmethods('%s',...) considering '%s' ...",
           pathbase, dent->d_name);
@@ -130,7 +133,7 @@ void readmethods(const char *pathbase, dselect_option **optionspp, int *nread) {
     strcpy(meth->path+baselen+1+methodlen,"/");
     meth->pathinmeth= meth->path+baselen+1+methodlen+1;
     meth->next= methods;
-    meth->prev = 0;
+    meth->prev = nullptr;
     if (methods)
       methods->prev = meth;
     methods= meth;
@@ -188,7 +191,7 @@ void readmethods(const char *pathbase, dselect_option **optionspp, int *nread) {
       if (!descfile) {
         if (errno != ENOENT)
           ohshite(_("unable to open option description file `%.250s'"),pathbuf);
-        opt->description= 0;
+        opt->description = nullptr;
       } else { /* descfile != 0 */
         if (fstat(fileno(descfile),&stab))
           ohshite(_("unable to stat option description file `%.250s'"),pathbuf);
@@ -229,7 +232,7 @@ void readmethods(const char *pathbase, dselect_option **optionspp, int *nread) {
   delete[] pathbuf;
 }
 
-static char *methoptfile= 0;
+static char *methoptfile = nullptr;
 
 void getcurrentopt() {
   char methoptbuf[IMETHODMAXLEN+1+IOPTIONMAXLEN+2];
@@ -237,10 +240,10 @@ void getcurrentopt() {
   int l;
   char *p;
 
-  if (methoptfile == NULL)
+  if (methoptfile == nullptr)
     methoptfile = dpkg_db_get_path(CMETHOPTFILE);
 
-  coption= 0;
+  coption = nullptr;
   cmo= fopen(methoptfile,"r");
   if (!cmo) {
     if (errno == ENOENT) return;

+ 1 - 1
dselect/mkcurkeys.pl

@@ -112,7 +112,7 @@ for my $i (1 .. 63) {
 p($comma, ',');
 
 print(<<'END') or die $!;
-  { -1,              0                    }
+  { -1,              nullptr              }
 END
 
 close(STDOUT) or die $!;

+ 1 - 1
dselect/pkgcmds.cc

@@ -112,7 +112,7 @@ void packagelist::setwant(pkginfo::pkgwant nwarg) {
     top= cursorline;
     bot= cursorline+1;
   } else {
-    packagelist *sub= new packagelist(bindings,0);
+    packagelist *sub = new packagelist(bindings, nullptr);
 
     affectedrange(&top,&bot);
     for (index= top; index < bot; index++) {

+ 4 - 3
dselect/pkgdepcon.cc

@@ -249,7 +249,7 @@ int packagelist::resolvedepcon(dependency *depends) {
     if (would_like_to_install(depends->up->clientdata->selected,depends->up) <= 0)
       return 0;
 
-    fixbyupgrade= 0;
+    fixbyupgrade = nullptr;
 
     possi = depends->list;
     while (possi && !deppossatisfied(possi, &fixbyupgrade))
@@ -277,7 +277,7 @@ int packagelist::resolvedepcon(dependency *depends) {
             this, depends, pkg_name(fixbyupgrade->pkg, pnaw_always));
       best= fixbyupgrade;
     } else {
-      best= 0;
+      best = nullptr;
       for (possi= depends->list;
            possi;
            possi= possi->next) {
@@ -343,7 +343,8 @@ int packagelist::resolvedepcon(dependency *depends) {
           "packagelist[%p]::resolvedepcon([%p]): conflict installing 1",
           this, depends);
 
-    if (!deppossatisfied(depends->list,0)) return 0;
+    if (!deppossatisfied(depends->list, nullptr))
+      return 0;
 
     debug(dbg_depcon,
           "packagelist[%p]::resolvedepcon([%p]): conflict satisfied - ouch",

+ 5 - 5
dselect/pkgdisplay.cc

@@ -38,7 +38,7 @@ const char
 			    N_("hold"),
 			    N_("remove"),
 			    N_("purge"),
-			    0 },
+			    nullptr },
 
   /* TRANSLATORS: The space is a trick to work around gettext which uses
    * the empty string to store information about the translation. DO NOT
@@ -46,7 +46,7 @@ const char
    * a single space. */
   *const eflagstrings[]=   { N_(" "),
 			     N_("REINSTALL"),
-			     0 },
+			     nullptr },
 
   *const statusstrings[]= { N_("not installed"),
 			    N_("removed (configs remain)"),
@@ -56,7 +56,7 @@ const char
 			    N_("awaiting trigger processing"),
 			    N_("triggered"),
 			    N_("installed"),
-			    0 },
+			    nullptr },
 
   *const prioritystrings[]=  { N_("Required"),
 			       N_("Important"),
@@ -65,7 +65,7 @@ const char
 			       N_("Extra"),
 			       N_("!Bug!"),
 			       N_("Unclassified"),
-			       0 },
+			       nullptr },
 
   *const relatestrings[]= { N_("suggests"),
 			    N_("recommends"),
@@ -76,7 +76,7 @@ const char
 			    N_("provides"),
 			    N_("replaces"),
 			    N_("enhances"),
-			    0 },
+			    nullptr },
 
   *const priorityabbrevs[]=  { N_("Req"),
 			       N_("Imp"),

+ 5 - 5
dselect/pkginfo.cc

@@ -70,11 +70,11 @@ packagelist::itr_recursive()
 }
 
 const packagelist::infotype packagelist::infoinfos[]= {
-  { &packagelist::itr_recursive,     &packagelist::itd_relations         },
-  { 0,                               &packagelist::itd_description       },
-  { 0,                               &packagelist::itd_statuscontrol     },
-  { 0,                               &packagelist::itd_availablecontrol  },
-  { 0,                 0                     }
+  { &packagelist::itr_recursive, &packagelist::itd_relations         },
+  { nullptr,                     &packagelist::itd_description       },
+  { nullptr,                     &packagelist::itd_statuscontrol     },
+  { nullptr,                     &packagelist::itd_availablecontrol  },
+  { nullptr,                     nullptr                             }
 };
 
 const packagelist::infotype *const packagelist::baseinfo= infoinfos;

+ 41 - 41
dselect/pkgkeys.cc

@@ -27,46 +27,46 @@
 #include "bindings.h"
 
 const keybindings::interpretation packagelist_kinterps[] = {
-  { "up",               0,  &packagelist::kd_up,               qa_noquit           },
-  { "down",             0,  &packagelist::kd_down,             qa_noquit           },
-  { "top",              0,  &packagelist::kd_top,              qa_noquit           },
-  { "bottom",           0,  &packagelist::kd_bottom,           qa_noquit           },
-  { "scrollon",         0,  &packagelist::kd_scrollon,         qa_noquit           },
-  { "scrollback",       0,  &packagelist::kd_scrollback,       qa_noquit           },
-  { "iscrollon",        0,  &packagelist::kd_iscrollon,        qa_noquit           },
-  { "iscrollback",      0,  &packagelist::kd_iscrollback,      qa_noquit           },
-  { "scrollon1",        0,  &packagelist::kd_scrollon1,        qa_noquit           },
-  { "scrollback1",      0,  &packagelist::kd_scrollback1,      qa_noquit           },
-  { "iscrollon1",       0,  &packagelist::kd_iscrollon1,       qa_noquit           },
-  { "iscrollback1",     0,  &packagelist::kd_iscrollback1,     qa_noquit           },
-  { "panon",            0,  &packagelist::kd_panon,            qa_noquit           },
-  { "panback",          0,  &packagelist::kd_panback,          qa_noquit           },
-  { "panon1",           0,  &packagelist::kd_panon1,           qa_noquit           },
-  { "panback1",         0,  &packagelist::kd_panback1,         qa_noquit           },
-  { "install",          0,  &packagelist::kd_select,           qa_noquit           },
-  { "remove",           0,  &packagelist::kd_deselect,         qa_noquit           },
-  { "purge",            0,  &packagelist::kd_purge,            qa_noquit           },
-  { "hold",             0,  &packagelist::kd_hold,             qa_noquit           },
-  { "unhold",           0,  &packagelist::kd_unhold,           qa_noquit           },
-  { "info",             0,  &packagelist::kd_info,             qa_noquit           },
-  { "toggleinfo",       0,  &packagelist::kd_toggleinfo,       qa_noquit           },
-  { "verbose",          0,  &packagelist::kd_verbose,          qa_noquit           },
-  { "versiondisplay",   0,  &packagelist::kd_versiondisplay,   qa_noquit           },
-  { "help",             0,  &packagelist::kd_help,             qa_noquit           },
-  { "search",           0,  &packagelist::kd_search,           qa_noquit           },
-  { "searchagain",      0,  &packagelist::kd_searchagain,      qa_noquit           },
-  { "swaporder",        0,  &packagelist::kd_swaporder,        qa_noquit           },
-  { "swapstatorder",    0,  &packagelist::kd_swapstatorder,    qa_noquit           },
-  { "redraw",           0,  &packagelist::kd_redraw,           qa_noquit           },
-  { "quitcheck",        0,  &packagelist::kd_quit_noop,        qa_quitchecksave    },
-  { "quitrejectsug",    0,  &packagelist::kd_revertdirect,     qa_quitnochecksave  },
-  { "quitnocheck",      0,  &packagelist::kd_quit_noop,        qa_quitnochecksave  },
-  { "abortnocheck",     0,  &packagelist::kd_revert_abort,     qa_quitnochecksave  },
-  { "revert",           0,  &packagelist::kd_revert_abort,     qa_noquit           },
-  { "revertsuggest",    0,  &packagelist::kd_revertsuggest,    qa_noquit           },
-  { "revertdirect",     0,  &packagelist::kd_revertdirect,     qa_noquit           },
-  { "revertinstalled",  0,  &packagelist::kd_revertinstalled,  qa_noquit           },
-  {  0,                 0,  0,                                qa_noquit           }
+  { "up",               nullptr,  &packagelist::kd_up,               qa_noquit           },
+  { "down",             nullptr,  &packagelist::kd_down,             qa_noquit           },
+  { "top",              nullptr,  &packagelist::kd_top,              qa_noquit           },
+  { "bottom",           nullptr,  &packagelist::kd_bottom,           qa_noquit           },
+  { "scrollon",         nullptr,  &packagelist::kd_scrollon,         qa_noquit           },
+  { "scrollback",       nullptr,  &packagelist::kd_scrollback,       qa_noquit           },
+  { "iscrollon",        nullptr,  &packagelist::kd_iscrollon,        qa_noquit           },
+  { "iscrollback",      nullptr,  &packagelist::kd_iscrollback,      qa_noquit           },
+  { "scrollon1",        nullptr,  &packagelist::kd_scrollon1,        qa_noquit           },
+  { "scrollback1",      nullptr,  &packagelist::kd_scrollback1,      qa_noquit           },
+  { "iscrollon1",       nullptr,  &packagelist::kd_iscrollon1,       qa_noquit           },
+  { "iscrollback1",     nullptr,  &packagelist::kd_iscrollback1,     qa_noquit           },
+  { "panon",            nullptr,  &packagelist::kd_panon,            qa_noquit           },
+  { "panback",          nullptr,  &packagelist::kd_panback,          qa_noquit           },
+  { "panon1",           nullptr,  &packagelist::kd_panon1,           qa_noquit           },
+  { "panback1",         nullptr,  &packagelist::kd_panback1,         qa_noquit           },
+  { "install",          nullptr,  &packagelist::kd_select,           qa_noquit           },
+  { "remove",           nullptr,  &packagelist::kd_deselect,         qa_noquit           },
+  { "purge",            nullptr,  &packagelist::kd_purge,            qa_noquit           },
+  { "hold",             nullptr,  &packagelist::kd_hold,             qa_noquit           },
+  { "unhold",           nullptr,  &packagelist::kd_unhold,           qa_noquit           },
+  { "info",             nullptr,  &packagelist::kd_info,             qa_noquit           },
+  { "toggleinfo",       nullptr,  &packagelist::kd_toggleinfo,       qa_noquit           },
+  { "verbose",          nullptr,  &packagelist::kd_verbose,          qa_noquit           },
+  { "versiondisplay",   nullptr,  &packagelist::kd_versiondisplay,   qa_noquit           },
+  { "help",             nullptr,  &packagelist::kd_help,             qa_noquit           },
+  { "search",           nullptr,  &packagelist::kd_search,           qa_noquit           },
+  { "searchagain",      nullptr,  &packagelist::kd_searchagain,      qa_noquit           },
+  { "swaporder",        nullptr,  &packagelist::kd_swaporder,        qa_noquit           },
+  { "swapstatorder",    nullptr,  &packagelist::kd_swapstatorder,    qa_noquit           },
+  { "redraw",           nullptr,  &packagelist::kd_redraw,           qa_noquit           },
+  { "quitcheck",        nullptr,  &packagelist::kd_quit_noop,        qa_quitchecksave    },
+  { "quitrejectsug",    nullptr,  &packagelist::kd_revertdirect,     qa_quitnochecksave  },
+  { "quitnocheck",      nullptr,  &packagelist::kd_quit_noop,        qa_quitnochecksave  },
+  { "abortnocheck",     nullptr,  &packagelist::kd_revert_abort,     qa_quitnochecksave  },
+  { "revert",           nullptr,  &packagelist::kd_revert_abort,     qa_noquit           },
+  { "revertsuggest",    nullptr,  &packagelist::kd_revertsuggest,    qa_noquit           },
+  { "revertdirect",     nullptr,  &packagelist::kd_revertdirect,     qa_noquit           },
+  { "revertinstalled",  nullptr,  &packagelist::kd_revertinstalled,  qa_noquit           },
+  { nullptr,            nullptr,  nullptr,                           qa_noquit           }
 };
 
 const keybindings::orgbinding packagelist_korgbindings[]= {
@@ -138,5 +138,5 @@ const keybindings::orgbinding packagelist_korgbindings[]= {
   { 'D',            "revertdirect"     },
   { 'C',            "revertinstalled"  },
 
-  {  -1,             0                 }
+  {  -1,            nullptr            }
 };

+ 24 - 22
dselect/pkglist.cc

@@ -104,7 +104,7 @@ void packagelist::discardheadings() {
     delete head;
     head= next;
   }
-  headings= 0;
+  headings = nullptr;
 }
 
 void packagelist::addheading(enum ssavailval ssavail,
@@ -127,7 +127,7 @@ void packagelist::addheading(enum ssavailval ssavail,
         section ? section : "<null>");
 
   struct pkgset *newset = new pkgset;
-  newset->name = NULL;
+  newset->name = nullptr;
   struct pkginfo *newhead = &newset->pkg;
   newhead->set = newset;
   newhead->priority= priority;
@@ -272,7 +272,7 @@ void packagelist::sortmakeheads() {
         this, sortorder, statsortorder);
 
   int nrealitems= nitems;
-  addheading(ssa_none,sss_none,pkginfo::pri_unset,0,0);
+  addheading(ssa_none, sss_none, pkginfo::pri_unset, nullptr, nullptr);
 
   assert(sortorder != so_unsorted);
   if (sortorder == so_alpha && statsortorder == sso_unsorted) { sortinplace(); return; }
@@ -282,7 +282,7 @@ void packagelist::sortmakeheads() {
 
   struct pkginfo *lastpkg;
   struct pkginfo *thispkg;
-  lastpkg= 0;
+  lastpkg = nullptr;
   int a;
   for (a=0; a<nrealitems; a++) {
     thispkg= table[a]->pkg;
@@ -328,15 +328,16 @@ void packagelist::sortmakeheads() {
 
     if (ssdiff)
       addheading(ssavail,ssstate,
-                 pkginfo::pri_unset,0, 0);
+                 pkginfo::pri_unset, nullptr, nullptr);
 
     if (sortorder == so_section && sectiondiff)
       addheading(ssavail,ssstate,
-                 pkginfo::pri_unset,0, thispkg->section ? thispkg->section : "");
+                 pkginfo::pri_unset, nullptr,
+                 thispkg->section ? thispkg->section : "");
 
     if (sortorder == so_priority && prioritydiff)
       addheading(ssavail,ssstate,
-                 thispkg->priority,thispkg->otherpriority, 0);
+                 thispkg->priority, thispkg->otherpriority, nullptr);
 
     if (sortorder != so_alpha && (prioritydiff || sectiondiff))
       addheading(ssavail,ssstate,
@@ -362,10 +363,10 @@ void packagelist::initialsetup() {
   nallocated= allpackages+150; // will realloc if necessary, so 150 not critical
   table= new struct perpackagestate*[nallocated];
 
-  depsdone= 0;
-  unavdone= 0;
-  currentinfo= 0;
-  headings= 0;
+  depsdone = nullptr;
+  unavdone = nullptr;
+  currentinfo = nullptr;
+  headings = nullptr;
   verbose = false;
   calcssadone = calcsssdone = false;
   searchdescr = false;
@@ -393,7 +394,8 @@ packagelist::packagelist(keybindings *kb) : baselist(kb) {
     if (pkg->status == pkginfo::stat_notinstalled &&
         !pkg->files &&
         pkg->want != pkginfo::want_install) {
-      pkg->clientdata= 0; continue;
+      pkg->clientdata = nullptr;
+      continue;
     }
     // treat all unknown packages as already seen
     state->direct= state->original= (pkg->want == pkginfo::want_unknown ? pkginfo::want_purge : pkg->want);
@@ -410,7 +412,7 @@ packagelist::packagelist(keybindings *kb) : baselist(kb) {
     }
     state->dpriority= dp_must;
     state->selected= state->suggested;
-    state->uprec= 0;
+    state->uprec = nullptr;
     state->relations.init();
     pkg->clientdata= state;
     table[nitems]= state;
@@ -460,7 +462,7 @@ perpackagestate::free(bool recursive)
             !(pkg->want == pkginfo::want_unknown && selected == pkginfo::want_purge)) {
           pkg->want= selected;
         }
-        pkg->clientdata= 0;
+        pkg->clientdata = nullptr;
       }
     }
     relations.destroy();
@@ -543,7 +545,7 @@ packagelist::matchsearch(int index)
   if (!name)
     return false;	/* Skip things without a name (seperators) */
 
-  if (regexec(&searchfsm, name, 0, NULL, 0) == 0)
+  if (regexec(&searchfsm, name, 0, nullptr, 0) == 0)
     return true;
 
   if (searchdescr) {
@@ -551,7 +553,7 @@ packagelist::matchsearch(int index)
     if (str_is_unset(descr))
       return false;
 
-    if (regexec(&searchfsm, descr, 0, NULL, 0)==0)
+    if (regexec(&searchfsm, descr, 0, nullptr, 0) == 0)
       return true;
   }
 
@@ -580,12 +582,12 @@ pkginfo **packagelist::display() {
     if (doupdate() == ERR)
       ohshite(_("doupdate failed"));
     signallist= this;
-    if (sigprocmask(SIG_UNBLOCK, &sigwinchset, 0))
+    if (sigprocmask(SIG_UNBLOCK, &sigwinchset, nullptr))
       ohshite(_("failed to unblock SIGWINCH"));
     do
     response= getch();
     while (response == ERR && errno == EINTR);
-    if (sigprocmask(SIG_BLOCK, &sigwinchset, 0))
+    if (sigprocmask(SIG_BLOCK, &sigwinchset, nullptr))
       ohshite(_("failed to re-block SIGWINCH"));
     if (response == ERR)
       ohshite(_("getch failed"));
@@ -602,23 +604,23 @@ pkginfo **packagelist::display() {
   if (interp->qa == qa_quitnochecksave ||
       modstatdb_get_status() == msdbrw_readonly) {
     debug(dbg_general, "packagelist[%p]::display() done - quitNOcheck", this);
-    return 0;
+    return nullptr;
   }
 
   if (recursive) {
     retl= new pkginfo*[nitems+1];
     for (index=0; index<nitems; index++) retl[index]= table[index]->pkg;
-    retl[nitems]= 0;
+    retl[nitems] = nullptr;
     debug(dbg_general, "packagelist[%p]::display() done, retl=%p", this, retl);
     return retl;
   } else {
-    packagelist *sub= new packagelist(bindings,0);
+    packagelist *sub = new packagelist(bindings, nullptr);
     for (index=0; index < nitems; index++)
       if (table[index]->pkg->set->name)
         sub->add(table[index]->pkg);
     repeatedlydisplay(sub,dp_must);
     debug(dbg_general,
           "packagelist[%p]::display() done, not recursive no retl", this);
-    return 0;
+    return nullptr;
   }
 }

+ 2 - 1
dselect/pkglist.h

@@ -215,7 +215,8 @@ protected:
   ~packagelist();
 };
 
-void repeatedlydisplay(packagelist *sub, showpriority, packagelist *unredisplay =0);
+void repeatedlydisplay(packagelist *sub, showpriority,
+                       packagelist *unredisplay = nullptr);
 int would_like_to_install(pkginfo::pkgwant, pkginfo *pkg);
 
 extern const char *const wantstrings[];

+ 2 - 2
dselect/pkgtop.cc

@@ -37,7 +37,7 @@ static const char *
 pkgprioritystring(const struct pkginfo *pkg)
 {
   if (pkg->priority == pkginfo::pri_unset) {
-    return 0;
+    return nullptr;
   } else if (pkg->priority == pkginfo::pri_other) {
     return pkg->otherpriority;
   } else {
@@ -53,7 +53,7 @@ int packagelist::describemany(char buf[], const char *prioritystring,
   int statindent;
 
   statindent= 0;
-  ssostring= 0;
+  ssostring = nullptr;
   ssoabbrev= _("All");
   switch (statsortorder) {
   case sso_avail:

+ 4 - 0
lib/dpkg/macros.h

@@ -80,6 +80,10 @@
 # endif
 #endif
 
+#if defined(__cplusplus) && __cplusplus < 201103L
+#define nullptr 0
+#endif
+
 #ifdef __cplusplus
 #define DPKG_BEGIN_DECLS	extern "C" {
 #define DPKG_END_DECLS		}

+ 49 - 0
m4/dpkg-compiler.m4

@@ -86,6 +86,9 @@ if test "x$enable_compiler_warnings" = "xyes"; then
   DPKG_WARNING_CC([-Wold-style-definition])
 
   DPKG_WARNING_CXX([-Wc++11-compat])
+  AS_IF([test "x$dpkg_cv_cxx11" = "xyes"], [
+    DPKG_WARNING_CXX([-Wzero-as-null-pointer-constant])
+  ])
 
   CFLAGS="$CWARNFLAGS $CFLAGS"
   CXXFLAGS="$CXXWARNFLAGS $CXXFLAGS"
@@ -175,3 +178,49 @@ AS_IF([test "x$dpkg_cv_c99" = "xyes"],
 		AC_DEFINE([HAVE_C99], 1)],
 	       [AC_MSG_ERROR([unsupported required C99 extensions])])])[]dnl
 ])# DPKG_C_C99
+
+# DPKG_TRY_CXX11([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+# --------------
+# Try compiling some C++11 code to see whether it works.
+AC_DEFUN([DPKG_TRY_CXX11], [
+  AC_LANG_PUSH([C++])
+  AC_COMPILE_IFELSE([
+    AC_LANG_PROGRAM([[
+]], [[
+	// Null pointer keyword.
+	void *ptr = nullptr;
+]])
+  ], [$1], [$2])
+  AC_LANG_POP([C++])dnl
+])# DPKG_TRY_CXX11
+
+# DPKG_CXX_CXX11
+# --------------
+# Check whether the compiler can do C++11.
+AC_DEFUN([DPKG_CXX_CXX11], [
+  AC_CACHE_CHECK([whether $CXX supports C++11], [dpkg_cv_cxx11], [
+    DPKG_TRY_CXX11([dpkg_cv_cxx11=yes], [dpkg_cv_cxx11=no])
+  ])
+  AS_IF([test "x$dpkg_cv_cxx11" != "xyes"], [
+    AC_CACHE_CHECK([for $CXX option to accept C++11], [dpkg_cv_cxx11_arg], [
+      dpkg_cv_cxx11_arg=none
+      dpkg_save_CXX="$CXX"
+      for arg in "-std=gnu++11" "-std=c++11"; do
+        CXX="$dpkg_save_CXX $arg"
+        DPKG_TRY_CXX11([dpkg_arg_worked=yes], [dpkg_arg_worked=no])
+        CXX="$dpkg_save_CXX"
+
+        AS_IF([test "x$dpkg_arg_worked" = "xyes"], [
+          dpkg_cv_cxx11_arg="$arg"; break
+        ])
+      done
+    ])
+    AS_IF([test "x$dpkg_cv_cxx11_arg" != "xnone"], [
+      CXX="$CXX $dpkg_cv_cxx11_arg"
+      dpkg_cv_cxx11=yes
+    ])
+  ])
+  AS_IF([test "x$dpkg_cv_cxx11" = "xyes"], [
+    AC_DEFINE([HAVE_CXX11], 1, [Define to 1 if the compiler supports C++11.])
+  ])[]dnl
+])# DPKG_CXX_CXX11