@@ -29,6 +29,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2929#include "marshal.h"
3030#include "import.h"
3131#include "importdl.h"
32+ #include "pymactoolbox.h"
3233
3334#include "pythonresources.h"
3435
@@ -1147,3 +1148,108 @@ PyMac_Buildwide(wide *w)
11471148 return PyInt_FromLong (w -> lo );
11481149 return Py_BuildValue ("(ll)" , w -> hi , w -> lo );
11491150}
1151+
1152+ #ifdef USE_TOOLBOX_OBJECT_GLUE
1153+ /*
1154+ ** Glue together the toolbox objects.
1155+ **
1156+ ** Because toolbox modules interdepend on each other, they use each others
1157+ ** object types, on MacOSX/MachO this leads to the situation that they
1158+ ** cannot be dynamically loaded (or they would all have to be lumped into
1159+ ** a single .so, but this would be bad for extensibility).
1160+ **
1161+ ** This file defines wrappers for all the _New and _Convert functions,
1162+ ** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers
1163+ ** check an indirection function pointer, and if it isn't filled in yet
1164+ ** they import the appropriate module, whose init routine should fill in
1165+ ** the pointer.
1166+ */
1167+
1168+ #define GLUE_NEW (object , routinename , module ) \
1169+ PyObject *(*PyMacGluePtr_##routinename)(object); \
1170+ \
1171+ PyObject *routinename(object cobj) { \
1172+ if (!PyMacGluePtr_##routinename) { \
1173+ if (!PyImport_ImportModule(module)) return NULL; \
1174+ if (!PyMacGluePtr_##routinename) { \
1175+ PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
1176+ return NULL; \
1177+ } \
1178+ } \
1179+ return (*PyMacGluePtr_##routinename)(cobj); \
1180+ }
1181+
1182+ #define GLUE_CONVERT (object , routinename , module ) \
1183+ int (*PyMacGluePtr_##routinename)(PyObject *, object *); \
1184+ \
1185+ int routinename(PyObject *pyobj, object *cobj) { \
1186+ if (!PyMacGluePtr_##routinename) { \
1187+ if (!PyImport_ImportModule(module)) return NULL; \
1188+ if (!PyMacGluePtr_##routinename) { \
1189+ PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
1190+ return NULL; \
1191+ } \
1192+ } \
1193+ return (*PyMacGluePtr_##routinename)(pyobj, cobj); \
1194+ }
1195+
1196+ GLUE_NEW (AppleEvent * , AEDesc_New , "AE" ) /* XXXX Why by address? */
1197+ GLUE_CONVERT (AppleEvent , AEDesc_Convert , "AE" )
1198+
1199+ GLUE_NEW (Component , CmpObj_New , "Cm" )
1200+ GLUE_CONVERT (Component , CmpObj_Convert , "Cm" )
1201+ GLUE_NEW (ComponentInstance , CmpInstObj_New , "Cm" )
1202+ GLUE_CONVERT (ComponentInstance , CmpInstObj_Convert , "Cm" )
1203+
1204+ GLUE_NEW (ControlHandle , CtlObj_New , "Ctl" )
1205+ GLUE_CONVERT (ControlHandle , CtlObj_Convert , "Ctl" )
1206+
1207+ GLUE_NEW (DialogPtr , DlgObj_New , "Dlg" )
1208+ GLUE_CONVERT (DialogPtr , DlgObj_Convert , "Dlg" )
1209+ GLUE_NEW (DialogPtr , DlgObj_WhichDialog , "Dlg" )
1210+
1211+ GLUE_NEW (DragReference , DragObj_New , "Drag" )
1212+ GLUE_CONVERT (DragReference , DragObj_Convert , "Drag" )
1213+
1214+ GLUE_NEW (ListHandle , ListObj_New , "List" )
1215+ GLUE_CONVERT (ListHandle , ListObj_Convert , "List" )
1216+
1217+ GLUE_NEW (MenuHandle , MenuObj_New , "Menu" )
1218+ GLUE_CONVERT (MenuHandle , MenuObj_Convert , "Menu" )
1219+
1220+ GLUE_NEW (GrafPtr , GrafObj_New , "Qd" )
1221+ GLUE_CONVERT (GrafPtr , GrafObj_Convert , "Qd" )
1222+ GLUE_NEW (BitMapPtr , BMObj_New , "Qd" )
1223+ GLUE_CONVERT (BitMapPtr , BMObj_Convert , "Qd" )
1224+ GLUE_NEW (RGBColor * , QdRGB_New , "Qd" ) /* XXXX Why? */
1225+ GLUE_CONVERT (RGBColor , QdRGB_Convert , "Qd" )
1226+
1227+ GLUE_NEW (GWorldPtr , GWorldObj_New , "Qdoffs" )
1228+ GLUE_CONVERT (GWorldPtr , GWorldObj_Convert , "Qdoffs" )
1229+
1230+ GLUE_NEW (Track , TrackObj_New , "Qt" )
1231+ GLUE_CONVERT (Track , TrackObj_Convert , "Qt" )
1232+ GLUE_NEW (Movie , MovieObj_New , "Qt" )
1233+ GLUE_CONVERT (Movie , MovieObj_Convert , "Qt" )
1234+ GLUE_NEW (MovieController , MovieCtlObj_New , "Qt" )
1235+ GLUE_CONVERT (MovieController , MovieCtlObj_Convert , "Qt" )
1236+ GLUE_NEW (TimeBase , TimeBaseObj_New , "Qt" )
1237+ GLUE_CONVERT (TimeBase , TimeBaseObj_Convert , "Qt" )
1238+ GLUE_NEW (UserData , UserDataObj_New , "Qt" )
1239+ GLUE_CONVERT (UserData , UserDataObj_Convert , "Qt" )
1240+ GLUE_NEW (Media , MediaObj_New , "Qt" )
1241+ GLUE_CONVERT (Media , MediaObj_Convert , "Qt" )
1242+
1243+ GLUE_NEW (Handle , ResObj_New , "Res" )
1244+ GLUE_CONVERT (Handle , ResObj_Convert , "Res" )
1245+ GLUE_NEW (Handle , OptResObj_New , "Res" )
1246+ GLUE_CONVERT (Handle , OptResObj_Convert , "Res" )
1247+
1248+ GLUE_NEW (TEHandle , TEObj_New , "TE" )
1249+ GLUE_CONVERT (TEHandle , TEObj_Convert , "TE" )
1250+
1251+ GLUE_NEW (WindowPtr , WinObj_New , "Win" )
1252+ GLUE_CONVERT (WindowPtr , WinObj_Convert , "Win" )
1253+ GLUE_NEW (WindowPtr , WinObj_WhichWindow , "Win" )
1254+
1255+ #endif /* USE_TOOLBOX_OBJECT_GLUE */
0 commit comments