Jack Jansen | 7467ce3 | 1995-02-13 11:41:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** mac __start for python-with-shared-library. |
| 3 | ** |
| 4 | ** Partially stolen from MW Startup.c, which is |
| 5 | ** Copyright © 1993 metrowerks inc. All Rights Reserved. |
| 6 | */ |
| 7 | |
| 8 | #include <setjmp.h> |
| 9 | |
Jack Jansen | eb26368 | 1996-02-20 16:26:19 +0000 | [diff] [blame] | 10 | #ifdef PRE_CW8 |
Jack Jansen | 7467ce3 | 1995-02-13 11:41:40 +0000 | [diff] [blame] | 11 | extern jmp_buf __program_exit; /* exit() does a longjmp() to here */ |
| 12 | extern void (*__atexit_hook)(void); /* atexit() sets this up if it is ever called */ |
| 13 | extern void (*___atexit_hook)(void); /* _atexit() sets this up if it is ever called */ |
| 14 | extern int __aborting; /* abort() sets this and longjmps to __program_exit */ |
Jack Jansen | eb26368 | 1996-02-20 16:26:19 +0000 | [diff] [blame] | 15 | #endif |
| 16 | |
| 17 | /* |
| 18 | * clear_stackframe_backlink - set 0(SP) to 0 |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | static asm void clear_stackframe_backlink(void) |
| 23 | { |
| 24 | li r3,0 |
| 25 | stw r3,0(SP) |
| 26 | blr |
| 27 | } |
Jack Jansen | 7467ce3 | 1995-02-13 11:41:40 +0000 | [diff] [blame] | 28 | |
| 29 | void __start(void) |
| 30 | { |
| 31 | char *argv = 0; |
| 32 | |
Jack Jansen | eb26368 | 1996-02-20 16:26:19 +0000 | [diff] [blame] | 33 | #ifdef PRE_CW8 |
Jack Jansen | 7467ce3 | 1995-02-13 11:41:40 +0000 | [diff] [blame] | 34 | if (setjmp(__program_exit) == 0) { // set up jmp_buf for exit() |
| 35 | main(0, &argv); // call main(argc, argv) |
| 36 | if (__atexit_hook) |
| 37 | __atexit_hook(); // call atexit() procs |
| 38 | } |
| 39 | if (!__aborting) { |
| 40 | if (___atexit_hook) |
| 41 | ___atexit_hook(); // call _atexit() procs |
| 42 | } |
| 43 | // ExitToShell(); |
Jack Jansen | eb26368 | 1996-02-20 16:26:19 +0000 | [diff] [blame] | 44 | #else |
| 45 | clear_stackframe_backlink(); |
| 46 | main(0, &argv); |
| 47 | exit(0); |
| 48 | #endif |
Jack Jansen | 7467ce3 | 1995-02-13 11:41:40 +0000 | [diff] [blame] | 49 | } |