gnustep-dev
[Top][All Lists]
Advanced

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

Re: Implementing CFSTR() in corebase


From: Eric Wasylishen
Subject: Re: Implementing CFSTR() in corebase
Date: Fri, 22 Jan 2010 17:19:10 -0700


On 2010-01-22, at 3:26 PM, Vincent R. wrote:

On Fri, 22 Jan 2010 13:26:00 -0700, Eric Wasylishen
<address@hidden>
wrote:
On 2010-01-22, at 9:53 AM, David Chisnall wrote:

Hi Stef,

I had this discussion with Eric yesterday, so good timing...

On OS X, CSTR() calls one of two functions.  


Hi,
On a related note, regarding Opal, David and I decided that Opal should
just use Foundation directly (internally). The main reasons are:

- There is no way (with the public API of CoreFoundation) to create new
CoreFoundation types . The CG objects need to respond to -[retain] and
-[release], as well as CFRetain(), and the other CF functions available
for
all CF types, so they really have to be instances of NSObject
subclasses.
- We need constant Obj-C/CF strings - it sounds like it is best to just
use @"...".

Initially I was interested in making Opal independent of Foundation, and
able to work with Apple's CF or CFLite, but now I think it's not worth
the
effort.

Hum Wait. This is exactly what I am working on windows. I have compiled
CoreFoundationLite and now I implement
CoreGraphics with openVG/cairo backend.

Cool, we should combine our efforts if possible! Implementing CG is a pretty big task, but Opal is quite far along already. It is licensed under the LGPL and copyright is assigned to the FSF - is that something you would be interested in working with?

First idea was also to be able to use Objective-C but when I read all your
stuff I think it's far too complicated
so I am happy to have a CoreFoundation/Coregraphics writtent in plain C.

Do you mean the Opal code looks far too complicated? IMHO it's pretty minimal and simple. (well, a lot of what I have been working on recently is still a rough prototype and needs to be cleaned up.) 

Opal is currently written all in C, and uses a simple home-made object system, so the CG types are not real CF or Objective-C objects. (I just made some changes yesterday so it uses Objective-C constant strings, but it's still all C other than that.) Making the CG objects in to real ObjC/CF objects is something we need to do at some point.

However I don't understand your sentence : "There is no way (with the
public API of CoreFoundation) to create new
CoreFoundation types"...
What do you mean ?

For instance my CGContext is implemented as shown below :

static CFRuntimeClass CGContextClass =
 {
   0, // version
   "CGContext", // className
   0, // init
   0, // copy
   CGContextFinalize, // finalize
0, // equal
0, // hash
0, // copyFormattingDesc
0 // copyDebugDesc
 };
CFTypeID __kCGContextID = _kCFRuntimeNotATypeID;


CFTypeID CGContextGetTypeID(void)
{
return CGTypeRegisterWithCallbacks(&__kCGContextID, &CGContextClass);
}

CFTypeID CGTypeRegisterWithCallbacks(CFTypeID* typeID, CFRuntimeClass*
rtclass)
{
CFTypeID id;

if (*typeID != _kCFRuntimeNotATypeID) { return *typeID; }


id = _CFRuntimeRegisterClass(rtclass);
*typeID = id;

return id;
}


CFTypeRef CGTypeCreateInstance(CFTypeID id, CFIndex size)
{
return CGTypeCreateInstanceWithAllocator(0, id, size);
}

CFTypeRef CGTypeCreateInstanceWithAllocator(CFAllocatorRef allocator,
CFTypeID id, CFIndex size)
{
CFTypeRef type;
CFRuntimeClass* rtc;
char* ptr;


/* Create the CFType */
//
type = _CFRuntimeCreateInstance(allocator, id, size, NULL);
CHK(type);

///* Init with zero values all fields except our base object */
ptr = (char*)type;
memset((void*)(ptr + sizeof(CFRuntimeBase)), 0, size);

return type;

Cleanup:
return NULL;
}


I am really a newbie at CoreFoundation - what I meant was I didn't see mention in the CoreFoundation documentation of how to create/register a new type.

If we could do something in Opal like what you showed and have it work on both CFLite and GNUstep base + corebase, and keep Opal written in plain C, that would be great. 

Regards,
Eric


reply via email to

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