OSDN Git Service

New structure containing fields used by the on_exit() function.
authornickc <nickc>
Fri, 6 Jun 2003 15:36:30 +0000 (15:36 +0000)
committernickc <nickc>
Fri, 6 Jun 2003 15:36:30 +0000 (15:36 +0000)
(struct _atexit): Include struct _on_exit_args.  For _REENT_SMALL do his via a
pointer that is initialised when needed.

newlib/ChangeLog
newlib/libc/include/sys/reent.h
newlib/libc/reent/reent.c
newlib/libc/stdlib/atexit.c
newlib/libc/stdlib/exit.c
newlib/libc/stdlib/on_exit.c

index 7dbfae3..a7d738a 100644 (file)
@@ -1,3 +1,20 @@
+2003-06-05  Nick Clifton  <nickc@redhat.com>
+       
+       * libc/include/sys/reent.h (struct _on_exit_args): New
+       structure containing fields used by the on_exit() function.
+        (struct _atexit): Include struct _on_exit_args.  For
+       _REENT_SMALL do his via a pointer that is initialised when
+       needed.
+        * libc/reent/reent.c (_reclaim_reent): Free the _on_exit_args
+       structure, if one has been allocated.
+        * libc/stdlib/atexit.c (atexit): Update indirection to
+       _fntypes field.
+        * libc/stdlib/on_exit.c (on_exit): Indirect via the
+       _on_exit_args structure.  For _REENT_SMALL, allocate a
+       structure if one does not exist.
+        * libc/stdlib/exit.c (exit): Indirect via the _on_exit_args
+       structure.
+
 2003-06-04  Jeff Johnston  <jjohnstn@redhat.com>
 
        * libc/sys/linux/net/Makefile.am: Remove extraneous markers.
index 2d6ce41..d1a04dc 100644 (file)
@@ -64,20 +64,24 @@ struct __tm
 
 #define        _ATEXIT_SIZE 32 /* must be at least 32 to guarantee ANSI conformance */
 
-#ifndef _REENT_SMALL
+struct _on_exit_args {
+       void *  _fnargs[_ATEXIT_SIZE];          /* fn args for on_exit */
+       __ULong _fntypes;                       /* type of exit routine -
+                                                  Must have at least _ATEXIT_SIZE bits */
+};
+
+#ifdef _REENT_SMALL
 struct _atexit {
-       struct  _atexit *_next;                 /* next in list */
        int     _ind;                           /* next index in this table */
        void    (*_fns[_ATEXIT_SIZE])(void);    /* the table itself */
-       void    *_fnargs[_ATEXIT_SIZE];         /* fn args for on_exit */
-       __ULong _fntypes;                       /* type of exit routine */
+        struct _on_exit_args * _on_exit_args_ptr;
 };
 #else
 struct _atexit {
+       struct  _atexit *_next;                 /* next in list */
        int     _ind;                           /* next index in this table */
        void    (*_fns[_ATEXIT_SIZE])(void);    /* the table itself */
-       void    *_fnargs[_ATEXIT_SIZE];         /* fn args for on_exit */
-       __ULong _fntypes;                       /* type of exit routine */
+        struct _on_exit_args _on_exit_args;
 };
 #endif
 
index 9300e8c..3ce02dc 100644 (file)
@@ -81,6 +81,8 @@ _DEFUN (_reclaim_reent, (ptr),
        _free_r (ptr, ptr->_localtime_buf);
       if (ptr->_asctime_buf)
        _free_r (ptr, ptr->_asctime_buf);
+      if (ptr->_atexit._on_exit_args_ptr)
+       _free_r (ptr->_atexit._on_exit_args_ptr);
 #else
       /* atexit stuff */
       if ((ptr->_atexit) && (ptr->_atexit != &ptr->_atexit0))
index 165b3cf..e0e4298 100644 (file)
@@ -65,16 +65,16 @@ _DEFUN (atexit,
 {
   register struct _atexit *p;
 
-/* _REENT_SMALL atexit() doesn't allow more than the required 32 entries.  */
+  /* _REENT_SMALL atexit() doesn't allow more than the required 32 entries.  */
 #ifndef _REENT_SMALL
   if ((p = _REENT->_atexit) == NULL)
     _REENT->_atexit = p = &_REENT->_atexit0;
   if (p->_ind >= _ATEXIT_SIZE)
     {
       if ((p = (struct _atexit *) malloc (sizeof *p)) == NULL)
-       return -1;
+        return -1;
       p->_ind = 0;
-      p->_fntypes = 0;
+      p->_on_exit_args._fntypes = 0;
       p->_next = _REENT->_atexit;
       _REENT->_atexit = p;
     }
index 54664fe..a659361 100644 (file)
@@ -60,20 +60,43 @@ _DEFUN (exit, (code),
        int code)
 {
   register struct _atexit *p;
+  register struct _on_exit_args * args;
   register int n;
-  int i = 1;
+  int i;
+
+  p = &_REENT->_atexit;
 
 #ifdef _REENT_SMALL
-  for (p = &_REENT->_atexit, n = p->_ind-1, i = (n>=0) ? (1<<n) : 0; 
-       n >= 0; --n, i >>= 1)
+  args = p->_on_exit_args_ptr;
+  
+  if (args == NULL)
+    {
+      for (n = p->_ind; n--;)
+        p->_fns[n] ();
+    }
+  else
+    {
+      for (n = p->_ind - 1, i = (n >= 0) ? (1 << n) : 0; n >= 0; --n, i >>= 1)
+        if (args->_fntypes & i)
+          (*((void (*)(int, void *)) p->_fns[n]))(code, args->_fnargs[n]);
+        else
+          p->_fns[n] ();
+    }
 #else
-  for (p = _REENT->_atexit; p; p = p->_next)
-    for (n = p->_ind - 1, i = (n >= 0) ? (1 << n) : 0; n >= 0; --n, i >>= 1)
+  do
+    {
+      args = & p->_on_exit_args;
+  
+      for (n = p->_ind - 1, i = (n >= 0) ? (1 << n) : 0; n >= 0; --n, i >>= 1)
+        if (args->_fntypes & i)
+          (*((void (*)(int, void *)) p->_fns[n]))(code, args->_fnargs[n]);
+        else
+          p->_fns[n] ();
+
+      p = p->_next;
+    }
+  while (p);
 #endif
-      if (p->_fntypes & i)
-        (*((void (*)(int, void *))p->_fns[n]))(code, p->_fnargs[n]);
-      else
-        (*p->_fns[n]) ();
 
   if (_REENT->__cleanup)
     (*_REENT->__cleanup) (_REENT);
index 1b6cd2a..b7bf6f3 100644 (file)
@@ -68,29 +68,40 @@ _DEFUN (on_exit,
        _VOID _EXFUN ((*fn), (int, _PTR)) _AND
         _PTR arg)
 {
+  struct _on_exit_args * args;
   register struct _atexit *p;
   void (*x)(void) = (void (*)(void))fn;
 
 /* _REENT_SMALL on_exit() doesn't allow more than the required 32 entries.  */
-#ifndef _REENT_SMALL
+#ifdef _REENT_SMALL
+  p = &_REENT->_atexit;
+  if (p->_ind >= _ATEXIT_SIZE)
+    return -1;
+  args = p->_on_exit_args_ptr;
+  if (args == NULL)
+    {
+      args = malloc (sizeof * p->_on_exit_args_ptr);
+      if (args == NULL)
+        return -1;
+      args->_fntypes = 0;
+      p->_on_exit_args_ptr = args;
+    }
+#else
   if ((p = _REENT->_atexit) == NULL)
     _REENT->_atexit = p = &_REENT->_atexit0;
   if (p->_ind >= _ATEXIT_SIZE)
     {
       if ((p = (struct _atexit *) malloc (sizeof *p)) == NULL)
-       return -1;
+        return -1;
       p->_ind = 0;
-      p->_fntypes = 0;
+      p->_on_exit_args._fntypes = 0;
       p->_next = _REENT->_atexit;
       _REENT->_atexit = p;
     }
-#else
-  p = &_REENT->_atexit;
-  if (p->_ind >= _ATEXIT_SIZE)
-    return -1;
+  args = & p->_on_exit_args;
 #endif
-  p->_fntypes |= (1 << p->_ind);
-  p->_fnargs[p->_ind] = arg;
+  args->_fntypes |= (1 << p->_ind);
+  args->_fnargs[p->_ind] = arg;
   p->_fns[p->_ind++] = x;
   return 0;
 }