public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH: ObjC testsuite use simple NSConstantString implementation
@ 2004-06-07 11:12 Ziemowit Laski
  2004-06-07 11:26 ` PATCH: ObjC testsuite use simple NSConstantString implementation -- TAKE 2 Ziemowit Laski
  0 siblings, 1 reply; 4+ messages in thread
From: Ziemowit Laski @ 2004-06-07 11:12 UTC (permalink / raw)
  To: Gcc Patch List, David Ayers

This is mostly David's work (thanks, David!), plus I'm reverting my 
ill-fated
'-framework Foundation' fix.  :-)  Will commit shortly unless someone 
screams.

[gcc/testsuite/ChangeLog]
2004-06-07  David Ayers  <d.ayers@inode.at>
	    Ziemowit Laski  <zlaski@apple.com>

	* lib/objc.exp (objc_target_compile): Revert the '-framework
	Foundation' flag fix, since bare Darwin does not ship
	with the Foundation framework.
	* objc/execute/next_mapping.h: Provide a local NSConstantString
	@interface and @implementation.
	* objc/execute/string1.m: Include "next_mapping.h" instead of
	<Foundation/NSString.h>.
	* objc/execute/string2.m: Likewise.
	* objc/execute/string3.m: Likewise.
	* objc/execute/string4.m: Likewise.

Index: gcc/testsuite/lib/objc.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/objc.exp,v
retrieving revision 1.22
diff -c -3 -p -r1.22 objc.exp
*** gcc/testsuite/lib/objc.exp  2 Jun 2004 19:48:49 -0000       1.22
--- gcc/testsuite/lib/objc.exp  7 Jun 2004 05:56:54 -0000
*************** proc objc_target_compile { source dest t
*** 144,150 ****
       global TOOL_OPTIONS
       global ld_library_path
       global objc_libgcc_s_path
-     global target_triplet

       set ld_library_path ".:${objc_libgcc_s_path}"
       lappend options "libs=-lobjc"
--- 144,149 ----
*************** proc objc_target_compile { source dest t
*** 183,196 ****
         lappend options "additional_flags=${objc_link_flags}"
         append ld_library_path ":${libobjc_dir}"
       }
-
-     # If we are running on Darwin, we'll need to point the linker at
-     # the Foundation framework, where many goodies (e.g., 
NSConstantString)
-     # reside.
-     if { [string match "*-*-darwin*" $target_triplet] } {
-       lappend options "libs=-framework Foundation"
-     }
-
       lappend options "compiler=$OBJC_UNDER_TEST"

       # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
--- 182,187 ----
Index: gcc/testsuite/objc/execute/next_mapping.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/next_mapping.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 next_mapping.h
*** gcc/testsuite/objc/execute/next_mapping.h   25 Sep 2003 01:26:00 
-0000      1.2
--- gcc/testsuite/objc/execute/next_mapping.h   7 Jun 2004 05:56:54 
-0000
***************
*** 1,10 ****
   /* This file "renames" various ObjC GNU runtime entry points
      (and fakes the existence of several others)
      if the NeXT runtime is being used.  */
! /* Author: Ziemowit Laski <zlaski@apple.com>  */

   #ifdef __NEXT_RUNTIME__
   #include <objc/objc-class.h>
   #include <ctype.h>

   #define objc_get_class(C)                     objc_getClass(C)
--- 1,12 ----
   /* This file "renames" various ObjC GNU runtime entry points
      (and fakes the existence of several others)
      if the NeXT runtime is being used.  */
! /* Authors: Ziemowit Laski <zlaski@apple.com>  */
! /*        David Ayers <d.ayers@inode.at>  */

   #ifdef __NEXT_RUNTIME__
   #include <objc/objc-class.h>
+ #include <objc/Object.h>
   #include <ctype.h>

   #define objc_get_class(C)                     objc_getClass(C)
*************** void objc_layout_structure_get_info (str
*** 848,851 ****
--- 850,891 ----
       *type = layout->prev_type;
   }

+ /* A small, portable NSConstantString implementation for use with the 
NeXT
+    runtime.
+
+    On full-fledged Mac OS X systems, NSConstantString is provided
+    as part of the Foundation framework.  However, on bare Darwin 
systems,
+    Foundation is not included, and hence there is no NSConstantString
+    implementation to link against.
+
+    This code is derived from the GNU runtime's NXConstantString 
implementation.
+ */
+
+ struct objc_class _NSConstantStringClassReference;
+
+ @interface NSConstantString : Object
+ {
+   char *c_string;
+   unsigned int len;
+ }
+
+ -(const char *) cString;
+ -(unsigned int) length;
+
+ @end
+
+ @implementation NSConstantString
+
+ -(const char *) cString
+ {
+   return (c_string);
+ }
+
+ -(unsigned int) length
+ {
+   return (len);
+ }
+
+ @end
+
   #endif  /* #ifdef __NEXT_RUNTIME__ */
Index: gcc/testsuite/objc/execute/string1.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/string1.m,v
retrieving revision 1.3
diff -c -3 -p -r1.3 string1.m
*** gcc/testsuite/objc/execute/string1.m        25 Sep 2003 01:26:00 
-0000      1.3
--- gcc/testsuite/objc/execute/string1.m        7 Jun 2004 05:56:54 
-0000
***************
*** 4,10 ****
   #include <stdlib.h>

   #ifdef __NEXT_RUNTIME__
! #import <Foundation/NSString.h>
   #else
   #include <objc/NXConstStr.h>
   #endif
--- 4,10 ----
   #include <stdlib.h>

   #ifdef __NEXT_RUNTIME__
! #include "next_mapping.h"
   #else
   #include <objc/NXConstStr.h>
   #endif
Index: gcc/testsuite/objc/execute/string2.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/string2.m,v
retrieving revision 1.3
diff -c -3 -p -r1.3 string2.m
*** gcc/testsuite/objc/execute/string2.m        25 Sep 2003 01:26:00 
-0000      1.3
--- gcc/testsuite/objc/execute/string2.m        7 Jun 2004 05:56:54 
-0000
***************
*** 4,10 ****
   #include <stdlib.h>

   #ifdef __NEXT_RUNTIME__
! #import <Foundation/NSString.h>
   #else
   #include <objc/NXConstStr.h>
   #endif
--- 4,10 ----
   #include <stdlib.h>

   #ifdef __NEXT_RUNTIME__
! #include "next_mapping.h"
   #else
   #include <objc/NXConstStr.h>
   #endif
Index: gcc/testsuite/objc/execute/string3.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/string3.m,v
retrieving revision 1.2
diff -c -3 -p -r1.2 string3.m
*** gcc/testsuite/objc/execute/string3.m        25 Sep 2003 01:26:00 
-0000      1.2
--- gcc/testsuite/objc/execute/string3.m        7 Jun 2004 05:56:54 
-0000
***************
*** 4,10 ****
   #include <stdlib.h>

   #ifdef __NEXT_RUNTIME__
! #import <Foundation/NSString.h>
   #else
   #include <objc/NXConstStr.h>
   #endif
--- 4,10 ----
   #include <stdlib.h>

   #ifdef __NEXT_RUNTIME__
! #include "next_mapping.h"
   #else
   #include <objc/NXConstStr.h>
   #endif
Index: gcc/testsuite/objc/execute/string4.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/string4.m,v
retrieving revision 1.2
diff -c -3 -p -r1.2 string4.m
*** gcc/testsuite/objc/execute/string4.m        25 Sep 2003 01:26:00 
-0000      1.2
--- gcc/testsuite/objc/execute/string4.m        7 Jun 2004 05:56:54 
-0000
***************
*** 4,10 ****
   #include <stdlib.h>

   #ifdef __NEXT_RUNTIME__
! #import <Foundation/NSString.h>
   #else
   #include <objc/NXConstStr.h>
   #endif
--- 4,10 ----
   #include <stdlib.h>

   #ifdef __NEXT_RUNTIME__
! #include "next_mapping.h"
   #else
   #include <objc/NXConstStr.h>
   #endif

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

* PATCH: ObjC testsuite use simple NSConstantString implementation -- TAKE 2
  2004-06-07 11:12 PATCH: ObjC testsuite use simple NSConstantString implementation Ziemowit Laski
@ 2004-06-07 11:26 ` Ziemowit Laski
  2004-06-07 21:09   ` David Ayers
  0 siblings, 1 reply; 4+ messages in thread
From: Ziemowit Laski @ 2004-06-07 11:26 UTC (permalink / raw)
  To: Gcc Patch List, David Ayers

Well, turns out that an __attribute__((constructor)) function was also 
needed to get David's NSConstantString metaclass off the ground...

[gcc/testsuite/ChangeLog]
2004-06-07  David Ayers  <d.ayers@inode.at>
	    Ziemowit Laski  <zlaski@apple.com>

	* lib/objc.exp (objc_target_compile): Revert the '-framework
	Foundation' flag fix, since bare Darwin does not ship
	with the Foundation framework.
	* objc/execute/next_mapping.h: Provide a local NSConstantString
	@interface and @implementation.
	(objc_constant_string_init): A constructor function, used to
	initialize the NSConstantString meta-class object.
	* objc/execute/string1.m: Include "next_mapping.h" instead of
	<Foundation/NSString.h>.
	* objc/execute/string2.m: Likewise.
	* objc/execute/string3.m: Likewise.
	* objc/execute/string4.m: Likewise.

Index: gcc/testsuite/lib/objc.exp
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/lib/objc.exp,v
retrieving revision 1.22
diff -u -3 -p -r1.22 objc.exp
--- gcc/testsuite/lib/objc.exp  2 Jun 2004 19:48:49 -0000       1.22
+++ gcc/testsuite/lib/objc.exp  7 Jun 2004 08:37:21 -0000
@@ -144,7 +144,6 @@ proc objc_target_compile { source dest t
      global TOOL_OPTIONS
      global ld_library_path
      global objc_libgcc_s_path
-    global target_triplet

      set ld_library_path ".:${objc_libgcc_s_path}"
      lappend options "libs=-lobjc"
@@ -183,14 +182,6 @@ proc objc_target_compile { source dest t
         lappend options "additional_flags=${objc_link_flags}"
         append ld_library_path ":${libobjc_dir}"
      }
-
-    # If we are running on Darwin, we'll need to point the linker at
-    # the Foundation framework, where many goodies (e.g., 
NSConstantString)
-    # reside.
-    if { [string match "*-*-darwin*" $target_triplet] } {
-       lappend options "libs=-framework Foundation"
-    }
-
      lappend options "compiler=$OBJC_UNDER_TEST"

      # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but
Index: gcc/testsuite/objc/execute/next_mapping.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/next_mapping.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 next_mapping.h
--- gcc/testsuite/objc/execute/next_mapping.h   25 Sep 2003 01:26:00 
-0000      1.2
+++ gcc/testsuite/objc/execute/next_mapping.h   7 Jun 2004 08:37:21 
-0000
@@ -1,10 +1,12 @@
  /* This file "renames" various ObjC GNU runtime entry points
     (and fakes the existence of several others)
     if the NeXT runtime is being used.  */
-/* Author: Ziemowit Laski <zlaski@apple.com>  */
+/* Authors: Ziemowit Laski <zlaski@apple.com>  */
+/*         David Ayers <d.ayers@inode.at>  */

  #ifdef __NEXT_RUNTIME__
  #include <objc/objc-class.h>
+#include <objc/Object.h>
  #include <ctype.h>

  #define objc_get_class(C)                      objc_getClass(C)
@@ -848,4 +850,52 @@ void objc_layout_structure_get_info (str
      *type = layout->prev_type;
  }

+/* A small, portable NSConstantString implementation for use with the 
NeXT
+   runtime.
+
+   On full-fledged Mac OS X systems, NSConstantString is provided
+   as part of the Foundation framework.  However, on bare Darwin 
systems,
+   Foundation is not included, and hence there is no NSConstantString
+   implementation to link against.
+
+   This code is derived from the GNU runtime's NXConstantString 
implementation.
+*/
+
+struct objc_class _NSConstantStringClassReference;
+
+@interface NSConstantString : Object
+{
+  char *c_string;
+  unsigned int len;
+}
+
+-(const char *) cString;
+-(unsigned int) length;
+
+@end
+
+@implementation NSConstantString
+
+-(const char *) cString
+{
+  return (c_string);
+}
+
+-(unsigned int) length
+{
+  return (len);
+}
+
+@end
+
+/* The NSConstantString metaclass will need to be initialized before 
we can
+   send messages to strings.  */
+
+void objc_constant_string_init (void) __attribute__((constructor));
+void objc_constant_string_init (void) {
+  memcpy (&_NSConstantStringClassReference,
+         objc_getClass ("NSConstantString"),
+         sizeof (_NSConstantStringClassReference));
+}
+
  #endif  /* #ifdef __NEXT_RUNTIME__ */
Index: gcc/testsuite/objc/execute/string1.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/string1.m,v
retrieving revision 1.3
diff -u -3 -p -r1.3 string1.m
--- gcc/testsuite/objc/execute/string1.m        25 Sep 2003 01:26:00 
-0000      1.3
+++ gcc/testsuite/objc/execute/string1.m        7 Jun 2004 08:37:21 
-0000
@@ -4,7 +4,7 @@
  #include <stdlib.h>

  #ifdef __NEXT_RUNTIME__
-#import <Foundation/NSString.h>
+#include "next_mapping.h"
  #else
  #include <objc/NXConstStr.h>
  #endif
Index: gcc/testsuite/objc/execute/string2.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/string2.m,v
retrieving revision 1.3
diff -u -3 -p -r1.3 string2.m
--- gcc/testsuite/objc/execute/string2.m        25 Sep 2003 01:26:00 
-0000      1.3
+++ gcc/testsuite/objc/execute/string2.m        7 Jun 2004 08:37:21 
-0000
@@ -4,7 +4,7 @@
  #include <stdlib.h>

  #ifdef __NEXT_RUNTIME__
-#import <Foundation/NSString.h>
+#include "next_mapping.h"
  #else
  #include <objc/NXConstStr.h>
  #endif
Index: gcc/testsuite/objc/execute/string3.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/string3.m,v
retrieving revision 1.2
diff -u -3 -p -r1.2 string3.m
--- gcc/testsuite/objc/execute/string3.m        25 Sep 2003 01:26:00 
-0000      1.2
+++ gcc/testsuite/objc/execute/string3.m        7 Jun 2004 08:37:21 
-0000
@@ -4,7 +4,7 @@
  #include <stdlib.h>

  #ifdef __NEXT_RUNTIME__
-#import <Foundation/NSString.h>
+#include "next_mapping.h"
  #else
  #include <objc/NXConstStr.h>
  #endif
Index: gcc/testsuite/objc/execute/string4.m
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/objc/execute/string4.m,v
retrieving revision 1.2
diff -u -3 -p -r1.2 string4.m
--- gcc/testsuite/objc/execute/string4.m        25 Sep 2003 01:26:00 
-0000      1.2
+++ gcc/testsuite/objc/execute/string4.m        7 Jun 2004 08:37:21 
-0000
@@ -4,7 +4,7 @@
  #include <stdlib.h>

  #ifdef __NEXT_RUNTIME__
-#import <Foundation/NSString.h>
+#include "next_mapping.h"
  #else
  #include <objc/NXConstStr.h>
  #endif

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

* Re: PATCH: ObjC testsuite use simple NSConstantString implementation -- TAKE 2
  2004-06-07 11:26 ` PATCH: ObjC testsuite use simple NSConstantString implementation -- TAKE 2 Ziemowit Laski
@ 2004-06-07 21:09   ` David Ayers
  2004-06-07 21:22     ` Ziemowit Laski
  0 siblings, 1 reply; 4+ messages in thread
From: David Ayers @ 2004-06-07 21:09 UTC (permalink / raw)
  To: Ziemowit Laski; +Cc: Gcc Patch List

Ziemowit Laski wrote:
> Well, turns out that an __attribute__((constructor)) function was also 
> needed to get David's NSConstantString metaclass off the ground...

I guess you've tested and got it working.  I thought according to 
extend.texi that:

"These attributes [constructor, destructor] are not currently 
implemented for Objective-C."

Does this refer to methods or is it obsolete?  Of course this is 
orthogonal to the patch itself.

Cheers,
David

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

* Re: PATCH: ObjC testsuite use simple NSConstantString implementation -- TAKE 2
  2004-06-07 21:09   ` David Ayers
@ 2004-06-07 21:22     ` Ziemowit Laski
  0 siblings, 0 replies; 4+ messages in thread
From: Ziemowit Laski @ 2004-06-07 21:22 UTC (permalink / raw)
  To: David Ayers; +Cc: Gcc Patch List


On 7 Jun, 2004, at 13.31, David Ayers wrote:

> Ziemowit Laski wrote:
>> Well, turns out that an __attribute__((constructor)) function was 
>> also needed to get David's NSConstantString metaclass off the 
>> ground...
>
> I guess you've tested and got it working.  I thought according to 
> extend.texi that:
>
> "These attributes [constructor, destructor] are not currently 
> implemented for Objective-C."
>
> Does this refer to methods or is it obsolete?

It refers to methods only.  In next_mapping.h, I used it in a plain 
vanilla C function, which is OK.


>   Of course this is orthogonal to the patch itself.

Yup. :-)

--Zem
--------------------------------------------------------------
Ziemowit Laski                 1 Infinite Loop, MS 301-2K
Mac OS X Compiler Group        Cupertino, CA USA  95014-2083
Apple Computer, Inc.           +1.408.974.6229  Fax .5477

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

end of thread, other threads:[~2004-06-07 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-07 11:12 PATCH: ObjC testsuite use simple NSConstantString implementation Ziemowit Laski
2004-06-07 11:26 ` PATCH: ObjC testsuite use simple NSConstantString implementation -- TAKE 2 Ziemowit Laski
2004-06-07 21:09   ` David Ayers
2004-06-07 21:22     ` Ziemowit Laski

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).