• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Static variables reset inside CFPlugin code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Static variables reset inside CFPlugin code


  • Subject: Static variables reset inside CFPlugin code
  • From: Grandinetti Philip <email@hidden>
  • Date: Thu, 29 Dec 2011 15:11:35 -0500

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@hidden)

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:

This email sent to email@hidden

  • Prev by Date: Re: viewWillAppear not called with UINavigationController containment
  • Next by Date: Re: RaiseMan Exception
  • Previous by thread: dns_sd and double nat
  • Next by thread: NSText showGuessPanel: problem
  • Index(es):
    • Date
    • Thread