external relocation entries in non-writable section? (SOLVED)
Rick Mann
rmann-d-lang at latencyzero.com
Tue Jan 30 14:21:55 PST 2007
Mostly solved. See below.
Anders F Björklund Wrote:
> Rick Mann wrote:
> > struct __CFString {};
> > typedef const __CFString* CFStringRef;
> >
> > extern (C)
> > CFStringRef
> > __CFStringMakeConstantString(char* cStr);
> >
> Maybe it has something to do with that extra "const" ? What is that ?
> (looks to me like it is trying to use the keyword like it was in C++)
This is how the C header had it defined. In particular, CFStringRef is supposed to point to an immutable CFString, and (not defined here) CFMutableStringRef points to a mutable one (in the C header it drops the "const").
I'm not sure how const works in D, although I know that you can't specify function parameters as const. I assume the "in" qualifier does the same thing, but I'm not sure (I've been able to write code that modifies unqualified parameters inside the function).
Ideally, I'd get a compile-time error if I passed a CFStringRef as a parameter that expected a CFMutableStringRef.
> Although when I tried it, it still worked OK even with the "const"...
>
> struct __CFString { } // opaque
> typedef const __CFString* CFStringRef;
>
> extern(C) CFStringRef __CFStringMakeConstantString(char *cStr);
> alias __CFStringMakeConstantString CFSTR; // only for string literals
>
>
> Then using it something like:
>
> err = CreateNibReference(CFSTR("main"), &nibRef);
> if (err != noErr) goto CantGetNibRef;
>
> So I'm not sure what else your code is doing differently than mine ?
I'm not either. I wrote a sample program defining everything in one file, and it worked fine. I also moved the defs to a separate file, and it still worked fine (with the "const" in there). I called CFShow() to output the value of the constructed CFStringRef, and it worked great. I can't figure out what's going on...hmm. I just went to reproduce the error, and now it seems to be working...?
Ah! In the same file that defines __CFStringMakeConstantString, I define this (lexically before __CFStringMakeConstantString):
CFStringRef
CFSTR(char[] inString)
{
return __CFStringMakeConstantString(inString.ptr);
}
If I move it to after __CFStringMakeConstantString(), then it works okay.
More information about the Digitalmars-d-learn
mailing list