[comp.sys.mac.programmer] Helpful Greps in LSC

pcossenb@rodan.acs.syr.edu (Paul C. Ossenbruggen) (05/27/89)

Here are some Grep search patterns that I have found useful for
finding assignments that may become invalid if memory is moved.
If you want to use these search strings simply check Grep in the
LSC Find dialog. The first string is good for finding problems
where you have assigned the result of a procedure to a dereferenced
relocatable block. For example, the assignment

        (**text).te = TENew(&rect, &rect);
        or
        (**blah).argh = NewHandle(42);

you would use this string:

        (\*\*.*)\..*=

or if you prefer to use this format:

        (*blah)->argh = NewHandle(42);

use this

        (\*.*)->.*=

and LSC will find all strings of the form (**xx).yy= or (*xx)->yy=
Now all you have to do is go through and check if the selected area
is equal to a function that may move memory.

Another string is one which will find functions such as this:

        HandToHand(&(**myHand).right);

you would use the grep string:

        &(\*\*.*)

This string tends to find a lot of things that are not problems
but situations like the following it may be very helpful. The hypothetical
function MashRect which is a function that creates a new region
which may move memory.

MashRect(rectRgn, &aRect, &(**mad).bRect);

The first two parameters are ok but the last one may cause
troubles because the result is being passed back to a
relocatable block. The solution would be to either lock the
"mad" handle or to use a temporary pointer.

Most of the time you avoid these situations in the first place
but it is better to check just to be sure. I does not take long
and may save you headaches later.

I hope this is helpful, to someone.

- Paul








-------------------------------------------------------------------------------
|  Paul C. Ossenbruggen                     pcossenb@rodan.acs.syr.edu        |
|  Syracuse University                      rspco@suvm.bitnet                 |
|                                            pcossenb@sunrise.acs.syr.edu      |