• 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
Re: What to do about "clobbered by `longjmp' or `vfork'" warnings?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What to do about "clobbered by `longjmp' or `vfork'" warnings?


  • Subject: Re: What to do about "clobbered by `longjmp' or `vfork'" warnings?
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 3 Dec 2003 13:30:29 +0000

On 3 Dec 2003, at 13:02, j o a r wrote:

>
> On 2003-12-03, at 12.30, Alastair Houghton wrote:
>
>> Having said that, you should probably fix your code; you don't
>> necessarily have to declare your variables volatile... it's normally
>> enough just to change their scope.
>
> As an example, how would I fix it in this case ("image" is the
> variable being possibly clobbered)?
>
> - (NSImage*)imageForTitle:(NSString*)string
> {
>   NSImage *image = [titles objectForKey:string];
>
>   if( !image )
>   {
>     NS_DURING;
>
>     if(( image = [self imageWithTitle:string] ))
>       [self setImage:image forTitle:string];
>
>     NS_HANDLER;
>
>     if( [[localException name] isEqualToString:NSImageCacheException] )
>       image = nil;
>     else
>       [localException raise];
>
>     NS_ENDHANDLER;
>   }
>
>   return image;
> }

Either make "image" volatile, or move the NS_DURING so that it wraps
the entire function, like this:

	- (NSImage *)imageForTitle:(NSString *)string
	{
	  NS_DURING {
	    NSImage *image = [titles objectForKey:string];

		if (!image) {
		  if ((image = [self imageWithTitle:string]))
			[self setImage:image forTitle:string];
		}

		NS_VALUERETURN (image);
	  } NS_HANDLER {
		if (![[localException name] isEqualToString:NSImageCacheException])
		  [localException raise];
	  } NS_ENDHANDLER;

	  return nil;
	}

or you could refactor the code to something like

	- (NSImage *)imageForTitle:(NSString *)string
	{
	  NSImage *image = [titles objectForKey:string];

	  if (image)
		return image;

	  return [self fetchImageForTitle:string];
	}

	- (NSImage *)fetchImageForTitle:(NSString *)string
	{
	  NS_DURING {
		NSImage *image = [self imageWithTitle:string];

		if (image)
		  [self setImage:image forTitle:string];

		NS_VALUERETURN (image);
	  } NS_HANDLER {
		if (![[localException name] isEqualToString:NSImageCacheException])
		  [localException raise];
	  } NS_ENDHANDLER;

	  return nil;
	}

I'm not sure which approach is best in this case; the first two cause a
small performance hit in the common case where the image is already in
your dictionary, whereas the last one adds an extra method to your
object.  Anyway, I don't think you'll get warnings from any of these
variants.

Kind regards,

Alastair.

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: What to do about "clobbered by `longjmp' or `vfork'" warnings?
      • From: j o a r <email@hidden>
References: 
 >What to do about "clobbered by `longjmp' or `vfork'" warnings? (From: j o a r <email@hidden>)
 >Re: What to do about "clobbered by `longjmp' or `vfork'" warnings? (From: Alastair Houghton <email@hidden>)
 >Re: What to do about "clobbered by `longjmp' or `vfork'" warnings? (From: j o a r <email@hidden>)

  • Prev by Date: Re: Auto-complete
  • Next by Date: Re: What to do about "clobbered by `longjmp' or `vfork'" warnings?
  • Previous by thread: Re: What to do about "clobbered by `longjmp' or `vfork'" warnings?
  • Next by thread: Re: What to do about "clobbered by `longjmp' or `vfork'" warnings?
  • Index(es):
    • Date
    • Thread