summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/snd
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2002-11-29 23:40:48 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2002-11-29 23:40:48 (GMT)
commitdbd5701d736a151d29fee4658228e16876626f47 (patch)
tree164a5bf1d9a00788bd229820df9bfa81d75933eb /Mac/Modules/snd
parent818855939ac016492cb59d1fc2fea94cc0764855 (diff)
downloadcpython-dbd5701d736a151d29fee4658228e16876626f47.zip
cpython-dbd5701d736a151d29fee4658228e16876626f47.tar.gz
cpython-dbd5701d736a151d29fee4658228e16876626f47.tar.bz2
Converted the Carbon modules to use PEP252-style objects, with
descriptors in stead of manual getattr hooks to get at attributes of the objects. For Qd I have in stead gotten rid of most of the attribute access in favor of the carbon-style accessor methods (with the exception of visRgn, to be done later), and of the Carbon.Qd.qd global object, for which accessor functions are also available. For List I have fixed the fact that various methods were incorrectly generated as functions. CF is untouched: PEP252 doesn't allow "poor-mans-inheritance" with basechain, so it will have to wait for PEP253 support.
Diffstat (limited to 'Mac/Modules/snd')
-rw-r--r--Mac/Modules/snd/_Sndmodule.c138
-rw-r--r--Mac/Modules/snd/sndsupport.py82
2 files changed, 122 insertions, 98 deletions
diff --git a/Mac/Modules/snd/_Sndmodule.c b/Mac/Modules/snd/_Sndmodule.c
index 7ce4799..412ae9d 100644
--- a/Mac/Modules/snd/_Sndmodule.c
+++ b/Mac/Modules/snd/_Sndmodule.c
@@ -300,14 +300,8 @@ static PyMethodDef SndCh_methods[] = {
{NULL, NULL, 0}
};
-static PyMethodChain SndCh_chain = { SndCh_methods, NULL };
+#define SndCh_getsetlist NULL
-static PyObject *SndCh_getattr(SndChannelObject *self, char *name)
-{
- return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name);
-}
-
-#define SndCh_setattr NULL
#define SndCh_compare NULL
@@ -324,14 +318,31 @@ static PyTypeObject SndChannel_Type = {
/* methods */
(destructor) SndCh_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- (getattrfunc) SndCh_getattr, /*tp_getattr*/
- (setattrfunc) SndCh_setattr, /*tp_setattr*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
(cmpfunc) SndCh_compare, /*tp_compare*/
(reprfunc) SndCh_repr, /*tp_repr*/
(PyNumberMethods *)0, /* tp_as_number */
(PySequenceMethods *)0, /* tp_as_sequence */
(PyMappingMethods *)0, /* tp_as_mapping */
(hashfunc) SndCh_hash, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ PyObject_GenericGetAttr, /*tp_getattro*/
+ PyObject_GenericSetAttr, /*tp_setattro */
+ 0, /*outputHook_tp_as_buffer*/
+ 0, /*outputHook_tp_flags*/
+ 0, /*outputHook_tp_doc*/
+ 0, /*outputHook_tp_traverse*/
+ 0, /*outputHook_tp_clear*/
+ 0, /*outputHook_tp_richcompare*/
+ 0, /*outputHook_tp_weaklistoffset*/
+ 0, /*outputHook_tp_iter*/
+ 0, /*outputHook_tp_iternext*/
+ SndCh_methods, /* tp_methods */
+ 0, /*outputHook_tp_members*/
+ SndCh_getsetlist, /*tp_getset*/
+ 0, /*outputHook_tp_base*/
};
/* ------------------- End object type SndChannel ------------------- */
@@ -391,52 +402,66 @@ static PyMethodDef SPBObj_methods[] = {
{NULL, NULL, 0}
};
-static PyMethodChain SPBObj_chain = { SPBObj_methods, NULL };
+static PyObject *SPBObj_get_inRefNum(SPBObject *self, void *closure)
+{
+ return Py_BuildValue("l", self->ob_spb.inRefNum);
+}
-static PyObject *SPBObj_getattr(SPBObject *self, char *name)
+static int SPBObj_set_inRefNum(SPBObject *self, PyObject *v, void *closure)
{
+ return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);
+ return 0;
+}
- if (strcmp(name, "inRefNum") == 0)
- return Py_BuildValue("l", self->ob_spb.inRefNum);
- else if (strcmp(name, "count") == 0)
- return Py_BuildValue("l", self->ob_spb.count);
- else if (strcmp(name, "milliseconds") == 0)
- return Py_BuildValue("l", self->ob_spb.milliseconds);
- else if (strcmp(name, "error") == 0)
- return Py_BuildValue("h", self->ob_spb.error);
- return Py_FindMethodInChain(&SPBObj_chain, (PyObject *)self, name);
+static PyObject *SPBObj_get_count(SPBObject *self, void *closure)
+{
+ return Py_BuildValue("l", self->ob_spb.count);
}
-static int SPBObj_setattr(SPBObject *self, char *name, PyObject *value)
+static int SPBObj_set_count(SPBObject *self, PyObject *v, void *closure)
{
+ return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);
+ return 0;
+}
- int rv = 0;
-
- if (strcmp(name, "inRefNum") == 0)
- rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
- else if (strcmp(name, "count") == 0)
- rv = PyArg_Parse(value, "l", &self->ob_spb.count);
- else if (strcmp(name, "milliseconds") == 0)
- rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
- else if (strcmp(name, "buffer") == 0)
- rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
- else if (strcmp(name, "completionRoutine") == 0) {
- self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
- self->ob_completion = value;
- Py_INCREF(value);
- rv = 1;
-#if !TARGET_API_MAC_CARBON
- } else if (strcmp(name, "interruptRoutine") == 0) {
- self->ob_spb.completionRoutine = NewSIInterruptUPP(SPB_interrupt);
- self->ob_interrupt = value;
- Py_INCREF(value);
- rv = 1;
-#endif
- }
- if ( rv ) return 0;
- else return -1;
+static PyObject *SPBObj_get_milliseconds(SPBObject *self, void *closure)
+{
+ return Py_BuildValue("l", self->ob_spb.milliseconds);
}
+static int SPBObj_set_milliseconds(SPBObject *self, PyObject *v, void *closure)
+{
+ return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);
+ return 0;
+}
+
+static PyObject *SPBObj_get_error(SPBObject *self, void *closure)
+{
+ return Py_BuildValue("h", self->ob_spb.error);
+}
+
+#define SPBObj_set_error NULL
+
+#define SPBObj_get_completionRoutine NULL
+
+static int SPBObj_set_completionRoutine(SPBObject *self, PyObject *v, void *closure)
+{
+ self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
+ self->ob_completion = v;
+ Py_INCREF(v);
+ return 0;
+ return 0;
+}
+
+static PyGetSetDef SPBObj_getsetlist[] = {
+ {"inRefNum", (getter)SPBObj_get_inRefNum, (setter)SPBObj_set_inRefNum, NULL},
+ {"count", (getter)SPBObj_get_count, (setter)SPBObj_set_count, NULL},
+ {"milliseconds", (getter)SPBObj_get_milliseconds, (setter)SPBObj_set_milliseconds, NULL},
+ {"error", (getter)SPBObj_get_error, (setter)SPBObj_set_error, NULL},
+ {"completionRoutine", (getter)SPBObj_get_completionRoutine, (setter)SPBObj_set_completionRoutine, NULL},
+};
+
+
#define SPBObj_compare NULL
#define SPBObj_repr NULL
@@ -452,14 +477,31 @@ static PyTypeObject SPB_Type = {
/* methods */
(destructor) SPBObj_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- (getattrfunc) SPBObj_getattr, /*tp_getattr*/
- (setattrfunc) SPBObj_setattr, /*tp_setattr*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
(cmpfunc) SPBObj_compare, /*tp_compare*/
(reprfunc) SPBObj_repr, /*tp_repr*/
(PyNumberMethods *)0, /* tp_as_number */
(PySequenceMethods *)0, /* tp_as_sequence */
(PyMappingMethods *)0, /* tp_as_mapping */
(hashfunc) SPBObj_hash, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ PyObject_GenericGetAttr, /*tp_getattro*/
+ PyObject_GenericSetAttr, /*tp_setattro */
+ 0, /*outputHook_tp_as_buffer*/
+ 0, /*outputHook_tp_flags*/
+ 0, /*outputHook_tp_doc*/
+ 0, /*outputHook_tp_traverse*/
+ 0, /*outputHook_tp_clear*/
+ 0, /*outputHook_tp_richcompare*/
+ 0, /*outputHook_tp_weaklistoffset*/
+ 0, /*outputHook_tp_iter*/
+ 0, /*outputHook_tp_iternext*/
+ SPBObj_methods, /* tp_methods */
+ 0, /*outputHook_tp_members*/
+ SPBObj_getsetlist, /*tp_getset*/
+ 0, /*outputHook_tp_base*/
};
/* ---------------------- End object type SPB ----------------------- */
diff --git a/Mac/Modules/snd/sndsupport.py b/Mac/Modules/snd/sndsupport.py
index 47c17ce..073f612 100644
--- a/Mac/Modules/snd/sndsupport.py
+++ b/Mac/Modules/snd/sndsupport.py
@@ -211,7 +211,7 @@ SPB_interrupt(SPBPtr my_spb)
# create the module and object definition and link them
-class SndObjectDefinition(ObjectDefinition):
+class SndObjectDefinition(PEP252Mixin, ObjectDefinition):
def outputStructMembers(self):
ObjectDefinition.outputStructMembers(self)
@@ -237,7 +237,37 @@ class SndObjectDefinition(ObjectDefinition):
#
-class SpbObjectDefinition(ObjectDefinition):
+class SpbObjectDefinition(PEP252Mixin, ObjectDefinition):
+ getsetlist = [
+ (
+ 'inRefNum',
+ 'return Py_BuildValue("l", self->ob_spb.inRefNum);',
+ 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);',
+ None,
+ ), (
+ 'count',
+ 'return Py_BuildValue("l", self->ob_spb.count);',
+ 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);',
+ None
+ ), (
+ 'milliseconds',
+ 'return Py_BuildValue("l", self->ob_spb.milliseconds);',
+ 'return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);',
+ None,
+ ), (
+ 'error',
+ 'return Py_BuildValue("h", self->ob_spb.error);',
+ None,
+ None
+ ), (
+ 'completionRoutine',
+ None,
+ """self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
+ self->ob_completion = v;
+ Py_INCREF(v);
+ return 0;""",
+ None,
+ )]
def outputStructMembers(self):
Output("/* Members used to implement callbacks: */")
@@ -286,54 +316,6 @@ class SpbObjectDefinition(ObjectDefinition):
Output("*p_itself = &((%s *)v)->ob_spb;", self.objecttype)
Output("return 1;")
OutRbrace()
-
- def outputSetattr(self):
- Output()
- Output("static int %s_setattr(%s *self, char *name, PyObject *value)",
- self.prefix, self.objecttype)
- OutLbrace()
- self.outputSetattrBody()
- OutRbrace()
-
- def outputSetattrBody(self):
- Output("""
- int rv = 0;
-
- if (strcmp(name, "inRefNum") == 0)
- rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
- else if (strcmp(name, "count") == 0)
- rv = PyArg_Parse(value, "l", &self->ob_spb.count);
- else if (strcmp(name, "milliseconds") == 0)
- rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
- else if (strcmp(name, "buffer") == 0)
- rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
- else if (strcmp(name, "completionRoutine") == 0) {
- self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
- self->ob_completion = value;
- Py_INCREF(value);
- rv = 1;
-#if !TARGET_API_MAC_CARBON
- } else if (strcmp(name, "interruptRoutine") == 0) {
- self->ob_spb.completionRoutine = NewSIInterruptUPP(SPB_interrupt);
- self->ob_interrupt = value;
- Py_INCREF(value);
- rv = 1;
-#endif
- }
- if ( rv ) return 0;
- else return -1;""")
-
- def outputGetattrHook(self):
- Output("""
- if (strcmp(name, "inRefNum") == 0)
- return Py_BuildValue("l", self->ob_spb.inRefNum);
- else if (strcmp(name, "count") == 0)
- return Py_BuildValue("l", self->ob_spb.count);
- else if (strcmp(name, "milliseconds") == 0)
- return Py_BuildValue("l", self->ob_spb.milliseconds);
- else if (strcmp(name, "error") == 0)
- return Py_BuildValue("h", self->ob_spb.error);""")
-
sndobject = SndObjectDefinition('SndChannel', 'SndCh', 'SndChannelPtr')