Mercurial > cpython-lru_cache-weakref
annotate Mac/Modules/macspeechmodule.c @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 91dd223829c6 |
| children | 82309c7325ef |
| rev | line source |
|---|---|
| 1922 | 1 /*********************************************************** |
|
5079
d6b292a33cfe
Added/updated copyright notices
Jack Jansen <jack.jansen@cwi.nl>
parents:
5071
diff
changeset
|
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
| 2091 | 3 The Netherlands. |
| 1922 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 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. | |
| 14 | |
| 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. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 25 | |
| 5071 | 26 #include "Python.h" |
|
13547
db963a615bc9
ANSIfication step 2: make sure all needed prototypes are available, and all needed
Jack Jansen <jack.jansen@cwi.nl>
parents:
12836
diff
changeset
|
27 #include "macglue.h" |
| 1922 | 28 |
|
5152
bd708fe1934b
- Changed GestaltEqu.h to Gestalt.h
Jack Jansen <jack.jansen@cwi.nl>
parents:
5079
diff
changeset
|
29 #include <Gestalt.h> |
| 2027 | 30 #include "Speech.h" |
| 31 | |
| 32 #ifdef __MWERKS__ | |
|
12836
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
33 #define OLDP2C 1 |
|
5429
ac235c9e6881
- Changed the m# format for PyArg_ParseTuple back to s#
Jack Jansen <jack.jansen@cwi.nl>
parents:
5152
diff
changeset
|
34 #include <TextUtils.h> |
|
12836
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
35 #ifndef c2pstr |
| 2027 | 36 #define c2pstr C2PStr |
|
12836
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
37 #endif |
|
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
38 #ifndef p2cstr |
| 2027 | 39 #define p2cstr P2CStr |
|
12836
3fe304050434
Made the core toolbox modules carbon-compatible using the new greylist feature of bgen: non-carbon methods are still included in non-carbon MacPython. The issue of backward compatibility of Python code is still open.
Jack Jansen <jack.jansen@cwi.nl>
parents:
6442
diff
changeset
|
40 #endif |
| 2027 | 41 #else |
| 1922 | 42 #include "pascal.h" |
| 2027 | 43 #endif /* __MWERKS__ */ |
| 44 | |
|
5152
bd708fe1934b
- Changed GestaltEqu.h to Gestalt.h
Jack Jansen <jack.jansen@cwi.nl>
parents:
5079
diff
changeset
|
45 #include <CodeFragments.h> |
| 2027 | 46 int lib_available; |
| 1922 | 47 |
| 48 /* Somehow the Apple Fix2X and X2Fix don't do what I expect */ | |
| 49 #define fixed2double(x) (((double)(x))/32768.0) | |
| 50 #define double2fixed(x) ((Fixed)((x)*32768.0)) | |
| 51 | |
| 52 char *CurrentSpeech; | |
| 5071 | 53 PyObject *ms_error_object; |
| 2027 | 54 int speech_available; |
| 1922 | 55 |
| 2027 | 56 static |
| 57 init_available() { | |
| 58 OSErr err; | |
| 59 long result; | |
| 60 | |
| 61 lib_available = ((ProcPtr)SpeakString != (ProcPtr)0); | |
| 62 err = Gestalt(gestaltSpeechAttr, &result); | |
| 63 if ( err == noErr && (result & (1<<gestaltSpeechMgrPresent))) | |
| 64 return 1; | |
| 65 return 0; | |
| 66 } | |
| 67 | |
| 68 static | |
| 69 check_available() { | |
| 70 if ( !speech_available ) { | |
| 5071 | 71 PyErr_SetString(ms_error_object, "Speech Mgr not available"); |
| 2027 | 72 return 0; |
| 73 } | |
| 74 if ( !lib_available ) { | |
| 5071 | 75 PyErr_SetString(ms_error_object, "Speech Mgr available, but shared lib missing"); |
| 2027 | 76 return 0; |
| 77 } | |
| 78 return 1; | |
| 1922 | 79 } |
| 80 | |
| 81 /* ------------- | |
| 82 ** | |
| 83 ** Part one - the speech channel object | |
| 84 */ | |
| 85 typedef struct { | |
| 5071 | 86 PyObject_HEAD |
| 1922 | 87 SpeechChannel chan; |
| 5071 | 88 PyObject *curtext; /* If non-NULL current text being spoken */ |
| 1922 | 89 } scobject; |
| 90 | |
| 5071 | 91 staticforward PyTypeObject sctype; |
| 1922 | 92 |
| 93 #define is_scobject(v) ((v)->ob_type == &sctype) | |
| 94 | |
| 95 static scobject * | |
| 96 newscobject(arg) | |
| 97 VoiceSpec *arg; | |
| 98 { | |
| 2027 | 99 scobject *self; |
| 1922 | 100 OSErr err; |
| 101 | |
| 5071 | 102 self = PyObject_NEW(scobject, &sctype); |
| 2027 | 103 if (self == NULL) |
| 1922 | 104 return NULL; |
| 2027 | 105 if ( (err=NewSpeechChannel(arg, &self->chan)) != 0) { |
| 5071 | 106 Py_DECREF(self); |
| 2027 | 107 return (scobject *)PyErr_Mac(ms_error_object, err); |
| 1922 | 108 } |
| 2027 | 109 self->curtext = NULL; |
| 110 return self; | |
| 1922 | 111 } |
| 112 | |
| 113 /* sc methods */ | |
| 114 | |
| 115 static void | |
| 2027 | 116 sc_dealloc(self) |
| 117 scobject *self; | |
| 1922 | 118 { |
| 2027 | 119 DisposeSpeechChannel(self->chan); |
| 5071 | 120 PyMem_DEL(self); |
| 1922 | 121 } |
| 122 | |
| 5071 | 123 static PyObject * |
| 1922 | 124 sc_Stop(self, args) |
| 125 scobject *self; | |
| 5071 | 126 PyObject *args; |
| 1922 | 127 { |
| 128 OSErr err; | |
| 129 | |
| 5071 | 130 if (!PyArg_NoArgs(args)) |
| 1922 | 131 return NULL; |
| 2027 | 132 if ((err=StopSpeech(self->chan)) != 0) { |
| 133 PyErr_Mac(ms_error_object, err); | |
| 134 return NULL; | |
| 135 } | |
| 1922 | 136 if ( self->curtext ) { |
| 5071 | 137 Py_DECREF(self->curtext); |
| 1922 | 138 self->curtext = NULL; |
| 139 } | |
| 5071 | 140 Py_INCREF(Py_None); |
| 141 return Py_None; | |
| 1922 | 142 } |
| 143 | |
| 5071 | 144 static PyObject * |
| 1922 | 145 sc_SpeakText(self, args) |
| 146 scobject *self; | |
| 5071 | 147 PyObject *args; |
| 1922 | 148 { |
| 149 OSErr err; | |
| 150 char *str; | |
| 151 int len; | |
| 152 | |
|
5429
ac235c9e6881
- Changed the m# format for PyArg_ParseTuple back to s#
Jack Jansen <jack.jansen@cwi.nl>
parents:
5152
diff
changeset
|
153 if (!PyArg_Parse(args, "s#", &str, &len)) |
| 1922 | 154 return NULL; |
| 155 if ( self->curtext ) { | |
| 156 StopSpeech(self->chan); | |
| 5071 | 157 Py_DECREF(self->curtext); |
| 1922 | 158 self->curtext = NULL; |
| 159 } | |
| 2027 | 160 if ((err=SpeakText(self->chan, (Ptr)str, (long)len)) != 0) { |
| 161 PyErr_Mac(ms_error_object, err); | |
| 162 return 0; | |
| 163 } | |
| 5071 | 164 (void)PyArg_Parse(args, "O", &self->curtext); /* Or should I check this? */ |
| 165 Py_INCREF(self->curtext); | |
| 166 Py_INCREF(Py_None); | |
| 167 return Py_None; | |
| 1922 | 168 } |
| 169 | |
| 5071 | 170 static PyObject * |
| 1922 | 171 sc_GetRate(self, args) |
| 172 scobject *self; | |
| 5071 | 173 PyObject *args; |
| 1922 | 174 { |
| 175 OSErr err; | |
| 176 Fixed farg; | |
| 177 | |
| 5071 | 178 if (!PyArg_NoArgs(args)) |
| 1922 | 179 return NULL; |
| 2027 | 180 if ((err=GetSpeechRate(self->chan, &farg)) != 0) { |
| 181 PyErr_Mac(ms_error_object, err); | |
| 182 return 0; | |
| 183 } | |
| 5071 | 184 return PyFloat_FromDouble(fixed2double(farg)); |
| 1922 | 185 } |
| 186 | |
| 5071 | 187 static PyObject * |
| 1922 | 188 sc_GetPitch(self, args) |
| 189 scobject *self; | |
| 5071 | 190 PyObject *args; |
| 1922 | 191 { |
| 192 OSErr err; | |
| 193 Fixed farg; | |
| 194 | |
| 5071 | 195 if (!PyArg_NoArgs(args)) |
| 1922 | 196 return NULL; |
| 2027 | 197 if ((err=GetSpeechPitch(self->chan, &farg)) != 0) { |
| 198 PyErr_Mac(ms_error_object, err); | |
| 199 return 0; | |
| 200 } | |
| 5071 | 201 return PyFloat_FromDouble(fixed2double(farg)); |
| 1922 | 202 } |
| 203 | |
| 5071 | 204 static PyObject * |
| 1922 | 205 sc_SetRate(self, args) |
| 206 scobject *self; | |
| 5071 | 207 PyObject *args; |
| 1922 | 208 { |
| 209 OSErr err; | |
| 210 double darg; | |
| 211 | |
| 5071 | 212 if (!PyArg_Parse(args, "d", &darg)) |
| 1922 | 213 return NULL; |
| 2027 | 214 if ((err=SetSpeechRate(self->chan, double2fixed(darg))) != 0) { |
| 215 PyErr_Mac(ms_error_object, err); | |
| 216 return 0; | |
| 217 } | |
| 5071 | 218 Py_INCREF(Py_None); |
| 219 return Py_None; | |
| 1922 | 220 } |
| 221 | |
| 5071 | 222 static PyObject * |
| 1922 | 223 sc_SetPitch(self, args) |
| 224 scobject *self; | |
| 5071 | 225 PyObject *args; |
| 1922 | 226 { |
| 227 OSErr err; | |
| 228 double darg; | |
| 229 | |
| 5071 | 230 if (!PyArg_Parse(args, "d", &darg)) |
| 1922 | 231 return NULL; |
| 2027 | 232 if ((err=SetSpeechPitch(self->chan, double2fixed(darg))) != 0) { |
| 233 PyErr_Mac(ms_error_object, err); | |
| 234 return NULL; | |
| 235 } | |
| 5071 | 236 Py_INCREF(Py_None); |
| 237 return Py_None; | |
| 1922 | 238 } |
| 239 | |
| 5071 | 240 static struct PyMethodDef sc_methods[] = { |
| 241 {"Stop", (PyCFunction)sc_Stop}, | |
| 242 {"SetRate", (PyCFunction)sc_SetRate}, | |
| 243 {"GetRate", (PyCFunction)sc_GetRate}, | |
| 244 {"SetPitch", (PyCFunction)sc_SetPitch}, | |
| 245 {"GetPitch", (PyCFunction)sc_GetPitch}, | |
| 246 {"SpeakText", (PyCFunction)sc_SpeakText}, | |
| 1922 | 247 {NULL, NULL} /* sentinel */ |
| 248 }; | |
| 249 | |
| 5071 | 250 static PyObject * |
| 2027 | 251 sc_getattr(self, name) |
| 252 scobject *self; | |
| 1922 | 253 char *name; |
| 254 { | |
| 5071 | 255 return Py_FindMethod(sc_methods, (PyObject *)self, name); |
| 1922 | 256 } |
| 257 | |
| 5071 | 258 static PyTypeObject sctype = { |
| 259 PyObject_HEAD_INIT(&PyType_Type) | |
| 1922 | 260 0, /*ob_size*/ |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
19032
diff
changeset
|
261 "macspeech.MacSpeechChannel", /*tp_name*/ |
| 1922 | 262 sizeof(scobject), /*tp_basicsize*/ |
| 263 0, /*tp_itemsize*/ | |
| 264 /* methods */ | |
| 265 (destructor)sc_dealloc, /*tp_dealloc*/ | |
| 266 0, /*tp_print*/ | |
| 267 (getattrfunc)sc_getattr, /*tp_getattr*/ | |
| 2027 | 268 0, /*tp_setattr*/ |
| 1922 | 269 0, /*tp_compare*/ |
| 270 0, /*tp_repr*/ | |
| 271 0, /*tp_as_number*/ | |
| 272 0, /*tp_as_sequence*/ | |
| 273 0, /*tp_as_mapping*/ | |
| 274 0, /*tp_hash*/ | |
| 275 }; | |
| 276 | |
| 277 /* ------------- | |
| 278 ** | |
| 279 ** Part two - the voice object | |
| 280 */ | |
| 281 typedef struct { | |
| 5071 | 282 PyObject_HEAD |
| 1922 | 283 int initialized; |
| 284 VoiceSpec vs; | |
| 285 VoiceDescription vd; | |
| 286 } mvobject; | |
| 287 | |
| 5071 | 288 staticforward PyTypeObject mvtype; |
| 1922 | 289 |
| 290 #define is_mvobject(v) ((v)->ob_type == &mvtype) | |
| 291 | |
| 292 static mvobject * | |
| 293 newmvobject() | |
| 294 { | |
| 2027 | 295 mvobject *self; |
| 5071 | 296 self = PyObject_NEW(mvobject, &mvtype); |
| 2027 | 297 if (self == NULL) |
| 1922 | 298 return NULL; |
| 2027 | 299 self->initialized = 0; |
| 300 return self; | |
| 1922 | 301 } |
| 302 | |
| 303 static int | |
| 304 initmvobject(self, ind) | |
| 305 mvobject *self; | |
| 306 int ind; | |
| 307 { | |
| 308 OSErr err; | |
| 309 | |
| 310 if ( (err=GetIndVoice((short)ind, &self->vs)) != 0 ) { | |
| 2027 | 311 PyErr_Mac(ms_error_object, err); |
| 1922 | 312 return 0; |
| 313 } | |
| 314 if ( (err=GetVoiceDescription(&self->vs, &self->vd, sizeof self->vd)) != 0) { | |
| 2027 | 315 PyErr_Mac(ms_error_object, err); |
| 1922 | 316 return 0; |
| 317 } | |
| 318 self->initialized = 1; | |
| 319 return 1; | |
| 320 } | |
| 321 /* mv methods */ | |
| 322 | |
| 323 static void | |
| 2027 | 324 mv_dealloc(self) |
| 325 mvobject *self; | |
| 1922 | 326 { |
| 5071 | 327 PyMem_DEL(self); |
| 1922 | 328 } |
| 329 | |
| 5071 | 330 static PyObject * |
| 1922 | 331 mv_getgender(self, args) |
| 332 mvobject *self; | |
| 5071 | 333 PyObject *args; |
| 1922 | 334 { |
| 5071 | 335 PyObject *rv; |
| 1922 | 336 |
| 5071 | 337 if (!PyArg_NoArgs(args)) |
| 1922 | 338 return NULL; |
| 339 if (!self->initialized) { | |
| 5071 | 340 PyErr_SetString(ms_error_object, "Uninitialized voice"); |
| 1922 | 341 return NULL; |
| 342 } | |
| 5071 | 343 rv = PyInt_FromLong(self->vd.gender); |
| 1922 | 344 return rv; |
| 345 } | |
| 346 | |
| 5071 | 347 static PyObject * |
| 1922 | 348 mv_newchannel(self, args) |
| 349 mvobject *self; | |
| 5071 | 350 PyObject *args; |
| 1922 | 351 { |
| 5071 | 352 if (!PyArg_NoArgs(args)) |
| 1922 | 353 return NULL; |
| 354 if (!self->initialized) { | |
| 5071 | 355 PyErr_SetString(ms_error_object, "Uninitialized voice"); |
| 1922 | 356 return NULL; |
| 357 } | |
| 5071 | 358 return (PyObject *)newscobject(&self->vs); |
| 1922 | 359 } |
| 360 | |
| 5071 | 361 static struct PyMethodDef mv_methods[] = { |
| 362 {"GetGender", (PyCFunction)mv_getgender}, | |
| 363 {"NewChannel", (PyCFunction)mv_newchannel}, | |
| 1922 | 364 {NULL, NULL} /* sentinel */ |
| 365 }; | |
| 366 | |
| 5071 | 367 static PyObject * |
| 2027 | 368 mv_getattr(self, name) |
| 369 mvobject *self; | |
| 1922 | 370 char *name; |
| 371 { | |
| 5071 | 372 return Py_FindMethod(mv_methods, (PyObject *)self, name); |
| 1922 | 373 } |
| 374 | |
| 5071 | 375 static PyTypeObject mvtype = { |
| 376 PyObject_HEAD_INIT(&PyType_Type) | |
| 1922 | 377 0, /*ob_size*/ |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
19032
diff
changeset
|
378 "macspeech.MacVoice", /*tp_name*/ |
| 1922 | 379 sizeof(mvobject), /*tp_basicsize*/ |
| 380 0, /*tp_itemsize*/ | |
| 381 /* methods */ | |
| 382 (destructor)mv_dealloc, /*tp_dealloc*/ | |
| 383 0, /*tp_print*/ | |
| 384 (getattrfunc)mv_getattr, /*tp_getattr*/ | |
| 2027 | 385 0, /*tp_setattr*/ |
| 1922 | 386 0, /*tp_compare*/ |
| 387 0, /*tp_repr*/ | |
| 388 0, /*tp_as_number*/ | |
| 389 0, /*tp_as_sequence*/ | |
| 390 0, /*tp_as_mapping*/ | |
| 391 0, /*tp_hash*/ | |
| 392 }; | |
| 393 | |
| 394 | |
| 395 /* ------------- | |
| 396 ** | |
| 397 ** Part three - The module interface | |
| 398 */ | |
| 399 | |
| 400 /* See if Speech manager available */ | |
| 401 | |
| 5071 | 402 static PyObject * |
| 1922 | 403 ms_Available(self, args) |
| 5071 | 404 PyObject *self; /* Not used */ |
| 405 PyObject *args; | |
| 1922 | 406 { |
| 407 | |
| 5071 | 408 if (!PyArg_NoArgs(args)) |
| 1922 | 409 return NULL; |
| 5071 | 410 return PyInt_FromLong(speech_available); |
| 1922 | 411 } |
| 412 | |
| 413 /* Count number of busy speeches */ | |
| 414 | |
| 5071 | 415 static PyObject * |
| 1922 | 416 ms_Busy(self, args) |
| 5071 | 417 PyObject *self; /* Not used */ |
| 418 PyObject *args; | |
| 1922 | 419 { |
| 420 short result; | |
| 421 | |
| 5071 | 422 if (!PyArg_NoArgs(args)) |
| 1922 | 423 return NULL; |
| 2027 | 424 if ( !check_available() ) |
| 425 return NULL; | |
| 1922 | 426 result = SpeechBusy(); |
| 5071 | 427 return PyInt_FromLong(result); |
| 1922 | 428 } |
| 429 | |
| 430 /* Say something */ | |
| 431 | |
| 5071 | 432 static PyObject * |
| 1922 | 433 ms_SpeakString(self, args) |
| 5071 | 434 PyObject *self; /* Not used */ |
| 435 PyObject *args; | |
| 1922 | 436 { |
| 437 OSErr err; | |
| 438 char *str; | |
| 439 int len; | |
| 440 | |
| 5071 | 441 if (!PyArg_Parse(args, "s", &str)) |
| 1922 | 442 return NULL; |
| 2027 | 443 if ( !check_available()) |
| 444 return NULL; | |
| 1922 | 445 if (CurrentSpeech) { |
| 446 /* Free the old speech, after killing it off | |
| 447 ** (note that speach is async and c2pstr works inplace) | |
| 448 */ | |
| 449 SpeakString("\p"); | |
| 450 free(CurrentSpeech); | |
| 451 } | |
| 452 len = strlen(str); | |
| 453 CurrentSpeech = malloc(len+1); | |
| 454 strcpy(CurrentSpeech, str); | |
| 455 err = SpeakString(c2pstr(CurrentSpeech)); | |
| 2027 | 456 if ( err ) { |
| 457 PyErr_Mac(ms_error_object, err); | |
| 458 return NULL; | |
| 459 } | |
| 5071 | 460 Py_INCREF(Py_None); |
| 461 return Py_None; | |
| 1922 | 462 } |
| 463 | |
| 464 | |
| 465 /* Count number of available voices */ | |
| 466 | |
| 5071 | 467 static PyObject * |
| 1922 | 468 ms_CountVoices(self, args) |
| 5071 | 469 PyObject *self; /* Not used */ |
| 470 PyObject *args; | |
| 1922 | 471 { |
| 472 short result; | |
| 473 | |
| 5071 | 474 if (!PyArg_NoArgs(args)) |
| 1922 | 475 return NULL; |
| 2027 | 476 if ( !check_available()) |
| 477 return NULL; | |
| 1922 | 478 CountVoices(&result); |
| 5071 | 479 return PyInt_FromLong(result); |
| 1922 | 480 } |
| 481 | |
| 5071 | 482 static PyObject * |
| 1922 | 483 ms_GetIndVoice(self, args) |
| 5071 | 484 PyObject *self; /* Not used */ |
| 485 PyObject *args; | |
| 1922 | 486 { |
| 487 mvobject *rv; | |
| 488 long ind; | |
| 489 | |
| 5071 | 490 if( !PyArg_Parse(args, "i", &ind)) |
| 2027 | 491 return NULL; |
| 492 if ( !check_available() ) | |
| 493 return NULL; | |
| 1922 | 494 rv = newmvobject(); |
| 495 if ( !initmvobject(rv, ind) ) { | |
| 5071 | 496 Py_DECREF(rv); |
| 1922 | 497 return NULL; |
| 498 } | |
| 5071 | 499 return (PyObject *)rv; |
| 1922 | 500 } |
| 501 | |
| 502 | |
| 5071 | 503 static PyObject * |
| 2027 | 504 ms_Version(self, args) |
| 5071 | 505 PyObject *self; /* Not used */ |
| 506 PyObject *args; | |
| 2027 | 507 { |
| 508 NumVersion v; | |
| 509 | |
| 5071 | 510 if (!PyArg_NoArgs(args)) |
| 2027 | 511 return NULL; |
| 512 if ( !check_available()) | |
| 513 return NULL; | |
| 514 v = SpeechManagerVersion(); | |
| 5071 | 515 return PyInt_FromLong(*(int *)&v); |
| 2027 | 516 } |
| 517 | |
| 1922 | 518 |
| 519 /* List of functions defined in the module */ | |
| 520 | |
| 5071 | 521 static struct PyMethodDef ms_methods[] = { |
| 1922 | 522 {"Available", ms_Available}, |
| 523 {"CountVoices", ms_CountVoices}, | |
| 524 {"Busy", ms_Busy}, | |
| 525 {"SpeakString", ms_SpeakString}, | |
| 526 {"GetIndVoice", ms_GetIndVoice}, | |
| 2027 | 527 {"Version", ms_Version}, |
| 1922 | 528 {NULL, NULL} /* sentinel */ |
| 529 }; | |
| 530 | |
| 531 /* Initialization function for the module (*must* be called initmacspeech) */ | |
| 532 | |
| 533 void | |
| 534 initmacspeech() | |
| 535 { | |
| 5071 | 536 PyObject *m, *d; |
| 1922 | 537 |
| 2027 | 538 speech_available = init_available(); |
| 1922 | 539 /* Create the module and add the functions */ |
| 5071 | 540 m = Py_InitModule("macspeech", ms_methods); |
| 1922 | 541 |
| 542 /* Add some symbolic constants to the module */ | |
| 5071 | 543 d = PyModule_GetDict(m); |
| 6442 | 544 ms_error_object = PyErr_NewException("macspeech.error", NULL, NULL); |
| 5071 | 545 PyDict_SetItemString(d, "error", ms_error_object); |
| 1922 | 546 } |
