Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6865f7

Browse files
committed
- 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.
1 parent 2e049b2 commit f6865f7

3 files changed

Lines changed: 77 additions & 14 deletions

File tree

Mac/Include/macglue.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ void PyMac_FixGUSIcd Py_PROTO((void)); /* Workaround for GUSI chdir() call */
4646
char *PyMac_StrError(int); /* strerror with mac errors */
4747

4848
extern int PyMac_DoYieldEnabled; /* Don't do eventloop when false */
49+
#ifdef USE_GUSI
50+
extern int PyMac_ConsoleIsDead; /* True when exiting */
51+
extern void PyMac_SetGUSISpin(void); /* Install our private GUSI spin routine */
52+
#endif
4953

5054
extern PyObject *PyMac_OSErrException; /* Exception for OSErr */
5155
PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */
5256

57+
#ifdef USE_MACTCP
5358
int PyMac_Idle Py_PROTO((void)); /* Idle routine */
59+
#endif
5460
void PyMac_Yield Py_PROTO((void)); /* optional idle routine for mainloop */
5561
void PyMac_SetYield Py_PROTO((long, long, long, long)); /* Set timeouts */
5662
PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
5763
PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
5864
void PyMac_HandleEvent Py_PROTO((EventRecord *)); /* Handle one event, if possible */
5965

60-
int PyMac_Idle(void); /* Idle routine */
61-
6266
int PyMac_FindResourceModule(char *, char *); /* Test for 'PYC ' resource in a file */
6367
PyObject * PyMac_LoadResourceModule(char *, char *); /* Load 'PYC ' resource from file */
6468

Mac/Python/macglue.c

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6565
#ifdef USE_GUSI
6666
#include <TFileSpec.h> /* For Path2FSSpec */
6767
#include <LowMem.h> /* For SetSFCurDir, etc */
68+
#include <GUSI.h>
6869
#endif
6970

7071
#ifndef HAVE_UNIVERSAL_HEADERS
@@ -110,6 +111,8 @@ extern FSSpec *mfs_GetFSSpecFSSpec();
110111
static int interrupted; /* Set to true when cmd-. seen */
111112
static RETSIGTYPE intcatcher Py_PROTO((int));
112113

114+
static void PyMac_DoYield Py_PROTO((int));
115+
113116
/*
114117
** We attempt to be a good citizen by giving up the CPU periodically.
115118
** When in the foreground we do this less often and for shorter periods
@@ -134,6 +137,11 @@ static int in_foreground;
134137
*/
135138
int PyMac_DoYieldEnabled = 1;
136139

140+
/*
141+
** Workaround for sioux/gusi combo: set when we are exiting
142+
*/
143+
int PyMac_ConsoleIsDead;
144+
137145
/*
138146
** Some stuff for our GetDirectory and PromptGetFile routines
139147
*/
@@ -171,6 +179,40 @@ PyMac_FixGUSIcd()
171179
void SpinCursor(short x) { /* Dummy */ }
172180
#endif /* __CFM68K */
173181

182+
/*
183+
** Replacement GUSI Spin function
184+
*/
185+
static int
186+
PyMac_GUSISpin(spin_msg msg, long arg)
187+
{
188+
static Boolean inForeground = true;
189+
WindowPtr win;
190+
EventRecord ev;
191+
int maysleep;
192+
193+
if (PyMac_ConsoleIsDead) return 0;
194+
#if 0
195+
if (inForeground)
196+
SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1);
197+
#endif
198+
199+
if (interrupted) return -1;
200+
201+
if ( msg == SP_AUTO_SPIN || ((msg==SP_SLEEP||msg==SP_SELECT) && arg <= yield_fg))
202+
maysleep = 0;
203+
else
204+
maysleep = 0;
205+
206+
PyMac_DoYield(maysleep);
207+
208+
return 0;
209+
}
210+
211+
void
212+
PyMac_SetGUSISpin() {
213+
GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin);
214+
}
215+
174216
#endif
175217

176218

@@ -403,7 +445,7 @@ PyMac_HandleEvent(evp)
403445
** Yield the CPU to other tasks.
404446
*/
405447
static void
406-
PyMac_DoYield()
448+
PyMac_DoYield(int maysleep)
407449
{
408450
EventRecord ev;
409451
long yield;
@@ -415,19 +457,25 @@ PyMac_DoYield()
415457
NGetTrapAddress(_Unimplemented, ToolTrap));
416458
}
417459

418-
if ( PyMac_DoYieldEnabled >= 0) {
460+
lastyield = TickCount();
419461
#ifndef THINK_C
420-
/* Under think this has been done before in intrcheck() or intrpeek() */
462+
/* Under think this has been done before in intrcheck() or intrpeek() */
463+
if (PyMac_DoYieldEnabled >= 0)
421464
scan_event_queue(0);
422465
#endif
466+
if (PyMac_DoYieldEnabled == 0)
423467
return;
424-
}
425468

426469
in_foreground = PyMac_InForeground();
427-
if ( in_foreground )
428-
yield = yield_fg;
429-
else
430-
yield = yield_bg;
470+
if ( maysleep ) {
471+
if ( in_foreground )
472+
yield = yield_fg;
473+
else
474+
yield = yield_bg;
475+
} else {
476+
yield = 0;
477+
}
478+
431479
while ( 1 ) {
432480
if ( no_waitnextevent ) {
433481
SystemTask();
@@ -440,7 +488,6 @@ PyMac_DoYield()
440488
break;
441489
PyMac_HandleEvent(&ev);
442490
}
443-
lastyield = TickCount();
444491
}
445492

446493
/*
@@ -455,9 +502,10 @@ PyMac_Yield() {
455502
else
456503
iv = interval_bg;
457504
if ( TickCount() > lastyield + iv )
458-
PyMac_DoYield();
505+
PyMac_DoYield(1);
459506
}
460507

508+
#ifdef USE_MACTCP
461509
/*
462510
** Idle routine for busy-wait loops.
463511
** Gives up CPU, handles events and returns true if an interrupt is pending
@@ -466,9 +514,11 @@ PyMac_Yield() {
466514
int
467515
PyMac_Idle()
468516
{
469-
PyMac_DoYield();
517+
PyMac_DoYield(1);
470518
return intrpeek();
471519
}
520+
#endif
521+
472522
/*
473523
** Returns true if the argument has a resource fork, and it contains
474524
** a 'PYC ' resource of the correct name

Mac/Python/macmain.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2828
#include "pythonresources.h"
2929
#include "import.h"
3030
#include "marshal.h"
31+
#include "macglue.h"
3132

3233
#include <Memory.h>
3334
#include <Resources.h>
@@ -108,6 +109,7 @@ init_common()
108109
#if defined(USE_GUSI)
109110
/* Setup GUSI */
110111
GUSIDefaultSetup();
112+
PyMac_SetGUSISpin();
111113
#endif
112114

113115
#ifdef USE_SIOUX
@@ -396,7 +398,14 @@ PyMac_Exit(status)
396398
}
397399
else
398400
SIOUXSettings.autocloseonquit = 1;
399-
#endif
401+
#ifdef USE_GUSI
402+
/*
403+
** Workaround for Sioux/GUSI combo: we should not call
404+
** SiouxHandleOneEvent after the window is closed
405+
*/
406+
PyMac_ConsoleIsDead = 1;
407+
#endif /* USE_GUSI */
408+
#endif /* USE_SIOUX */
400409
#ifdef THINK_C
401410
console_options.pause_atexit = keep;
402411
#endif

0 commit comments

Comments
 (0)