Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gcc 3.3 try - catch -finally



On Friday, June 27, 2003, at 01:10 PM, Jeff Harrell wrote:
I've never written a single line of Windows code in my life, so I'm not sure I understand exactly what you describe. But it sounds to me like what you're talking about allows the program to deal with things at runtime that should not (in the traditional UNIX paradigm) be dealt with at run time. Segmentation violations *should* be fatal, because they should *never* happen. Adding an exception handler for them implies that they might happen sometimes, and that statement is never true.

(That said, it does sound useful in a way, but there's nothing that you could do in a SEGV handler [for example] that you couldn't more easily do in your debugger after your program has dumped core. If your program still throws SEGV's, you should be running it through your debugger anyway.)

For normal programs I do agree with you that signal handlers will not provide you with anything a debugger would not, but there are a couple of very useful cases in which you actually can make use of these things (albeit they may not very portable but code like this never is.)

One example that jumps to mind is that many garbage collection schemes are implemented via SEGV or something similar. What happens is that a space for allocation is set up and the last page is marked off limits. Then when the program wants to allocate more memory it just increments the top-o-the-heap pointer and goes on. When the space is full this will trigger a SEGV which trigger the garbage collection. This is a great scheme for programs which allocate lots of little objects as an allocation is only a pointer increment. Now your signal handler needs to be able to recognize that this SEGV is really a "good" one and then it needs to be able to properly restart the program, which is not easy and certainly not portable.

A second example I have seen used SIGBUS on a machine where all memory reference had to be on word boundaries. An attempt to use an unaligned pointer resulted in a SIGBUS signal that would normally mean just as much as a SIGSEGV and kill your program. But in this case they used unaligned pointers to mark "external" objects and when one was dereferenced the SIGBUS was caught and the appropriate action taken. This was in an interpreter which was trying to differentiate between objects which were system objects and those which belonged to the program being interpreted. I don't know exactly what considerations made this a good approach, maybe they just did it because they could... :-)

-Eric
_______________________________________________
projectbuilder-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/projectbuilder-users
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: gcc 3.3 try - catch -finally (From: Jeff Harrell <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.