summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/qd
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2001-05-17 21:58:34 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2001-05-17 21:58:34 (GMT)
commit0e04eecdbf8467cf3fe055e41e96fa48507b998c (patch)
tree0c3373b79a29ab55b8c542fd06ddbc9d78dd9d39 /Mac/Modules/qd
parent99f9baa33190482784900970fd3e1c76e7cb48d6 (diff)
downloadcpython-0e04eecdbf8467cf3fe055e41e96fa48507b998c.zip
cpython-0e04eecdbf8467cf3fe055e41e96fa48507b998c.tar.gz
cpython-0e04eecdbf8467cf3fe055e41e96fa48507b998c.tar.bz2
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.
Diffstat (limited to 'Mac/Modules/qd')
-rw-r--r--Mac/Modules/qd/Qdmodule.c34
-rw-r--r--Mac/Modules/qd/qdsupport.py36
2 files changed, 70 insertions, 0 deletions
diff --git a/Mac/Modules/qd/Qdmodule.c b/Mac/Modules/qd/Qdmodule.c
index 12f44f4..9c3280e 100644
--- a/Mac/Modules/qd/Qdmodule.c
+++ b/Mac/Modules/qd/Qdmodule.c
@@ -10,6 +10,22 @@
#include <QuickDraw.h>
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_GrafObj_New(GrafPtr);
+extern int _GrafObj_Convert(PyObject *, GrafPtr *);
+extern PyObject *_BMObj_New(BitMapPtr);
+extern int _BMObj_Convert(PyObject *, BitMapPtr *);
+extern PyObject *_QdRGB_New(RGBColorPtr);
+extern int _QdRGB_Convert(PyObject *, RGBColorPtr *);
+
+#define GrafObj_New _GrafObj_New
+#define GrafObj_Convert _GrafObj_Convert
+#define BMObj_New _BMObj_New
+#define BMObj_Convert _BMObj_Convert
+#define QdRGB_New _QdRGB_New
+#define QdRGB_Convert _QdRGB_Convert
+#endif
+
#if !ACCESSOR_CALLS_ARE_FUNCTIONS
#define GetPortBitMapForCopyBits(port) ((const struct BitMap *)&((GrafPort *)(port))->portBits)
#define GetPortPixMap(port) (((CGrafPtr)(port))->portPixMap)
@@ -144,6 +160,16 @@ GrafObj_Convert(v, p_itself)
PyObject *v;
GrafPtr *p_itself;
{
+#if 1
+ {
+ WindowRef win;
+ if (WinObj_Convert(v, &win) && v) {
+ *p_itself = (GrafPtr)GetWindowPort(win);
+ return 1;
+ }
+ PyErr_Clear();
+ }
+#else
if (DlgObj_Check(v)) {
DialogRef dlg = (DialogRef)((GrafPortObject *)v)->ob_itself;
*p_itself = (GrafPtr)GetWindowPort(GetDialogWindow(dlg));
@@ -154,6 +180,7 @@ GrafObj_Convert(v, p_itself)
*p_itself = (GrafPtr)GetWindowPort(win);
return 1;
}
+#endif
if (!GrafObj_Check(v))
{
PyErr_SetString(PyExc_TypeError, "GrafPort required");
@@ -6194,6 +6221,13 @@ void initQd()
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(BMObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(BMObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(GrafObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GrafObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(QdRGB_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(QdRGB_Convert);
+
m = Py_InitModule("Qd", Qd_methods);
d = PyModule_GetDict(m);
diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py
index fe606f5..705cc4e 100644
--- a/Mac/Modules/qd/qdsupport.py
+++ b/Mac/Modules/qd/qdsupport.py
@@ -63,6 +63,22 @@ PenState_ptr = StructInputBufferType('PenState')
includestuff = includestuff + """
#include <%s>""" % MACHEADERFILE + """
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+extern PyObject *_GrafObj_New(GrafPtr);
+extern int _GrafObj_Convert(PyObject *, GrafPtr *);
+extern PyObject *_BMObj_New(BitMapPtr);
+extern int _BMObj_Convert(PyObject *, BitMapPtr *);
+extern PyObject *_QdRGB_New(RGBColorPtr);
+extern int _QdRGB_Convert(PyObject *, RGBColorPtr *);
+
+#define GrafObj_New _GrafObj_New
+#define GrafObj_Convert _GrafObj_Convert
+#define BMObj_New _BMObj_New
+#define BMObj_Convert _BMObj_Convert
+#define QdRGB_New _QdRGB_New
+#define QdRGB_Convert _QdRGB_Convert
+#endif
+
#if !ACCESSOR_CALLS_ARE_FUNCTIONS
#define GetPortBitMapForCopyBits(port) ((const struct BitMap *)&((GrafPort *)(port))->portBits)
#define GetPortPixMap(port) (((CGrafPtr)(port))->portPixMap)
@@ -201,6 +217,15 @@ variablestuff = """
}
"""
+initstuff = initstuff + """
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(BMObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(BMObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(GrafObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GrafObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(QdRGB_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(QdRGB_Convert);
+"""
+
## not yet...
##
##class Region_ObjectDefinition(GlobalObjectDefinition):
@@ -219,6 +244,16 @@ class MyGRObjectDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def outputCheckConvertArg(self):
+ Output("#if 1")
+ OutLbrace()
+ Output("WindowRef win;")
+ OutLbrace("if (WinObj_Convert(v, &win) && v)")
+ Output("*p_itself = (GrafPtr)GetWindowPort(win);")
+ Output("return 1;")
+ OutRbrace()
+ Output("PyErr_Clear();")
+ OutRbrace()
+ Output("#else")
OutLbrace("if (DlgObj_Check(v))")
Output("DialogRef dlg = (DialogRef)((GrafPortObject *)v)->ob_itself;")
Output("*p_itself = (GrafPtr)GetWindowPort(GetDialogWindow(dlg));")
@@ -229,6 +264,7 @@ class MyGRObjectDefinition(GlobalObjectDefinition):
Output("*p_itself = (GrafPtr)GetWindowPort(win);")
Output("return 1;")
OutRbrace()
+ Output("#endif")
def outputGetattrHook(self):
Output("#if !ACCESSOR_CALLS_ARE_FUNCTIONS")
Output("""