[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Implementing CFSTR() in corebase
From: |
Richard Frith-Macdonald |
Subject: |
Re: Implementing CFSTR() in corebase |
Date: |
Fri, 22 Jan 2010 17:16:37 +0000 |
On 22 Jan 2010, at 16:33, Stef Bidi wrote:
> Fred and I have been discussing how to implement this function/macro for use
> with corebase. If you haven't noticed yet CFSTR() is not currently
> implemented in corebase. The problem we've been running into is how is
> constant strings implemented in ObjC. Using a test and the GCC manual we
> were able to get an idea of what the constant string structure looks like at
> compile time, but still have no idea how it's implemented after that (GCC
> manual says the runtime sets the Class * to the constant string class at
> runtime).
>
> I was hoping someone with more experience of how the objc runtimes and
> compilers work to help solve this dilema.
I think you probably need compiler support for that. Not sure though.
A constant string is a structure with three values:
First, a pointer to the class
Second, a pointer to the C string data
Third, an unsigned integer length of the C string data
Now clearly it's easy to do part of that:
#define CFSTR(X) ({\
static struct { Class isa; const char *ptr; unsigned int len } str = {C, X,
sizeof(X)-1};\
(CFStringRef)str;\
})
The problem is how to initialise the class pointer value 'C' above.
It should be a pointer to the constant class supplied by the objc runtime /
base library, and we obviously can't know that in general.
However, as I understand it, the idea is that this (corebase) should be built
on top of GNUstep-base, so as we know it's always going to be linked with the
base library, it might be possible to take advantage of the fact that we know
that the base library defines NSConstantString as the class for constant
strings, and get the compiler to initialise the 'isa' field with the
appropriate external reference for the linker to fixup at runtime. You would
need to look into that (ask someone who knows more about low level
compiler/linker stuff than me) to find out if it's really possible.
- Re: Implementing CFSTR() in corebase, (continued)
- Re: Implementing CFSTR() in corebase, David Chisnall, 2010/01/22
- Re: Implementing CFSTR() in corebase, Eric Wasylishen, 2010/01/22
- Re: Implementing CFSTR() in corebase, Vincent R., 2010/01/22
- Re: Implementing CFSTR() in corebase, Eric Wasylishen, 2010/01/22
- Re: Implementing CFSTR() in corebase, Fred Kiefer, 2010/01/23
- Re: Implementing CFSTR() in corebase, Vincent Richomme, 2010/01/23
- Re: Implementing CFSTR() in corebase, David Chisnall, 2010/01/23
- Re: Implementing CFSTR() in corebase, Stef Bidi, 2010/01/22
- Re: Implementing CFSTR() in corebase, David Chisnall, 2010/01/22
- Re: Implementing CFSTR() in corebase, David Chisnall, 2010/01/23
Re: Implementing CFSTR() in corebase,
Richard Frith-Macdonald <=