mirror of https://github.com/python/cpython
modernized/rationalized, added PyMac_BuildOSType
This commit is contained in:
parent
8d6c180c8d
commit
8f69179f97
|
@ -2,11 +2,15 @@
|
|||
#include <Types.h>
|
||||
#include <Resources.h>
|
||||
|
||||
char *macstrerror PROTO((int)); /* strerror with mac errors */
|
||||
object *PyErr_Mac PROTO((object *, int)); /* Exception with a mac error */
|
||||
int PyMac_Idle PROTO((void)); /* Idle routine */
|
||||
int GetOSType PROTO((object *, ResType *)); /* argument parser for OSType */
|
||||
int GetStr255 PROTO((object *, Str255)); /* argument parser for Str255 */
|
||||
int GetFSSpec PROTO((object *, FSSpec *)); /* argument parser for FSSpec */
|
||||
object *PyMac_BuildFSSpec PROTO((FSSpec *)); /* Convert FSSpec to python object */
|
||||
char *macstrerror Py_PROTO((int)); /* strerror with mac errors */
|
||||
PyObject *PyErr_Mac Py_PROTO((PyObject *, int)); /* Exception with a mac error */
|
||||
int PyMac_Idle Py_PROTO((void)); /* Idle routine */
|
||||
int PyMac_GetOSType Py_PROTO((PyObject *, ResType *)); /* argument parser for OSType */
|
||||
int PyMac_GetStr255 Py_PROTO((PyObject *, Str255)); /* argument parser for Str255 */
|
||||
int PyMac_GetFSSpec Py_PROTO((PyObject *, FSSpec *)); /* argument parser for FSSpec */
|
||||
PyObject *PyMac_BuildFSSpec Py_PROTO((FSSpec *)); /* Convert FSSpec to PyObject */
|
||||
PyObject *PyMac_BuildOSType Py_PROTO((OSType)); /* Convert OSType to PyObject */
|
||||
|
||||
#define GetOSType PyMac_GetOSType
|
||||
#define GetStr255 PyMac_GetStr255
|
||||
#define GetFSSpec PyMac_GetFSSpec
|
||||
|
|
|
@ -63,10 +63,12 @@ PyErr_Mac(PyObject *eobj, int err)
|
|||
char *msg;
|
||||
PyObject *v;
|
||||
|
||||
if (err == 0) {
|
||||
if (err == 0 && !PyErr_Occurred()) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
if (err == -1 && PyErr_Occurred())
|
||||
return NULL;
|
||||
msg = macstrerror(err);
|
||||
v = Py_BuildValue("(is)", err, msg);
|
||||
PyErr_SetObject(eobj, v);
|
||||
|
@ -102,7 +104,7 @@ PyMac_Idle()
|
|||
|
||||
/* Convert a ResType argument */
|
||||
int
|
||||
GetOSType(PyObject *v, ResType *pr)
|
||||
PyMac_GetOSType(PyObject *v, ResType *pr)
|
||||
{
|
||||
if (!PyString_Check(v) || PyString_Size(v) != 4) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
|
@ -115,7 +117,7 @@ GetOSType(PyObject *v, ResType *pr)
|
|||
|
||||
/* Convert a Str255 argument */
|
||||
int
|
||||
GetStr255(PyObject *v, Str255 pbuf)
|
||||
PyMac_GetStr255(PyObject *v, Str255 pbuf)
|
||||
{
|
||||
int len;
|
||||
if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) {
|
||||
|
@ -136,7 +138,7 @@ GetStr255(PyObject *v, Str255 pbuf)
|
|||
** this is probably sys7 dependent anyway).
|
||||
*/
|
||||
int
|
||||
GetFSSpec(PyObject *v, FSSpec *fs)
|
||||
PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
|
||||
{
|
||||
Str255 path;
|
||||
short refnum;
|
||||
|
@ -172,3 +174,10 @@ PyMac_BuildFSSpec(FSSpec *fs)
|
|||
{
|
||||
return Py_BuildValue("(iis#)", fs->vRefNum, fs->parID, &fs->name[1], fs->name[0]);
|
||||
}
|
||||
|
||||
/* Convert an OSType value to a 4-char string object */
|
||||
PyObject *
|
||||
PyMac_BuildOSType(OSType t)
|
||||
{
|
||||
return PyString_FromStringAndSize((char *)&t, 4);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue