Is -fconstant-string-class broken under the XCode/Next runtime

Member
Posts: 64
Joined: 2005.06
Post: #1
Because I've been writing cross-platform code for the past couple of weeks now, I've dropped Cocoa beyond using it as glue. All platform specific code, Cocoa or Win32 API is handled by custom abstraction classes that provide a unified interface to make platform independent code (I tried SDL but found I didn't like it after using it for a couple days).

The easy part surprisingly was recreating new object, array, ect. classes and re-implementing some of the basic features such as retain counts (as well as a ridiculously simple but ultimately effective autorelease system), delegation and other useful goodies.

Where I'm stumped however is in changing the class used for static strings (@""). Using the GNU runtime, -fconstant-string-class works great and has no problem, under the Next runtime however, it crashes the second you send it a message. What XCode's debugger is telling me is that its actually taking my class and using it to encapsulate an NSConstantString.

I made sure I do have the appropriate matching instance variables (which is why it runs under the GNU runtime) and I've also tried a supposed fix I found on Apple's mailing list...

Code:
static struct objc_class _DFStringClassReference;

@implementation DFString

+ (void)load;
{
    // Left in to show alternate method that also didn't work
    //Class cls = objc_getClass("DFString");
    //memcpy(&_DFStringClassReference, cls, sizeof(_DFStringClassReference));

    memcpy(&_DFStringClassReference, self, sizeof(_DFStringClassReference));
    objc_addClass(&_DFStringClassReference);
}

...but that has also failed to produce results other than to have the compiler balk at me for using deprecated methods objc_class and objc_getClass. Is the -fconstant-string-class flag really broken or am I simply missing a part of the picture?

Taking the question in a different direction, should I even bother? In researching static strings, I found that they are kept for ease of use, but are actually a memory leak as they cannot be released even if you call release on them. They allocate and keep the memory until you terminate the program.

To be truthful, I don't even really use them as I prefer c strings to begin with; I'm mainly interested in correctly implementing them for sake of completion and to prevent future errors (in case I forget and use a static string only to run into a hard to track error).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Is there something wrong with gnustep-base as a Foundation implementation for Windows/Linux? I've had good success with it on Linux.

It wouldn't surprise me at all if -fconstant-string-class is broken in Apple's GCC, since @"" and __builtin___CFStringMakeConstantString are probably equivalently hard-coded to make NSCFString objects.
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #3
OneSadCookie Wrote:Is there something wrong with gnustep-base as a Foundation implementation for Windows/Linux? I've had good success with it on Linux.

It wouldn't surprise me at all if -fconstant-string-class is broken in Apple's GCC, since @"" and __builtin___CFStringMakeConstantString are probably equivalently hard-coded to make NSCFString objects.

I actually installed GNUStep-base when I first started cross-platform development, but I came to resent that users would have to install it before they would be able to run my programs. This is fine for a smaller library such as SDL, but users become wary when you have to install a large library for a small application.

This is one of my concerns about audio; I want to try OpenAL as the sound library. Browsing the OpenAL site reveals that although Vista has changed how hardware acceleration for audio works, OpenAL is actually gaining support on Windows due to DirectX10 ties that have been made with it (making OpenAL the easiest to use hardware accelerated sound library). Unfortunately it requires that users install it before you can use it, as Windows doesn't come pre-installed with it.

On the flip side of things, SDL is such a small library that I wasn't concerned about users having to install it; I decided not to use it simply because I don't like its implementation (and I must be a masochist to do it myself).

To be honest, because I'm more concerned about game development for Windows than utilities, the small library of objects I've written are really bare-bones. They implement what I would need and/or would like to see for game development and not much more. If I need further functionality in the future, I can add it.

As for the utilities I do write (namely for myself), I just stick with Cocoa and keep them just for the Mac. Assuming I ever need to write a non-game in Windows; after dealing with Windows roundabout way it handles GUIs, I'd sooner draw the interface in an OpenGL context than deal with native Windows.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Your users shouldn't have to install anything, why not just ship what you need with your app?
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #5
The GNUStep FAQ says otherwise; well, it says that you must have a compiled .dll to link to: http://wiki.gnustep.org/index.php/User_FAQ

MinGW install Readme: http://www.gnustep.org/resources/documen...ADME.MinGW

The problem with including it with the app is (as far the readme claims) is the extremely large size. Now, you can strip the .dll you ship with your application but I honestly haven't checked the size of a stripped .dll as it's obviously going to increase in size the more of the foundation you use in your application.

You said you've used it OSC; what can I expect if I do use it?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
The full libgnustep-base.so on Linux is 3.8M. That's pretty trivial, for what it gives you, IMO. Your graphics and audio will easily outweigh that.

Obviously if you don't need the whole thing you could build a custom version that only includes the bits you need.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
To be clear, I'm not advocating using the gnustep appkit compatibility layer, I've never met anyone with anything good to say about that. I just think there's better things to spend your time on than reimplementing NSString, NSArray, etc.
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #8
OneSadCookie Wrote:The full libgnustep-base.so on Linux is 3.8M. That's pretty trivial, for what it gives you, IMO. Your graphics and audio will easily outweigh that.

Obviously if you don't need the whole thing you could build a custom version that only includes the bits you need.

I seem to remember the package I downloaded when I installed it was larger than that, but you're right; in the scheme of things, 3.8M is nothing and I think I will look into using it again. Although I think I'm going to keep my Array class; it's much simpler than NSArray, but despite using a stack, can still store any object and is faster (at least on MacOS X), likely because it is simpler.

OneSadCookie Wrote:To be clear, I'm not advocating using the gnustep appkit compatibility layer, I've never met anyone with anything good to say about that. I just think there's better things to spend your time on than reimplementing NSString, NSArray, etc.

Oh no, I understand we're just talking about the Foundation base. I'm not even sure what purpose the Appkit would serve on Windows anyways.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #9
You're going to have to ship the libobjc runtime anyway, why not include foundation as well?

It's not magic, it's Ruby.
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #10
Nayr Wrote:You're going to have to ship the libobjc runtime anyway, why not include foundation as well?

I was under the impression that libobjc is compiled into the program as it is the basic Objective-C runtime; at least nothing I've found about programming Obj-C on MinGW says anything about distributing the library for the program to run.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
GNU libobjc on Linux at least is a shared library (104K). Check the license before you statically link it Wink
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #12
OSC, does the Linux version require your project to use a folder named <AppName>.app with the executable and all the files inside, and distribute it that way? When I originally had tried it out I thought that was just a simple way to compile things, but after researching more into it, apparently you must release your program like that.

Also, I don't know what I've broken, but I cannot get it to recognize NSString or other Foundation classes despite it finding <Foundation/Foundation.h> and having worked previously.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #13
Well, if you want any NSBundle functionality to work, yes, you need the right directory structure. If not using that, I didn't see anything that would force that structure. I don't see it being a big deal anyway, that's the natural structure on Mac OS X, and on the other systems, apps typically come with some random directory structure of gunk anyway.
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #14
My only problem with the file structure is the requirement of the .app at the end, otherwise the directory structure is fine by me. Really that is only nitpicking and doesn't really bother me, I'm just curious.

I just realized that when talking about the libobjc library earlier, were you talking about the replacement libobjc library provided when you install GNUStep-base or the one provided by gcc. I've been using the one provided by gcc and it's a static library and must be built with the program (although I suppose you could build it as a dynamic library and then link to it).

Getting back to using foundation, something must be going on as it says it can find it using <Foundation/Foundation.h> but none of the Foundation works and I can't find the library installed anywhere.
Quote this message in a reply
Member
Posts: 64
Joined: 2005.06
Post: #15
I just checked it out and libobjc (the version gcc includes) is a static library and is compiled into every program linking it. I just tried it on another PC that has no chance of libobjc being on it already so I know it was statically linked.

As for the legal side of statically linking libobjc; from everything I can see, libobjc and any variants are covered under the LGPL or GPL (depending on which variant). In either case, if I understand the licenses correctly, you can release your software under any license with no need to include the linked libraries or any source code.

Of course, most of those licenses are still gobbled gook to me, so I could very well be wrong.
[Add] Looking through the source files for versions of libobjc included with Cocotron and gcc 4.0, they both are under GPL with the GPL License exception allowing you to link to a shared or static version of libobjc without any restrictions.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  formatting value in a string sefiroths 3 3,867 Dec 12, 2011 02:41 AM
Last Post: sefiroths
  Getting a value from a String Megamac04 5 3,657 Jan 31, 2010 04:23 PM
Last Post: smasher
  Parsing from a string to something faster? Madrayken 3 3,003 Aug 10, 2009 03:32 PM
Last Post: smasher
  string to interger comparison? dareuhl 8 4,221 May 22, 2008 05:44 PM
Last Post: OneSadCookie
  char array versus pointer to string constant question WhatMeWorry 7 7,202 Jan 30, 2007 12:26 PM
Last Post: bronxbomber92