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

Skip to content

Commit b19a645

Browse files
committed
more think/mw changes
1 parent d9ff26b commit b19a645

2 files changed

Lines changed: 71 additions & 12 deletions

File tree

Mac/Modules/ae/AEmodule.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,45 @@ extern int MenuObj_Convert(PyObject *, MenuHandle *);
3030
extern PyObject *CtlObj_New(ControlHandle);
3131
extern int CtlObj_Convert(PyObject *, ControlHandle *);
3232

33+
extern PyObject *WinObj_WhichWindow(WindowPtr);
34+
3335
#include <AppleEvents.h>
3436

3537
#ifdef THINK_C
38+
#define AEIdleProcPtr IdleProcPtr
3639
#define AEFilterProcPtr EventFilterProcPtr
3740
#define AEEventHandlerProcPtr EventHandlerProcPtr
3841
#endif
3942

43+
#ifndef __MWERKS__
44+
/* Actually, this is "if not universal headers".
45+
** I'm trying to setup the code here so that is easily automated,
46+
** as follows:
47+
** - Use the UPP in the source
48+
** - for pre-universal headers, #define each UPP as the corresponding ProcPtr
49+
** - for each routine we pass we declare a upp_xxx that
50+
** we initialize to the correct value in the init routine.
51+
*/
52+
#define AEIdleUPP AEIdleProcPtr
53+
#define AEFilterUPP AEFilterProcPtr
54+
#define AEEventHandlerUPP AEEventHandlerProcPtr
55+
#define NewAEIdleProc(x) (x)
56+
#define NewAEFilterProc(x) (x)
57+
#define NewAEEventHandlerProc(x) (x)
58+
#endif
59+
4060
static pascal OSErr GenericEventHandler(); /* Forward */
4161

62+
AEEventHandlerUPP upp_GenericEventHandler;
63+
4264
static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
4365
{
4466
(void) PyMac_Idle();
4567
return 0;
4668
}
4769

70+
AEIdleUPP upp_AEIdleProc;
71+
4872
static PyObject *AE_Error;
4973

5074
/* ----------------------- Object type AEDesc ----------------------- */
@@ -733,8 +757,8 @@ static PyObject *AEDesc_AESend(_self, _args)
733757
sendMode,
734758
sendPriority,
735759
timeOutInTicks,
736-
AEIdleProc,
737-
(AEFilterProcPtr)0);
760+
upp_AEIdleProc,
761+
(AEFilterUPP)0);
738762
if (_err != noErr) return PyMac_Error(_err);
739763
_res = Py_BuildValue("O&",
740764
AEDesc_New, &reply);
@@ -778,7 +802,7 @@ static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args)
778802
PyObject *_res = NULL;
779803
OSErr _err;
780804
AppleEvent reply;
781-
AEEventHandlerProcPtr dispatcher__proc__ = GenericEventHandler;
805+
AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler;
782806
PyObject *dispatcher;
783807
if (!PyArg_ParseTuple(_args, "O&O",
784808
AEDesc_Convert, &reply,
@@ -790,6 +814,7 @@ static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args)
790814
if (_err != noErr) return PyMac_Error(_err);
791815
Py_INCREF(Py_None);
792816
_res = Py_None;
817+
Py_INCREF(dispatcher); /* XXX leak, but needed */
793818
return _res;
794819
}
795820

@@ -1103,7 +1128,7 @@ static PyObject *AE_AEInteractWithUser(_self, _args)
11031128
return NULL;
11041129
_err = AEInteractWithUser(timeOutInTicks,
11051130
(NMRecPtr)0,
1106-
AEIdleProc);
1131+
upp_AEIdleProc);
11071132
if (_err != noErr) return PyMac_Error(_err);
11081133
Py_INCREF(Py_None);
11091134
_res = Py_None;
@@ -1118,7 +1143,7 @@ static PyObject *AE_AEInstallEventHandler(_self, _args)
11181143
OSErr _err;
11191144
AEEventClass theAEEventClass;
11201145
AEEventID theAEEventID;
1121-
AEEventHandlerProcPtr handler__proc__ = GenericEventHandler;
1146+
AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler;
11221147
PyObject *handler;
11231148
if (!PyArg_ParseTuple(_args, "O&O&O",
11241149
PyMac_GetOSType, &theAEEventClass,
@@ -1132,6 +1157,7 @@ static PyObject *AE_AEInstallEventHandler(_self, _args)
11321157
if (_err != noErr) return PyMac_Error(_err);
11331158
Py_INCREF(Py_None);
11341159
_res = Py_None;
1160+
Py_INCREF(handler); /* XXX leak, but needed */
11351161
return _res;
11361162
}
11371163

@@ -1149,7 +1175,7 @@ static PyObject *AE_AERemoveEventHandler(_self, _args)
11491175
return NULL;
11501176
_err = AERemoveEventHandler(theAEEventClass,
11511177
theAEEventID,
1152-
GenericEventHandler,
1178+
upp_GenericEventHandler,
11531179
0);
11541180
if (_err != noErr) return PyMac_Error(_err);
11551181
Py_INCREF(Py_None);
@@ -1244,6 +1270,9 @@ void initAE()
12441270

12451271

12461272

1273+
upp_AEIdleProc = NewAEIdleProc(AEIdleProc);
1274+
upp_GenericEventHandler = NewAEEventHandlerProc(GenericEventHandler);
1275+
12471276

12481277
m = Py_InitModule("AE", AE_methods);
12491278
d = PyModule_GetDict(m);

Mac/Modules/ae/aesupport.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class EHType(Type):
3939
def __init__(self, name = 'EventHandler', format = ''):
4040
Type.__init__(self, name, format)
4141
def declare(self, name):
42-
Output("AEEventHandlerProcPtr %s__proc__ = GenericEventHandler;", name)
42+
Output("AEEventHandlerUPP %s__proc__ = upp_GenericEventHandler;", name)
4343
Output("PyObject *%s;", name)
4444
def getargsFormat(self):
4545
return "O"
@@ -53,19 +53,21 @@ def mkvalueFormat(self):
5353
return "O"
5454
def mkvalueArgs(self, name):
5555
return name
56+
def cleanup(self, name):
57+
Output("Py_INCREF(%s); /* XXX leak, but needed */", name)
5658

5759
class EHNoRefConType(EHType):
5860
def passInput(self, name):
59-
return "GenericEventHandler"
61+
return "upp_GenericEventHandler"
6062

6163
EventHandler = EHType()
6264
EventHandlerNoRefCon = EHNoRefConType()
6365

6466

65-
IdleProcPtr = FakeType("AEIdleProc")
66-
EventFilterProcPtr = FakeType("(AEFilterProcPtr)0")
67+
IdleProcPtr = FakeType("upp_AEIdleProc")
68+
EventFilterProcPtr = FakeType("(AEFilterUPP)0")
6769
NMRecPtr = FakeType("(NMRecPtr)0")
68-
EventHandlerProcPtr = FakeType("GenericEventHandler")
70+
EventHandlerProcPtr = FakeType("upp_GenericEventHandler")
6971
AlwaysFalse = FakeType("0")
7072

7173

@@ -77,16 +79,39 @@ def passInput(self, name):
7779
#include <AppleEvents.h>
7880
7981
#ifdef THINK_C
82+
#define AEIdleProcPtr IdleProcPtr
8083
#define AEFilterProcPtr EventFilterProcPtr
8184
#define AEEventHandlerProcPtr EventHandlerProcPtr
8285
#endif
8386
87+
#ifndef __MWERKS__
88+
/* Actually, this is "if not universal headers".
89+
** I'm trying to setup the code here so that is easily automated,
90+
** as follows:
91+
** - Use the UPP in the source
92+
** - for pre-universal headers, #define each UPP as the corresponding ProcPtr
93+
** - for each routine we pass we declare a upp_xxx that
94+
** we initialize to the correct value in the init routine.
95+
*/
96+
#define AEIdleUPP AEIdleProcPtr
97+
#define AEFilterUPP AEFilterProcPtr
98+
#define AEEventHandlerUPP AEEventHandlerProcPtr
99+
#define NewAEIdleProc(x) (x)
100+
#define NewAEFilterProc(x) (x)
101+
#define NewAEEventHandlerProc(x) (x)
102+
#endif
103+
84104
static pascal OSErr GenericEventHandler(); /* Forward */
85105
106+
AEEventHandlerUPP upp_GenericEventHandler;
107+
86108
static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
87109
{
88-
return !PyMac_Idle();
110+
(void) PyMac_Idle();
111+
return 0;
89112
}
113+
114+
AEIdleUPP upp_AEIdleProc;
90115
"""
91116

92117
finalstuff = finalstuff + """
@@ -121,6 +146,11 @@ def passInput(self, name):
121146
}
122147
"""
123148

149+
initstuff = initstuff + """
150+
upp_AEIdleProc = NewAEIdleProc(AEIdleProc);
151+
upp_GenericEventHandler = NewAEEventHandlerProc(GenericEventHandler);
152+
"""
153+
124154
module = MacModule('AE', 'AE', includestuff, finalstuff, initstuff)
125155

126156
class AEDescDefiniton(ObjectDefinition):

0 commit comments

Comments
 (0)