summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/res
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/res
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/res')
-rw-r--r--Mac/Modules/res/_Resmodule.c114
-rw-r--r--Mac/Modules/res/ressupport.py92
2 files changed, 111 insertions, 95 deletions
diff --git a/Mac/Modules/res/_Resmodule.c b/Mac/Modules/res/_Resmodule.c
index 421b9d7..1884230 100644
--- a/Mac/Modules/res/_Resmodule.c
+++ b/Mac/Modules/res/_Resmodule.c
@@ -551,54 +551,61 @@ static PyMethodDef ResObj_methods[] = {
{NULL, NULL, 0}
};
-PyMethodChain ResObj_chain = { ResObj_methods, NULL };
-
-static PyObject *ResObj_getattr(ResourceObject *self, char *name)
-{
-
- if (strcmp(name, "size") == 0)
- return PyInt_FromLong(GetHandleSize(self->ob_itself));
- if (strcmp(name, "data") == 0) {
- PyObject *res;
- char state;
- state = HGetState(self->ob_itself);
- HLock(self->ob_itself);
- res = PyString_FromStringAndSize(
- *self->ob_itself,
- GetHandleSize(self->ob_itself));
- HUnlock(self->ob_itself);
- HSetState(self->ob_itself, state);
- return res;
- }
- if (strcmp(name, "__members__") == 0)
- return Py_BuildValue("[ss]", "data", "size");
-
- return Py_FindMethodInChain(&ResObj_chain, (PyObject *)self, name);
+static PyObject *ResObj_get_data(ResourceObject *self, void *closure)
+{
+
+ PyObject *res;
+ char state;
+
+ state = HGetState(self->ob_itself);
+ HLock(self->ob_itself);
+ res = PyString_FromStringAndSize(
+ *self->ob_itself,
+ GetHandleSize(self->ob_itself));
+ HUnlock(self->ob_itself);
+ HSetState(self->ob_itself, state);
+ return res;
+
+}
+
+static int ResObj_set_data(ResourceObject *self, PyObject *v, void *closure)
+{
+
+ char *data;
+ long size;
+
+ if ( v == NULL )
+ return -1;
+ if ( !PyString_Check(v) )
+ return -1;
+ size = PyString_Size(v);
+ data = PyString_AsString(v);
+ /* XXXX Do I need the GetState/SetState calls? */
+ SetHandleSize(self->ob_itself, size);
+ if ( MemError())
+ return -1;
+ HLock(self->ob_itself);
+ memcpy((char *)*self->ob_itself, data, size);
+ HUnlock(self->ob_itself);
+ /* XXXX Should I do the Changed call immedeately? */
+ return 0;
+
+ return 0;
}
-static int
-ResObj_setattr(ResourceObject *self, char *name, PyObject *value)
+static PyObject *ResObj_get_size(ResourceObject *self, void *closure)
{
- char *data;
- long size;
-
- if (strcmp(name, "data") != 0 || value == NULL )
- return -1;
- if ( !PyString_Check(value) )
- return -1;
- size = PyString_Size(value);
- data = PyString_AsString(value);
- /* XXXX Do I need the GetState/SetState calls? */
- SetHandleSize(self->ob_itself, size);
- if ( MemError())
- return -1;
- HLock(self->ob_itself);
- memcpy((char *)*self->ob_itself, data, size);
- HUnlock(self->ob_itself);
- /* XXXX Should I do the Changed call immedeately? */
- return 0;
+ return PyInt_FromLong(GetHandleSize(self->ob_itself));
}
+#define ResObj_set_size NULL
+
+static PyGetSetDef ResObj_getsetlist[] = {
+ {"data", (getter)ResObj_get_data, (setter)ResObj_set_data, "The resource data"},
+ {"size", (getter)ResObj_get_size, (setter)ResObj_set_size, "The length of the resource data"},
+ {NULL, NULL, NULL, NULL},
+};
+
#define ResObj_compare NULL
@@ -615,14 +622,31 @@ PyTypeObject Resource_Type = {
/* methods */
(destructor) ResObj_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- (getattrfunc) ResObj_getattr, /*tp_getattr*/
- (setattrfunc) ResObj_setattr, /*tp_setattr*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
(cmpfunc) ResObj_compare, /*tp_compare*/
(reprfunc) ResObj_repr, /*tp_repr*/
(PyNumberMethods *)0, /* tp_as_number */
(PySequenceMethods *)0, /* tp_as_sequence */
(PyMappingMethods *)0, /* tp_as_mapping */
(hashfunc) ResObj_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*/
+ ResObj_methods, /* tp_methods */
+ 0, /*outputHook_tp_members*/
+ ResObj_getsetlist, /*tp_getset*/
+ 0, /*outputHook_tp_base*/
};
/* -------------------- End object type Resource -------------------- */
diff --git a/Mac/Modules/res/ressupport.py b/Mac/Modules/res/ressupport.py
index c0bfc8a..8f6cb8d 100644
--- a/Mac/Modules/res/ressupport.py
+++ b/Mac/Modules/res/ressupport.py
@@ -100,51 +100,49 @@ initstuff = initstuff + """
module = MacModule('_Res', 'Res', includestuff, finalstuff, initstuff)
-getattrHookCode = """
-if (strcmp(name, "size") == 0)
- return PyInt_FromLong(GetHandleSize(self->ob_itself));
-if (strcmp(name, "data") == 0) {
- PyObject *res;
- char state;
- state = HGetState(self->ob_itself);
- HLock(self->ob_itself);
- res = PyString_FromStringAndSize(
- *self->ob_itself,
- GetHandleSize(self->ob_itself));
- HUnlock(self->ob_itself);
- HSetState(self->ob_itself, state);
- return res;
-}
-if (strcmp(name, "__members__") == 0)
- return Py_BuildValue("[ss]", "data", "size");
-"""
-
-setattrCode = """
-static int
-ResObj_setattr(ResourceObject *self, char *name, PyObject *value)
-{
- char *data;
- long size;
+class ResDefinition(PEP252Mixin, GlobalObjectDefinition):
+ getsetlist = [
+ ('data',
+ """
+ PyObject *res;
+ char state;
+
+ state = HGetState(self->ob_itself);
+ HLock(self->ob_itself);
+ res = PyString_FromStringAndSize(
+ *self->ob_itself,
+ GetHandleSize(self->ob_itself));
+ HUnlock(self->ob_itself);
+ HSetState(self->ob_itself, state);
+ return res;
+ """,
+ """
+ char *data;
+ long size;
- if (strcmp(name, "data") != 0 || value == NULL )
- return -1;
- if ( !PyString_Check(value) )
- return -1;
- size = PyString_Size(value);
- data = PyString_AsString(value);
- /* XXXX Do I need the GetState/SetState calls? */
- SetHandleSize(self->ob_itself, size);
- if ( MemError())
- return -1;
- HLock(self->ob_itself);
- memcpy((char *)*self->ob_itself, data, size);
- HUnlock(self->ob_itself);
- /* XXXX Should I do the Changed call immedeately? */
- return 0;
-}
-"""
-
-class ResDefinition(GlobalObjectDefinition):
+ if ( v == NULL )
+ return -1;
+ if ( !PyString_Check(v) )
+ return -1;
+ size = PyString_Size(v);
+ data = PyString_AsString(v);
+ /* XXXX Do I need the GetState/SetState calls? */
+ SetHandleSize(self->ob_itself, size);
+ if ( MemError())
+ return -1;
+ HLock(self->ob_itself);
+ memcpy((char *)*self->ob_itself, data, size);
+ HUnlock(self->ob_itself);
+ /* XXXX Should I do the Changed call immedeately? */
+ return 0;
+ """,
+ 'The resource data'
+ ), (
+ 'size',
+ 'return PyInt_FromLong(GetHandleSize(self->ob_itself));',
+ None,
+ 'The length of the resource data'
+ )]
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
@@ -163,12 +161,6 @@ class ResDefinition(GlobalObjectDefinition):
Output("PyErr_Clear();")
OutRbrace()
- def outputGetattrHook(self):
- Output(getattrHookCode)
-
- def outputSetattr(self):
- Output(setattrCode)
-
def outputStructMembers(self):
GlobalObjectDefinition.outputStructMembers(self)
Output("void (*ob_freeit)(%s ptr);", self.itselftype)