The following commit has been merged in the master branch:
commit b94d25d09f8bf55a68e17379581fb2ba71ae26aa
Author: Guillem Jover <[email protected]>
Date:   Sun Oct 17 05:50:02 2010 +0200

    Use push_error_context() instead of ad-hoc code

diff --git a/TODO b/TODO
index ad1a1bd..d31ef5d 100644
--- a/TODO
+++ b/TODO
@@ -31,7 +31,6 @@ TODO
  * Code cleanup / bug fixes:
    - Get rid of static variables inside functions.
    - Coalesce admindir / infodir / foodir generation.
-   - Get rid of setjmp (at least in the general case, keep for dpkg itself?)
    - Coalesce hash and checksum functions.
    - Split modstatdb_rw into mode and flags.
    - Move fd function out of mlib.
diff --git a/dpkg-deb/main.c b/dpkg-deb/main.c
index a909e39..ef01bc6 100644
--- a/dpkg-deb/main.c
+++ b/dpkg-deb/main.c
@@ -183,7 +183,6 @@ static void setcompresstype(const struct cmdinfo *cip, 
const char *value) {
 }
 
 int main(int argc, const char *const *argv) {
-  jmp_buf ejbuf;
   dofunction *action;
 
   setlocale(LC_NUMERIC, "POSIX");
@@ -191,7 +190,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
-  standard_startup(&ejbuf);
+  standard_startup();
   myopt(&argv, cmdinfos);
 
   if (!cipaction) badusage(_("need an action option"));
diff --git a/dpkg-split/main.c b/dpkg-split/main.c
index 8f33ab2..9901263 100644
--- a/dpkg-split/main.c
+++ b/dpkg-split/main.c
@@ -148,7 +148,6 @@ static const struct cmdinfo cmdinfos[]= {
 };
 
 int main(int argc, const char *const *argv) {
-  jmp_buf ejbuf;
   int l;
   char *p;
   dofunction *action;
@@ -157,7 +156,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
-  standard_startup(&ejbuf);
+  standard_startup();
   myopt(&argv, cmdinfos);
 
   if (!cipaction) badusage(_("need an action option"));
diff --git a/lib/dpkg/dpkg.h b/lib/dpkg/dpkg.h
index 7a06b53..7e62fc6 100644
--- a/lib/dpkg/dpkg.h
+++ b/lib/dpkg/dpkg.h
@@ -106,11 +106,8 @@ DPKG_BEGIN_DECLS
 
 /*** from startup.c ***/
 
-#define standard_startup(ejbuf) do {\
-  if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
-    catch_fatal_error(); \
-  }\
-  push_error_handler(ejbuf, print_fatal_error, NULL); \
+#define standard_startup() do { \
+  push_error_context(); \
   umask(022); /* Make sure all our status databases are readable. */\
 } while (0)
 
diff --git a/lib/dpkg/test.h b/lib/dpkg/test.h
index 670001b..a1d0fa7 100644
--- a/lib/dpkg/test.h
+++ b/lib/dpkg/test.h
@@ -43,13 +43,7 @@ const char thisname[] = "test";
 int
 main(int argc, char **argv)
 {
-       jmp_buf ejbuf;
-
-       /* Initialize environment. */
-       if (setjmp(ejbuf)) {
-               catch_fatal_error();
-       }
-       push_error_handler(&ejbuf, print_fatal_error, NULL);
+       push_error_context();
 
        test();
 
diff --git a/src/divertcmd.c b/src/divertcmd.c
index aeeb5e8..94fd085 100644
--- a/src/divertcmd.c
+++ b/src/divertcmd.c
@@ -704,7 +704,6 @@ static const struct cmdinfo cmdinfos[] = {
 int
 main(int argc, const char * const *argv)
 {
-       jmp_buf ejbuf;
        const char *env_pkgname;
        int (*actionfunction)(const char *const *argv);
        int ret;
@@ -713,7 +712,7 @@ main(int argc, const char * const *argv)
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       standard_startup(&ejbuf);
+       standard_startup();
        myopt(&argv, cmdinfos);
 
        env_pkgname = getenv(MAINTSCRIPTPKGENVVAR);
diff --git a/src/main.c b/src/main.c
index 8558d56..2972f14 100644
--- a/src/main.c
+++ b/src/main.c
@@ -564,7 +564,6 @@ void execbackend(const char *const *argv) {
 }
 
 void commandfd(const char *const *argv) {
-  jmp_buf ejbuf;
   struct varbuf linevb = VARBUF_INIT;
   const char * pipein;
   const char **newargs = NULL;
@@ -587,15 +586,12 @@ void commandfd(const char *const *argv) {
   if ((in= fdopen(infd, "r")) == NULL)
     ohshite(_("couldn't open `%i' for stream"), (int) infd);
 
-  if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
-    catch_fatal_error();
-  }
-
   for (;;) {
     bool mode = false;
     int argc= 1;
     lno= 0;
-    push_error_handler(&ejbuf, print_fatal_error, NULL);
+
+    push_error_context();
 
     do { c= getc(in); if (c == '\n') lno++; } while (c != EOF && isspace(c));
     if (c == EOF) break;
@@ -665,14 +661,13 @@ void commandfd(const char *const *argv) {
 
 
 int main(int argc, const char *const *argv) {
-  jmp_buf ejbuf;
   void (*actionfunction)(const char *const *argv);
 
   setlocale(LC_ALL, "");
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
-  standard_startup(&ejbuf);
+  standard_startup();
   loadcfgfile(DPKG, cmdinfos);
   myopt(&argv, cmdinfos);
 
diff --git a/src/querycmd.c b/src/querycmd.c
index 78a0fb0..77cb381 100644
--- a/src/querycmd.c
+++ b/src/querycmd.c
@@ -672,7 +672,6 @@ static const struct cmdinfo cmdinfos[]= {
 };
 
 int main(int argc, const char *const *argv) {
-  jmp_buf ejbuf;
   int (*actionfunction)(const char *const *argv);
   int ret;
 
@@ -680,7 +679,7 @@ int main(int argc, const char *const *argv) {
   bindtextdomain(PACKAGE, LOCALEDIR);
   textdomain(PACKAGE);
 
-  standard_startup(&ejbuf);
+  standard_startup();
   myopt(&argv, cmdinfos);
 
   if (!cipaction) badusage(_("need an action option"));
diff --git a/src/statcmd.c b/src/statcmd.c
index e696458..43a1098 100644
--- a/src/statcmd.c
+++ b/src/statcmd.c
@@ -372,7 +372,6 @@ static const struct cmdinfo cmdinfos[] = {
 int
 main(int argc, const char *const *argv)
 {
-       jmp_buf ejbuf;
        int (*actionfunction)(const char *const *argv);
        int ret;
 
@@ -380,7 +379,7 @@ main(int argc, const char *const *argv)
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       standard_startup(&ejbuf);
+       standard_startup();
        myopt(&argv, cmdinfos);
 
        if (!cipaction)
diff --git a/src/trigcmd.c b/src/trigcmd.c
index c13323f..d0ff3d1 100644
--- a/src/trigcmd.c
+++ b/src/trigcmd.c
@@ -180,7 +180,6 @@ static const struct cmdinfo cmdinfos[] = {
 int
 main(int argc, const char *const *argv)
 {
-       jmp_buf ejbuf;
        int uf;
        const char *badname;
        enum trigdef_updateflags tduf;
@@ -189,7 +188,7 @@ main(int argc, const char *const *argv)
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       standard_startup(&ejbuf);
+       standard_startup();
        myopt(&argv, cmdinfos);
 
        setvbuf(stdout, NULL, _IONBF, 0);

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to