bug-gnustep
[Top][All Lists]
Advanced

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

Support request id 100307 (fwd)


From: Nicola Pero
Subject: Support request id 100307 (fwd)
Date: Sun, 13 Jan 2002 12:39:24 +0000 (GMT)

---------- Forwarded message ----------
Date: Sat, 12 Jan 2002 19:34:18 -0800
From: Kaelin Colclasure <kaelin@acm.org>
To: Nicola Pero <nicola@brainstorm.co.uk>
Subject: Support request id 100307

I posted a bug report on Savannah, but the code I included as a
possible fix got badly mangled by the Web interface, so I thought I'd
mail it to you directly.

+ (BOOL) _addFrameworkFromClass:(Class)frameworkClass
{
  int             len;

  if (frameworkClass == Nil)
    return NO;

  len = strlen(frameworkClass->name);

  if (len > 12*sizeof(char)
    && !strncmp("NSFramework_", frameworkClass->name, sizeof(char)*12))
    {
      NSBundle   *bundle = _loadingBundle;
      NSString  **fmClasses;

      /*
       * This following block used to be executed unconditionally, and
       * would ultimately fail when a framework's code was being
       * dynamically loaded because it was allocating a new NSBundle
       * instance and initializing its path to nil. Now we are first
       * checking _loadingBundle, and if non-nil we initialize the
       * existing bundle instead of creating a new one.
       * -- Kaelin 01/13/2002
       */
      if (bundle == nil) {
        NSString *bundlePath = nil;
        NSString *varEnv, *path, *name;

        name = [NSString stringWithCString: &frameworkClass->name[12]];
        
        varEnv = [frameworkClass frameworkEnv];
        if (varEnv && [varEnv length])
          bundlePath = [[[NSProcessInfo processInfo] environment]
                         objectForKey: varEnv];
        
        path = [frameworkClass frameworkPath];
        if (path && [path length])
          {
            if (bundlePath)
              bundlePath = [bundlePath stringByAppendingPathComponent: path];
            else
              bundlePath = path;
          }
        else
          bundlePath = [bundlePath
                stringByAppendingPathComponent: @"Library/Frameworks"];
        
        bundlePath = [bundlePath stringByAppendingPathComponent:
                [NSString stringWithFormat: @"%@.framework", name]];
        
        bundle = [[NSBundle alloc] initWithPath: bundlePath];
      }
      
      bundle->_bundleType = NSBUNDLE_FRAMEWORK;
      bundle->_codeLoaded = YES;
      bundle->_frameworkVersion = RETAIN([frameworkClass frameworkVersion]);
      bundle->_bundleClasses = RETAIN([NSMutableArray arrayWithCapacity: 2]);

      fmClasses = [frameworkClass frameworkClasses];

      while (*fmClasses)
        {
          NSValue *value;
          Class    class = NSClassFromString(*fmClasses);

          value = [NSValue valueWithNonretainedObject: class];

          [(NSMutableArray *)[bundle _bundleClasses] addObject: value];

#if 0     /*
           * This isn't needed anymore, because now if we're loading a
           * bundle, that's the one we just updated...
           */
          if (_loadingBundle)
            {
              NSEnumerator *classEnum;
              NSValue      *obj;

              classEnum = [_loadingBundle->_bundleClasses objectEnumerator];
              while ((obj = [classEnum nextObject]))
                {
                  if ([obj nonretainedObjectValue] == class)
                    {
                      [(NSMutableArray *)_loadingBundle->_bundleClasses
                        removeObject: obj];
                      break;
                    }
                }
            }
#endif

          fmClasses++;
        }

      return YES;
    }

  return NO;
}




reply via email to

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