[m-rev.] diff/review: deep profiler enhancements

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jul 4 01:20:16 AEST 2001


On 03-Jul-2001, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> > Get rid of the `#define MDPROF_NUM_SIGNAL_NUMBERS 12'
> > and replace it with
> > 
> > 	extern const int	signal_numbers[];
> > 	extern const int	MDPROF_num_signal_numbers;
> > 
> > and
> > 
> > 	#define MDPROF_ARRAY_LEN(a) (sizeof(a)/sizeof((a)[0]))
> > 
> > 	const int signal_numbers[] = { ... }
> > 	const int MDPROF_num_signal_numbers = MDPROF_ARRAY_LEN(signal_numbers);
> 
> I originally did that. I switched to the current unsatisfactory scheme when
> code very like the above caused gcc to abort with the usual message about
> spilling a forbidden register, and simple code transformations failed to work
> around the problem.

Ouch.

In that case, there should be a comment explaining why the code is
written in that way.

Another alternative that might avoid both the gcc abort and the need
to hard-code the array length would be to use a sentinel value, e.g. 0
or -1, to indicate the end of the array.  (Note that ISO C and Posix
signal numbers are guaranteed to be positive integers.)

> > > +	void	(*handler)(void);
> > 
> > This is a type error; the arguments types to handler() don't
> > match the types that signal() or sigaction() expects.
> > It happens to work on many C implementations, but it's not
> > guaranteed to work.
> 
> As I recall, I don't think there is consistency about various operating
> system flavours about the arguments passed to signal handlers. I would
> love to be proven wrong on this, though.

No, you're right.  The way to solve this is to use some abstraction
in runtime/mercury_signal.h, so that it can then be

	#include "mercury_signal.h"

	/* MR_SignalHandler is a typedef for the appropriate function type */
	MR_SignalHandler *handler;	

	/* MR_SignalHandlerRet is a typedef for the appropriate return type */
	/* MR_SIGNAL_HANDLER_ARGS is a macro for the argument decls */
	static MR_SignalHandlerRet
	my_handler(MR_SIGNAL_HANDLER_ARGS)
	{
		...
	}

	...

	handler = my_handler;

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list