I'm loading and creating a CFplugin using Core Foundation and running into a
strange behavior where all the static variables defined throughout my code get
reset to their initialization values when running code inside plugin. For
example, I define a static variable and functions in a file foo.c
static int foo = 0;
void setFoo(void) { foo = 42;}
void printFoo(void) {fprintf(stderr, "foo is %d\n",foo);}
then I install and call the plugin code using
printFoo(); // <- prints "0"
setFoo(); // <- sets foo to 42
printFoo(); // <- prints "42"
PluginInterfaceRef *iunknown = CFPlugInInstanceCreate(kCFAllocatorDefault,
factoryID, kMyPluginTypeUUID);
printFoo(); // <- prints "42"
which looks okay, but inside the factory function, called by
CFPlugInInstanceCreate,...
void *myFactory(CFAllocatorRef allocator, CFUUIDRef typeID) {
if(!CFEqual(typeID, kMyPluginTypeUUID)) return NULL;
MyPluginRef result = MyPluginCreate(typeID);
printFoo(); // <- prints "0" ??
return result;
}
printFoo() returns "0", and not "42".
I'm using Xcode 4.2.1, and all the functions appear to be running in the main
thread.
Any ideas why this is happening, and suggestions for making static variables
available inside the plugin?
_______________________________________________
Cocoa-dev mailing list ([email protected])
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/archive%40mail-archive.com
This email sent to [email protected]