[Top][All Lists]

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

Re: Can't mix native exceptions and ObjC++

From: Larry Campbell
Subject: Re: Can't mix native exceptions and ObjC++
Date: Sun, 30 Dec 2007 13:43:36 -0500

On Dec 26, 2007, at 7:22 PM, Larry Campbell wrote:

Before I spend a lot of time figuring out how to fix this, I thought I'd ping the list to see if anyone else has run into this. I just tried turning on native Objective-C exceptions (--enable-native-objc- exceptions to gnustep-base/configure). Everything seems to build OK, but if there are any Objective-C++ modules that use exceptions in my link, the link fails with:

        undefined reference to `typeinfo for NSException*'

As long as there's no Objective-C++ (.mm) in the link, I'm fine.

This happens with both (gnustep-make 1.13.0 + gnustep-base 1.13.1) and (gnustep-make 2.0.2 + gnustep-base 1.14.1). I tried renaming NSException.m to NSException.mm (and fixing the type errors the stricter compile revealed); no joy.

Has anyone already run into this (and, hopefully, fixed it)?

- lc

Did a little experimenting, and it seems native exceptions are broken even more badly than I first thought. If I compile this test program:

#include <Foundation/Foundation.h>

@interface ETest : NSObject {
- (void)doSomething;

@implementation ETest
- (void)doSomething
id exc = [NSException exceptionWithName:@"foo" reason:@"foo" userInfo:nil];
  NSLog(@"Throwing 0x%x", exc);

int main(int argc, const char *argv[])
  NSAutoreleasePool *pool = [NSAutoreleasePool new];
  ETest *et = [ETest new];
  @try {
    [et doSomething];
  } @catch(id exc) {
    NSLog(@"Caught 0x%x", exc);
    NSLog(@"Caught %@", exc);
  [pool release];
  return 0;

as Objective-C (a .m file), it works as expected and produces this output:

2007-12-30 13:36:08.471 etest[18679] Start
2007-12-30 13:36:08.473 etest[18679] Throwing 0x80b7818
2007-12-30 13:36:08.474 etest[18679] Caught 0x80b7818
2007-12-30 13:36:08.474 etest[18679] Caught <NSException: 0x80b7818> NAME:foo REASON:foo
2007-12-30 13:36:08.474 etest[18679] End

But if I rename it to a .mm file and adjust the GNUmakefile accordingly, it instead does this:

2007-12-30 13:34:58.131 etest[18625] Start
2007-12-30 13:34:58.133 etest[18625] Throwing 0x80c43b8
2007-12-30 13:34:58.134 etest[18625] Caught 0x80bf9b8
Segmentation fault (core dumped)

Note that the pointer caught in the second example is not the same as the pointer thrown!

The code compiles and runs just fine on Mac OS X 10.5.

I suppose this is starting to look more like a gcc bug than a gnustep bug. I'm using gcc 4.1.2 on linux/x86.

- lc

reply via email to

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