This commit is contained in:
Jack Jansen 1997-01-30 15:48:07 +00:00
parent 22023f4b77
commit f5c20575cb
5 changed files with 615 additions and 619 deletions

View File

@ -26,7 +26,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* ctbcm objects */
#include "allobjects.h"
#include "Python.h"
#include "macglue.h"
@ -46,19 +46,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define _CommToolboxTrap 0x8B
#define _UnimplementedOSTrap 0x9F
extern object *PyErr_Mac(object *,int);
extern PyObject *PyErr_Mac(PyObject *,int);
static object *ErrorObject;
static PyObject *ErrorObject;
typedef struct {
OB_HEAD
PyObject_HEAD
ConnHandle hdl; /* The handle to the connection */
object *callback; /* Python callback routine */
PyObject *callback; /* Python callback routine */
int has_callback; /* True if callback not None */
int err; /* Error to pass to the callback */
} ctbcmobject;
staticforward typeobject ctbcmtype;
staticforward PyTypeObject ctbcmtype;
#define is_ctbcmobject(v) ((v)->ob_type == &ctbcmtype)
@ -86,7 +86,7 @@ initialize_ctb()
initialized = 0;
if ( !TrapAvailable(_CommToolboxTrap, OSTrap) ) {
err_setstr(ErrorObject, "CTB not available");
PyErr_SetString(ErrorObject, "CTB not available");
return 0;
}
if ( (err=InitCTBUtilities()) ) {
@ -110,16 +110,16 @@ ctbcm_pycallback(arg)
void *arg;
{
ctbcmobject *self = (ctbcmobject *)arg;
object *args, *rv;
PyObject *args, *rv;
if ( !self->has_callback ) /* It could have been removed in the meantime */
return 0;
args = mkvalue("(i)", self->err);
rv = call_object(self->callback, args);
DECREF(args);
args = Py_BuildValue("(i)", self->err);
rv = PyEval_CallObject(self->callback, args);
Py_DECREF(args);
if( rv == NULL )
return -1;
DECREF(rv);
Py_DECREF(rv);
return 0;
}
@ -139,15 +139,15 @@ ctbcm_ctbcallback(hconn)
static ctbcmobject *
newctbcmobject(arg)
object *arg;
PyObject *arg;
{
ctbcmobject *self;
self = NEWOBJ(ctbcmobject, &ctbcmtype);
self = PyObject_NEW(ctbcmobject, &ctbcmtype);
if (self == NULL)
return NULL;
self->hdl = NULL;
INCREF(None);
self->callback = None;
Py_INCREF(Py_None);
self->callback = Py_None;
self->has_callback = 0;
return self;
}
@ -164,104 +164,104 @@ ctbcm_dealloc(self)
CMDispose(self->hdl);
self->hdl = NULL;
}
DEL(self);
PyMem_DEL(self);
}
static object *
static PyObject *
ctbcm_open(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
long timeout;
OSErr err;
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
if (!getargs(args, "l", &timeout))
if (!PyArg_Parse(args, "l", &timeout))
return NULL;
if ( (err=CMOpen(self->hdl, self->has_callback, cb_upp, timeout)) < 0)
return PyErr_Mac(ErrorObject, (int)err);
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
ctbcm_listen(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
long timeout;
OSErr err;
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
if (!getargs(args, "l", &timeout))
if (!PyArg_Parse(args, "l", &timeout))
return NULL;
if ( (err=CMListen(self->hdl,self->has_callback, cb_upp, timeout)) < 0)
return PyErr_Mac(ErrorObject, (int)err);
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
ctbcm_accept(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
int accept;
OSErr err;
if (!getargs(args, "i", &accept))
if (!PyArg_Parse(args, "i", &accept))
return NULL;
if ( (err=CMAccept(self->hdl, accept)) < 0)
return PyErr_Mac(ErrorObject, (int)err);
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
ctbcm_close(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
int now;
long timeout;
OSErr err;
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
if (!getargs(args, "(li)", &timeout, &now))
if (!PyArg_Parse(args, "(li)", &timeout, &now))
return NULL;
if ( (err=CMClose(self->hdl, self->has_callback, cb_upp, timeout, now)) < 0)
return PyErr_Mac(ErrorObject, (int)err);
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
ctbcm_read(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
long timeout, len;
int chan;
CMFlags flags;
OSErr err;
object *rv;
PyObject *rv;
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
if (!getargs(args, "(lil)", &len, &chan, &timeout))
if (!PyArg_Parse(args, "(lil)", &len, &chan, &timeout))
return NULL;
if ((rv=newsizedstringobject(NULL, len)) == NULL)
if ((rv=PyString_FromStringAndSize(NULL, len)) == NULL)
return NULL;
if ((err=CMRead(self->hdl, (Ptr)getstringvalue(rv), &len, (CMChannel)chan,
if ((err=CMRead(self->hdl, (Ptr)PyString_AsString(rv), &len, (CMChannel)chan,
self->has_callback, cb_upp, timeout, &flags)) < 0)
return PyErr_Mac(ErrorObject, (int)err);
resizestring(&rv, len);
return mkvalue("(Oi)", rv, (int)flags);
_PyString_Resize(&rv, len);
return Py_BuildValue("(Oi)", rv, (int)flags);
}
static object *
static PyObject *
ctbcm_write(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
long timeout, len;
int chan, ilen, flags;
@ -269,184 +269,184 @@ ctbcm_write(self, args)
char *buf;
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
if (!getargs(args, "(s#ili)", &buf, &ilen, &chan, &timeout, &flags))
if (!PyArg_Parse(args, "(s#ili)", &buf, &ilen, &chan, &timeout, &flags))
return NULL;
len = ilen;
if ((err=CMWrite(self->hdl, (Ptr)buf, &len, (CMChannel)chan,
self->has_callback, cb_upp, timeout, (CMFlags)flags)) < 0)
return PyErr_Mac(ErrorObject, (int)err);
return newintobject((int)len);
return PyInt_FromLong((int)len);
}
static object *
static PyObject *
ctbcm_status(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
CMBufferSizes sizes;
CMStatFlags flags;
OSErr err;
object *rv;
PyObject *rv;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if ((err=CMStatus(self->hdl, sizes, &flags)) < 0)
return PyErr_Mac(ErrorObject, (int)err);
rv = mkvalue("(llllll)", sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5]);
rv = Py_BuildValue("(llllll)", sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5]);
if ( rv == NULL )
return NULL;
return mkvalue("(Ol)", rv, (long)flags);
return Py_BuildValue("(Ol)", rv, (long)flags);
}
static object *
static PyObject *
ctbcm_getconfig(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
char *rv;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if ((rv=(char *)CMGetConfig(self->hdl)) == NULL ) {
err_setstr(ErrorObject, "CMGetConfig failed");
PyErr_SetString(ErrorObject, "CMGetConfig failed");
return NULL;
}
return newstringobject(rv);
return PyString_FromString(rv);
}
static object *
static PyObject *
ctbcm_setconfig(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
char *cfg;
OSErr err;
if (!getargs(args, "s", &cfg))
if (!PyArg_Parse(args, "s", &cfg))
return NULL;
if ((err=CMSetConfig(self->hdl, (Ptr)cfg)) < 0)
return PyErr_Mac(ErrorObject, err);
return newintobject((int)err);
return PyInt_FromLong((int)err);
}
static object *
static PyObject *
ctbcm_choose(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
int rv;
Point pt;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
pt.v = 40;
pt.h = 40;
rv=CMChoose(&self->hdl, pt, (ConnectionChooseIdleUPP)0);
return newintobject(rv);
return PyInt_FromLong(rv);
}
static object *
static PyObject *
ctbcm_idle(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
CMIdle(self->hdl);
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
ctbcm_abort(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
CMAbort(self->hdl);
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
ctbcm_reset(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
CMReset(self->hdl);
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
ctbcm_break(self, args)
ctbcmobject *self;
object *args;
PyObject *args;
{
long duration;
ConnectionCompletionUPP cb_upp = NewConnectionCompletionProc(ctbcm_ctbcallback);
if (!getargs(args, "l", &duration))
if (!PyArg_Parse(args, "l", &duration))
return NULL;
CMBreak(self->hdl, duration,self->has_callback, cb_upp);
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static struct methodlist ctbcm_methods[] = {
{"Open", (method)ctbcm_open},
{"Close", (method)ctbcm_close},
{"Read", (method)ctbcm_read},
{"Write", (method)ctbcm_write},
{"Status", (method)ctbcm_status},
{"GetConfig", (method)ctbcm_getconfig},
{"SetConfig", (method)ctbcm_setconfig},
{"Choose", (method)ctbcm_choose},
{"Idle", (method)ctbcm_idle},
{"Listen", (method)ctbcm_listen},
{"Accept", (method)ctbcm_accept},
{"Abort", (method)ctbcm_abort},
{"Reset", (method)ctbcm_reset},
{"Break", (method)ctbcm_break},
static struct PyMethodDef ctbcm_methods[] = {
{"Open", (PyCFunction)ctbcm_open},
{"Close", (PyCFunction)ctbcm_close},
{"Read", (PyCFunction)ctbcm_read},
{"Write", (PyCFunction)ctbcm_write},
{"Status", (PyCFunction)ctbcm_status},
{"GetConfig", (PyCFunction)ctbcm_getconfig},
{"SetConfig", (PyCFunction)ctbcm_setconfig},
{"Choose", (PyCFunction)ctbcm_choose},
{"Idle", (PyCFunction)ctbcm_idle},
{"Listen", (PyCFunction)ctbcm_listen},
{"Accept", (PyCFunction)ctbcm_accept},
{"Abort", (PyCFunction)ctbcm_abort},
{"Reset", (PyCFunction)ctbcm_reset},
{"Break", (PyCFunction)ctbcm_break},
{NULL, NULL} /* sentinel */
};
static object *
static PyObject *
ctbcm_getattr(self, name)
ctbcmobject *self;
char *name;
{
if ( strcmp(name, "callback") == 0 ) {
INCREF(self->callback);
Py_INCREF(self->callback);
return self->callback;
}
return findmethod(ctbcm_methods, (object *)self, name);
return Py_FindMethod(ctbcm_methods, (PyObject *)self, name);
}
static int
ctbcm_setattr(self, name, v)
ctbcmobject *self;
char *name;
object *v;
PyObject *v;
{
if ( strcmp(name, "callback") != 0 ) {
err_setstr(AttributeError, "ctbcm objects have callback attr only");
PyErr_SetString(PyExc_AttributeError, "ctbcm objects have callback attr only");
return -1;
}
if ( v == NULL ) {
v = None;
v = Py_None;
}
INCREF(v); /* XXXX Must I do this? */
Py_INCREF(v); /* XXXX Must I do this? */
self->callback = v;
self->has_callback = (v != None);
self->has_callback = (v != Py_None);
return 0;
}
statichere typeobject ctbcmtype = {
OB_HEAD_INIT(&Typetype)
statichere PyTypeObject ctbcmtype = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"ctbcm", /*tp_name*/
sizeof(ctbcmobject), /*tp_basicsize*/
@ -467,13 +467,13 @@ statichere typeobject ctbcmtype = {
/* Function of no arguments returning new ctbcm object */
static object *
static PyObject *
ctb_cmnew(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
int strlen;
object *sizes_obj;
PyObject *sizes_obj;
char *c_str;
unsigned char p_str[255];
CMBufferSizes sizes;
@ -481,16 +481,16 @@ ctb_cmnew(self, args)
ConnHandle hdl;
ctbcmobject *rv;
if (!getargs(args, "(s#O)", &c_str, &strlen, &sizes_obj))
if (!PyArg_Parse(args, "(s#O)", &c_str, &strlen, &sizes_obj))
return NULL;
strncpy((char *)p_str+1, c_str, strlen);
p_str[0] = strlen;
if (!initialize_ctb())
return NULL;
if ( sizes_obj == None ) {
if ( sizes_obj == Py_None ) {
memset(sizes, '\0', sizeof sizes);
} else {
if ( !getargs(sizes_obj, "(llllll)", &sizes[0], &sizes[1], &sizes[2],
if ( !PyArg_Parse(sizes_obj, "(llllll)", &sizes[0], &sizes[1], &sizes[2],
&sizes[3], &sizes[4], &sizes[5]))
return NULL;
}
@ -498,7 +498,7 @@ ctb_cmnew(self, args)
return PyErr_Mac(ErrorObject, procid);
hdl = CMNew(procid, cmNoMenus|cmQuiet, sizes, 0, 0);
if ( hdl == NULL ) {
err_setstr(ErrorObject, "CMNew failed");
PyErr_SetString(ErrorObject, "CMNew failed");
return NULL;
}
rv = newctbcmobject(args);
@ -506,26 +506,26 @@ ctb_cmnew(self, args)
return NULL; /* XXXX Should dispose of hdl */
rv->hdl = hdl;
CMSetUserData(hdl, (long)rv);
return (object *)rv;
return (PyObject *)rv;
}
static object *
static PyObject *
ctb_available(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
int ok;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
ok = initialize_ctb();
err_clear();
return newintobject(ok);
PyErr_Clear();
return PyInt_FromLong(ok);
}
/* List of functions defined in the module */
static struct methodlist ctb_methods[] = {
static struct PyMethodDef ctb_methods[] = {
{"CMNew", ctb_cmnew},
{"available", ctb_available},
{NULL, NULL} /* sentinel */
@ -537,15 +537,15 @@ static struct methodlist ctb_methods[] = {
void
initctb()
{
object *m, *d, *o;
PyObject *m, *d, *o;
/* Create the module and add the functions */
m = initmodule("ctb", ctb_methods);
m = Py_InitModule("ctb", ctb_methods);
/* Add some symbolic constants to the module */
d = getmoduledict(m);
d = PyModule_GetDict(m);
#define CMCONST(name, value) o = newintobject(value); dictinsert(d, name, o)
#define CMCONST(name, value) o = PyInt_FromLong(value); PyDict_SetItemString(d, name, o)
CMCONST("cmData", 1);
CMCONST("cmCntl", 2);
@ -576,10 +576,10 @@ initctb()
CMCONST("cmStatusListenPend", 0x2000);
CMCONST("cmStatusIncomingCallPresent", 0x4000);
ErrorObject = newstringobject("ctb.error");
dictinsert(d, "error", ErrorObject);
ErrorObject = PyString_FromString("ctb.error");
PyDict_SetItemString(d, "error", ErrorObject);
/* Check for errors */
if (err_occurred())
fatal("can't initialize module ctb");
if (PyErr_Occurred())
Py_FatalError("can't initialize module ctb");
}

View File

@ -24,26 +24,25 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Macintosh Gestalt interface */
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include <Types.h>
#include <GestaltEqu.h>
static object *
static PyObject *
gestalt_gestalt(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
OSErr iErr;
char *str;
int size;
OSType selector;
long response;
if (!getargs(args, "s#", &str, &size))
if (!PyArg_Parse(args, "s#", &str, &size))
return NULL;
if (size != 4) {
err_setstr(TypeError, "gestalt arg must be 4-char string");
PyErr_SetString(PyExc_TypeError, "gestalt arg must be 4-char string");
return NULL;
}
selector = *(OSType*)str;
@ -51,13 +50,13 @@ gestalt_gestalt(self, args)
if (iErr != 0) {
char buf[100];
sprintf(buf, "Gestalt error code %d", iErr);
err_setstr(RuntimeError, buf);
PyErr_SetString(PyExc_RuntimeError, buf);
return NULL;
}
return newintobject(response);
return PyInt_FromLong(response);
}
static struct methodlist gestalt_methods[] = {
static struct PyMethodDef gestalt_methods[] = {
{"gestalt", gestalt_gestalt},
{NULL, NULL} /* Sentinel */
};
@ -65,5 +64,5 @@ static struct methodlist gestalt_methods[] = {
void
initgestalt()
{
initmodule("gestalt", gestalt_methods);
Py_InitModule("gestalt", gestalt_methods);
}

View File

@ -22,8 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
#include "allobjects.h"
#include "modsupport.h" /* For getargs() etc. */
#include "Python.h"
#include "macglue.h"
#include <Memory.h>
@ -39,17 +38,17 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define FileFilterUPP FileFilterProcPtr
#endif
static object *ErrorObject;
static PyObject *ErrorObject;
/* ----------------------------------------------------- */
/* Declarations for objects of type Alias */
typedef struct {
OB_HEAD
PyObject_HEAD
AliasHandle alias;
} mfsaobject;
staticforward typeobject Mfsatype;
staticforward PyTypeObject Mfsatype;
#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype)
@ -57,11 +56,11 @@ staticforward typeobject Mfsatype;
/* Declarations for objects of type FSSpec */
typedef struct {
OB_HEAD
PyObject_HEAD
FSSpec fsspec;
} mfssobject;
staticforward typeobject Mfsstype;
staticforward PyTypeObject Mfsstype;
#define is_mfssobject(v) ((v)->ob_type == &Mfsstype)
@ -70,11 +69,11 @@ staticforward typeobject Mfsstype;
/* Declarations for objects of type FInfo */
typedef struct {
OB_HEAD
PyObject_HEAD
FInfo finfo;
} mfsiobject;
staticforward typeobject Mfsitype;
staticforward PyTypeObject Mfsitype;
#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype)
@ -83,17 +82,17 @@ mfssobject *newmfssobject(FSSpec *fss); /* Forward */
/* ---------------------------------------------------------------- */
static object *
static PyObject *
mfsa_Resolve(self, args)
mfsaobject *self;
object *args;
PyObject *args;
{
FSSpec from, *fromp, result;
Boolean changed;
OSErr err;
from.name[0] = 0;
if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &from))
if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from))
return NULL;
if (from.name[0] )
fromp = &from;
@ -104,39 +103,39 @@ mfsa_Resolve(self, args)
PyErr_Mac(ErrorObject, err);
return NULL;
}
return mkvalue("(Oi)", newmfssobject(&result), (int)changed);
return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed);
}
static object *
static PyObject *
mfsa_GetInfo(self, args)
mfsaobject *self;
object *args;
PyObject *args;
{
Str63 value;
int i;
OSErr err;
if (!newgetargs(args, "i", &i))
if (!PyArg_ParseTuple(args, "i", &i))
return NULL;
err = GetAliasInfo(self->alias, (AliasInfoType)i, value);
if ( err ) {
PyErr_Mac(ErrorObject, err);
return 0;
}
return newsizedstringobject((char *)&value[1], value[0]);
return PyString_FromStringAndSize((char *)&value[1], value[0]);
}
static object *
static PyObject *
mfsa_Update(self, args)
mfsaobject *self;
object *args;
PyObject *args;
{
FSSpec target, fromfile, *fromfilep;
OSErr err;
Boolean changed;
fromfile.name[0] = 0;
if (!newgetargs(args, "O&|O&", PyMac_GetFSSpec, &target,
if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target,
PyMac_GetFSSpec, &fromfile))
return NULL;
if ( fromfile.name[0] )
@ -148,20 +147,20 @@ mfsa_Update(self, args)
PyErr_Mac(ErrorObject, err);
return 0;
}
return mkvalue("i", (int)changed);
return Py_BuildValue("i", (int)changed);
}
static struct methodlist mfsa_methods[] = {
{"Resolve", (method)mfsa_Resolve, 1},
{"GetInfo", (method)mfsa_GetInfo, 1},
{"Update", (method)mfsa_Update, 1},
static struct PyMethodDef mfsa_methods[] = {
{"Resolve", (PyCFunction)mfsa_Resolve, 1},
{"GetInfo", (PyCFunction)mfsa_GetInfo, 1},
{"Update", (PyCFunction)mfsa_Update, 1},
{NULL, NULL} /* sentinel */
};
/* ---------- */
static object *
static PyObject *
mfsa_getattr(self, name)
mfsaobject *self;
char *name;
@ -176,7 +175,7 @@ mfsa_getattr(self, name)
HUnlock((Handle)self->alias);
return rv;
}
return findmethod(mfsa_methods, (object *)self, name);
return Py_FindMethod(mfsa_methods, (PyObject *)self, name);
}
mfsaobject *
@ -185,7 +184,7 @@ newmfsaobject(alias)
{
mfsaobject *self;
self = NEWOBJ(mfsaobject, &Mfsatype);
self = PyObject_NEW(mfsaobject, &Mfsatype);
if (self == NULL)
return NULL;
self->alias = alias;
@ -203,11 +202,11 @@ mfsa_dealloc(self)
}
#endif
DEL(self);
PyMem_DEL(self);
}
statichere typeobject Mfsatype = {
OB_HEAD_INIT(&Typetype)
statichere PyTypeObject Mfsatype = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"Alias", /*tp_name*/
sizeof(mfsaobject), /*tp_basicsize*/
@ -230,7 +229,7 @@ statichere typeobject Mfsatype = {
/* ---------------------------------------------------------------- */
static struct methodlist mfsi_methods[] = {
static struct PyMethodDef mfsi_methods[] = {
{NULL, NULL} /* sentinel */
};
@ -242,7 +241,7 @@ newmfsiobject()
{
mfsiobject *self;
self = NEWOBJ(mfsiobject, &Mfsitype);
self = PyObject_NEW(mfsiobject, &Mfsitype);
if (self == NULL)
return NULL;
memset((char *)&self->finfo, '\0', sizeof(self->finfo));
@ -253,10 +252,10 @@ static void
mfsi_dealloc(self)
mfsiobject *self;
{
DEL(self);
PyMem_DEL(self);
}
static object *
static PyObject *
mfsi_getattr(self, name)
mfsiobject *self;
char *name;
@ -272,7 +271,7 @@ mfsi_getattr(self, name)
else if ( strcmp(name, "Fldr") == 0 )
return Py_BuildValue("i", (int)self->finfo.fdFldr);
else
return findmethod(mfsi_methods, (object *)self, name);
return Py_FindMethod(mfsi_methods, (PyObject *)self, name);
}
@ -280,13 +279,13 @@ static int
mfsi_setattr(self, name, v)
mfsiobject *self;
char *name;
object *v;
PyObject *v;
{
int rv;
int i;
if ( v == NULL ) {
err_setstr(AttributeError, "Cannot delete attribute");
PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
return -1;
}
if ( strcmp(name, "Type") == 0 )
@ -302,7 +301,7 @@ mfsi_setattr(self, name, v)
rv = PyArg_Parse(v, "i", &i);
self->finfo.fdFldr = (short)i;
} else {
err_setstr(AttributeError, "No such attribute");
PyErr_SetString(PyExc_AttributeError, "No such attribute");
return -1;
}
if (rv)
@ -311,8 +310,8 @@ mfsi_setattr(self, name, v)
}
static typeobject Mfsitype = {
OB_HEAD_INIT(&Typetype)
static PyTypeObject Mfsitype = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"FInfo object", /*tp_name*/
sizeof(mfsiobject), /*tp_basicsize*/
@ -340,7 +339,7 @@ static typeobject Mfsitype = {
*/
FSSpec *
mfs_GetFSSpecFSSpec(self)
object *self;
PyObject *self;
{
if ( is_mfssobject(self) )
return &((mfssobject *)self)->fsspec;
@ -395,46 +394,46 @@ PyMac_SetFileDates(fss, crdat, mddat, bkdat)
return error;
}
static object *
static PyObject *
mfss_as_pathname(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
char strbuf[257];
OSErr err;
if (!newgetargs(args, ""))
if (!PyArg_ParseTuple(args, ""))
return NULL;
err = PyMac_GetFullPath(&self->fsspec, strbuf);
if ( err ) {
PyErr_Mac(ErrorObject, err);
return NULL;
}
return newstringobject(strbuf);
return PyString_FromString(strbuf);
}
static object *
static PyObject *
mfss_as_tuple(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
if (!newgetargs(args, ""))
if (!PyArg_ParseTuple(args, ""))
return NULL;
return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID,
&self->fsspec.name[1], self->fsspec.name[0]);
}
static object *
static PyObject *
mfss_NewAlias(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
FSSpec src, *srcp;
OSErr err;
AliasHandle alias;
src.name[0] = 0;
if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &src))
if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src))
return NULL;
if ( src.name[0] )
srcp = &src;
@ -446,37 +445,37 @@ mfss_NewAlias(self, args)
return NULL;
}
return (object *)newmfsaobject(alias);
return (PyObject *)newmfsaobject(alias);
}
static object *
static PyObject *
mfss_NewAliasMinimal(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
OSErr err;
AliasHandle alias;
if (!newgetargs(args, ""))
if (!PyArg_ParseTuple(args, ""))
return NULL;
err = NewAliasMinimal(&self->fsspec, &alias);
if ( err ) {
PyErr_Mac(ErrorObject, err);
return NULL;
}
return (object *)newmfsaobject(alias);
return (PyObject *)newmfsaobject(alias);
}
/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
static object *
static PyObject *
mfss_GetCreatorType(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
OSErr err;
FInfo info;
if (!newgetargs(args, ""))
if (!PyArg_ParseTuple(args, ""))
return NULL;
err = FSpGetFInfo(&self->fsspec, &info);
if ( err ) {
@ -487,16 +486,16 @@ mfss_GetCreatorType(self, args)
PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType);
}
static object *
static PyObject *
mfss_SetCreatorType(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
OSErr err;
OSType creator, type;
FInfo info;
if (!newgetargs(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
return NULL;
err = FSpGetFInfo(&self->fsspec, &info);
if ( err ) {
@ -510,78 +509,78 @@ mfss_SetCreatorType(self, args)
PyErr_Mac(ErrorObject, err);
return NULL;
}
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
mfss_GetFInfo(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
OSErr err;
mfsiobject *fip;
if (!newgetargs(args, ""))
if (!PyArg_ParseTuple(args, ""))
return NULL;
if ( (fip=newmfsiobject()) == NULL )
return NULL;
err = FSpGetFInfo(&self->fsspec, &fip->finfo);
if ( err ) {
PyErr_Mac(ErrorObject, err);
DECREF(fip);
Py_DECREF(fip);
return NULL;
}
return (object *)fip;
return (PyObject *)fip;
}
static object *
static PyObject *
mfss_SetFInfo(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
OSErr err;
mfsiobject *fip;
if (!newgetargs(args, "O!", &Mfsitype, &fip))
if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip))
return NULL;
err = FSpSetFInfo(&self->fsspec, &fip->finfo);
if ( err ) {
PyErr_Mac(ErrorObject, err);
return NULL;
}
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
mfss_GetDates(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
OSErr err;
unsigned long crdat, mddat, bkdat;
if (!newgetargs(args, ""))
if (!PyArg_ParseTuple(args, ""))
return NULL;
err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat);
if ( err ) {
PyErr_Mac(ErrorObject, err);
return NULL;
}
return mkvalue("ddd", (double)crdat, (double)mddat, (double)bkdat);
return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat);
}
static object *
static PyObject *
mfss_SetDates(self, args)
mfssobject *self;
object *args;
PyObject *args;
{
OSErr err;
double crdat, mddat, bkdat;
if (!newgetargs(args, "ddd", &crdat, &mddat, &bkdat))
if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat))
return NULL;
err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat,
(unsigned long)mddat, (unsigned long)bkdat);
@ -589,35 +588,35 @@ mfss_SetDates(self, args)
PyErr_Mac(ErrorObject, err);
return NULL;
}
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static struct methodlist mfss_methods[] = {
{"as_pathname", (method)mfss_as_pathname, 1},
{"as_tuple", (method)mfss_as_tuple, 1},
{"NewAlias", (method)mfss_NewAlias, 1},
{"NewAliasMinimal", (method)mfss_NewAliasMinimal, 1},
{"GetCreatorType", (method)mfss_GetCreatorType, 1},
{"SetCreatorType", (method)mfss_SetCreatorType, 1},
{"GetFInfo", (method)mfss_GetFInfo, 1},
{"SetFInfo", (method)mfss_SetFInfo, 1},
{"GetDates", (method)mfss_GetDates, 1},
{"SetDates", (method)mfss_SetDates, 1},
static struct PyMethodDef mfss_methods[] = {
{"as_pathname", (PyCFunction)mfss_as_pathname, 1},
{"as_tuple", (PyCFunction)mfss_as_tuple, 1},
{"NewAlias", (PyCFunction)mfss_NewAlias, 1},
{"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1},
{"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1},
{"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1},
{"GetFInfo", (PyCFunction)mfss_GetFInfo, 1},
{"SetFInfo", (PyCFunction)mfss_SetFInfo, 1},
{"GetDates", (PyCFunction)mfss_GetDates, 1},
{"SetDates", (PyCFunction)mfss_SetDates, 1},
{NULL, NULL} /* sentinel */
};
/* ---------- */
static object *
static PyObject *
mfss_getattr(self, name)
mfssobject *self;
char *name;
{
if ( strcmp(name, "data") == 0)
return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec));
return findmethod(mfss_methods, (object *)self, name);
return Py_FindMethod(mfss_methods, (PyObject *)self, name);
}
mfssobject *
@ -626,7 +625,7 @@ newmfssobject(fss)
{
mfssobject *self;
self = NEWOBJ(mfssobject, &Mfsstype);
self = PyObject_NEW(mfssobject, &Mfsstype);
if (self == NULL)
return NULL;
self->fsspec = *fss;
@ -637,10 +636,10 @@ static void
mfss_dealloc(self)
mfssobject *self;
{
DEL(self);
PyMem_DEL(self);
}
static object *
static PyObject *
mfss_repr(self)
mfssobject *self;
{
@ -650,7 +649,7 @@ mfss_repr(self)
self->fsspec.vRefNum,
self->fsspec.parID,
self->fsspec.name[0], self->fsspec.name+1);
return newstringobject(buf);
return PyString_FromString(buf);
}
static int
@ -673,8 +672,8 @@ mfss_compare(v, w)
return res;
}
statichere typeobject Mfsstype = {
OB_HEAD_INIT(&Typetype)
statichere PyTypeObject Mfsstype = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"FSSpec", /*tp_name*/
sizeof(mfssobject), /*tp_basicsize*/
@ -695,29 +694,29 @@ statichere typeobject Mfsstype = {
/* End of code for FSSpec objects */
/* -------------------------------------------------------- */
static object *
static PyObject *
mfs_ResolveAliasFile(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
FSSpec fss;
Boolean chain = 1, isfolder, wasaliased;
OSErr err;
if (!newgetargs(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain))
return NULL;
err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased);
if ( err ) {
PyErr_Mac(ErrorObject, err);
return NULL;
}
return mkvalue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased);
}
static object *
static PyObject *
mfs_StandardGetFile(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
SFTypeList list;
short numtypes;
@ -725,7 +724,7 @@ mfs_StandardGetFile(self, args)
list[0] = list[1] = list[2] = list[3] = 0;
numtypes = 0;
if (!newgetargs(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0],
PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
PyMac_GetOSType, &list[3]) )
return NULL;
@ -735,13 +734,13 @@ mfs_StandardGetFile(self, args)
if ( numtypes == 0 )
numtypes = -1;
StandardGetFile((FileFilterUPP)0, numtypes, list, &reply);
return mkvalue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
}
static object *
static PyObject *
mfs_PromptGetFile(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
SFTypeList list;
short numtypes;
@ -750,7 +749,7 @@ mfs_PromptGetFile(self, args)
list[0] = list[1] = list[2] = list[3] = 0;
numtypes = 0;
if (!newgetargs(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0],
PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2],
PyMac_GetOSType, &list[3]) )
return NULL;
@ -760,30 +759,30 @@ mfs_PromptGetFile(self, args)
if ( numtypes == 0 )
numtypes = -1;
PyMac_PromptGetFile(numtypes, list, &reply, prompt);
return mkvalue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood);
}
static object *
static PyObject *
mfs_StandardPutFile(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
Str255 prompt, dft;
StandardFileReply reply;
dft[0] = 0;
if (!newgetargs(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) )
return NULL;
StandardPutFile(prompt, dft, &reply);
return mkvalue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood);
}
/*
** Set initial directory for file dialogs */
static object *
static PyObject *
mfs_SetFolder(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
FSSpec spec;
FSSpec ospec;
@ -797,53 +796,53 @@ mfs_SetFolder(self, args)
/* Go to working directory by default */
(void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec);
if (!newgetargs(args, "|O&", PyMac_GetFSSpec, &spec))
if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec))
return NULL;
/* Set standard-file working directory */
LMSetSFSaveDisk(-spec.vRefNum);
LMSetCurDirStore(spec.parID);
return (object *)newmfssobject(&ospec);
return (PyObject *)newmfssobject(&ospec);
}
static object *
static PyObject *
mfs_FSSpec(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
FSSpec fss;
if (!newgetargs(args, "O&", PyMac_GetFSSpec, &fss))
if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
return NULL;
return (object *)newmfssobject(&fss);
return (PyObject *)newmfssobject(&fss);
}
static object *
static PyObject *
mfs_RawFSSpec(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
FSSpec *fssp;
int size;
if (!newgetargs(args, "s#", &fssp, &size))
if (!PyArg_ParseTuple(args, "s#", &fssp, &size))
return NULL;
if ( size != sizeof(FSSpec) ) {
PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record");
return NULL;
}
return (object *)newmfssobject(fssp);
return (PyObject *)newmfssobject(fssp);
}
static object *
static PyObject *
mfs_RawAlias(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
char *dataptr;
Handle h;
int size;
if (!newgetargs(args, "s#", &dataptr, &size))
if (!PyArg_ParseTuple(args, "s#", &dataptr, &size))
return NULL;
h = NewHandle(size);
if ( h == NULL ) {
@ -853,29 +852,29 @@ mfs_RawAlias(self, args)
HLock(h);
memcpy((char *)*h, dataptr, size);
HUnlock(h);
return (object *)newmfsaobject((AliasHandle)h);
return (PyObject *)newmfsaobject((AliasHandle)h);
}
static object *
static PyObject *
mfs_GetDirectory(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
FSSpec fsdir;
int ok;
char *prompt = NULL;
if (!newgetargs(args, "|s", &prompt) )
if (!PyArg_ParseTuple(args, "|s", &prompt) )
return NULL;
ok = PyMac_GetDirectory(&fsdir, prompt);
return mkvalue("(Oi)", newmfssobject(&fsdir), ok);
return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok);
}
static object *
static PyObject *
mfs_FindFolder(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
OSErr err;
short where;
@ -884,46 +883,46 @@ mfs_FindFolder(self, args)
short refnum;
long dirid;
if (!newgetargs(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) )
return NULL;
err = FindFolder(where, which, (Boolean)create, &refnum, &dirid);
if ( err ) {
PyErr_Mac(ErrorObject, err);
return NULL;
}
return mkvalue("(ii)", refnum, dirid);
return Py_BuildValue("(ii)", refnum, dirid);
}
static object *
static PyObject *
mfs_FindApplication(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
OSErr err;
OSType which;
FSSpec fss;
if (!newgetargs(args, "O&", PyMac_GetOSType, &which) )
if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) )
return NULL;
err = FindApplicationFromCreator(which, &fss);
if ( err ) {
PyErr_Mac(ErrorObject, err);
return NULL;
}
return (object *)newmfssobject(&fss);
return (PyObject *)newmfssobject(&fss);
}
static object *
static PyObject *
mfs_FInfo(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
return (object *)newmfsiobject();
return (PyObject *)newmfsiobject();
}
/* List of methods defined in the module */
static struct methodlist mfs_methods[] = {
static struct PyMethodDef mfs_methods[] = {
{"ResolveAliasFile", mfs_ResolveAliasFile, 1},
{"StandardGetFile", mfs_StandardGetFile, 1},
{"PromptGetFile", mfs_PromptGetFile, 1},
@ -946,19 +945,19 @@ static struct methodlist mfs_methods[] = {
void
initmacfs()
{
object *m, *d;
PyObject *m, *d;
/* Create the module and add the functions */
m = initmodule("macfs", mfs_methods);
m = Py_InitModule("macfs", mfs_methods);
/* Add some symbolic constants to the module */
d = getmoduledict(m);
ErrorObject = newstringobject("macfs.error");
dictinsert(d, "error", ErrorObject);
d = PyModule_GetDict(m);
ErrorObject = PyString_FromString("macfs.error");
PyDict_SetItemString(d, "error", ErrorObject);
/* XXXX Add constants here */
/* Check for errors */
if (err_occurred())
fatal("can't initialize module macfs");
if (PyErr_Occurred())
Py_FatalError("can't initialize module macfs");
}

View File

@ -24,8 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Mac module implementation */
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include "ceval.h"
#include <stdio.h>
@ -89,100 +88,100 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef USE_GUSI
int chdir PROTO((const char *path));
int mkdir PROTO((const char *path, int mode));
DIR * opendir PROTO((char *));
void closedir PROTO((DIR *));
struct dirent * readdir PROTO((DIR *));
int rmdir PROTO((const char *path));
int sync PROTO((void));
int chdir Py_PROTO((const char *path));
int mkdir Py_PROTO((const char *path, int mode));
DIR * opendir Py_PROTO((char *));
void closedir Py_PROTO((DIR *));
struct dirent * readdir Py_PROTO((DIR *));
int rmdir Py_PROTO((const char *path));
int sync Py_PROTO((void));
#if defined(THINK_C) || defined(__SC__)
int unlink PROTO((char *));
int unlink Py_PROTO((char *));
#else
int unlink PROTO((const char *));
int unlink Py_PROTO((const char *));
#endif
#endif /* USE_GUSI */
char *getwd PROTO((char *));
char *getbootvol PROTO((void));
char *getwd Py_PROTO((char *));
char *getbootvol Py_PROTO((void));
static object *MacError; /* Exception mac.error */
static PyObject *MacError; /* Exception mac.error */
/* Set a MAC-specific error from errno, and return NULL */
static object *
static PyObject *
mac_error()
{
return err_errno(MacError);
return PyErr_SetFromErrno(MacError);
}
/* MAC generic methods */
static object *
static PyObject *
mac_1str(args, func)
object *args;
int (*func) FPROTO((const char *));
PyObject *args;
int (*func) Py_FPROTO((const char *));
{
char *path1;
int res;
if (!getargs(args, "s", &path1))
if (!PyArg_Parse(args, "s", &path1))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = (*func)(path1);
END_SAVE
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
mac_2str(args, func)
object *args;
int (*func) FPROTO((const char *, const char *));
PyObject *args;
int (*func) Py_FPROTO((const char *, const char *));
{
char *path1, *path2;
int res;
if (!getargs(args, "(ss)", &path1, &path2))
if (!PyArg_Parse(args, "(ss)", &path1, &path2))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = (*func)(path1, path2);
END_SAVE
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
mac_strint(args, func)
object *args;
int (*func) FPROTO((const char *, int));
PyObject *args;
int (*func) Py_FPROTO((const char *, int));
{
char *path;
int i;
int res;
if (!getargs(args, "(si)", &path, &i))
if (!PyArg_Parse(args, "(si)", &path, &i))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = (*func)(path, i);
END_SAVE
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
mac_chdir(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
#ifdef USE_GUSI
object *rv;
PyObject *rv;
/* Change MacOS's idea of wd too */
rv = mac_1str(args, chdir);
@ -194,264 +193,264 @@ mac_chdir(self, args)
}
static object *
static PyObject *
mac_close(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
int fd, res;
if (!getargs(args, "i", &fd))
if (!PyArg_Parse(args, "i", &fd))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = close(fd);
END_SAVE
Py_END_ALLOW_THREADS
#ifndef USE_GUSI
/* GUSI gives surious errors here? */
if (res < 0)
return mac_error();
#endif
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
#ifdef WEHAVE_DUP
static object *
static PyObject *
mac_dup(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
int fd;
if (!getargs(args, "i", &fd))
if (!PyArg_Parse(args, "i", &fd))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
fd = dup(fd);
END_SAVE
Py_END_ALLOW_THREADS
if (fd < 0)
return mac_error();
return newintobject((long)fd);
return PyInt_FromLong((long)fd);
}
#endif
#ifdef WEHAVE_FDOPEN
static object *
static PyObject *
mac_fdopen(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
extern int fclose PROTO((FILE *));
extern int fclose Py_PROTO((FILE *));
int fd;
char *mode;
FILE *fp;
if (!getargs(args, "(is)", &fd, &mode))
if (!PyArg_Parse(args, "(is)", &fd, &mode))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
fp = fdopen(fd, mode);
END_SAVE
Py_END_ALLOW_THREADS
if (fp == NULL)
return mac_error();
return newopenfileobject(fp, "(fdopen)", mode, fclose);
return PyFile_FromFile(fp, "(fdopen)", mode, fclose);
}
#endif
static object *
static PyObject *
mac_getbootvol(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
char *res;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = getbootvol();
END_SAVE
Py_END_ALLOW_THREADS
if (res == NULL)
return mac_error();
return newstringobject(res);
return PyString_FromString(res);
}
static object *
static PyObject *
mac_getcwd(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
char path[MAXPATHLEN];
char *res;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
#ifdef USE_GUSI
res = getcwd(path, sizeof path);
#else
res = getwd(path);
#endif
END_SAVE
Py_END_ALLOW_THREADS
if (res == NULL) {
err_setstr(MacError, path);
PyErr_SetString(MacError, path);
return NULL;
}
return newstringobject(res);
return PyString_FromString(res);
}
static object *
static PyObject *
mac_listdir(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
char *name;
object *d, *v;
PyObject *d, *v;
DIR *dirp;
struct dirent *ep;
if (!getargs(args, "s", &name))
if (!PyArg_Parse(args, "s", &name))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
if ((dirp = opendir(name)) == NULL) {
RET_SAVE
Py_BLOCK_THREADS
return mac_error();
}
if ((d = newlistobject(0)) == NULL) {
if ((d = PyList_New(0)) == NULL) {
closedir(dirp);
RET_SAVE
Py_BLOCK_THREADS
return NULL;
}
while ((ep = readdir(dirp)) != NULL) {
v = newstringobject(ep->d_name);
v = PyString_FromString(ep->d_name);
if (v == NULL) {
DECREF(d);
Py_DECREF(d);
d = NULL;
break;
}
if (addlistitem(d, v) != 0) {
DECREF(v);
DECREF(d);
if (PyList_Append(d, v) != 0) {
Py_DECREF(v);
Py_DECREF(d);
d = NULL;
break;
}
DECREF(v);
Py_DECREF(v);
}
closedir(dirp);
END_SAVE
Py_END_ALLOW_THREADS
return d;
}
static object *
static PyObject *
mac_lseek(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
int fd;
int where;
int how;
long res;
if (!getargs(args, "(iii)", &fd, &where, &how))
if (!PyArg_Parse(args, "(iii)", &fd, &where, &how))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = lseek(fd, (long)where, how);
END_SAVE
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
return newintobject(res);
return PyInt_FromLong(res);
}
static object *
static PyObject *
mac_mkdir(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
int res;
char *path;
int mode = 0777; /* Unused */
if (!newgetargs(args, "s|i", &path, &mode))
if (!PyArg_ParseTuple(args, "s|i", &path, &mode))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
#ifdef USE_GUSI
res = mkdir(path);
#else
res = mkdir(path, mode);
#endif
END_SAVE
Py_END_ALLOW_THREADS
if (res < 0)
return mac_error();
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
mac_open(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
char *path;
int mode;
int fd;
if (!getargs(args, "(si)", &path, &mode))
if (!PyArg_Parse(args, "(si)", &path, &mode))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
fd = open(path, mode);
END_SAVE
Py_END_ALLOW_THREADS
if (fd < 0)
return mac_error();
return newintobject((long)fd);
return PyInt_FromLong((long)fd);
}
static object *
static PyObject *
mac_read(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
int fd, size;
object *buffer;
if (!getargs(args, "(ii)", &fd, &size))
PyObject *buffer;
if (!PyArg_Parse(args, "(ii)", &fd, &size))
return NULL;
buffer = newsizedstringobject((char *)NULL, size);
buffer = PyString_FromStringAndSize((char *)NULL, size);
if (buffer == NULL)
return NULL;
BGN_SAVE
size = read(fd, getstringvalue(buffer), size);
END_SAVE
Py_BEGIN_ALLOW_THREADS
size = read(fd, PyString_AsString(buffer), size);
Py_END_ALLOW_THREADS
if (size < 0) {
DECREF(buffer);
Py_DECREF(buffer);
return mac_error();
}
resizestring(&buffer, size);
_PyString_Resize(&buffer, size);
return buffer;
}
static object *
static PyObject *
mac_rename(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
return mac_2str(args, rename);
}
static object *
static PyObject *
mac_rmdir(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
return mac_1str(args, rmdir);
}
static object *
static PyObject *
mac_stat(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
struct stat st;
char *path;
int res;
if (!getargs(args, "s", &path))
if (!PyArg_Parse(args, "s", &path))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = stat(path, &st);
END_SAVE
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
#if 1
return mkvalue("(lllllllddd)",
return Py_BuildValue("(lllllllddd)",
(long)st.st_mode,
(long)st.st_ino,
(long)st.st_dev,
@ -463,7 +462,7 @@ mac_stat(self, args)
(double)st.st_mtime,
(double)st.st_ctime);
#else
return mkvalue("(llllllllll)",
return Py_BuildValue("(llllllllll)",
(long)st.st_mode,
(long)st.st_ino,
(long)st.st_dev,
@ -477,34 +476,34 @@ mac_stat(self, args)
#endif
}
static object *
static PyObject *
mac_xstat(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
struct macstat mst;
struct stat st;
char *path;
int res;
if (!getargs(args, "s", &path))
if (!PyArg_Parse(args, "s", &path))
return NULL;
/*
** Convoluted: we want stat() and xstat() to agree, so we call both
** stat and macstat, and use the latter only for values not provided by
** the former.
*/
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = macstat(path, &mst);
END_SAVE
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = stat(path, &st);
END_SAVE
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
#if 1
return mkvalue("(llllllldddls#s#)",
return Py_BuildValue("(llllllldddls#s#)",
(long)st.st_mode,
(long)st.st_ino,
(long)st.st_dev,
@ -519,7 +518,7 @@ mac_xstat(self, args)
mst.st_creator, 4,
mst.st_type, 4);
#else
return mkvalue("(llllllllllls#s#)",
return Py_BuildValue("(llllllllllls#s#)",
(long)st.st_mode,
(long)st.st_ino,
(long)st.st_dev,
@ -536,61 +535,61 @@ mac_xstat(self, args)
#endif
}
static object *
static PyObject *
mac_sync(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
int res;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res = sync();
END_SAVE
Py_END_ALLOW_THREADS
if (res != 0)
return mac_error();
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
mac_unlink(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
return mac_1str(args, (int (*)(const char *))unlink);
}
static object *
static PyObject *
mac_write(self, args)
object *self;
object *args;
PyObject *self;
PyObject *args;
{
int fd, size;
char *buffer;
if (!getargs(args, "(is#)", &fd, &buffer, &size))
if (!PyArg_Parse(args, "(is#)", &fd, &buffer, &size))
return NULL;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
size = write(fd, buffer, size);
END_SAVE
Py_END_ALLOW_THREADS
if (size < 0)
return mac_error();
return newintobject((long)size);
return PyInt_FromLong((long)size);
}
#ifdef USE_MALLOC_DEBUG
static object *
static PyObject *
mac_mstats(self, args)
object*self;
object *args;
PyObject*self;
PyObject *args;
{
mstats("python");
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
#endif USE_MALLOC_DEBUG
static struct methodlist mac_methods[] = {
static struct PyMethodDef mac_methods[] = {
{"chdir", mac_chdir},
{"close", mac_close},
#ifdef WEHAVE_DUP
@ -625,13 +624,13 @@ static struct methodlist mac_methods[] = {
void
initmac()
{
object *m, *d;
PyObject *m, *d;
m = initmodule("mac", mac_methods);
d = getmoduledict(m);
m = Py_InitModule("mac", mac_methods);
d = PyModule_GetDict(m);
/* Initialize mac.error exception */
MacError = newstringobject("mac.error");
if (MacError == NULL || dictinsert(d, "error", MacError) != 0)
fatal("can't define mac.error");
MacError = PyString_FromString("mac.error");
if (MacError == NULL || PyDict_SetItemString(d, "error", MacError) != 0)
Py_FatalError("can't define mac.error");
}

View File

@ -24,8 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* xx module */
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include <GestaltEqu.h>
#include "Speech.h"
@ -48,7 +47,7 @@ int lib_available;
#define double2fixed(x) ((Fixed)((x)*32768.0))
char *CurrentSpeech;
object *ms_error_object;
PyObject *ms_error_object;
int speech_available;
static
@ -68,12 +67,12 @@ init_available() {
static
check_available() {
if ( !speech_available ) {
err_setstr(ms_error_object, "Speech Mgr not available");
PyErr_SetString(ms_error_object, "Speech Mgr not available");
return 0;
}
#ifdef __powerc
if ( !lib_available ) {
err_setstr(ms_error_object, "Speech Mgr available, but shared lib missing");
PyErr_SetString(ms_error_object, "Speech Mgr available, but shared lib missing");
return 0;
}
#endif
@ -85,12 +84,12 @@ check_available() {
** Part one - the speech channel object
*/
typedef struct {
OB_HEAD
PyObject_HEAD
SpeechChannel chan;
object *curtext; /* If non-NULL current text being spoken */
PyObject *curtext; /* If non-NULL current text being spoken */
} scobject;
staticforward typeobject sctype;
staticforward PyTypeObject sctype;
#define is_scobject(v) ((v)->ob_type == &sctype)
@ -101,11 +100,11 @@ newscobject(arg)
scobject *self;
OSErr err;
self = NEWOBJ(scobject, &sctype);
self = PyObject_NEW(scobject, &sctype);
if (self == NULL)
return NULL;
if ( (err=NewSpeechChannel(arg, &self->chan)) != 0) {
DECREF(self);
Py_DECREF(self);
return (scobject *)PyErr_Mac(ms_error_object, err);
}
self->curtext = NULL;
@ -119,146 +118,146 @@ sc_dealloc(self)
scobject *self;
{
DisposeSpeechChannel(self->chan);
DEL(self);
PyMem_DEL(self);
}
static object *
static PyObject *
sc_Stop(self, args)
scobject *self;
object *args;
PyObject *args;
{
OSErr err;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if ((err=StopSpeech(self->chan)) != 0) {
PyErr_Mac(ms_error_object, err);
return NULL;
}
if ( self->curtext ) {
DECREF(self->curtext);
Py_DECREF(self->curtext);
self->curtext = NULL;
}
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
sc_SpeakText(self, args)
scobject *self;
object *args;
PyObject *args;
{
OSErr err;
char *str;
int len;
if (!getargs(args, "s#", &str, &len))
if (!PyArg_Parse(args, "s#", &str, &len))
return NULL;
if ( self->curtext ) {
StopSpeech(self->chan);
DECREF(self->curtext);
Py_DECREF(self->curtext);
self->curtext = NULL;
}
if ((err=SpeakText(self->chan, (Ptr)str, (long)len)) != 0) {
PyErr_Mac(ms_error_object, err);
return 0;
}
(void)getargs(args, "O", &self->curtext); /* Or should I check this? */
INCREF(self->curtext);
INCREF(None);
return None;
(void)PyArg_Parse(args, "O", &self->curtext); /* Or should I check this? */
Py_INCREF(self->curtext);
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
sc_GetRate(self, args)
scobject *self;
object *args;
PyObject *args;
{
OSErr err;
Fixed farg;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if ((err=GetSpeechRate(self->chan, &farg)) != 0) {
PyErr_Mac(ms_error_object, err);
return 0;
}
return newfloatobject(fixed2double(farg));
return PyFloat_FromDouble(fixed2double(farg));
}
static object *
static PyObject *
sc_GetPitch(self, args)
scobject *self;
object *args;
PyObject *args;
{
OSErr err;
Fixed farg;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if ((err=GetSpeechPitch(self->chan, &farg)) != 0) {
PyErr_Mac(ms_error_object, err);
return 0;
}
return newfloatobject(fixed2double(farg));
return PyFloat_FromDouble(fixed2double(farg));
}
static object *
static PyObject *
sc_SetRate(self, args)
scobject *self;
object *args;
PyObject *args;
{
OSErr err;
double darg;
if (!getargs(args, "d", &darg))
if (!PyArg_Parse(args, "d", &darg))
return NULL;
if ((err=SetSpeechRate(self->chan, double2fixed(darg))) != 0) {
PyErr_Mac(ms_error_object, err);
return 0;
}
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static object *
static PyObject *
sc_SetPitch(self, args)
scobject *self;
object *args;
PyObject *args;
{
OSErr err;
double darg;
if (!getargs(args, "d", &darg))
if (!PyArg_Parse(args, "d", &darg))
return NULL;
if ((err=SetSpeechPitch(self->chan, double2fixed(darg))) != 0) {
PyErr_Mac(ms_error_object, err);
return NULL;
}
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
static struct methodlist sc_methods[] = {
{"Stop", (method)sc_Stop},
{"SetRate", (method)sc_SetRate},
{"GetRate", (method)sc_GetRate},
{"SetPitch", (method)sc_SetPitch},
{"GetPitch", (method)sc_GetPitch},
{"SpeakText", (method)sc_SpeakText},
static struct PyMethodDef sc_methods[] = {
{"Stop", (PyCFunction)sc_Stop},
{"SetRate", (PyCFunction)sc_SetRate},
{"GetRate", (PyCFunction)sc_GetRate},
{"SetPitch", (PyCFunction)sc_SetPitch},
{"GetPitch", (PyCFunction)sc_GetPitch},
{"SpeakText", (PyCFunction)sc_SpeakText},
{NULL, NULL} /* sentinel */
};
static object *
static PyObject *
sc_getattr(self, name)
scobject *self;
char *name;
{
return findmethod(sc_methods, (object *)self, name);
return Py_FindMethod(sc_methods, (PyObject *)self, name);
}
static typeobject sctype = {
OB_HEAD_INIT(&Typetype)
static PyTypeObject sctype = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"MacSpeechChannel", /*tp_name*/
sizeof(scobject), /*tp_basicsize*/
@ -281,13 +280,13 @@ static typeobject sctype = {
** Part two - the voice object
*/
typedef struct {
OB_HEAD
PyObject_HEAD
int initialized;
VoiceSpec vs;
VoiceDescription vd;
} mvobject;
staticforward typeobject mvtype;
staticforward PyTypeObject mvtype;
#define is_mvobject(v) ((v)->ob_type == &mvtype)
@ -295,7 +294,7 @@ static mvobject *
newmvobject()
{
mvobject *self;
self = NEWOBJ(mvobject, &mvtype);
self = PyObject_NEW(mvobject, &mvtype);
if (self == NULL)
return NULL;
self->initialized = 0;
@ -326,56 +325,56 @@ static void
mv_dealloc(self)
mvobject *self;
{
DEL(self);
PyMem_DEL(self);
}
static object *
static PyObject *
mv_getgender(self, args)
mvobject *self;
object *args;
PyObject *args;
{
object *rv;
PyObject *rv;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if (!self->initialized) {
err_setstr(ms_error_object, "Uninitialized voice");
PyErr_SetString(ms_error_object, "Uninitialized voice");
return NULL;
}
rv = newintobject(self->vd.gender);
rv = PyInt_FromLong(self->vd.gender);
return rv;
}
static object *
static PyObject *
mv_newchannel(self, args)
mvobject *self;
object *args;
PyObject *args;
{
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if (!self->initialized) {
err_setstr(ms_error_object, "Uninitialized voice");
PyErr_SetString(ms_error_object, "Uninitialized voice");
return NULL;
}
return (object *)newscobject(&self->vs);
return (PyObject *)newscobject(&self->vs);
}
static struct methodlist mv_methods[] = {
{"GetGender", (method)mv_getgender},
{"NewChannel", (method)mv_newchannel},
static struct PyMethodDef mv_methods[] = {
{"GetGender", (PyCFunction)mv_getgender},
{"NewChannel", (PyCFunction)mv_newchannel},
{NULL, NULL} /* sentinel */
};
static object *
static PyObject *
mv_getattr(self, name)
mvobject *self;
char *name;
{
return findmethod(mv_methods, (object *)self, name);
return Py_FindMethod(mv_methods, (PyObject *)self, name);
}
static typeobject mvtype = {
OB_HEAD_INIT(&Typetype)
static PyTypeObject mvtype = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"MacVoice", /*tp_name*/
sizeof(mvobject), /*tp_basicsize*/
@ -401,46 +400,46 @@ static typeobject mvtype = {
/* See if Speech manager available */
static object *
static PyObject *
ms_Available(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
return newintobject(speech_available);
return PyInt_FromLong(speech_available);
}
/* Count number of busy speeches */
static object *
static PyObject *
ms_Busy(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
short result;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if ( !check_available() )
return NULL;
result = SpeechBusy();
return newintobject(result);
return PyInt_FromLong(result);
}
/* Say something */
static object *
static PyObject *
ms_SpeakString(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
OSErr err;
char *str;
int len;
if (!getstrarg(args, &str))
if (!PyArg_Parse(args, "s", &str))
return NULL;
if ( !check_available())
return NULL;
@ -459,68 +458,68 @@ ms_SpeakString(self, args)
PyErr_Mac(ms_error_object, err);
return NULL;
}
INCREF(None);
return None;
Py_INCREF(Py_None);
return Py_None;
}
/* Count number of available voices */
static object *
static PyObject *
ms_CountVoices(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
short result;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if ( !check_available())
return NULL;
CountVoices(&result);
return newintobject(result);
return PyInt_FromLong(result);
}
static object *
static PyObject *
ms_GetIndVoice(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
mvobject *rv;
long ind;
if( !getargs(args, "i", &ind))
if( !PyArg_Parse(args, "i", &ind))
return NULL;
if ( !check_available() )
return NULL;
rv = newmvobject();
if ( !initmvobject(rv, ind) ) {
DECREF(rv);
Py_DECREF(rv);
return NULL;
}
return (object *)rv;
return (PyObject *)rv;
}
static object *
static PyObject *
ms_Version(self, args)
object *self; /* Not used */
object *args;
PyObject *self; /* Not used */
PyObject *args;
{
NumVersion v;
if (!getnoarg(args))
if (!PyArg_NoArgs(args))
return NULL;
if ( !check_available())
return NULL;
v = SpeechManagerVersion();
return newintobject(*(int *)&v);
return PyInt_FromLong(*(int *)&v);
}
/* List of functions defined in the module */
static struct methodlist ms_methods[] = {
static struct PyMethodDef ms_methods[] = {
{"Available", ms_Available},
{"CountVoices", ms_CountVoices},
{"Busy", ms_Busy},
@ -535,18 +534,18 @@ static struct methodlist ms_methods[] = {
void
initmacspeech()
{
object *m, *d;
PyObject *m, *d;
speech_available = init_available();
/* Create the module and add the functions */
m = initmodule("macspeech", ms_methods);
m = Py_InitModule("macspeech", ms_methods);
/* Add some symbolic constants to the module */
d = getmoduledict(m);
ms_error_object = newstringobject("macspeech.error");
dictinsert(d, "error", ms_error_object);
d = PyModule_GetDict(m);
ms_error_object = PyString_FromString("macspeech.error");
PyDict_SetItemString(d, "error", ms_error_object);
/* Check for errors */
if (err_occurred())
fatal("can't initialize module macspeech");
if (PyErr_Occurred())
Py_FatalError("can't initialize module macspeech");
}