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

Skip to content

Commit 0e04eec

Browse files
committed
First step in porting MacPython modules to OSX/unix: break all references between modules except for the obj_New() and obj_Convert() routines, the PyArg_Parse and Py_BuildValue helpers.
And these can now be vectored through glue routines (by defining USE_TOOLBOX_OBJECT_GLUE) which will do the necessary imports, whereupon the module's init routine will tell the glue routine about the real conversion routine address and everything is fine again.
1 parent 99f9baa commit 0e04eec

26 files changed

Lines changed: 463 additions & 2 deletions

Mac/Modules/ae/AEmodule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
#include <AppleEvents.h>
1212
#include <AEObjects.h>
1313

14+
#ifdef USE_TOOLBOX_OBJECT_GLUE
15+
extern PyObject *_AEDesc_New(AEDesc *);
16+
extern int _AEDesc_Convert(PyObject *, AEDesc *);
17+
18+
#define AEDesc_New _AEDesc_New
19+
#define AEDesc_Convert _AEDesc_Convert
20+
#endif
21+
1422
static pascal OSErr GenericEventHandler(); /* Forward */
1523

1624
AEEventHandlerUPP upp_GenericEventHandler;
@@ -1331,6 +1339,8 @@ void initAE()
13311339

13321340
upp_AEIdleProc = NewAEIdleProc(AEIdleProc);
13331341
upp_GenericEventHandler = NewAEEventHandlerProc(GenericEventHandler);
1342+
PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc_New);
1343+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc_Convert);
13341344

13351345

13361346
m = Py_InitModule("AE", AE_methods);

Mac/Modules/ae/aesupport.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def passInput(self, name):
8585
#include <AppleEvents.h>
8686
#include <AEObjects.h>
8787
88+
#ifdef USE_TOOLBOX_OBJECT_GLUE
89+
extern PyObject *_AEDesc_New(AEDesc *);
90+
extern int _AEDesc_Convert(PyObject *, AEDesc *);
91+
92+
#define AEDesc_New _AEDesc_New
93+
#define AEDesc_Convert _AEDesc_Convert
94+
#endif
95+
8896
static pascal OSErr GenericEventHandler(); /* Forward */
8997
9098
AEEventHandlerUPP upp_GenericEventHandler;
@@ -138,6 +146,8 @@ def passInput(self, name):
138146
initstuff = initstuff + """
139147
upp_AEIdleProc = NewAEIdleProc(AEIdleProc);
140148
upp_GenericEventHandler = NewAEEventHandlerProc(GenericEventHandler);
149+
PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc_New);
150+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc_Convert);
141151
"""
142152

143153
module = MacModule('AE', 'AE', includestuff, finalstuff, initstuff)

Mac/Modules/cm/Cmmodule.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
#include "pymactoolbox.h"
1010

1111
#include <Components.h>
12+
#ifdef USE_TOOLBOX_OBJECT_GLUE
13+
extern PyObject *_CmpObj_New(Component);
14+
extern int _CmpObj_Convert(PyObject *, Component *);
15+
extern PyObject *_CmpInstObj_New(ComponentInstance);
16+
extern int _CmpInstObj_Convert(PyObject *, ComponentInstance *);
17+
18+
#define CmpObj_New _CmpObj_New
19+
#define CmpObj_Convert _CmpObj_Convert
20+
#define CmpInstObj_New _CmpInstObj_New
21+
#define CmpInstObj_Convert _CmpInstObj_Convert
22+
#endif
1223

1324
/*
1425
** Parse/generate ComponentDescriptor records
@@ -825,6 +836,11 @@ void initCm()
825836

826837

827838

839+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CmpObj_New);
840+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CmpObj_Convert);
841+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CmpInstObj_New);
842+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CmpInstObj_Convert);
843+
828844

829845
m = Py_InitModule("Cm", Cm_methods);
830846
d = PyModule_GetDict(m);

Mac/Modules/cm/cmsupport.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222

2323
includestuff = includestuff + """
2424
#include <%s>""" % MACHEADERFILE + """
25+
#ifdef USE_TOOLBOX_OBJECT_GLUE
26+
extern PyObject *_CmpObj_New(Component);
27+
extern int _CmpObj_Convert(PyObject *, Component *);
28+
extern PyObject *_CmpInstObj_New(ComponentInstance);
29+
extern int _CmpInstObj_Convert(PyObject *, ComponentInstance *);
30+
31+
#define CmpObj_New _CmpObj_New
32+
#define CmpObj_Convert _CmpObj_Convert
33+
#define CmpInstObj_New _CmpInstObj_New
34+
#define CmpInstObj_Convert _CmpInstObj_Convert
35+
#endif
2536
2637
/*
2738
** Parse/generate ComponentDescriptor records
@@ -52,6 +63,13 @@
5263
5364
"""
5465

66+
initstuff = initstuff + """
67+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CmpObj_New);
68+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CmpObj_Convert);
69+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CmpInstObj_New);
70+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CmpInstObj_Convert);
71+
"""
72+
5573
ComponentDescription = OpaqueType('ComponentDescription', 'CmpDesc')
5674
Component = OpaqueByValueType('Component', C_OBJECTPREFIX)
5775
ComponentInstance = OpaqueByValueType('ComponentInstance', CI_OBJECTPREFIX)

Mac/Modules/ctl/Ctlmodule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
#include <ControlDefinitions.h>
1414
#endif
1515

16+
#ifdef USE_TOOLBOX_OBJECT_GLUE
17+
extern PyObject *_CtlObj_New(ControlHandle);
18+
extern int _CtlObj_Convert(PyObject *, ControlHandle *);
19+
20+
#define CtlObj_New _CtlObj_New
21+
#define CtlObj_Convert _CtlObj_Convert
22+
#endif
23+
1624
staticforward PyObject *CtlObj_WhichControl(ControlHandle);
1725

1826
#define as_Control(h) ((ControlHandle)h)
@@ -2925,6 +2933,8 @@ void initCtl()
29252933
myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
29262934
myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
29272935
mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
2936+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CtlObj_New);
2937+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CtlObj_Convert);
29282938

29292939

29302940
m = Py_InitModule("Ctl", Ctl_methods);

Mac/Modules/ctl/ctlsupport.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
#include <ControlDefinitions.h>
5555
#endif
5656
57+
#ifdef USE_TOOLBOX_OBJECT_GLUE
58+
extern PyObject *_CtlObj_New(ControlHandle);
59+
extern int _CtlObj_Convert(PyObject *, ControlHandle *);
60+
61+
#define CtlObj_New _CtlObj_New
62+
#define CtlObj_Convert _CtlObj_Convert
63+
#endif
64+
5765
staticforward PyObject *CtlObj_WhichControl(ControlHandle);
5866
5967
#define as_Control(h) ((ControlHandle)h)
@@ -316,6 +324,8 @@
316324
myidleproc_upp = NewControlUserPaneIdleProc(myidleproc);
317325
myhittestproc_upp = NewControlUserPaneHitTestProc(myhittestproc);
318326
mytrackingproc_upp = NewControlUserPaneTrackingProc(mytrackingproc);
327+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CtlObj_New);
328+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CtlObj_Convert);
319329
"""
320330

321331
class MyObjectDefinition(ObjectIdentityMixin, GlobalObjectDefinition):

Mac/Modules/dlg/Dlgmodule.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
#include "pymactoolbox.h"
1010

1111
#include <Dialogs.h>
12+
#ifdef USE_TOOLBOX_OBJECT_GLUE
13+
extern PyObject *_DlgObj_New(DialogRef);
14+
extern PyObject *_DlgObj_WhichDialog(DialogRef);
15+
extern int _DlgObj_Convert(PyObject *, DialogRef *);
16+
17+
#define DlgObj_New _DlgObj_New
18+
#define DlgObj_WhichDialog _DlgObj_WhichDialog
19+
#define DlgObj_Convert _DlgObj_Convert
20+
#endif
1221

1322
#if !ACCESSOR_CALLS_ARE_FUNCTIONS
1423
#define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH)
@@ -1468,7 +1477,7 @@ static PyMethodDef Dlg_methods[] = {
14681477

14691478

14701479
/* Return the WindowPtr corresponding to a DialogObject */
1471-
1480+
#if 0
14721481
WindowPtr
14731482
DlgObj_ConvertToWindow(self)
14741483
PyObject *self;
@@ -1477,6 +1486,7 @@ DlgObj_ConvertToWindow(self)
14771486
return GetDialogWindow(((DialogObject *)self)->ob_itself);
14781487
return NULL;
14791488
}
1489+
#endif
14801490
/* Return the object corresponding to the dialog, or None */
14811491

14821492
PyObject *
@@ -1516,6 +1526,10 @@ void initDlg()
15161526

15171527

15181528

1529+
PyMac_INIT_TOOLBOX_OBJECT_NEW(DlgObj_New);
1530+
PyMac_INIT_TOOLBOX_OBJECT_NEW(DlgObj_WhichDialog);
1531+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DlgObj_Convert);
1532+
15191533

15201534
m = Py_InitModule("Dlg", Dlg_methods);
15211535
d = PyModule_GetDict(m);

Mac/Modules/dlg/dlgsupport.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232

3333
includestuff = includestuff + """
3434
#include <Dialogs.h>
35+
#ifdef USE_TOOLBOX_OBJECT_GLUE
36+
extern PyObject *_DlgObj_New(DialogRef);
37+
extern PyObject *_DlgObj_WhichDialog(DialogRef);
38+
extern int _DlgObj_Convert(PyObject *, DialogRef *);
39+
40+
#define DlgObj_New _DlgObj_New
41+
#define DlgObj_WhichDialog _DlgObj_WhichDialog
42+
#define DlgObj_Convert _DlgObj_Convert
43+
#endif
3544
3645
#if !ACCESSOR_CALLS_ARE_FUNCTIONS
3746
#define GetDialogTextEditHandle(dlg) (((DialogPeek)(dlg))->textH)
@@ -139,7 +148,7 @@
139148

140149
finalstuff = finalstuff + """
141150
/* Return the WindowPtr corresponding to a DialogObject */
142-
151+
#if 0
143152
WindowPtr
144153
DlgObj_ConvertToWindow(self)
145154
PyObject *self;
@@ -148,6 +157,7 @@
148157
return GetDialogWindow(((DialogObject *)self)->ob_itself);
149158
return NULL;
150159
}
160+
#endif
151161
/* Return the object corresponding to the dialog, or None */
152162
153163
PyObject *
@@ -180,6 +190,12 @@
180190
}
181191
"""
182192

193+
initstuff = initstuff + """
194+
PyMac_INIT_TOOLBOX_OBJECT_NEW(DlgObj_New);
195+
PyMac_INIT_TOOLBOX_OBJECT_NEW(DlgObj_WhichDialog);
196+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DlgObj_Convert);
197+
"""
198+
183199

184200
# Define a class which specializes our object definition
185201
class MyObjectDefinition(GlobalObjectDefinition):

Mac/Modules/drag/Dragmodule.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ DragInputUPP dragglue_InputUPP;
1919
DragDrawingUPP dragglue_DrawingUPP;
2020
#endif
2121

22+
#ifdef USE_TOOLBOX_OBJECT_GLUE
23+
extern PyObject *_DragObj_New(DragRef);
24+
extern int _DragObj_Convert(PyObject *, DragRef *);
25+
26+
#define DragObj_New _DragObj_New
27+
#define DragObj_Convert _DragObj_Convert
28+
#endif
29+
2230
static PyObject *Drag_Error;
2331

2432
/* ---------------------- Object type DragObj ----------------------- */
@@ -1040,6 +1048,9 @@ void initDrag()
10401048

10411049

10421050

1051+
PyMac_INIT_TOOLBOX_OBJECT_NEW(DragObj_New);
1052+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragObj_Convert);
1053+
10431054

10441055
m = Py_InitModule("Drag", Drag_methods);
10451056
d = PyModule_GetDict(m);

Mac/Modules/drag/dragsupport.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
DragInputUPP dragglue_InputUPP;
5555
DragDrawingUPP dragglue_DrawingUPP;
5656
#endif
57+
58+
#ifdef USE_TOOLBOX_OBJECT_GLUE
59+
extern PyObject *_DragObj_New(DragRef);
60+
extern int _DragObj_Convert(PyObject *, DragRef *);
61+
62+
#define DragObj_New _DragObj_New
63+
#define DragObj_Convert _DragObj_Convert
64+
#endif
5765
"""
5866

5967
finalstuff = finalstuff + """
@@ -153,6 +161,11 @@
153161
154162
"""
155163

164+
initstuff = initstuff + """
165+
PyMac_INIT_TOOLBOX_OBJECT_NEW(DragObj_New);
166+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragObj_Convert);
167+
"""
168+
156169
variablestuff = """
157170
dragglue_TrackingHandlerUPP = NewDragTrackingHandlerProc(dragglue_TrackingHandler);
158171
dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerProc(dragglue_ReceiveHandler);

0 commit comments

Comments
 (0)