bug-cvs
[Top][All Lists]
Advanced

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

RE: Windows Build: feature branch, src/exithandle.c,


From: Conrad T. Pino
Subject: RE: Windows Build: feature branch, src/exithandle.c,
Date: Sat, 15 May 2004 15:02:00 -0700

Hi Larry,

> From: Larry Jones
> 
> That just silences the warning, it doesn't fix the problem.  As I said
> before, the problem is that signal handlers take one argument and exit
> handlers take no arguments, but we're trying to use the same functions
> for both -- you can't do that because the two different function types
> could have completely different calling conventions.  The only way to
> fix the problem is to have two separate functions (although one could
> just be a wrapper for the other), but it's not clear that it's worth it
> since the problem is purely theoretical -- there are no known
> implementations where the current code actually fails.

This is a deeper solution using a wrapper.

> I object to silencing the warning without fixing the problem, but I
> don't object to not fixing the problem.  :-)

I agree about silencing without fixing and
I'd like to make the warning go away.

> -Larry Jones

Conrad

Index: src/cvs.h
===================================================================
RCS file: /cvs/ccvs/src/cvs.h,v
retrieving revision 1.292
diff -u -p -r1.292 cvs.h
--- src/cvs.h   9 May 2004 04:01:20 -0000       1.292
+++ src/cvs.h   15 May 2004 21:49:18 -0000
@@ -606,8 +606,11 @@ int cvs_casecmp (const char *, const cha
 #endif
 
 /* exithandle.c */
-void signals_register (RETSIGTYPE (*handler)(int));
-void cleanup_register (void (*handler) (void));
+typedef RETSIGTYPE (*signals_handler_t) (int);
+typedef void (*cleanup_handler_t) (void);
+
+void signals_register (signals_handler_t handler);
+void cleanup_register (cleanup_handler_t handler);
 
 void strip_trailing_slashes (char *path);
 void update_delproc (Node * p);

Index: src/exithandle.c
===================================================================
RCS file: /cvs/ccvs/src/exithandle.c,v
retrieving revision 1.1
diff -u -p -r1.1 exithandle.c
--- src/exithandle.c    5 Oct 2003 03:32:45 -0000       1.1
+++ src/exithandle.c    15 May 2004 21:49:18 -0000
@@ -14,7 +14,7 @@
  * Register a handler for all signals.
  */
 void
-signals_register (RETSIGTYPE (*handler)(int))
+signals_register (signals_handler_t handler)
 {
 #ifndef DONT_USE_SIGNALS
 #ifdef SIGABRT
@@ -38,12 +38,64 @@ signals_register (RETSIGTYPE (*handler)(
 #endif /* !DONT_USE_SIGNALS */
 }
 
+#ifndef DONT_USE_SIGNALS
+#define cleanup_array_size 16
+static int cleanup_in_use = 0;
+
+static cleanup_handler_t cleanup_handlers[ cleanup_array_size ];
+
+static int
+cleanup_signals_handler (int signal)
+{
+       int index;
+
+       /* run in reverse registration order like signals */
+       for ( index = cleanup_in_use; --index >= 0; )
+               (*cleanup_handlers[ index ]) ();
+
+       return 0;
+}
+#endif /* !DONT_USE_SIGNALS */
+
 /*
  * Register a handler for all signals and exit.
  */
 void
-cleanup_register (void (*handler) (void))
+cleanup_register (cleanup_handler_t handler)
 {
-    signals_register (handler);
+#ifndef DONT_USE_SIGNALS
+       int index;
+
+       if ( cleanup_in_use >= cleanup_array_size )
+       {
+               fprintf (stderr, "file %s line %d increase 
cleanup_array_size\n", __FILE__, __LINE__ );
+               abort ();
+       }
+
+    if (cleanup_in_use == 0) signals_register (cleanup_signals_handler);
+
+       /* determine if handler is already registered */
+       for ( index = 0; index < cleanup_in_use; )
+       {
+               if ( cleanup_handlers[ index ] == handler )
+               {
+                       --cleanup_in_use;
+                       break;
+               }
+
+               ++index;
+       }
+       /* handler was registered prior to last registration */
+       while ( index < cleanup_in_use )
+       {
+               /* remove old registration by moving successors one position */
+               cleanup_handlers[ index ] = cleanup_handlers[ index + 1 ];
+               ++index;
+       }
+       /* register at end of list */
+       cleanup_handlers[ index ] = handler;
+       cleanup_in_use = index + 1;
+#endif /* !DONT_USE_SIGNALS */
+
     atexit (handler);
 }





reply via email to

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