28
28
#include "CFBundle_Internal.h"
29
29
#include "CFInternal.h"
30
30
31
+
31
32
static void _registerFactory (const void * key , const void * val , void * context ) {
32
33
CFStringRef factoryIDStr = (CFStringRef )key ;
33
34
CFStringRef factoryFuncStr = (CFStringRef )val ;
@@ -120,32 +121,44 @@ __private_extern__ void _CFBundleInitPlugIn(CFBundleRef bundle) {
120
121
CFDictionaryApplyFunction (typeDict , _registerType , bundle );
121
122
}
122
123
123
- /* Now do dynamic registration if necessary */
124
+ /* Now set key for dynamic registration if necessary */
124
125
if (doDynamicReg ) {
126
+ CFDictionarySetValue ((CFMutableDictionaryRef )infoDict , CFSTR ("CFPlugInNeedsDynamicRegistration" ), CFSTR ("YES" ));
127
+ if (CFBundleIsExecutableLoaded (bundle )) _CFBundlePlugInLoaded (bundle );
128
+ }
129
+ }
130
+
131
+ __private_extern__ void _CFBundlePlugInLoaded (CFBundleRef bundle ) {
132
+ CFDictionaryRef infoDict = CFBundleGetInfoDictionary (bundle );
133
+ CFStringRef tempStr ;
134
+ CFPlugInDynamicRegisterFunction func = NULL ;
135
+
136
+ if (!__CFBundleGetPlugInData (bundle )-> _isPlugIn || __CFBundleGetPlugInData (bundle )-> _isDoingDynamicRegistration || !infoDict || !CFBundleIsExecutableLoaded (bundle )) return ;
137
+
138
+ tempStr = CFDictionaryGetValue (infoDict , CFSTR ("CFPlugInNeedsDynamicRegistration" ));
139
+ if (tempStr != NULL && CFGetTypeID (tempStr ) == CFStringGetTypeID () && CFStringCompare (tempStr , CFSTR ("YES" ), kCFCompareCaseInsensitive ) == kCFCompareEqualTo ) {
140
+ CFDictionaryRemoveValue ((CFMutableDictionaryRef )infoDict , CFSTR ("CFPlugInNeedsDynamicRegistration" ));
125
141
tempStr = CFDictionaryGetValue (infoDict , kCFPlugInDynamicRegisterFunctionKey );
126
142
if (tempStr == NULL || CFGetTypeID (tempStr ) != CFStringGetTypeID () || CFStringGetLength (tempStr ) <= 0 ) {
127
143
tempStr = CFSTR ("CFPlugInDynamicRegister" );
128
144
}
129
145
__CFBundleGetPlugInData (bundle )-> _loadOnDemand = false;
146
+ __CFBundleGetPlugInData (bundle )-> _isDoingDynamicRegistration = true;
130
147
131
- if (CFBundleLoadExecutable (bundle )) {
132
- CFPlugInDynamicRegisterFunction func = NULL ;
133
-
134
- __CFBundleGetPlugInData (bundle )-> _isDoingDynamicRegistration = true;
135
-
136
- /* Find the symbol and call it. */
137
- func = (CFPlugInDynamicRegisterFunction )CFBundleGetFunctionPointerForName (bundle , tempStr );
138
- if (func ) {
139
- func (bundle );
140
- // MF:!!! Unload function is never called. Need to deal with this!
141
- }
148
+ /* Find the symbol and call it. */
149
+ func = (CFPlugInDynamicRegisterFunction )CFBundleGetFunctionPointerForName (bundle , tempStr );
150
+ if (func ) {
151
+ func (bundle );
152
+ // MF:!!! Unload function is never called. Need to deal with this!
153
+ }
142
154
143
- __CFBundleGetPlugInData (bundle )-> _isDoingDynamicRegistration = false;
144
- if (__CFBundleGetPlugInData (bundle )-> _loadOnDemand && (__CFBundleGetPlugInData (bundle )-> _instanceCount == 0 )) {
145
- /* Unload now if we can/should. */
146
- CFBundleUnloadExecutable (bundle );
147
- }
155
+ __CFBundleGetPlugInData (bundle )-> _isDoingDynamicRegistration = false;
156
+ if (__CFBundleGetPlugInData (bundle )-> _loadOnDemand && (__CFBundleGetPlugInData (bundle )-> _instanceCount == 0 )) {
157
+ /* Unload now if we can/should. */
158
+ CFBundleUnloadExecutable (bundle );
148
159
}
160
+ } else {
161
+ CFDictionaryRemoveValue ((CFMutableDictionaryRef )infoDict , CFSTR ("CFPlugInNeedsDynamicRegistration" ));
149
162
}
150
163
}
151
164
@@ -169,7 +182,8 @@ UInt32 CFPlugInGetTypeID(void) {
169
182
}
170
183
171
184
CFPlugInRef CFPlugInCreate (CFAllocatorRef allocator , CFURLRef plugInURL ) {
172
- return (CFPlugInRef )CFBundleCreate (allocator , plugInURL );
185
+ CFBundleRef bundle = CFBundleCreate (allocator , plugInURL );
186
+ return (CFPlugInRef )bundle ;
173
187
}
174
188
175
189
CFBundleRef CFPlugInGetBundle (CFPlugInRef plugIn ) {
0 commit comments