Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strategies to prevent class name clashes




On 15 Feb '08, at 3:42 AM, Arne Scheffler wrote:

the toolkit in question is VSTGUI. It's a C++ cross-platform UI library. It is statically linked into every plug-in. Mostly the users of it won't use Objective-C by them self.
The problem I did face was that I have an ivar which is a C++ class of the lib. And when I used this ivar and the C++ object had a different layout than at build time it crashed.

I'm confused — is this a problem of collisions between C++ classes or Obj-C classes?


If the C++ code is statically linked into each plugin, then it can't conflict between multiple plugins. Each one will be directly calling its own copy of the code, even if the C++ classnames and namespaces are the same.

Objective-C classes _will_ conflict between multiple plugins, if they have the same name. So what you have to do is make sure that every plugin that statically links shared Obj-C code renames the classes with unique prefixes. Basically, any time you write an Obj-C bundle or framework, all the classes in it need to have a unique prefix, whether or not you wrote those classes yourself.

It sounds like what's happening to you is that some of your classes load out of your bundle and some get loaded from another plugin, and these mismatched classes are passing C++ object pointers between themselves. So when code from one plugin allocates a C++ object (with one version of the C++ code), and then code from a different plugin receives a pointer to that object and tries to operate on it using a different version of the C++ code, you go boom.

But that's not a C++ specific problem. As soon as you have parts of different versions of a library loaded and calling into each other, there will be trouble. I've had this happen with Obj-C and pure C code as well. You have to uniquify your Obj-C class names to avoid this.

—Jens_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Strategies to prevent class name clashes (From: Arne Scheffler <email@hidden>)
 >Re: Strategies to prevent class name clashes (From: Lieven Dekeyser <email@hidden>)
 >Re: Strategies to prevent class name clashes (From: Uli Kusterer <email@hidden>)
 >Re: Strategies to prevent class name clashes (From: Arne Scheffler <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.