public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* cp/errfn.c
@ 1998-02-02 15:13 John Carr
  1998-02-06  0:57 ` cp/errfn.c Jeffrey A Law
  0 siblings, 1 reply; 6+ messages in thread
From: John Carr @ 1998-02-02 15:13 UTC (permalink / raw)
  To: egcs

I have been trying to build 32 to 64 bit cross compilers using long long as
HOST_WIDE_INT.  I ran into a serious problem in C++.  It can't print
warnings or errors.  cp/errfn.c works only by chance, when all function
arguments are passed the same way as a HOST_WIDE_INT.

This is a new version of cp/errfn.c, changed to use stdarg.  The diffs are
larger than the file so I am just sending the new file.

#include "config.h"
#include "tree.h"
#include <stdio.h>
#include <ctype.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif

/* cp_printer is the type of a function which converts an argument into
   a string for digestion by printf.  The cp_printer function should deal
   with all memory management; the functions in this file will not free
   the char*s returned.  See error.c for an example use of this code.  */

typedef char* cp_printer PROTO((tree, int));
extern cp_printer * cp_printers[256];

/* Whether or not we should try to be quiet for errors and warnings; this is
   used to avoid being too talkative about problems with tentative choices
   when we're computing the conversion costs for a method call.  */
int cp_silent = 0;

typedef void errorfn ();	/* deliberately vague */

extern char* cp_file_of PROTO((tree));
extern int   cp_line_of PROTO((tree));

#define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)

/* This function supports only `%s', `%d', and the C++ print codes.  */

#ifdef __STDC__
static void
cp_thing (errorfn *errfn, int atarg1, const char *format, va_list ap)
#else
static void
cp_thing (errfn, atarg1, format, ap)
     errorfn *errfn;
     int atarg1;
     const char *format;
     va_list ap;
#endif
{
  static char *buf;
  static long buflen;
  long len;
  long offset;
  const char *f;
  tree atarg = 0;

  len = strlen (format) + 1;
  if (len > buflen)
    {
      buflen = len;
      buf = xmalloc (buflen);
    }
  offset = 0;

  for (f = format; *f; ++f)
    {
      cp_printer * function;
      int alternate;
      int maybe_here;
      
      /* ignore text */
      if (*f != '%')
	{
	  buf[offset++] = *f;
	  continue;
	}

      ++f;

      alternate = 0;
      maybe_here = 0;

      /* Check for '+' and '#' (in that order). */
      if (*f == '+')
	{
	  maybe_here = 1;
	  ++f;
	}
      if (*f == '#')
	{
	  alternate = 1;
	  ++f;
	}

      /* no field width or precision */

      function = cp_printers[(int)*f];

      if (function || *f == 's')
	{
	  char *p;
	  int plen;

	  if (*f == 's')
	    {
	      p = va_arg (ap, char *);
	    }
	  else
	    {
	      tree t = va_arg (ap, tree);
	      if (maybe_here && atarg == 0)
		atarg = t;

	      p = (*function) (t, alternate);
	    }

	  plen = strlen (p);
	  len += plen;
	  if (len > buflen)
	    {
	      buflen = len;
	      buf = xrealloc (buf, len);
	    }
	  strcpy (buf + offset, p);
	  offset += plen;
	}
      else
	{
	  if (*f != 'd')
	    abort ();
	  len += HOST_BITS_PER_INT / 2;
	  if (len > buflen)
	    {
	      buflen = len;
	      buf = xmalloc (len);
	    }
	  sprintf (buf + offset, "%d", va_arg (ap, int));
	  offset += strlen (buf + offset);
	  /* With an ANSI C library one could write
	     out += sprintf (...); */
	}
    }
  buf[offset] = '\0';

  if (atarg)
    {
      char *file = cp_file_of (atarg);
      int   line = cp_line_of (atarg);
      (*errfn) (file, line, "%s", buf);
    }
  else
    (*errfn) ("%s", buf);

}

#ifdef __STDC__
#define DECLARE(name) void name (const char *format, ...)
#define INIT va_start (ap, format)
#else
#define DECLARE(name) void name (format, va_alist) char *format; va_dcl
#define INIT va_start (ap)
#endif

DECLARE (cp_error)
{
  extern errorfn error;
  va_list ap;
  INIT;
  if (! cp_silent)
    cp_thing (error, 0, format, ap);
  va_end (ap);
}

DECLARE (cp_warning)
{
  extern errorfn warning;
  va_list ap;
  INIT;
  if (! cp_silent)
    cp_thing (warning, 0, format, ap);
  va_end (ap);
}

DECLARE (cp_pedwarn)
{
  va_list ap;
  INIT;
  if (! cp_silent)
    cp_thing ((errorfn *) pedwarn, 0, format, ap);
  va_end (ap);
}

DECLARE (cp_compiler_error)
{
  extern errorfn compiler_error;
  va_list ap;
  INIT;
  if (! cp_silent)
    cp_thing (compiler_error, 0, format, ap);
  va_end (ap);
}

DECLARE (cp_sprintf)
{
  va_list ap;
  INIT;
  cp_thing ((errorfn *) sprintf, 0, format, ap);
  va_end (ap);
}

DECLARE (cp_error_at)
{
  va_list ap;
  INIT;
  if (! cp_silent)
    cp_thing ((errorfn *) error_with_file_and_line, 1, format, ap);
  va_end (ap);
}

DECLARE (cp_warning_at)
{
  va_list ap;
  INIT;
  if (! cp_silent)
    cp_thing ((errorfn *) warning_with_file_and_line, 1, format, ap);
  va_end (ap);
}

DECLARE (cp_pedwarn_at)
{
  va_list ap;
  INIT;
  if (! cp_silent)
    cp_thing ((errorfn *) pedwarn_with_file_and_line, 1, format, ap);
  va_end (ap);
}



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: cp/errfn.c
  1998-02-02 15:13 cp/errfn.c John Carr
@ 1998-02-06  0:57 ` Jeffrey A Law
  0 siblings, 0 replies; 6+ messages in thread
From: Jeffrey A Law @ 1998-02-06  0:57 UTC (permalink / raw)
  To: John Carr; +Cc: egcs

  In message < 199802022158.QAA25954@jfc. >you write:
  > 
  > I have been trying to build 32 to 64 bit cross compilers using long long as
  > HOST_WIDE_INT.  I ran into a serious problem in C++.  It can't print
  > warnings or errors.  cp/errfn.c works only by chance, when all function
  > arguments are passed the same way as a HOST_WIDE_INT.
  > 
  > This is a new version of cp/errfn.c, changed to use stdarg.  The diffs are
  > larger than the file so I am just sending the new file.
Even if the diffs are larger than the whole file, it's easier on us if you
send diffs instead.  Less likely to end up overwriting someone else's
changes.  Can you send diffs instead?

Thanks!

jeff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: cp/errfn.c
  2000-07-06 22:34 ` cp/errfn.c Mark Mitchell
@ 2000-07-07  5:53   ` Philipp Thomas
  0 siblings, 0 replies; 6+ messages in thread
From: Philipp Thomas @ 2000-07-07  5:53 UTC (permalink / raw)
  To: Mark Mitchell; +Cc: gcc

* Mark Mitchell (mark@codesourcery.com) [20000707 07:34]:

> And errfns.c is code that is likely to end up more widely shared than it
> presently is.
> 
> Does that make sense?

Yes, it does. Thanks for the explanation.

Philipp

-- 
Philipp Thomas <pthomas@suse.de>
Development, SuSE GmbH, Schanzaecker Str. 10, D-90443 Nuremberg, Germany

#define NINODE  50              /* number of in core inodes */
#define NPROC   30              /* max number of processes */
 	-- Version 7 UNIX for PDP 11, /usr/include/sys/param.h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: cp/errfn.c
  2000-07-06 21:06 cp/errfn.c Philipp Thomas
@ 2000-07-06 22:34 ` Mark Mitchell
  2000-07-07  5:53   ` cp/errfn.c Philipp Thomas
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Mitchell @ 2000-07-06 22:34 UTC (permalink / raw)
  To: pthomas; +Cc: gcc

>>>>> "Philipp" == Philipp Thomas <pthomas@suse.de> writes:

    Philipp> Mark,

    Philipp> errfn.c uses K&R funtion definitions. As it's allways
    Philipp> compiled by gcc, I'd say there is no need to do
    Philipp> so. Equally so for using VPARAMS.

In general, we've tried to avoid making code in the C++ front-end
impossible to compile with other compilers.  We haven't tried too hard
to make sure in can be compiled with other compilers -- but we've
tried not to do obviously unfriendly things.  The reason is that code
tends to migrate from one place in the compiler to another.  And
errfns.c is code that is likely to end up more widely shared than it
presently is.

Does that make sense?

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* cp/errfn.c
@ 2000-07-06 21:06 Philipp Thomas
  2000-07-06 22:34 ` cp/errfn.c Mark Mitchell
  0 siblings, 1 reply; 6+ messages in thread
From: Philipp Thomas @ 2000-07-06 21:06 UTC (permalink / raw)
  To: gcc; +Cc: Mark Mitchell

Mark,

errfn.c uses K&R funtion definitions. As it's allways compiled by gcc, I'd
say there is no need to do so. Equally so for using VPARAMS. 

And, last and least, couldn't code like the below also vanish (more specific the
ANIS_PROTOTYPES guards)? We use gcc, so we have our own varargs.h and I thus
see no reason for that.

#ifndef ANSI_PROTOTYPES
  char *format;
#endif
  va_list ap;

  VA_START (ap, format);

#ifndef ANSI_PROTOTYPES
  format = va_arg (ap, char *);
#endif
 
Philipp

-- 
Philipp Thomas <pthomas@suse.de>
Development, SuSE GmbH, Schanzaecker Str. 10, D-90443 Nuremberg, Germany

#define NINODE  50              /* number of in core inodes */
#define NPROC   30              /* max number of processes */
 	-- Version 7 UNIX for PDP 11, /usr/include/sys/param.h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: cp/errfn.c
@ 1998-02-02 19:07 Mike Stump
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Stump @ 1998-02-02 19:07 UTC (permalink / raw)
  To: egcs, jfc

> From: John Carr <jfc@mit.edu>
> To: egcs@cygnus.com
> Date: Mon, 02 Feb 1998 16:58:46 -0500

> The diffs are larger than the file so I am just sending the new
> file.

Please don't do this.  The reason is that is someone else modifies it
in between the time you fetched it and the time the patch is
installed, their work is silently lost.  With a patch, work is never
silently lost.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-07-07  5:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-02 15:13 cp/errfn.c John Carr
1998-02-06  0:57 ` cp/errfn.c Jeffrey A Law
1998-02-02 19:07 cp/errfn.c Mike Stump
2000-07-06 21:06 cp/errfn.c Philipp Thomas
2000-07-06 22:34 ` cp/errfn.c Mark Mitchell
2000-07-07  5:53   ` cp/errfn.c Philipp Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).