[Python-checkins] CVS: python/dist/src/Python structmember.c,2.19,2.20

Guido van Rossum gvanrossum@users.sourceforge.net
2001年9月17日 12:28:10 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv23085/Python
Modified Files:
	structmember.c 
Log Message:
Add support for restricting access based on restricted execution mode.
Renamed the 'readonly' field to 'flags' and defined some new flag
bits: READ_RESTRICTED and WRITE_RESTRICTED, as well as a shortcut
RESTRICTED that means both.
Index: structmember.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/structmember.c,v
retrieving revision 2.19
retrieving revision 2.20
diff -C2 -d -r2.19 -r2.20
*** structmember.c	2001年01月27日 06:20:08	2.19
--- structmember.c	2001年09月17日 19:28:08	2.20
***************
*** 39,42 ****
--- 39,48 ----
 		if (strcmp(l->name, name) == 0) {
 			PyObject *v;
+ 			if ((l->flags & READ_RESTRICTED) &&
+ 			 PyEval_GetRestricted()) {
+ 				PyErr_SetString(PyExc_RuntimeError,
+ 						"restricted attribute");
+ 				return NULL;
+ 			}
 			addr += l->offset;
 			switch (l->type) {
***************
*** 134,146 ****
 	for (l = mlist; l->name != NULL; l++) {
 		if (strcmp(l->name, name) == 0) {
 #ifdef macintosh
! 			if (l->readonly || l->type == T_STRING ||
! 			 l->type == T_PSTRING)
 			{
- #else
- 			if (l->readonly || l->type == T_STRING ) {
- #endif /* macintosh */
 				PyErr_SetString(PyExc_TypeError,
 						"readonly attribute");
 				return -1;
 			}
--- 140,157 ----
 	for (l = mlist; l->name != NULL; l++) {
 		if (strcmp(l->name, name) == 0) {
+ 			if ((l->flags & READONLY) || l->type == T_STRING
 #ifdef macintosh
! 			 || l->type == T_PSTRING
! #endif
! 				)
 			{
 				PyErr_SetString(PyExc_TypeError,
 						"readonly attribute");
+ 				return -1;
+ 			}
+ 			if ((l->flags & WRITE_RESTRICTED) &&
+ 			 PyEval_GetRestricted()) {
+ 				PyErr_SetString(PyExc_RuntimeError,
+ 						"restricted attribute");
 				return -1;
 			}

AltStyle によって変換されたページ (->オリジナル) /