This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Add a predefined symbol __NEXT_RUNTIME__ to ObjC


One of the little peculiarities of GNU Objective-C is that it supports
two incompatible runtimes, the original "NeXT" runtime, and a later
workalike called the "GNU" runtime.  The two runtimes actually have
different user-visible API, and it's been a longstanding wishlist
item to provide a way for source code to know which is in use.  This
patch does that by using all the nice new predefine mechy to define a
__NEXT_RUNTIME__ macro, and includes a sample usage in one of the test
cases that has been failing on Darwin for some time.

Since there may be better ideas about how to accomplish this, I'm going
to let this sit for a day before committing.  (If anybody is wondering,
I chose __NEXT_RUNTIME__ instead of __GNU_RUNTIME__ because it's the
exceptional rather than the default situation.)

Bootstraps and passes testsuite on i686-pc-linux and powerpc-apple-darwin.

Stan

2002-08-15  Stan Shebs  <shebs@apple.com>

       * c-common.c (cb_register_builds): Define __NEXT_RUNTIME__
       for ObjC with -fnext-runtime.
       * doc/cpp.texi: Document it.

[testsuite]
2002-08-15  Stan Shebs  <shebs@apple.com>

       * objc/execute/selector-1.m: Add __NEXT_RUNTIME__ case.

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.365
diff -p -r1.365 c-common.c
*** c-common.c  12 Aug 2002 06:02:52 -0000      1.365
--- c-common.c  15 Aug 2002 19:00:21 -0000
*************** cb_register_builtins (pfile)
*** 4745,4750 ****
--- 4745,4754 ----
   if (!flag_signed_char)
     cpp_define (pfile, "__CHAR_UNSIGNED__");

+   /* Make the choice of ObjC runtime visible to source code.  */
+   if (flag_objc && flag_next_runtime)
+     cpp_define (pfile, "__NEXT_RUNTIME__");
+
   /* A straightforward target hook doesn't work, because of problems
      linking that hook's body when part of non-C front ends.  */
 # define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
Index: doc/cpp.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/cpp.texi,v
retrieving revision 1.40
diff -p -r1.40 cpp.texi
*** doc/cpp.texi        6 Aug 2002 20:35:45 -0000       1.40
--- doc/cpp.texi        15 Aug 2002 19:00:24 -0000
*************** the typedefs.
*** 2003,2008 ****
--- 2003,2012 ----
 This macro is defined, with value 1, if the compiler uses the old
 mechanism based on @code{setjmp} and @code{longjmp} for exception
 handling.
+
+ @item __NEXT_RUNTIME__
+ This macro is defined, with value 1, when the NeXT runtime
+ (as in @option{-fnext-runtime}) is in use for Objective-C.
 @end table

 @node System-specific Predefined Macros
Index: testsuite/objc/execute/selector-1.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/selector-1.m,v
retrieving revision 1.2
diff -p -r1.2 selector-1.m
*** testsuite/objc/execute/selector-1.m 12 Mar 2001 06:24:50 -0000      1.2
--- testsuite/objc/execute/selector-1.m 15 Aug 2002 19:00:24 -0000
***************
*** 6,17 ****
 int main (void)
 {
   SEL selector;

   selector = @selector (alloc);
!   if (strcmp (sel_get_name (selector), "alloc"))
!     {
!       abort ();
!     }

   return 0;
 }
--- 6,21 ----
 int main (void)
 {
   SEL selector;
+   char *selname;

   selector = @selector (alloc);
! #ifdef __NEXT_RUNTIME__
!   selname = sel_getName (selector);
! #else
!   selname = sel_get_name (selector);
! #endif
!   if (strcmp (selname, "alloc"))
!     abort ();

   return 0;
 }





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