Runtime Patches for CodeWarrior
Neil A Six, Pascal Programmer
by Neil A Six
Having problems with mysterious Pascal computation errors on the Macintosh? They may be getting masked by unduly "tolerant" Pascal runtime functions. Pascal is supposed to embed runtime checks (when requested) for mathematical operations in its object code, but many compilers omit some (perhaps because few developers take runtime checks seriously, dismissing them as a waste of CPU time). Since some Pascal predefined functions are implemented in the runtime library, it's possible to "patch" them to correct any deficiencies. The more checks that are enabled, the less time one spends fishing around in the debugger or seeding your code with error tests. Also, I believe that checks should be enabled even for deliverable code. The time one spends debugging software problems usually exceeds time lost due to runtime checks, and even if the time lost is significant, that is likely to be true only for a small part of the program. Also, better for a user to complain "I got a runtime error" rather than "it locks up."
This provides a patch for certain CodeWarrior Pascal built-in math functions that are unsatisfactory as implemented by MetroWerks since they fail to perform runtime checks on their results. Apple's obsolete Paslib.o has similar deficiencies. What this does is simply override some functions defined in the default runtime library; all one needs to do is add one of these MPW object files to a CodeWarrior project:
Library Precede in project with... PASCAL.68K.Lib
MathRuntime_Tune.a.o PASCAL (f).68K.Lib
MathRuntime_Tune(f).a.o PASCAL.PPC.Lib MathRuntime_Tune.s.o
NOTE: Click on any MathRuntime link in the table above to download a binhexed copy of the library.
The following linker warnings should result (depending on whether a project actually uses any of these functions); always put the patch object code before the Pascal runtime library. To revert to the original library functions, simply remove the patch library from the project.Link Warning : ignored: '__Trunc__' in MathRuntime.c Previously defined in MathRuntime_Tune.a.o Link Warning : ignored: '__Round__' in MathRuntime.c Previously defined in MathRuntime_Tune.a.o Link Warning : ignored: '__POW__' in MathRuntime.c Previously defined in MathRuntime_Tune.a.o Link Warning : ignored: '__RTLABS__' in MathRuntime.c Previously defined in MathRuntime_Tune.a.o
Functions Replaced Function Link Name Mac CPU Comments Abs __RTLABS__ 680x0 Checks overflow;
can't fix PPC since Abs is inlined.
** integer __POW__ All but
Checks overflow; faster (very fast when base=2). Sqr integer __POW__ All but
As for ** Trunc __Trunc__ All Checks for NaNs, infinities, or outside LongInt bounds Round __Round__ All As for Trunc; faster;
fixes defect in CW 7 and maybe others;
This does biased rounding (as do most Pascals).
Note: The libraries were tested under CW 7; please inform me if they fail under a different release. The program mathrt_t.p confirms whether these patches work (it also shows how to handle Macintosh machine exceptions). The (f) versions of Round and Trunc are tuned to perform well on the MC68040 FPU.