*p++ = ptr->year[1] + '0'; *p++ = ptr->serial[0] + '0'; *p++ = ptr->serial[1] + '0'; *p++ = ptr->serial[2] + '0'; *p++ = ptr->serial[3] + '0'; *p++ = ptr->serial[4] + '0';#undef ptr break; case cd_control: v = PyInt_FromLong((long) *((unchar *) data)); break; } PyTuple_SetItem(args, 2, v); if (PyErr_Occurred()) { Py_DECREF(args); return; } result = PyEval_CallObject(self->ob_cdcallbacks[type].ob_cdcallback, args); Py_DECREF(args); Py_XDECREF(result);} static PyObject *CD_deleteparser(cdparserobject *self, PyObject *args){ int i; if (!PyArg_ParseTuple(args, ":deleteparser")) return NULL; CDdeleteparser(self->ob_cdparser); self->ob_cdparser = NULL; /* no sense in keeping the callbacks, so remove them */ for (i = 0; i < NCALLBACKS; i++) { Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); self->ob_cdcallbacks[i].ob_cdcallback = NULL; Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; } Py_INCREF(Py_None); return Py_None;} static PyObject *CD_parseframe(cdparserobject *self, PyObject *args){ char *cdfp; int length; CDFRAME *p; if (!PyArg_ParseTuple(args, "s#:parseframe", &cdfp, &length)) return NULL; if (length % sizeof(CDFRAME) != 0) { PyErr_SetString(PyExc_TypeError, "bad length"); return NULL; } p = (CDFRAME *) cdfp; while (length > 0) { CDparseframe(self->ob_cdparser, p); length -= sizeof(CDFRAME); p++; if (PyErr_Occurred()) return NULL; } Py_INCREF(Py_None); return Py_None;} static PyObject *CD_removecallback(cdparserobject *self, PyObject *args){ int type; if (!PyArg_ParseTuple(args, "i:removecallback", &type)) return NULL; if (type < 0 || type >= NCALLBACKS) { PyErr_SetString(PyExc_TypeError, "bad type"); return NULL; } CDremovecallback(self->ob_cdparser, (CDDATATYPES) type); Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); self->ob_cdcallbacks[type].ob_cdcallback = NULL; Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL; Py_INCREF(Py_None); return Py_None;} static PyObject *CD_resetparser(cdparserobject *self, PyObject *args){ if (!PyArg_ParseTuple(args, ":resetparser")) return NULL; CDresetparser(self->ob_cdparser); Py_INCREF(Py_None); return Py_None;} static PyObject *CD_addcallback(cdparserobject *self, PyObject *args){ int type; PyObject *func, *funcarg; /* XXX - more work here */ if (!PyArg_ParseTuple(args, "iOO:addcallback", &type, &func, &funcarg)) return NULL; if (type < 0 || type >= NCALLBACKS) { PyErr_SetString(PyExc_TypeError, "argument out of range"); return NULL; } #ifdef CDsetcallback CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, (void *) self);#else CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, (void *) self);#endif Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); Py_INCREF(func); self->ob_cdcallbacks[type].ob_cdcallback = func; Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); Py_INCREF(funcarg); self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg; /* if (type == cd_audio) { sigfpe_[_UNDERFL].repls = _ZERO; handle_sigfpes(_ON, _EN_UNDERFL, NULL, _ABORT_ON_ERROR, NULL); }*/ Py_INCREF(Py_None); return Py_None;} static PyMethodDef cdparser_methods[] = { {"addcallback", (PyCFunction)CD_addcallback, METH_VARARGS}, {"deleteparser", (PyCFunction)CD_deleteparser, METH_VARARGS}, {"parseframe", (PyCFunction)CD_parseframe, METH_VARARGS}, {"removecallback", (PyCFunction)CD_removecallback, METH_VARARGS}, {"resetparser", (PyCFunction)CD_resetparser, METH_VARARGS}, /* backward compatibility */ {"setcallback", (PyCFunction)CD_addcallback, METH_VARARGS}, {NULL, NULL} /* sentinel */}; static voidcdparser_dealloc(cdparserobject *self){ int i; for (i = 0; i < NCALLBACKS; i++) { Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); self->ob_cdcallbacks[i].ob_cdcallback = NULL; Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; } CDdeleteparser(self->ob_cdparser); PyObject_Del(self);} static PyObject *cdparser_getattr(cdparserobject *self, char *name){ if (self->ob_cdparser == NULL) { PyErr_SetString(PyExc_RuntimeError, "no parser active"); return NULL; } return Py_FindMethod(cdparser_methods, (PyObject *)self, name);} PyTypeObject CdParsertype = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "cd.cdparser", /*tp_name*/ sizeof(cdparserobject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)cdparser_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)cdparser_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/}; static PyObject *newcdparserobject(CDPARSER *cdp){ cdparserobject *p; int i; p = PyObject_New(cdparserobject, &CdParsertype); if (p == NULL) return NULL; p->ob_cdparser = cdp; for (i = 0; i < NCALLBACKS; i++) { p->ob_cdcallbacks[i].ob_cdcallback = NULL; p->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; } return (PyObject *) p;} static PyObject *CD_createparser(PyObject *self, PyObject *args){ CDPARSER *cdp; if (!PyArg_ParseTuple(args, ":createparser")) return NULL; cdp = CDcreateparser(); if (cdp == NULL) { PyErr_SetString(CdError, "createparser failed"); return NULL; } return newcdparserobject(cdp);} static PyObject *CD_msftoframe(PyObject *self, PyObject *args){ int min, sec, frame; if (!PyArg_ParseTuple(args, "iii:msftoframe", &min, &sec, &frame)) return NULL; return PyInt_FromLong((long) CDmsftoframe(min, sec, frame));} static PyMethodDef CD_methods[] = { {"open", (PyCFunction)CD_open, METH_VARARGS}, {"createparser", (PyCFunction)CD_createparser, METH_VARARGS}, {"msftoframe", (PyCFunction)CD_msftoframe, METH_VARARGS}, {NULL, NULL} /* Sentinel */}; voidinitcd(void){ PyObject *m, *d; m = Py_InitModule("cd", CD_methods); if (m == NULL) return; d = PyModule_GetDict(m); CdError = PyErr_NewException("cd.error", NULL, NULL); PyDict_SetItemString(d, "error", CdError); /* Identifiers for the different types of callbacks from the parser */ PyDict_SetItemString(d, "audio", PyInt_FromLong((long) cd_audio)); PyDict_SetItemString(d, "pnum", PyInt_FromLong((long) cd_pnum)); PyDict_SetItemString(d, "index", PyInt_FromLong((long) cd_index)); PyDict_SetItemString(d, "ptime", PyInt_FromLong((long) cd_ptime)); PyDict_SetItemString(d, "atime", PyInt_FromLong((long) cd_atime)); PyDict_SetItemString(d, "catalog", PyInt_FromLong((long) cd_catalog)); PyDict_SetItemString(d, "ident", PyInt_FromLong((long) cd_ident)); PyDict_SetItemString(d, "control", PyInt_FromLong((long) cd_control)); /* Block size information for digital audio data */ PyDict_SetItemString(d, "DATASIZE", PyInt_FromLong((long) CDDA_DATASIZE)); PyDict_SetItemString(d, "BLOCKSIZE", PyInt_FromLong((long) CDDA_BLOCKSIZE)); /* Possible states for the cd player */ PyDict_SetItemString(d, "ERROR", PyInt_FromLong((long) CD_ERROR)); PyDict_SetItemString(d, "NODISC", PyInt_FromLong((long) CD_NODISC)); PyDict_SetItemString(d, "READY", PyInt_FromLong((long) CD_READY)); PyDict_SetItemString(d, "PLAYING", PyInt_FromLong((long) CD_PLAYING)); PyDict_SetItemString(d, "PAUSED", PyInt_FromLong((long) CD_PAUSED)); PyDict_SetItemString(d, "STILL", PyInt_FromLong((long) CD_STILL));#ifdef CD_CDROM /* only newer versions of the library */ PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM));#endif}Lines 501–796 of 796. Previous lines
*p++ = ptr->year[1] + '0'; *p++ = ptr->serial[0] + '0'; *p++ = ptr->serial[1] + '0'; *p++ = ptr->serial[2] + '0'; *p++ = ptr->serial[3] + '0'; *p++ = ptr->serial[4] + '0'; #undef ptr break; case cd_control: v = PyInt_FromLong((long) *((unchar *) data)); break; } PyTuple_SetItem(args, 2, v); if (PyErr_Occurred()) { Py_DECREF(args); return; } result = PyEval_CallObject(self->ob_cdcallbacks[type].ob_cdcallback, args); Py_DECREF(args); Py_XDECREF(result); } static PyObject * CD_deleteparser(cdparserobject *self, PyObject *args) { int i; if (!PyArg_ParseTuple(args, ":deleteparser")) return NULL; CDdeleteparser(self->ob_cdparser); self->ob_cdparser = NULL; /* no sense in keeping the callbacks, so remove them */ for (i = 0; i < NCALLBACKS; i++) { Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); self->ob_cdcallbacks[i].ob_cdcallback = NULL; Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; } Py_INCREF(Py_None); return Py_None; } static PyObject * CD_parseframe(cdparserobject *self, PyObject *args) { char *cdfp; int length; CDFRAME *p; if (!PyArg_ParseTuple(args, "s#:parseframe", &cdfp, &length)) return NULL; if (length % sizeof(CDFRAME) != 0) { PyErr_SetString(PyExc_TypeError, "bad length"); return NULL; } p = (CDFRAME *) cdfp; while (length > 0) { CDparseframe(self->ob_cdparser, p); length -= sizeof(CDFRAME); p++; if (PyErr_Occurred()) return NULL; } Py_INCREF(Py_None); return Py_None; } static PyObject * CD_removecallback(cdparserobject *self, PyObject *args) { int type; if (!PyArg_ParseTuple(args, "i:removecallback", &type)) return NULL; if (type < 0 || type >= NCALLBACKS) { PyErr_SetString(PyExc_TypeError, "bad type"); return NULL; } CDremovecallback(self->ob_cdparser, (CDDATATYPES) type); Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); self->ob_cdcallbacks[type].ob_cdcallback = NULL; Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); self->ob_cdcallbacks[type].ob_cdcallbackarg = NULL; Py_INCREF(Py_None); return Py_None; } static PyObject * CD_resetparser(cdparserobject *self, PyObject *args) { if (!PyArg_ParseTuple(args, ":resetparser")) return NULL; CDresetparser(self->ob_cdparser); Py_INCREF(Py_None); return Py_None; } static PyObject * CD_addcallback(cdparserobject *self, PyObject *args) { int type; PyObject *func, *funcarg; /* XXX - more work here */ if (!PyArg_ParseTuple(args, "iOO:addcallback", &type, &func, &funcarg)) return NULL; if (type < 0 || type >= NCALLBACKS) { PyErr_SetString(PyExc_TypeError, "argument out of range"); return NULL; } #ifdef CDsetcallback CDaddcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, (void *) self); #else CDsetcallback(self->ob_cdparser, (CDDATATYPES) type, CD_callback, (void *) self); #endif Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallback); Py_INCREF(func); self->ob_cdcallbacks[type].ob_cdcallback = func; Py_XDECREF(self->ob_cdcallbacks[type].ob_cdcallbackarg); Py_INCREF(funcarg); self->ob_cdcallbacks[type].ob_cdcallbackarg = funcarg; /* if (type == cd_audio) { sigfpe_[_UNDERFL].repls = _ZERO; handle_sigfpes(_ON, _EN_UNDERFL, NULL, _ABORT_ON_ERROR, NULL); } */ Py_INCREF(Py_None); return Py_None; } static PyMethodDef cdparser_methods[] = { {"addcallback", (PyCFunction)CD_addcallback, METH_VARARGS}, {"deleteparser", (PyCFunction)CD_deleteparser, METH_VARARGS}, {"parseframe", (PyCFunction)CD_parseframe, METH_VARARGS}, {"removecallback", (PyCFunction)CD_removecallback, METH_VARARGS}, {"resetparser", (PyCFunction)CD_resetparser, METH_VARARGS}, /* backward compatibility */ {"setcallback", (PyCFunction)CD_addcallback, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; static void cdparser_dealloc(cdparserobject *self) { int i; for (i = 0; i < NCALLBACKS; i++) { Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallback); self->ob_cdcallbacks[i].ob_cdcallback = NULL; Py_XDECREF(self->ob_cdcallbacks[i].ob_cdcallbackarg); self->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; } CDdeleteparser(self->ob_cdparser); PyObject_Del(self); } static PyObject * cdparser_getattr(cdparserobject *self, char *name) { if (self->ob_cdparser == NULL) { PyErr_SetString(PyExc_RuntimeError, "no parser active"); return NULL; } return Py_FindMethod(cdparser_methods, (PyObject *)self, name); } PyTypeObject CdParsertype = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "cd.cdparser", /*tp_name*/ sizeof(cdparserobject), /*tp_size*/ 0, /*tp_itemsize*/ /* methods */ (destructor)cdparser_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ (getattrfunc)cdparser_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ }; static PyObject * newcdparserobject(CDPARSER *cdp) { cdparserobject *p; int i; p = PyObject_New(cdparserobject, &CdParsertype); if (p == NULL) return NULL; p->ob_cdparser = cdp; for (i = 0; i < NCALLBACKS; i++) { p->ob_cdcallbacks[i].ob_cdcallback = NULL; p->ob_cdcallbacks[i].ob_cdcallbackarg = NULL; } return (PyObject *) p; } static PyObject * CD_createparser(PyObject *self, PyObject *args) { CDPARSER *cdp; if (!PyArg_ParseTuple(args, ":createparser")) return NULL; cdp = CDcreateparser(); if (cdp == NULL) { PyErr_SetString(CdError, "createparser failed"); return NULL; } return newcdparserobject(cdp); } static PyObject * CD_msftoframe(PyObject *self, PyObject *args) { int min, sec, frame; if (!PyArg_ParseTuple(args, "iii:msftoframe", &min, &sec, &frame)) return NULL; return PyInt_FromLong((long) CDmsftoframe(min, sec, frame)); } static PyMethodDef CD_methods[] = { {"open", (PyCFunction)CD_open, METH_VARARGS}, {"createparser", (PyCFunction)CD_createparser, METH_VARARGS}, {"msftoframe", (PyCFunction)CD_msftoframe, METH_VARARGS}, {NULL, NULL} /* Sentinel */ }; void initcd(void) { PyObject *m, *d; m = Py_InitModule("cd", CD_methods); if (m == NULL) return; d = PyModule_GetDict(m); CdError = PyErr_NewException("cd.error", NULL, NULL); PyDict_SetItemString(d, "error", CdError); /* Identifiers for the different types of callbacks from the parser */ PyDict_SetItemString(d, "audio", PyInt_FromLong((long) cd_audio)); PyDict_SetItemString(d, "pnum", PyInt_FromLong((long) cd_pnum)); PyDict_SetItemString(d, "index", PyInt_FromLong((long) cd_index)); PyDict_SetItemString(d, "ptime", PyInt_FromLong((long) cd_ptime)); PyDict_SetItemString(d, "atime", PyInt_FromLong((long) cd_atime)); PyDict_SetItemString(d, "catalog", PyInt_FromLong((long) cd_catalog)); PyDict_SetItemString(d, "ident", PyInt_FromLong((long) cd_ident)); PyDict_SetItemString(d, "control", PyInt_FromLong((long) cd_control)); /* Block size information for digital audio data */ PyDict_SetItemString(d, "DATASIZE", PyInt_FromLong((long) CDDA_DATASIZE)); PyDict_SetItemString(d, "BLOCKSIZE", PyInt_FromLong((long) CDDA_BLOCKSIZE)); /* Possible states for the cd player */ PyDict_SetItemString(d, "ERROR", PyInt_FromLong((long) CD_ERROR)); PyDict_SetItemString(d, "NODISC", PyInt_FromLong((long) CD_NODISC)); PyDict_SetItemString(d, "READY", PyInt_FromLong((long) CD_READY)); PyDict_SetItemString(d, "PLAYING", PyInt_FromLong((long) CD_PLAYING)); PyDict_SetItemString(d, "PAUSED", PyInt_FromLong((long) CD_PAUSED)); PyDict_SetItemString(d, "STILL", PyInt_FromLong((long) CD_STILL)); #ifdef CD_CDROM /* only newer versions of the library */ PyDict_SetItemString(d, "CDROM", PyInt_FromLong((long) CD_CDROM)); #endif }