Jack Jansen | f57a4a2 | 2001-05-17 22:11:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | ** mactoolboxglue.c - Glue together the toolbox objects. |
| 3 | ** |
| 4 | ** Because toolbox modules interdepend on each other, they use each others |
| 5 | ** object types, on MacOSX/MachO this leads to the situation that they |
| 6 | ** cannot be dynamically loaded (or they would all have to be lumped into |
| 7 | ** a single .so, but this would be bad for extensibility). |
| 8 | ** |
| 9 | ** This file defines wrappers for all the _New and _Convert functions, |
| 10 | ** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers |
| 11 | ** check an indirection function pointer, and if it isn't filled in yet |
| 12 | ** they import the appropriate module, whose init routine should fill in |
| 13 | ** the pointer. |
| 14 | */ |
| 15 | |
| 16 | #ifdef USE_TOOLBOX_OBJECT_GLUE |
| 17 | |
| 18 | #include "python.h" |
| 19 | #include "pymactoolbox.h" |
| 20 | |
| 21 | #define GLUE_NEW(object, routinename, module) \ |
| 22 | PyObject *(*PyMacGluePtr_##routinename)(object); \ |
| 23 | \ |
| 24 | PyObject *routinename(object cobj) { \ |
| 25 | if (!PyMacGluePtr_##routinename) { \ |
| 26 | if (!PyImport_ImportModule(module)) return NULL; \ |
| 27 | if (!PyMacGluePtr_##routinename) { \ |
| 28 | PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ |
| 29 | return NULL; \ |
| 30 | } \ |
| 31 | } \ |
| 32 | return (*PyMacGluePtr_##routinename)(cobj); \ |
| 33 | } |
| 34 | |
| 35 | #define GLUE_CONVERT(object, routinename, module) \ |
| 36 | int (*PyMacGluePtr_##routinename)(PyObject *, object *); \ |
| 37 | \ |
| 38 | int routinename(PyObject *pyobj, object *cobj) { \ |
| 39 | if (!PyMacGluePtr_##routinename) { \ |
| 40 | if (!PyImport_ImportModule(module)) return NULL; \ |
| 41 | if (!PyMacGluePtr_##routinename) { \ |
| 42 | PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ |
| 43 | return NULL; \ |
| 44 | } \ |
| 45 | } \ |
| 46 | return (*PyMacGluePtr_##routinename)(pyobj, cobj); \ |
| 47 | } |
| 48 | |
| 49 | GLUE_NEW(AppleEvent *, AEDesc_New, "AE") /* XXXX Why by address? */ |
| 50 | GLUE_CONVERT(AppleEvent, AEDesc_Convert, "AE") |
| 51 | |
| 52 | GLUE_NEW(Component, CmpObj_New, "Cm") |
| 53 | GLUE_CONVERT(Component, CmpObj_Convert, "Cm") |
| 54 | GLUE_NEW(ComponentInstance, CmpInstObj_New, "Cm") |
| 55 | GLUE_CONVERT(ComponentInstance, CmpInstObj_Convert, "Cm") |
| 56 | |
| 57 | GLUE_NEW(ControlHandle, CtlObj_New, "Ctl") |
| 58 | GLUE_CONVERT(ControlHandle, CtlObj_Convert, "Ctl") |
| 59 | |
| 60 | GLUE_NEW(DialogPtr, DlgObj_New, "Dlg") |
| 61 | GLUE_CONVERT(DialogPtr, DlgObj_Convert, "Dlg") |
| 62 | GLUE_NEW(DialogPtr, DlgObj_WhichDialog, "Dlg") |
| 63 | |
| 64 | GLUE_NEW(DragReference, DragObj_New, "Drag") |
| 65 | GLUE_CONVERT(DragReference, DragObj_Convert, "Drag") |
| 66 | |
| 67 | GLUE_NEW(ListHandle, ListObj_New, "List") |
| 68 | GLUE_CONVERT(ListHandle, ListObj_Convert, "List") |
| 69 | |
| 70 | GLUE_NEW(MenuHandle, MenuObj_New, "Menu") |
| 71 | GLUE_CONVERT(MenuHandle, MenuObj_Convert, "Menu") |
| 72 | |
| 73 | GLUE_NEW(GrafPtr, GrafObj_New, "Qd") |
| 74 | GLUE_CONVERT(GrafPtr, GrafObj_Convert, "Qd") |
| 75 | GLUE_NEW(BitMapPtr, BMObj_New, "Qd") |
| 76 | GLUE_CONVERT(BitMapPtr, BMObj_Convert, "Qd") |
| 77 | GLUE_NEW(RGBColor *, QdRGB_New, "Qd") /* XXXX Why? */ |
| 78 | GLUE_CONVERT(RGBColor, QdRGB_Convert, "Qd") |
| 79 | |
| 80 | GLUE_NEW(GWorldPtr, GWorldObj_New, "Qdoffs") |
| 81 | GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Qdoffs") |
| 82 | |
| 83 | GLUE_NEW(Track, TrackObj_New, "Qt") |
| 84 | GLUE_CONVERT(Track, TrackObj_Convert, "Qt") |
| 85 | GLUE_NEW(Movie, MovieObj_New, "Qt") |
| 86 | GLUE_CONVERT(Movie, MovieObj_Convert, "Qt") |
| 87 | GLUE_NEW(MovieController, MovieCtlObj_New, "Qt") |
| 88 | GLUE_CONVERT(MovieController, MovieCtlObj_Convert, "Qt") |
| 89 | GLUE_NEW(TimeBase, TimeBaseObj_New, "Qt") |
| 90 | GLUE_CONVERT(TimeBase, TimeBaseObj_Convert, "Qt") |
| 91 | GLUE_NEW(UserData, UserDataObj_New, "Qt") |
| 92 | GLUE_CONVERT(UserData, UserDataObj_Convert, "Qt") |
| 93 | GLUE_NEW(Media, MediaObj_New, "Qt") |
| 94 | GLUE_CONVERT(Media, MediaObj_Convert, "Qt") |
| 95 | |
| 96 | GLUE_NEW(Handle, ResObj_New, "Res") |
| 97 | GLUE_CONVERT(Handle, ResObj_Convert, "Res") |
| 98 | GLUE_NEW(Handle, OptResObj_New, "Res") |
| 99 | GLUE_CONVERT(Handle, OptResObj_Convert, "Res") |
| 100 | |
| 101 | GLUE_NEW(TEHandle, TEObj_New, "TE") |
| 102 | GLUE_CONVERT(TEHandle, TEObj_Convert, "TE") |
| 103 | |
| 104 | GLUE_NEW(WindowPtr, WinObj_New, "Win") |
| 105 | GLUE_CONVERT(WindowPtr, WinObj_Convert, "Win") |
| 106 | GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Win") |
| 107 | |
| 108 | #endif /* USE_TOOLBOX_OBJECT_GLUE */ |