This is the mail archive of the gcc@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]

Re: [libobjc] Shouldn't "version" take a long?


Please forgive me if I'm being dense, I'm very new to Objective-C.

The problem was that a class in GNUMail (PGPController) implemented a method thusly:

- (NSString *) version
{
  return @"v0.9.1";
}

That method is declared in the GNUMailBundle protocol. GNUMail would segfault when the pointer returned by that method was accessed in any way. I looked at it in gdb and figured out that the pointer was being truncated to 4 bytes (I have an LP64 system.) Renaming the method made the truncation and crash go away.

Object.m declares a "version" class method that returns an int. NSObject in the GNUStep base library also has a "version" class method that returns an int. I don't know what the rules are in Objective-C for overloading by return type, but gcc did not complain when it compiled PGPController. (The output from gcc 4.1.2 for that class is at the end of this message.)

Incidentally, what are the rules for overloading by return type? I looked around and all I found was this:

"Although identically named class methods and instance methods are represented by the same selector, they can have different argument and return types."
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_4_section_6.html


Which makes me think that what GNUMail does should be allowed. I don't know where the confusion between pointer and int is coming in.

Thanks,
Jose.




x86_64-pc-linux-gnu-gcc PGPController.m -c \
-MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -D_REENTRANT -fPIC -g -Wall -DDEBUG -fno-omit-frame-pointer -DGSWARN -DGSDIAGNOSE -Wno-import -march=nocona -pipe -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -fgnu-runtime -Wall -Wno-import -fconstant-string-class=NSConstantString -I../../Framework/GNUMail -I. -I/var/tmp/portage/gnustep-apps/gnumail-1.2.0_pre3/temp/GNUstep/Library/Headers -I/usr/GNUstep/Local/Library/Headers -I/usr/GNUstep/System/Library/Headers \
-o obj/PGPController.o
PGPController.m:743: warning: incomplete implementation of class 'PGPController'
PGPController.m:743: warning: method definition for '-bodyWasDecoded:forMessage:' not found
PGPController.m:743: warning: method definition for '-bodyWillBeDecoded:forMessage:' not found
PGPController.m:743: warning: method definition for '-bodyWasEncoded:forMessage:' not found
PGPController.m:743: warning: method definition for '-bodyWillBeEncoded:forMessage:' not found
PGPController.m:743: warning: method definition for '-composeViewAccessoryWillBeRemovedFromSuperview:' not found
PGPController.m:743: warning: class 'PGPController' does not fully implement the 'GNUMailBundle' protocol



Andrew Pinski wrote:
On 9/26/07, Jose Quinteiro <gentoo@quinteiro.org> wrote:
Hello,

The getter/setter for version in Object.M gets/takes an int, and they
eventually get/set the "version" field in struct objc_class.   This
field is declared as a long in objc/objc.h.

Why? Any change here will change the ABI so it incorrect thing to do. So the GNUMail issue seems like people are ignoring warnings that GCC generates about methods are not declared in the class.

-- Pinski


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