bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC/base] Minor GSObjCRuntime usage cleanups


From: David Ayers
Subject: [RFC/base] Minor GSObjCRuntime usage cleanups
Date: Tue, 29 Jul 2003 13:28:37 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4b) Gecko/20030507

Hello Richard,

Thanks for the corrections in the NSUndoManager docs :-) When you reread your own documentation over and over are keep restructuring... But I guess you know what I'm talking about. I'm surprised, you didn't find more issues, I'm sure they're still hiding. I'll reread it later some time and fix any issues.

I take it, your currently still working on the NSSocket issues of gdnc/NSDistributedNotificationCenter. If not, then maybe we should add some #warning to gdnc/NSDistributedNotificationCenter to remind us that if still needs fixing up. Code like this:
if (0 && isLocal == YES && service != GDNC_NETWORK)
is likely to go unnoticed for a while.

In GSFFInvocation/GSFFCallInvocation you changed the NSCAssert1 to an explicit [NSExcaption raise:-...]. I take it that's because Asserts are there to be removable by compiler options, but the exception should stay. But you also used sel_get_name in favor of GSNameFromSelector. Was that merely habit? Or is there some technical reason for it (avoiding the check for nil...)? If not, I'd like to commit this patch that uses the GSObjCRuntime functions. People learn from our patches and I think we should try to be consistent in our conventions and use the API we define.

I'd kind of like GSObjCRuntime to turn into a real abstraction layer of the runtimes.

This would also introduce:
GS_STATIC_INLINE const char *
GSClassNameFromObject(id obj)
{
 if (obj == 0)
   return 0;
 return object_get_class_name(obj);
}

There are cases I haven't dared yet convert:
object_is_instance(obj)->GSObjCIsInstance(obj)
or
object_get_class(obj)->GSObjCClass(obj)

because of potential differing implementations and requirements (e.g. obj being null, but that has been tested before in most cases). But maybe we should first decide whether the GSObjCRuntime funcktions should in general be nil tolarant.

There are also minor details of the testing subdirectory. It currently still fails to build for me in gstcpport-client:
Making all for test_tool gstcpport-client...
Compiling file gstcpport-client.m ...
gstcpport-client.m: In function `main':
gstcpport-client.m:27: warning: assignment from incompatible pointer type
gstcpport-client.m:33: warning: `GSTcpPort' does not respond to `sendBeforeDate:components:from:reserved:'
Linking test_tool gstcpport-client ...
shared_obj/gstcpport-client.o(.data.rel+0xb0): In function `main':
/usr/local/src/cvs/gnustep/core/base/Testing/gstcpport-client.m:24: undefined reference to `__objc_class_name_GSTcpPort'
collect2: ld returned 1 exit status
make[1]: *** [shared_obj/gstcpport-client] Error 1
make: *** [gstcpport-client.all.test-tool.variables] Error 2

I'm sure you can quickly solve it if you have the time, otherwise I'll look into it later. Richt now I'd like to turn my attention to the Header issue.

Well, here it is and if no one object's I'll commit this soon.

       * Headers/gnustep/base/GSObjCRuntime.h
       (GSClassNameFromObject): New function.
       * Source/GSFFCallInvocation.m
       (gs_find_best_typed_sel): Replace sel_get_name with
       GSNameFromSelector.
       (-[GSFFCallInvocation invokeWithTarget:]): Replace
       class_get_super_class with GSObjCSuper.
       (GSInvocationCallback): Replace NSCAssert2 with NSException,
       object_get_class_name with GSClassNameFromObject and sel_get_name
       with GSNameFromSelector.
       * Source/GSFFCallInvocation.m
       (gs_find_best_typed_sel): Replace sel_get_name with
       GSNameFromSelector.
       (-[GSFFIInvocation invokeWithTarget:]): Replace
       class_get_super_class with GSObjCSuper.
       (GSInvocationCallback): Replace NSCAssert2 with NSException,
       object_get_class_name with GSClassNameFromObject and sel_get_name
       with GSNameFromSelector.
       * Testing/Makefile.postamble: Make 'all' a prerequsite of 'check'.
       * Testing/nsbundle.m (main): Adapt to new file system layout.



Cheers,
David
Index: Headers/gnustep/base/GSObjCRuntime.h
===================================================================
RCS file: 
/cvsroot/gnustep/gnustep/core/base/Headers/gnustep/base/GSObjCRuntime.h,v
retrieving revision 1.20
diff -u -r1.20 GSObjCRuntime.h
--- Headers/gnustep/base/GSObjCRuntime.h        7 Jul 2003 10:31:59 -0000       
1.20
+++ Headers/gnustep/base/GSObjCRuntime.h        29 Jul 2003 11:23:29 -0000
@@ -187,6 +187,18 @@
 }
 
 /**
+ * Return the name of the object's class, or a nul pointer if no object
+ * was supplied.
+ */
+GS_STATIC_INLINE const char *
+GSClassNameFromObject(id obj)
+{
+  if (obj == 0)
+    return 0;
+  return object_get_class_name(obj);
+}
+
+/**
  * Return the name of the supplied selector, or a nul pointer if no selector
  * was supplied.
  */
Index: Source/GSFFCallInvocation.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Source/GSFFCallInvocation.m,v
retrieving revision 1.35
diff -u -r1.35 GSFFCallInvocation.m
--- Source/GSFFCallInvocation.m 28 Jul 2003 10:53:18 -0000      1.35
+++ Source/GSFFCallInvocation.m 29 Jul 2003 11:23:29 -0000
@@ -214,12 +214,11 @@
     {
       if (object_is_instance (receiver))
         {
-          return GSGetInstanceMethod (object_get_class
-                                              (receiver), sel);
+          return GSGetInstanceMethod(object_get_class(receiver), sel);
         }
       else if (object_is_class (receiver))
         {
-          return GSGetClassMethod (receiver, sel);
+          return GSGetClassMethod(receiver, sel);
         }
     }
 
@@ -248,7 +247,7 @@
 {
   if (!sel_get_type (sel))
     {
-      const char *name = sel_get_name (sel);
+      const char *name = GSNameFromSelector(sel);
       
       if (name)
        {
@@ -679,9 +678,9 @@
 
       s.self = _target;
       if (GSObjCIsInstance(_target))
-       s.class = class_get_super_class(GSObjCClass(_target));
+       s.class = GSObjCSuper(GSObjCClass(_target));
       else
-       s.class = class_get_super_class((Class)_target);
+       s.class = GSObjCSuper((Class)_target);
       imp = objc_msg_lookup_super(&s, _selector);
     }
   else
@@ -801,9 +800,13 @@
   
   if (!fwdInvMethod)
     {
-      NSCAssert2 (0, @"GSFFCallInvocation: Class '%s' does not respond"
-                  @" to forwardInvocation: for '%s'",
-                  object_get_class_name (obj), sel_get_name(selector));
+      [NSException raise: NSInvalidArgumentException
+                  format: @"GSFFCallInvocation: Class '%s(%s)'"
+                          @" does not respond"
+                          @" to forwardInvocation: for '%s'",
+                  GSClassNameFromObject(obj),
+                  GSObjCIsInstance(obj) ? "instance" : "class",
+                  selector ? GSNameFromSelector(selector) : "(null)"];
     }
   
   sig = nil;
@@ -831,7 +834,7 @@
 
       if (runtimeTypes == 0 || strcmp(receiverTypes, runtimeTypes) != 0)
        {
-         const char    *runtimeName = sel_get_name (selector);
+         const char    *runtimeName = GSNameFromSelector(selector);
 
          selector = sel_get_typed_uid (runtimeName, receiverTypes);
          if (selector == 0)
@@ -864,9 +867,9 @@
     {
       [NSException raise: NSInvalidArgumentException
                  format: @"%s(%s) does not recognize %s",
-        object_get_class_name(obj),
+        GSClassNameFromObject(obj),
         GSObjCIsInstance(obj) ? "instance" : "class",
-        selector ? sel_get_name(selector) : "(null)"];
+        selector ? GSNameFromSelector(selector) : "(null)"];
     }
     
   invocation = [[GSFFCallInvocation alloc] initWithMethodSignature: sig];
Index: Source/GSFFIInvocation.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Source/GSFFIInvocation.m,v
retrieving revision 1.21
diff -u -r1.21 GSFFIInvocation.m
--- Source/GSFFIInvocation.m    28 Jul 2003 10:53:18 -0000      1.21
+++ Source/GSFFIInvocation.m    29 Jul 2003 11:23:29 -0000
@@ -61,13 +61,11 @@
     {
       if (object_is_instance (receiver))
         {
-          return GSGetInstanceMethod (object_get_class
-                                              (receiver), sel);
+          return GSGetInstanceMethod(object_get_class (receiver), sel);
         }
       else if (object_is_class (receiver))
         {
-          return GSGetClassMethod (object_get_class
-                                           (receiver), sel);
+          return GSGetClassMethod(object_get_class (receiver), sel);
         }
     }
 
@@ -96,7 +94,7 @@
 {
   if (!sel_get_type (sel))
     {
-      const char *name = sel_get_name (sel);
+      const char *name = GSNameFromSelector(sel);
       
       if (name)
        {
@@ -325,9 +323,9 @@
 
       s.self = _target;
       if (GSObjCIsInstance(_target))
-       s.class = class_get_super_class(GSObjCClass(_target));
+       s.class = GSObjCSuper(GSObjCClass(_target));
       else
-       s.class = class_get_super_class((Class)_target);
+       s.class = GSObjCSuper((Class)_target);
       imp = objc_msg_lookup_super(&s, _selector);
     }
   else
@@ -420,9 +418,12 @@
   
   if (!fwdInvMethod)
     {
-      NSCAssert2 (0, @"GSFFIInvocation: Class '%s' does not respond"
-                  @" to forwardInvocation: for '%s'",
-                  object_get_class_name (obj), sel_get_name(selector));
+      [NSException raise: NSInvalidArgumentException
+                  format: @"GSFFIInvocation: Class '%s'(%s) does not respond"
+                          @" to forwardInvocation: for '%s'",
+                  GSClassNameFromObject(obj),
+                  GSObjCIsInstance(obj) ? "instance" : "class",
+                  selector ? GSNameFromSelector(selector) : "(null)"];
     }
        
   sig = nil;
@@ -446,7 +447,7 @@
 
       if (runtimeTypes == 0 || strcmp(receiverTypes, runtimeTypes) != 0)
        {
-         const char    *runtimeName = sel_get_name (selector);
+         const char    *runtimeName = GSNameFromSelector(selector);
 
          selector = sel_get_typed_uid (runtimeName, receiverTypes);
          if (selector == 0)
@@ -479,9 +480,9 @@
     {
       [NSException raise: NSInvalidArgumentException
                  format: @"%s(%s) does not recognize %s",
-        object_get_class_name(obj),
+        GSClassNameFromObject(obj),
         GSObjCIsInstance(obj) ? "instance" : "class",
-        selector ? sel_get_name(selector) : "(null)"];
+        selector ? GSNameFromSelector(selector) : "(null)"];
     }
     
   invocation = [[GSFFIInvocation alloc] initWithCallback: cif
Index: Testing/Makefile.postamble
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Testing/Makefile.postamble,v
retrieving revision 1.6
diff -u -r1.6 Makefile.postamble
--- Testing/Makefile.postamble  24 Jun 2003 03:46:13 -0000      1.6
+++ Testing/Makefile.postamble  29 Jul 2003 11:23:30 -0000
@@ -66,7 +66,7 @@
 after-distclean::
        rm -f cstream.dat fref.dat nsarchiver.dat
 
-check::
+check:: all
        for f in $(CHECKABLE_TOOLS); do \
          obj/$$f ; \
        done
Index: Testing/nsbundle.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/base/Testing/nsbundle.m,v
retrieving revision 1.14
diff -u -r1.14 nsbundle.m
--- Testing/nsbundle.m  30 May 2003 02:54:49 -0000      1.14
+++ Testing/nsbundle.m  29 Jul 2003 11:23:30 -0000
@@ -48,9 +48,13 @@
     printf("Looking for LoadMe bundle...\n");
     path = [path stringByDeletingLastPathComponent];
     path = [path stringByDeletingLastPathComponent];
-    path = [path stringByDeletingLastPathComponent];
-    path = [path stringByDeletingLastPathComponent];
-    path = [path stringByDeletingLastPathComponent];
+    if ([[path lastPathComponent] isEqualToString:@"Testing"] == NO)
+      {
+       /* Delete library combo */
+       path = [path stringByDeletingLastPathComponent];
+       path = [path stringByDeletingLastPathComponent];
+       path = [path stringByDeletingLastPathComponent];
+      }
     printf("  Bundle directory is %s\n", [path cString]);
     path = [NSBundle pathForResource:@"LoadMe" ofType:@"bundle"
                      inDirectory: path];


reply via email to

[Prev in Thread] Current Thread [Next in Thread]