bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] libports: Code clean up.


From: Neal H Walfield
Subject: [PATCH] libports: Code clean up.
Date: Sat, 31 Mar 2001 10:43:02 +0200
User-agent: Mutt/1.3.15i

On Mon, Mar 26, 2001 at 04:25:55PM -0500, Roland McGrath wrote:
> Can you separate your miscellaneous fixes from the weak symbol stuff?  In
> general, please separate logically separable changes and post them
> separately.  Then we can easily check in your various small fixes before
> addressing the whole weak symbol quagmire.  And even if we were to decide
> to commit all these changes, it is still best to have them separate so it
> is easy to back out one logically isolated change distinct from other
> changes.

Here is the code clean up.

2001-03-29  Neal H Walfield  <neal@cs.uml.edu>

        * claim-right.c (ports_claim_right):  Include errno.h and
        assert.h.  Add assertions.  Clean up the logic.

        * create-bucket.c (ports_create_bucket): Include errno.h
        and stdlib.h.  Do not include assert.h.  Turn assertions
        into errors that set errno and return NULL.
        * create-class.c (ports_create_class): Likewise.

        * create-internal.c (_ports_create_internal): On error, do
        no deallocate a send right but a receive right.

        * init.c: Do not initialize global variables to 0.
        * interrupt-notified-rpcs.c: Likewise.

        * port-deref.c (ports_port_deref):  Simplify logic.

        * reallocate-port.c (ports_reallocate_port): Assert return from
        mach_port_move_member.
        * transfer-right.c (ports_transfer_right): Likewise.

diff -urN hurd-20010329-snapshot/libports/claim-right.c 
hurd-20010329/libports/claim-right.c
--- hurd-20010329-snapshot/libports/claim-right.c       Tue May 14 14:56:33 1996
+++ hurd-20010329/libports/claim-right.c        Fri Mar 30 21:05:40 2001
@@ -1,5 +1,5 @@
 /* Take a receive right away from a port
-   Copyright (C) 1996 Free Software Foundation, Inc.
+   Copyright (C) 1996, 2001 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
@@ -20,33 +20,34 @@
 
 
 #include "ports.h"
+#include <assert.h>
+#include <errno.h>
 #include <hurd/ihash.h>
 
 mach_port_t
 ports_claim_right (void *portstruct)
 {
+  error_t err;
   struct port_info *pi = portstruct;
-  mach_port_t ret;
+  mach_port_t ret = pi->port_right;
 
-  if (pi->port_right != MACH_PORT_NULL)
+  if (ret == MACH_PORT_NULL)
+    return ret;
+
+  mutex_lock (&_ports_lock);
+  ihash_locp_remove (pi->bucket->htable, pi->hentry);
+  err = mach_port_move_member (mach_task_self (), ret, MACH_PORT_NULL);
+  assert_perror (err);
+  pi->port_right = MACH_PORT_NULL;
+  if (pi->flags & PORT_HAS_SENDRIGHTS)
     {
-      ret = pi->port_right;
-      
-      mutex_lock (&_ports_lock);
-      ihash_locp_remove (pi->bucket->htable, pi->hentry);
-      mach_port_move_member (mach_task_self (), ret, MACH_PORT_NULL);
-      pi->port_right = MACH_PORT_NULL;
-      if (pi->flags & PORT_HAS_SENDRIGHTS)
-       {
-         pi->flags &= ~PORT_HAS_SENDRIGHTS;
-         mutex_unlock (&_ports_lock);
-         ports_port_deref (pi);
-       }
-      else
-       mutex_unlock (&_ports_lock);
+      pi->flags &= ~PORT_HAS_SENDRIGHTS;
+      mutex_unlock (&_ports_lock);
+      ports_port_deref (pi);
     }
   else
-    ret = MACH_PORT_NULL;
+    mutex_unlock (&_ports_lock);
+
   return ret;
 }
 
diff -urN hurd-20010329-snapshot/libports/create-bucket.c 
hurd-20010329/libports/create-bucket.c
--- hurd-20010329-snapshot/libports/create-bucket.c     Fri Feb 14 06:58:46 1997
+++ hurd-20010329/libports/create-bucket.c      Fri Mar 30 21:19:14 2001
@@ -1,5 +1,5 @@
 /* Create a port bucket
-   Copyright (C) 1995, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1997, 2001 Free Software Foundation, Inc.
    Written by Michael I. Bushnell.
 
    This file is part of the GNU Hurd.
@@ -19,7 +19,8 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 #include "ports.h"
-#include <assert.h>
+#include <errno.h>
+#include <stdlib.h>
 #include <hurd/ihash.h>
 #include <cthreads.h>
 
@@ -30,14 +31,30 @@
   error_t err;
 
   ret = malloc (sizeof (struct port_bucket));
-  assert (ret);
+  if (! ret)
+    {
+      errno = ENOMEM;
+      return NULL;
+    }
 
   err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_PORT_SET, 
                            &ret->portset);
-  assert_perror (err);
+  if (err)
+    {
+      errno = err;
+      free (ret);
+      return NULL;
+    }
 
   err = ihash_create (&ret->htable);
-  assert_perror (err);
+  if (err)
+    {
+      errno = err;
+      mach_port_mod_refs (mach_task_self (), ret->portset,
+                         MACH_PORT_RIGHT_PORT_SET, -1);
+      free (ret);
+      return NULL;
+    }
 
   ret->rpcs = ret->flags = ret->count = 0;
 
diff -urN hurd-20010329-snapshot/libports/create-class.c 
hurd-20010329/libports/create-class.c
--- hurd-20010329-snapshot/libports/create-class.c      Sat Jan 27 18:12:56 1996
+++ hurd-20010329/libports/create-class.c       Fri Mar 30 21:36:52 2001
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1995 Free Software Foundation, Inc.
+   Copyright (C) 1995,2001 Free Software Foundation, Inc.
    Written by Michael I. Bushnell.
 
    This file is part of the GNU Hurd.
@@ -20,7 +20,7 @@
 
 #include "ports.h"
 #include <stdlib.h>
-#include <assert.h>
+#include <errno.h>
 
 struct port_class *
 ports_create_class (void (*clean_routine)(void *),
@@ -29,7 +29,12 @@
   struct port_class *cl;
   
   cl = malloc (sizeof (struct port_class));
-  assert (cl);
+  if (! cl)
+    {
+      errno = ENOMEM;
+      return NULL;
+    }
+
   cl->clean_routine = clean_routine;
   cl->dropweak_routine = dropweak_routine;
   cl->flags = 0;
diff -urN hurd-20010329-snapshot/libports/create-internal.c 
hurd-20010329/libports/create-internal.c
--- hurd-20010329-snapshot/libports/create-internal.c   Fri Jul 19 07:11:34 1996
+++ hurd-20010329/libports/create-internal.c    Fri Mar 30 21:32:09 2001
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1996 Free Software Foundation, Inc.
+   Copyright (C) 1996,2001 Free Software Foundation, Inc.
    Written by Michael I. Bushnell, p/BSG.
 
    This file is part of the GNU Hurd.
@@ -48,7 +48,9 @@
   pi = malloc (size);
   if (! pi)
     {
-      mach_port_deallocate (mach_task_self (), port);
+      err = mach_port_mod_refs (mach_task_self (), port,
+                               MACH_PORT_RIGHT_RECEIVE, -1);
+      assert_perror (err);
       return ENOMEM;
     }
 
@@ -94,7 +96,12 @@
   mutex_unlock (&_ports_lock);
   
   if (install)
-    mach_port_move_member (mach_task_self (), pi->port_right, bucket->portset);
+    {
+      err = mach_port_move_member (mach_task_self (), pi->port_right,
+                                  bucket->portset);
+      if (err)
+       goto lose;
+    }
 
   *(void **)result = pi;
   return 0;
@@ -103,7 +110,9 @@
   err = EINTR;
  lose:
   mutex_unlock (&_ports_lock);
-  mach_port_mod_refs (mach_task_self (), port, MACH_PORT_RIGHT_RECEIVE, -1);
+  err = mach_port_mod_refs (mach_task_self (), port,
+                           MACH_PORT_RIGHT_RECEIVE, -1);
+  assert_perror (err);
   free (pi);
 
   return err;
diff -urN hurd-20010329-snapshot/libports/init.c hurd-20010329/libports/init.c
--- hurd-20010329-snapshot/libports/init.c      Tue Jun 20 18:31:54 1995
+++ hurd-20010329/libports/init.c       Fri Mar 30 21:51:06 2001
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1995 Free Software Foundation, Inc.
+   Copyright (C) 1995, 2001 Free Software Foundation, Inc.
    Written by Michael I. Bushnell.
 
    This file is part of the GNU Hurd.
@@ -23,6 +23,6 @@
 
 struct mutex _ports_lock = MUTEX_INITIALIZER;
 struct condition _ports_block = CONDITION_INITIALIZER;
-struct port_bucket *_ports_all_buckets = 0;
-int _ports_total_rpcs = 0;
-int _ports_flags = 0;
+struct port_bucket *_ports_all_buckets;
+int _ports_total_rpcs;
+int _ports_flags;
diff -urN hurd-20010329-snapshot/libports/interrupt-notified-rpcs.c 
hurd-20010329/libports/interrupt-notified-rpcs.c
--- hurd-20010329-snapshot/libports/interrupt-notified-rpcs.c   Thu Dec 28 
19:15:10 1995
+++ hurd-20010329/libports/interrupt-notified-rpcs.c    Fri Mar 30 21:51:06 2001
@@ -1,8 +1,8 @@
 /* Handle interruping rpcs because of notification
 
-   Copyright (C) 1995 Free Software Foundation, Inc.
+   Copyright (C) 1995, 2001 Free Software Foundation, Inc.
 
-   Written by Miles Bader <miles@gnu.ai.mit.edu>
+   Written by Miles Bader <miles@gnu.org>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -21,11 +21,11 @@
 #include "ports.h"
 
 /* A linked list of ports for which notification has been requested.  */
-struct ports_notify *_ports_notifications = 0;
+struct ports_notify *_ports_notifications;
 
 /* Free lists for notify structures.  */
-struct ports_notify *_ports_free_ports_notifies = 0;
-struct rpc_notify *_ports_free_rpc_notifies = 0;
+struct ports_notify *_ports_free_ports_notifies;
+struct rpc_notify *_ports_free_rpc_notifies;
 
 /* Interrupt any rpcs on OBJECT that have requested such.  */
 void
diff -urN hurd-20010329-snapshot/libports/port-deref.c 
hurd-20010329/libports/port-deref.c
--- hurd-20010329-snapshot/libports/port-deref.c        Tue Jun 20 18:31:54 1995
+++ hurd-20010329/libports/port-deref.c Fri Mar 30 21:28:10 2001
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1995 Free Software Foundation, Inc.
+   Copyright (C) 1995, 2001 Free Software Foundation, Inc.
    Written by Michael I. Bushnell.
 
    This file is part of the GNU Hurd.
@@ -32,11 +32,11 @@
   
   mutex_lock (&_ports_lock);
   
-  if (pi->refcnt == 1 && pi->weakrefcnt && !trieddroppingweakrefs)
+  if (pi->refcnt == 1 && pi->weakrefcnt
+      && pi->class->dropweak_routine && !trieddroppingweakrefs)
     {
       mutex_unlock (&_ports_lock);
-      if (pi->class->dropweak_routine)
-       (*pi->class->dropweak_routine) (pi);
+      (*pi->class->dropweak_routine) (pi);
       trieddroppingweakrefs = 1;
       goto retry;
     }
diff -urN hurd-20010329-snapshot/libports/reallocate-port.c 
hurd-20010329/libports/reallocate-port.c
--- hurd-20010329-snapshot/libports/reallocate-port.c   Fri Mar 29 16:24:08 1996
+++ hurd-20010329/libports/reallocate-port.c    Fri Mar 30 21:40:58 2001
@@ -1,5 +1,5 @@
 /* 
-   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 2001 Free Software Foundation, Inc.
    Written by Michael I. Bushnell.
 
    This file is part of the GNU Hurd.
@@ -52,8 +52,9 @@
   ihash_add (pi->bucket->htable, pi->port_right, pi, &pi->hentry);
   mutex_unlock (&_ports_lock);
 
-  mach_port_move_member (mach_task_self (), pi->port_right, 
-                        pi->bucket->portset);
+  err = mach_port_move_member (mach_task_self (), pi->port_right, 
+                              pi->bucket->portset);
+  assert_perror (err);
 
   if (dropref)
     ports_port_deref (pi);
diff -urN hurd-20010329-snapshot/libports/transfer-right.c 
hurd-20010329/libports/transfer-right.c
--- hurd-20010329-snapshot/libports/transfer-right.c    Fri Mar 29 15:34:56 1996
+++ hurd-20010329/libports/transfer-right.c     Fri Mar 30 21:47:04 2001
@@ -20,6 +20,7 @@
 
 
 #include "ports.h"
+#include <assert.h>
 #include <hurd/ihash.h>
 
 error_t
@@ -56,6 +57,7 @@
       ihash_locp_remove (topi->bucket->htable, topi->hentry);
       err = mach_port_mod_refs (mach_task_self (), topi->port_right,
                                MACH_PORT_RIGHT_RECEIVE, -1);
+      assert_perror (err);
       if ((topi->flags & PORT_HAS_SENDRIGHTS) && !hassendrights)
        {
          dereftopi = 1;
@@ -77,7 +79,11 @@
     {
       ihash_add (topi->bucket->htable, port, topi, &topi->hentry);
       if (topi->bucket != frompi->bucket)
-       mach_port_move_member (mach_task_self (), port, topi->bucket->portset);
+        {
+         err = mach_port_move_member (mach_task_self (), port,
+                                      topi->bucket->portset);
+         assert_perror (err);
+       }
     }
   
   mutex_unlock (&_ports_lock);

Attachment: pgpP_IEZ8C1un.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]