Mailing List Archive

CVS: python/dist/src/Objects funcobject.c,2.37.4.2,2.37.4.3
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv5915

Modified Files:
Tag: descr-branch
funcobject.c
Log Message:
Use PyGeneric_{Get,Set}Attr. We still need wrappers for the peculiar
additional constraints on the type of some special attributes and the
tests for restricted execution.

(Note that the restricted access test in func_getattro doesn't make
much sense. In restricted mode, it disallows getting attributes whose
name *doesn't* start with underscore -- this forbids access to most
user attributes, but allows (writable!) access to the __dict__
attribute. This was probably never reviewed when user attributes were
added. Unclear what should be done, so for now I'm leaving it in.)


Index: funcobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/funcobject.c,v
retrieving revision 2.37.4.2
retrieving revision 2.37.4.3
diff -C2 -r2.37.4.2 -r2.37.4.3
*** funcobject.c 2001/05/06 02:31:13 2.37.4.2
--- funcobject.c 2001/05/11 20:45:22 2.37.4.3
***************
*** 143,149 ****

static PyObject *
! func_getattro(PyFunctionObject *op, PyObject *name)
{
- PyObject *rtn;
char *sname = PyString_AsString(name);

--- 143,148 ----

static PyObject *
! func_getattro(PyObject *op, PyObject *name)
{
char *sname = PyString_AsString(name);

***************
*** 154,176 ****
}

! /* no API for PyMember_HasAttr() */
! rtn = PyMember_Get((char *)op, func_memberlist, sname);
!
! if (rtn == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
! PyErr_Clear();
! if (op->func_dict != NULL) {
! rtn = PyDict_GetItem(op->func_dict, name);
! Py_XINCREF(rtn);
! }
! if (rtn == NULL)
! PyErr_SetObject(PyExc_AttributeError, name);
! }
! return rtn;
}

static int
! func_setattro(PyFunctionObject *op, PyObject *name, PyObject *value)
{
- int rtn;
char *sname = PyString_AsString(name);

--- 153,162 ----
}

! return PyGeneric_GetAttr(op, name);
}

static int
! func_setattro(PyObject *op, PyObject *name, PyObject *value)
{
char *sname = PyString_AsString(name);

***************
*** 218,246 ****
}

! rtn = PyMember_Set((char *)op, func_memberlist, sname, value);
! if (rtn < 0 && PyErr_ExceptionMatches(PyExc_AttributeError)) {
! PyErr_Clear();
! if (op->func_dict == NULL) {
! /* don't create the dict if we're deleting an
! * attribute. In that case, we know we'll get an
! * AttributeError.
! */
! if (value == NULL) {
! PyErr_SetString(PyExc_AttributeError, sname);
! return -1;
! }
! op->func_dict = PyDict_New();
! if (op->func_dict == NULL)
! return -1;
! }
! if (value == NULL)
! rtn = PyDict_DelItem(op->func_dict, name);
! else
! rtn = PyDict_SetItem(op->func_dict, name, value);
! /* transform KeyError into AttributeError */
! if (rtn < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
! PyErr_SetString(PyExc_AttributeError, sname);
! }
! return rtn;
}

--- 204,208 ----
}

! return PyGeneric_SetAttr(op, name, value);
}

***************
*** 397,402 ****
function_call, /* tp_call */
0, /* tp_str */
! (getattrofunc)func_getattro, /* tp_getattro */
! (setattrofunc)func_setattro, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
--- 359,364 ----
function_call, /* tp_call */
0, /* tp_str */
! func_getattro, /* tp_getattro */
! func_setattro, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
***************
*** 409,413 ****
0, /* tp_iternext */
0, /* tp_methods */
! 0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
--- 371,375 ----
0, /* tp_iternext */
0, /* tp_methods */
! func_memberlist, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
***************
*** 415,417 ****
--- 377,381 ----
func_descr_get, /* tp_descr_get */
0, /* tp_descr_set */
+ 0, /* tp_construct */
+ offsetof(PyFunctionObject, func_dict), /* tp_dictoffset */
};