home *** CD-ROM | disk | FTP | other *** search
- /* $Id */
-
- #ifndef __CALLBACK_H__
- #define __CALLBACK_H__
-
-
- #ifdef __GNUC__
- #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 95)
-
- /*
-
- This is a workaround for a bug in the current version of gcc (2.7.2.2):
-
- gcc assumes that no one will touch %a4 after it is set up in crt0.o.
- This isn't true if a function is called as a callback by something
- that wasn't compiled by gcc (like FrmCloseAllForms()). It may also
- not be true if it is used as a callback by something in a different
- shared library.
-
- In any function in your code that is called _directly from the OS_
- (like custom draw routines, event handlers, etc.), insert CALLBACK_PROLOGUE
- at the beginning (right after the local var declarations), and
- CALLBACK_EPILOGUE at the end (right before the "return"). NOTE: make sure
- that it is _impossible_ for your routine to return without executing
- the CALLBACK_EPILOGUE. Also, make sure to #include "callback.h", of course.
-
- There is a compiler flag that attempts to do this, but last I checked,
- the code it generates was wrong; it forgot to restore the original %a4 value.
-
- - Ian
-
- */
-
- register void *reg_a4 asm("%a4");
-
- #define CALLBACK_PROLOGUE \
- void *save_a4 = reg_a4; asm("move.l %%a5,%%a4; sub.l #edata,%%a4" : :);
-
- #define CALLBACK_EPILOGUE reg_a4 = save_a4;
-
- #else
-
- /* We don't need the macros for newer versions of gcc */
-
- #define CALLBACK_PROLOGUE /* dummy macro */
- #define CALLBACK_EPILOGUE /* dummy macro */
-
- #endif
-
- #else
-
- /* We don't need the macros for code warrior */
-
- #define CALLBACK_PROLOGUE /* dummy macro */
- #define CALLBACK_EPILOGUE /* dummy macro */
-
- #endif
-
- #endif
-