1 /***********************************************************
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI not be used in advertising or publicity pertaining to
13 distribution of the software without specific, written prior permission.
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 ******************************************************************/
25 /* Macintosh Gestalt interface */
29 #include <Carbon/Carbon.h>
31 /* Convert a 4-char string object argument to an OSType value */
33 convert_to_OSType(PyObject
*v
, OSType
*pr
)
36 if (!PyUnicode_Check(v
) || PyUnicode_GetSize(v
) != 4) {
37 PyErr_SetString(PyExc_TypeError
,
38 "OSType arg must be string of 4 chars");
41 memcpy((char *)&tmp
, _PyUnicode_AsString(v
), 4);
42 *pr
= (OSType
)ntohl(tmp
);
47 gestalt_gestalt(PyObject
*self
, PyObject
*args
)
52 if (!PyArg_ParseTuple(args
, "O&", convert_to_OSType
, &selector
))
54 iErr
= Gestalt(selector
, &response
);
56 PyErr_SetString(PyExc_OSError
,
57 "non-zero exit code!");
60 return PyLong_FromLong(response
);
63 static struct PyMethodDef gestalt_methods
[] = {
64 {"gestalt", gestalt_gestalt
, METH_VARARGS
},
65 {NULL
, NULL
} /* Sentinel */
68 static struct PyModuleDef gestaltmodule
= {
69 PyModuleDef_HEAD_INIT
,
83 return PyModule_Create(&gestaltmodule
);