This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C99 assert


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 6/26/2007 2:07 PM:
> Jeff Johnston <jjohnstn <at> redhat.com> writes:
[see thread at http://sourceware.org/ml/newlib/2007/msg00763.html -
cygwin's assert currently doesn't comply with POSIX]
> 
>> Hi Eric,
>>
>>    I'd like to see backward-compatiblity to be the old-style message 
>> format.  I don't see the point of saying: function <blank>.  So, old 
>> compiled calls to __assert would behave as they always have.  Similarly, 
>> for systems without function capability, I would like to use the old 
>> message format.  My take would be to have both __assert and 
>> __assert_func and have assert map to the appropriate call.  I also think 
>> that the function should be quoted or you should use a colon (e.g. 
>> function: getparms) for clarification.
>>
> 
> How about the following, then?
> 
> 2007-06-26  Eric Blake  <ebb9@byu.net>
> 
> 	Support __func__ in assert, as required by C99.
> 	* libc/stdlib/assert.c (__assert_func): New function.
> 	(__assert): Use __assert_func.
> 	* libc/include/assert.h (assert) [!NDEBUG]: Use __assert_func when
> 	possible.

If I check in just the above newlib patch, CVS cygwin will be broken when
trying to use assert (and simply exporting __assert_func won't help, since
cygwin's assert.cc must provide all symbols present in newlib's assert.c).
 Likewise, this patch without newlib would break (because assert.h is
maintained by newlib).  So, is it OK to apply this patch at the same time
as the newlib patch, to avoid breakage?

2007-06-26  Eric Blake  <ebb9@byu.net>

	* assert.cc (__assert_func): New function, to match newlib header
	change.
	* cygwin.din: Export __assert_func.
	* include/cygwin/version.h: Bump API minor number.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGgbZm84KuGfSFAYARAlGEAJ0SkMaoL1uk3ubAKlpOAHEpqwyoKgCfWvO1
Ab5YpcbXTEG7FSab/uuxDZo=
=W9ry
-----END PGP SIGNATURE-----
Index: cygwin.din
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/cygwin.din,v
retrieving revision 1.176
diff -u -p -r1.176 cygwin.din
--- cygwin.din	21 Jun 2007 15:57:54 -0000	1.176
+++ cygwin.din	27 Jun 2007 00:43:20 -0000
@@ -118,6 +118,7 @@ _asprintf = asprintf SIGFE
 asprintf_r = _asprintf_r SIGFE
 _asprintf_r SIGFE
 __assert SIGFE
+__assert_func SIGFE
 __assertfail SIGFE
 atan NOSIGFE
 _atan = atan NOSIGFE
Index: assert.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/assert.cc,v
retrieving revision 1.9
diff -u -p -r1.9 assert.cc
--- assert.cc	19 Sep 2002 15:12:48 -0000	1.9
+++ assert.cc	27 Jun 2007 00:43:20 -0000
@@ -1,6 +1,6 @@
 /* assert.cc: Handle the assert macro for WIN32.
 
-   Copyright 1997, 1998, 2000, 2001 Red Hat, Inc.
+   Copyright 1997, 1998, 2000, 2001, 2007 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -23,6 +23,13 @@ details. */
 extern "C" void
 __assert (const char *file, int line, const char *failedexpr)
 {
+  __assert_func (file, line, NULL, failedexpr);
+}
+
+extern "C" void
+__assert_func (const char *file, int line, const char *func,
+	       const char *failedexpr)
+{
   HANDLE h;
 
   /* If we don't have a console in a Windows program, then bring up a
@@ -35,15 +42,17 @@ __assert (const char *file, int line, co
       char *buf;
 
       buf = (char *) alloca (100 + strlen (failedexpr));
-      __small_sprintf (buf, "Failed assertion\n\t%s\nat line %d of file %s",
-		failedexpr, line, file);
+      __small_sprintf (buf, "Failed assertion\n\t%s\nat line %d of file %s%s%s",
+		       failedexpr, line, file,
+		       func ? "\nin function " : "", func ? func : "");
       MessageBox (NULL, buf, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
     }
   else
     {
       CloseHandle (h);
-      small_printf ("assertion \"%s\" failed: file \"%s\", line %d\n",
-		    failedexpr, file, line);
+      small_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
+		    failedexpr, file, line,
+		    func ? ", function: " : "", func ? func : "");
     }
 
 #ifdef DEBUGGING
Index: include/cygwin/version.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/cygwin/version.h,v
retrieving revision 1.246
diff -u -p -r1.246 version.h
--- include/cygwin/version.h	21 Jun 2007 15:57:54 -0000	1.246
+++ include/cygwin/version.h	27 Jun 2007 00:43:20 -0000
@@ -313,12 +313,13 @@ details. */
       171: Export exp10, exp10f, pow10, pow10f, strcasestr, funopen,
            fopencookie.
       172: Export getifaddrs, freeifaddrs.
+      173: Export __assert_func.
      */
 
      /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 172
+#define CYGWIN_VERSION_API_MINOR 173
 
      /* There is also a compatibity version number associated with the
 	shared memory regions.  It is incremented when incompatible

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]