Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b5074b

Browse files
committed
added acces to the cellSize field, rewrote setattr code
1 parent b26fbc6 commit 3b5074b

2 files changed

Lines changed: 32 additions & 24 deletions

File tree

Mac/Modules/list/_Listmodule.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,12 @@ PyMethodChain ListObj_chain = { ListObj_methods, NULL };
607607
static PyObject *ListObj_getattr(ListObject *self, char *name)
608608
{
609609
{
610-
/* XXXX Should we HLock() here?? */
611610
if ( strcmp(name, "listFlags") == 0 )
612611
return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff);
613612
if ( strcmp(name, "selFlags") == 0 )
614613
return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff);
614+
if ( strcmp(name, "cellSize") == 0 )
615+
return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->cellSize);
615616
}
616617
return Py_FindMethodInChain(&ListObj_chain, (PyObject *)self, name);
617618
}
@@ -620,19 +621,22 @@ static int
620621
ListObj_setattr(ListObject *self, char *name, PyObject *value)
621622
{
622623
long intval;
623-
624-
if ( value == NULL || !PyInt_Check(value) )
624+
int err = 0;
625+
626+
if ( value == NULL ) {
627+
PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
625628
return -1;
626-
intval = PyInt_AsLong(value);
627-
if (strcmp(name, "listFlags") == 0 ) {
628-
SetListFlags(self->ob_itself, intval);
629-
return 0;
630-
}
631-
if (strcmp(name, "selFlags") == 0 ) {
632-
SetListSelectionFlags(self->ob_itself, intval);
633-
return 0;
634629
}
635-
return -1;
630+
if (strcmp(name, "listFlags") == 0 )
631+
err = PyArg_Parse(value, "B", &(*self->ob_itself)->listFlags);
632+
else if (strcmp(name, "selFlags") == 0 )
633+
err = PyArg_Parse(value, "B", &(*self->ob_itself)->selFlags);
634+
else if (strcmp(name, "cellSize") == 0 )
635+
err = PyArg_Parse(value, "O&", PyMac_GetPoint, &(*self->ob_itself)->cellSize);
636+
else
637+
PyErr_SetString(PyExc_AttributeError, "No such attribute");
638+
if (err) return 0;
639+
else return -1;
636640
}
637641

638642

Mac/Modules/list/listsupport.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,31 +137,35 @@ def parseArgumentList(self, args):
137137
self.argumentList.append(self.itself)
138138

139139
getattrHookCode = """{
140-
/* XXXX Should we HLock() here?? */
141140
if ( strcmp(name, "listFlags") == 0 )
142141
return Py_BuildValue("l", (long)GetListFlags(self->ob_itself) & 0xff);
143142
if ( strcmp(name, "selFlags") == 0 )
144143
return Py_BuildValue("l", (long)GetListSelectionFlags(self->ob_itself) & 0xff);
144+
if ( strcmp(name, "cellSize") == 0 )
145+
return Py_BuildValue("O&", PyMac_BuildPoint, (*self->ob_itself)->cellSize);
145146
}"""
146147

147148
setattrCode = """
148149
static int
149150
ListObj_setattr(ListObject *self, char *name, PyObject *value)
150151
{
151152
long intval;
152-
153-
if ( value == NULL || !PyInt_Check(value) )
153+
int err = 0;
154+
155+
if ( value == NULL ) {
156+
PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute");
154157
return -1;
155-
intval = PyInt_AsLong(value);
156-
if (strcmp(name, "listFlags") == 0 ) {
157-
SetListFlags(self->ob_itself, intval);
158-
return 0;
159-
}
160-
if (strcmp(name, "selFlags") == 0 ) {
161-
SetListSelectionFlags(self->ob_itself, intval);
162-
return 0;
163158
}
164-
return -1;
159+
if (strcmp(name, "listFlags") == 0 )
160+
err = PyArg_Parse(value, "B", &(*self->ob_itself)->listFlags);
161+
else if (strcmp(name, "selFlags") == 0 )
162+
err = PyArg_Parse(value, "B", &(*self->ob_itself)->selFlags);
163+
else if (strcmp(name, "cellSize") == 0 )
164+
err = PyArg_Parse(value, "O&", PyMac_GetPoint, &(*self->ob_itself)->cellSize);
165+
else
166+
PyErr_SetString(PyExc_AttributeError, "No such attribute");
167+
if (err) return 0;
168+
else return -1;
165169
}
166170
"""
167171

0 commit comments

Comments
 (0)