Kaydet (Commit) f6865f77 authored tarafından Jack Jansen's avatar Jack Jansen

- Fixed PyMac_DoYield:

  - Update lastyield correctly
  - Do event handling if PyMac_YieldEnabled > 0 (previous cmd-. fix
    broke this)
- Use our own GUSISpin routine: fixes crash when exiting with sockets
  open and keeps windows, etc reacting consistently when waiting for
  accepts(), etc.
üst 2e049b2b
...@@ -46,19 +46,23 @@ void PyMac_FixGUSIcd Py_PROTO((void)); /* Workaround for GUSI chdir() call */ ...@@ -46,19 +46,23 @@ void PyMac_FixGUSIcd Py_PROTO((void)); /* Workaround for GUSI chdir() call */
char *PyMac_StrError(int); /* strerror with mac errors */ char *PyMac_StrError(int); /* strerror with mac errors */
extern int PyMac_DoYieldEnabled; /* Don't do eventloop when false */ extern int PyMac_DoYieldEnabled; /* Don't do eventloop when false */
#ifdef USE_GUSI
extern int PyMac_ConsoleIsDead; /* True when exiting */
extern void PyMac_SetGUSISpin(void); /* Install our private GUSI spin routine */
#endif
extern PyObject *PyMac_OSErrException; /* Exception for OSErr */ extern PyObject *PyMac_OSErrException; /* Exception for OSErr */
PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */ PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */
#ifdef USE_MACTCP
int PyMac_Idle Py_PROTO((void)); /* Idle routine */ int PyMac_Idle Py_PROTO((void)); /* Idle routine */
#endif
void PyMac_Yield Py_PROTO((void)); /* optional idle routine for mainloop */ void PyMac_Yield Py_PROTO((void)); /* optional idle routine for mainloop */
void PyMac_SetYield Py_PROTO((long, long, long, long)); /* Set timeouts */ void PyMac_SetYield Py_PROTO((long, long, long, long)); /* Set timeouts */
PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */ PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */ PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
void PyMac_HandleEvent Py_PROTO((EventRecord *)); /* Handle one event, if possible */ void PyMac_HandleEvent Py_PROTO((EventRecord *)); /* Handle one event, if possible */
int PyMac_Idle(void); /* Idle routine */
int PyMac_FindResourceModule(char *, char *); /* Test for 'PYC ' resource in a file */ int PyMac_FindResourceModule(char *, char *); /* Test for 'PYC ' resource in a file */
PyObject * PyMac_LoadResourceModule(char *, char *); /* Load 'PYC ' resource from file */ PyObject * PyMac_LoadResourceModule(char *, char *); /* Load 'PYC ' resource from file */
......
...@@ -65,6 +65,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -65,6 +65,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifdef USE_GUSI #ifdef USE_GUSI
#include <TFileSpec.h> /* For Path2FSSpec */ #include <TFileSpec.h> /* For Path2FSSpec */
#include <LowMem.h> /* For SetSFCurDir, etc */ #include <LowMem.h> /* For SetSFCurDir, etc */
#include <GUSI.h>
#endif #endif
#ifndef HAVE_UNIVERSAL_HEADERS #ifndef HAVE_UNIVERSAL_HEADERS
...@@ -110,6 +111,8 @@ extern FSSpec *mfs_GetFSSpecFSSpec(); ...@@ -110,6 +111,8 @@ extern FSSpec *mfs_GetFSSpecFSSpec();
static int interrupted; /* Set to true when cmd-. seen */ static int interrupted; /* Set to true when cmd-. seen */
static RETSIGTYPE intcatcher Py_PROTO((int)); static RETSIGTYPE intcatcher Py_PROTO((int));
static void PyMac_DoYield Py_PROTO((int));
/* /*
** We attempt to be a good citizen by giving up the CPU periodically. ** We attempt to be a good citizen by giving up the CPU periodically.
** When in the foreground we do this less often and for shorter periods ** When in the foreground we do this less often and for shorter periods
...@@ -134,6 +137,11 @@ static int in_foreground; ...@@ -134,6 +137,11 @@ static int in_foreground;
*/ */
int PyMac_DoYieldEnabled = 1; int PyMac_DoYieldEnabled = 1;
/*
** Workaround for sioux/gusi combo: set when we are exiting
*/
int PyMac_ConsoleIsDead;
/* /*
** Some stuff for our GetDirectory and PromptGetFile routines ** Some stuff for our GetDirectory and PromptGetFile routines
*/ */
...@@ -171,6 +179,40 @@ PyMac_FixGUSIcd() ...@@ -171,6 +179,40 @@ PyMac_FixGUSIcd()
void SpinCursor(short x) { /* Dummy */ } void SpinCursor(short x) { /* Dummy */ }
#endif /* __CFM68K */ #endif /* __CFM68K */
/*
** Replacement GUSI Spin function
*/
static int
PyMac_GUSISpin(spin_msg msg, long arg)
{
static Boolean inForeground = true;
WindowPtr win;
EventRecord ev;
int maysleep;
if (PyMac_ConsoleIsDead) return 0;
#if 0
if (inForeground)
SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1);
#endif
if (interrupted) return -1;
if ( msg == SP_AUTO_SPIN || ((msg==SP_SLEEP||msg==SP_SELECT) && arg <= yield_fg))
maysleep = 0;
else
maysleep = 0;
PyMac_DoYield(maysleep);
return 0;
}
void
PyMac_SetGUSISpin() {
GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin);
}
#endif #endif
...@@ -403,7 +445,7 @@ PyMac_HandleEvent(evp) ...@@ -403,7 +445,7 @@ PyMac_HandleEvent(evp)
** Yield the CPU to other tasks. ** Yield the CPU to other tasks.
*/ */
static void static void
PyMac_DoYield() PyMac_DoYield(int maysleep)
{ {
EventRecord ev; EventRecord ev;
long yield; long yield;
...@@ -415,19 +457,25 @@ PyMac_DoYield() ...@@ -415,19 +457,25 @@ PyMac_DoYield()
NGetTrapAddress(_Unimplemented, ToolTrap)); NGetTrapAddress(_Unimplemented, ToolTrap));
} }
if ( PyMac_DoYieldEnabled >= 0) { lastyield = TickCount();
#ifndef THINK_C #ifndef THINK_C
/* Under think this has been done before in intrcheck() or intrpeek() */ /* Under think this has been done before in intrcheck() or intrpeek() */
if (PyMac_DoYieldEnabled >= 0)
scan_event_queue(0); scan_event_queue(0);
#endif #endif
if (PyMac_DoYieldEnabled == 0)
return; return;
}
in_foreground = PyMac_InForeground(); in_foreground = PyMac_InForeground();
if ( in_foreground ) if ( maysleep ) {
yield = yield_fg; if ( in_foreground )
else yield = yield_fg;
yield = yield_bg; else
yield = yield_bg;
} else {
yield = 0;
}
while ( 1 ) { while ( 1 ) {
if ( no_waitnextevent ) { if ( no_waitnextevent ) {
SystemTask(); SystemTask();
...@@ -440,7 +488,6 @@ PyMac_DoYield() ...@@ -440,7 +488,6 @@ PyMac_DoYield()
break; break;
PyMac_HandleEvent(&ev); PyMac_HandleEvent(&ev);
} }
lastyield = TickCount();
} }
/* /*
...@@ -455,9 +502,10 @@ PyMac_Yield() { ...@@ -455,9 +502,10 @@ PyMac_Yield() {
else else
iv = interval_bg; iv = interval_bg;
if ( TickCount() > lastyield + iv ) if ( TickCount() > lastyield + iv )
PyMac_DoYield(); PyMac_DoYield(1);
} }
#ifdef USE_MACTCP
/* /*
** Idle routine for busy-wait loops. ** Idle routine for busy-wait loops.
** Gives up CPU, handles events and returns true if an interrupt is pending ** Gives up CPU, handles events and returns true if an interrupt is pending
...@@ -466,9 +514,11 @@ PyMac_Yield() { ...@@ -466,9 +514,11 @@ PyMac_Yield() {
int int
PyMac_Idle() PyMac_Idle()
{ {
PyMac_DoYield(); PyMac_DoYield(1);
return intrpeek(); return intrpeek();
} }
#endif
/* /*
** Returns true if the argument has a resource fork, and it contains ** Returns true if the argument has a resource fork, and it contains
** a 'PYC ' resource of the correct name ** a 'PYC ' resource of the correct name
......
...@@ -28,6 +28,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -28,6 +28,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "pythonresources.h" #include "pythonresources.h"
#include "import.h" #include "import.h"
#include "marshal.h" #include "marshal.h"
#include "macglue.h"
#include <Memory.h> #include <Memory.h>
#include <Resources.h> #include <Resources.h>
...@@ -108,6 +109,7 @@ init_common() ...@@ -108,6 +109,7 @@ init_common()
#if defined(USE_GUSI) #if defined(USE_GUSI)
/* Setup GUSI */ /* Setup GUSI */
GUSIDefaultSetup(); GUSIDefaultSetup();
PyMac_SetGUSISpin();
#endif #endif
#ifdef USE_SIOUX #ifdef USE_SIOUX
...@@ -396,7 +398,14 @@ PyMac_Exit(status) ...@@ -396,7 +398,14 @@ PyMac_Exit(status)
} }
else else
SIOUXSettings.autocloseonquit = 1; SIOUXSettings.autocloseonquit = 1;
#endif #ifdef USE_GUSI
/*
** Workaround for Sioux/GUSI combo: we should not call
** SiouxHandleOneEvent after the window is closed
*/
PyMac_ConsoleIsDead = 1;
#endif /* USE_GUSI */
#endif /* USE_SIOUX */
#ifdef THINK_C #ifdef THINK_C
console_options.pause_atexit = keep; console_options.pause_atexit = keep;
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment