summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2001-05-17 22:11:44 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2001-05-17 22:11:44 (GMT)
commitf57a4a2e97476234fbc994221328008fc0508078 (patch)
tree57abd74fcb5fb2bc97da6aa9910d1b319c56d6f3 /Mac
parent0e04eecdbf8467cf3fe055e41e96fa48507b998c (diff)
downloadcpython-f57a4a2e97476234fbc994221328008fc0508078.zip
cpython-f57a4a2e97476234fbc994221328008fc0508078.tar.gz
cpython-f57a4a2e97476234fbc994221328008fc0508078.tar.bz2
Glue code to connect obj_New and obj_Convert routines (the PyArg_Parse and Py_BuildTuple helpers) from one dynamically imported module to another.
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Include/pymactoolbox.h29
-rw-r--r--Mac/Python/mactoolboxglue.c108
2 files changed, 131 insertions, 6 deletions
diff --git a/Mac/Include/pymactoolbox.h b/Mac/Include/pymactoolbox.h
index 827a146..3eb58b1 100644
--- a/Mac/Include/pymactoolbox.h
+++ b/Mac/Include/pymactoolbox.h
@@ -15,6 +15,28 @@
#include <Movies.h>
#include <Errors.h>
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+/*
+** These macros are used in the module init code. If we use toolbox object glue
+** it sets the function pointer to point to the real function.
+*/
+#define PyMac_INIT_TOOLBOX_OBJECT_NEW(rtn) { \
+ extern PyObject *(*PyMacGluePtr_##rtn)(object); \
+ PyMacGluePtr_##rtn = _##rtn; \
+}
+#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(rtn) { \
+ extern int (*PyMacGluePtr_##rtn)(object); \
+ PyMacGluePtr_##rtn = _##rtn; \
+}
+#else
+/*
+** If we don't use toolbox object glue the init macros are empty. Moreover, we define
+** _xxx_New to be the same as xxx_New, and the code in mactoolboxglue isn't included.
+*/
+#define PyMac_INIT_TOOLBOX_OBJECT_NEW(rtn)
+#define PyMac_INIT_TOOLBOX_OBJECT_CONVERT(rtn)
+#endif /* USE_TOOLBOX_OBJECT_GLUE */
+
/* AE exports */
extern PyObject *AEDesc_New(AppleEvent *); /* XXXX Why passed by address?? */
extern int AEDesc_Convert(PyObject *, AppleEvent *);
@@ -32,10 +54,7 @@ extern int CtlObj_Convert(PyObject *, ControlHandle *);
/* Dlg exports */
extern PyObject *DlgObj_New(DialogPtr);
extern int DlgObj_Convert(PyObject *, DialogPtr *);
-extern WindowPtr DlgObj_ConvertToWindow(PyObject *);
extern PyObject *DlgObj_WhichDialog(DialogPtr);
-extern PyTypeObject Dialog_Type;
-#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
/* Drag exports */
extern PyObject *DragObj_New(DragReference);
@@ -67,7 +86,7 @@ extern int TrackObj_Convert(PyObject *, Track *);
extern PyObject *MovieObj_New(Movie);
extern int MovieObj_Convert(PyObject *, Movie *);
extern PyObject *MovieCtlObj_New(MovieController);
-extern int MovieCtlObj_Convert(PyObject *, TimeBase *);
+extern int MovieCtlObj_Convert(PyObject *, MovieController *);
extern PyObject *TimeBaseObj_New(TimeBase);
extern int TimeBaseObj_Convert(PyObject *, TimeBase *);
extern PyObject *UserDataObj_New(UserData);
@@ -89,8 +108,6 @@ extern int TEObj_Convert(PyObject *, TEHandle *);
extern PyObject *WinObj_New(WindowPtr);
extern int WinObj_Convert(PyObject *, WindowPtr *);
extern PyObject *WinObj_WhichWindow(WindowPtr);
-extern PyTypeObject Window_Type;
-#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
#ifdef __cplusplus
diff --git a/Mac/Python/mactoolboxglue.c b/Mac/Python/mactoolboxglue.c
new file mode 100644
index 0000000..fa910e3
--- /dev/null
+++ b/Mac/Python/mactoolboxglue.c
@@ -0,0 +1,108 @@
+/*
+** mactoolboxglue.c - Glue together the toolbox objects.
+**
+** Because toolbox modules interdepend on each other, they use each others
+** object types, on MacOSX/MachO this leads to the situation that they
+** cannot be dynamically loaded (or they would all have to be lumped into
+** a single .so, but this would be bad for extensibility).
+**
+** This file defines wrappers for all the _New and _Convert functions,
+** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers
+** check an indirection function pointer, and if it isn't filled in yet
+** they import the appropriate module, whose init routine should fill in
+** the pointer.
+*/
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+
+#include "python.h"
+#include "pymactoolbox.h"
+
+#define GLUE_NEW(object, routinename, module) \
+PyObject *(*PyMacGluePtr_##routinename)(object); \
+\
+PyObject *routinename(object cobj) { \
+ if (!PyMacGluePtr_##routinename) { \
+ if (!PyImport_ImportModule(module)) return NULL; \
+ if (!PyMacGluePtr_##routinename) { \
+ PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
+ return NULL; \
+ } \
+ } \
+ return (*PyMacGluePtr_##routinename)(cobj); \
+}
+
+#define GLUE_CONVERT(object, routinename, module) \
+int (*PyMacGluePtr_##routinename)(PyObject *, object *); \
+\
+int routinename(PyObject *pyobj, object *cobj) { \
+ if (!PyMacGluePtr_##routinename) { \
+ if (!PyImport_ImportModule(module)) return NULL; \
+ if (!PyMacGluePtr_##routinename) { \
+ PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
+ return NULL; \
+ } \
+ } \
+ return (*PyMacGluePtr_##routinename)(pyobj, cobj); \
+}
+
+GLUE_NEW(AppleEvent *, AEDesc_New, "AE") /* XXXX Why by address? */
+GLUE_CONVERT(AppleEvent, AEDesc_Convert, "AE")
+
+GLUE_NEW(Component, CmpObj_New, "Cm")
+GLUE_CONVERT(Component, CmpObj_Convert, "Cm")
+GLUE_NEW(ComponentInstance, CmpInstObj_New, "Cm")
+GLUE_CONVERT(ComponentInstance, CmpInstObj_Convert, "Cm")
+
+GLUE_NEW(ControlHandle, CtlObj_New, "Ctl")
+GLUE_CONVERT(ControlHandle, CtlObj_Convert, "Ctl")
+
+GLUE_NEW(DialogPtr, DlgObj_New, "Dlg")
+GLUE_CONVERT(DialogPtr, DlgObj_Convert, "Dlg")
+GLUE_NEW(DialogPtr, DlgObj_WhichDialog, "Dlg")
+
+GLUE_NEW(DragReference, DragObj_New, "Drag")
+GLUE_CONVERT(DragReference, DragObj_Convert, "Drag")
+
+GLUE_NEW(ListHandle, ListObj_New, "List")
+GLUE_CONVERT(ListHandle, ListObj_Convert, "List")
+
+GLUE_NEW(MenuHandle, MenuObj_New, "Menu")
+GLUE_CONVERT(MenuHandle, MenuObj_Convert, "Menu")
+
+GLUE_NEW(GrafPtr, GrafObj_New, "Qd")
+GLUE_CONVERT(GrafPtr, GrafObj_Convert, "Qd")
+GLUE_NEW(BitMapPtr, BMObj_New, "Qd")
+GLUE_CONVERT(BitMapPtr, BMObj_Convert, "Qd")
+GLUE_NEW(RGBColor *, QdRGB_New, "Qd") /* XXXX Why? */
+GLUE_CONVERT(RGBColor, QdRGB_Convert, "Qd")
+
+GLUE_NEW(GWorldPtr, GWorldObj_New, "Qdoffs")
+GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Qdoffs")
+
+GLUE_NEW(Track, TrackObj_New, "Qt")
+GLUE_CONVERT(Track, TrackObj_Convert, "Qt")
+GLUE_NEW(Movie, MovieObj_New, "Qt")
+GLUE_CONVERT(Movie, MovieObj_Convert, "Qt")
+GLUE_NEW(MovieController, MovieCtlObj_New, "Qt")
+GLUE_CONVERT(MovieController, MovieCtlObj_Convert, "Qt")
+GLUE_NEW(TimeBase, TimeBaseObj_New, "Qt")
+GLUE_CONVERT(TimeBase, TimeBaseObj_Convert, "Qt")
+GLUE_NEW(UserData, UserDataObj_New, "Qt")
+GLUE_CONVERT(UserData, UserDataObj_Convert, "Qt")
+GLUE_NEW(Media, MediaObj_New, "Qt")
+GLUE_CONVERT(Media, MediaObj_Convert, "Qt")
+
+GLUE_NEW(Handle, ResObj_New, "Res")
+GLUE_CONVERT(Handle, ResObj_Convert, "Res")
+GLUE_NEW(Handle, OptResObj_New, "Res")
+GLUE_CONVERT(Handle, OptResObj_Convert, "Res")
+
+GLUE_NEW(TEHandle, TEObj_New, "TE")
+GLUE_CONVERT(TEHandle, TEObj_Convert, "TE")
+
+GLUE_NEW(WindowPtr, WinObj_New, "Win")
+GLUE_CONVERT(WindowPtr, WinObj_Convert, "Win")
+GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Win")
+
+#endif /* USE_TOOLBOX_OBJECT_GLUE */ \ No newline at end of file