Kaydet (Commit) b7e79e5f authored tarafından Guido van Rossum's avatar Guido van Rossum

Got rid of {Get,Set}FileType in favor of {Get,Set}CreatorAndType --

the former had their arguments reversed compared to all Apple's
routines (e.g. FSpOpenResFile()).

Also fixed the SoundMgr UserRoutine (Jack fixed it but put the fix
between #ifdef __MWERKS__ ... #endif :-( ).

NB eventually this module should disappear in favor of separate
modules per manager (e.g. Resources, Sound, Files, ...).
üst c02311ba
...@@ -71,7 +71,6 @@ Rsrc_FromHandle(Handle h) ...@@ -71,7 +71,6 @@ Rsrc_FromHandle(Handle h)
static void static void
Rsrc_Dealloc(RsrcObject *r) Rsrc_Dealloc(RsrcObject *r)
{ {
/* XXXX Note by Jack: shouldn't we ReleaseResource here? */
PyMem_DEL(r); PyMem_DEL(r);
} }
...@@ -120,8 +119,8 @@ Rsrc_AsString(RsrcObject *r, PyObject *args) ...@@ -120,8 +119,8 @@ Rsrc_AsString(RsrcObject *r, PyObject *args)
} }
static PyMethodDef Rsrc_Methods[] = { static PyMethodDef Rsrc_Methods[] = {
{"GetResInfo", (PyCFunction)Rsrc_GetResInfo, 1}, {"GetResInfo", (PyCFunction)Rsrc_GetResInfo, 1},
{"AsString", (PyCFunction)Rsrc_AsString, 1}, {"AsString", (PyCFunction)Rsrc_AsString, 1},
{"AsBytes", (PyCFunction)Rsrc_AsBytes, 1}, {"AsBytes", (PyCFunction)Rsrc_AsBytes, 1},
{NULL, NULL} /* Sentinel */ {NULL, NULL} /* Sentinel */
}; };
...@@ -179,51 +178,42 @@ MacOS_GetNamedResource(PyObject *self, PyObject *args) ...@@ -179,51 +178,42 @@ MacOS_GetNamedResource(PyObject *self, PyObject *args)
/* Miscellaneous File System Operations */ /* Miscellaneous File System Operations */
static PyObject * static PyObject *
MacOS_GetFileType(PyObject *self, PyObject *args) MacOS_GetCreatorAndType(PyObject *self, PyObject *args)
{ {
Str255 name; Str255 name;
FInfo info; FInfo info;
PyObject *type, *creator, *res; PyObject *creator, *type, *res;
OSErr err; OSErr err;
if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, &name)) if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, &name))
return NULL; return NULL;
if ((err = GetFInfo(name, 0, &info)) != noErr) { if ((err = GetFInfo(name, 0, &info)) != noErr)
errno = err; return PyErr_Mac(MacOS_Error, err);
PyErr_SetFromErrno(MacOS_Error);
return NULL;
}
type = PyString_FromStringAndSize((char *)&info.fdType, 4);
creator = PyString_FromStringAndSize((char *)&info.fdCreator, 4); creator = PyString_FromStringAndSize((char *)&info.fdCreator, 4);
res = Py_BuildValue("OO", type, creator); type = PyString_FromStringAndSize((char *)&info.fdType, 4);
Py_DECREF(type); res = Py_BuildValue("OO", creator, type);
Py_DECREF(creator); Py_DECREF(creator);
Py_DECREF(type);
return res; return res;
} }
static PyObject * static PyObject *
MacOS_SetFileType(PyObject *self, PyObject *args) MacOS_SetCreatorAndType(PyObject *self, PyObject *args)
{ {
Str255 name; Str255 name;
ResType type, creator; ResType creator, type;
FInfo info; FInfo info;
OSErr err; OSErr err;
if (!PyArg_ParseTuple(args, "O&O&O&", if (!PyArg_ParseTuple(args, "O&O&O&",
PyMac_GetStr255, &name, PyMac_GetOSType, &type, PyMac_GetOSType, &creator)) PyMac_GetStr255, &name, PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
return NULL;
if ((err = GetFInfo(name, 0, &info)) != noErr) {
errno = err;
PyErr_SetFromErrno(MacOS_Error);
return NULL; return NULL;
} if ((err = GetFInfo(name, 0, &info)) != noErr)
info.fdType = type; return PyErr_Mac(MacOS_Error, err);
info.fdCreator = creator; info.fdCreator = creator;
if ((err = SetFInfo(name, 0, &info)) != noErr) { info.fdType = type;
errno = err; if ((err = SetFInfo(name, 0, &info)) != noErr)
PyErr_SetFromErrno(MacOS_Error); return PyErr_Mac(MacOS_Error, err);
return NULL;
}
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
...@@ -411,19 +401,11 @@ MySafeCallback(arg) ...@@ -411,19 +401,11 @@ MySafeCallback(arg)
} }
static pascal void static pascal void
#ifdef __MWERKS__
MyUserRoutine(SndChannelPtr chan, SndCommand *cmd) MyUserRoutine(SndChannelPtr chan, SndCommand *cmd)
#else
MyUserRoutine(SndChannelPtr chan, SndCommand cmd)
#endif
{ {
cbinfo *p = (cbinfo *)chan->userInfo; cbinfo *p = (cbinfo *)chan->userInfo;
long A5 = SetA5(p->A5); long A5 = SetA5(p->A5);
#ifdef __MWERKS__
p->cmd = *cmd; p->cmd = *cmd;
#else
p->cmd = cmd;
#endif
Py_AddPendingCall(MySafeCallback, (void *)p); Py_AddPendingCall(MySafeCallback, (void *)p);
SetA5(A5); SetA5(A5);
} }
...@@ -589,8 +571,8 @@ static PyMethodDef MacOS_Methods[] = { ...@@ -589,8 +571,8 @@ static PyMethodDef MacOS_Methods[] = {
{"AcceptHighLevelEvent", MacOS_AcceptHighLevelEvent, 1}, {"AcceptHighLevelEvent", MacOS_AcceptHighLevelEvent, 1},
{"GetResource", MacOS_GetResource, 1}, {"GetResource", MacOS_GetResource, 1},
{"GetNamedResource", MacOS_GetNamedResource, 1}, {"GetNamedResource", MacOS_GetNamedResource, 1},
{"GetFileType", MacOS_GetFileType, 1}, {"GetCreatorAndType", MacOS_GetCreatorAndType, 1},
{"SetFileType", MacOS_SetFileType, 1}, {"SetCreatorAndType", MacOS_SetCreatorAndType, 1},
{"SndNewChannel", MacOS_SndNewChannel, 1}, {"SndNewChannel", MacOS_SndNewChannel, 1},
{"SndPlay", MacOS_SndPlay, 1}, {"SndPlay", MacOS_SndPlay, 1},
{"SndControl", MacOS_SndControl, 1}, {"SndControl", MacOS_SndControl, 1},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment