10000 Disable support for access statement · python/cpython@0dfcf75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0dfcf75

Browse files
committed
Disable support for access statement
1 parent aacdc9d commit 0dfcf75

File tree

9 files changed

+649
-633
lines changed
Filter options

9 files changed

+649
-633
lines changed

Grammar/Grammar

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ fplist: fpdef (',' fpdef)* [',']
2929

3030
stmt: simple_stmt | compound_stmt
3131
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
32-
small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt
32+
#small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt | access_stmt | exec_stmt
33+
small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | import_stmt | global_stmt | exec_stmt
3334
expr_stmt: testlist ('=' testlist)*
3435
# For assignments, additional restrictions enforced by the interpreter
3536
print_stmt: 'print' (test ',')* [test]
@@ -43,10 +44,10 @@ raise_stmt: 'raise' test [',' test [',' test]]
4344
import_stmt: 'import' dotted_name (',' dotted_name)* | 'from' dotted_name 'import' ('*' | NAME (',' NAME)*)
4445
dotted_name: NAME ('.' NAME)*
4546
global_stmt: 'global' NAME (',' NAME)*
46-
access_stmt: 'access' ('*' | NAME (',' NAME)*) ':' accesstype (',' accesstype)*
47-
accesstype: NAME+
48-
# accesstype should be ('public' | 'protected' | 'private') ['read'] ['write']
49-
# but can't be because that would create undesirable reserved words!
47+
#access_stmt: 'access' ('*' | NAME (',' NAME)*) ':' accesstype (',' accesstype)*
48+
#accesstype: NAME+
49+
## accesstype should be ('public' | 'protected' | 'private') ['read'] ['write']
50+
## but can't be because that would create undesirable reserved words!
5051
exec_stmt: 'exec' expr ['in' test [',' test]]
5152

5253
compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef

Include/accessobject.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2828
2929
******************************************************************/
3030

31+
/* This object type is no longer supported */
32+
33+
#ifdef SUPPORT_OBSOLETE_ACCESS
34+
3135
/* Access object interface */
3236

3337
/* Access mode bits (note similarity with UNIX permissions) */
@@ -60,6 +64,8 @@ int PyAccess_HasValue Py_PROTO((PyObject *));
6064

6165
extern DL_IMPORT(PyTypeObject) PyAnyNumber_Type, PyAnySequence_Type, PyAnyMapping_Type;
6266

67+
#endif /* !SUPPORT_OBSOLETE_ACCESS */
68+
6369
#ifdef __cplusplus
6470
}
6571
#endif

Include/graminit.h

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,36 @@
2121
#define import_stmt 276
2222
#define dotted_name 277
2323
#define global_stmt 278
24-
#define access_stmt 279
25-
#define accesstype 280
26-
#define exec_stmt 281
27-
#define compound_stmt 282
28-
#define if_stmt 283
29-
#define while_stmt 284
30-
#define for_stmt 285
31-
#define try_stmt 286
32-
#define except_clause 287
33-
#define suite 288
34-
#define test 289
35-
#define and_test 290
36-
#define not_test 291
37-
#define comparison 292
38-
#define comp_op 293
39-
#define expr 294
40-
#define xor_expr 295
41-
#define and_expr 296
42-
#define shift_expr 297
43-
#define arith_expr 298
44-
#define term 299
45-
#define factor 300
46-
#define power 301
47-
#define atom 302
48-
#define lambdef 303
49-
#define trailer 304
50-
#define subscriptlist 305
51-
#define subscript 306
52-
#define sliceop 307
53-
#define exprlist 308
54-
#define testlist 309
55-
#define dictmaker 310
56-
#define classdef 311
57-
#define arglist 312
58-
#define argument 313
24+
#define exec_stmt 279
25+
#define compound_stmt 280
26+
#define if_stmt 281
27+
#define while_stmt 282
28+
#define for_stmt 283
29+
#define try_stmt 284
30+
#define except_clause 285
31+
#define suite 286
32+
#define test 287
33+
#define and_test 288
34+
#define not_test 289
35+
#define comparison 290
36+
#define comp_op 291
37+
#define expr 292
38+
#define xor_expr 293
39+
#define and_expr 294
40+
#define shift_expr 295
41+
#define arith_expr 296
42+
#define term 297
43+
#define factor 298
44+
#define power 299
45+
#define atom 300
46+
#define lambdef 301
47+
#define trailer 302
48+
#define subscriptlist 303
49+
#define subscript 304
50+
#define sliceop 305
51+
#define exprlist 306
52+
#define testlist 307
53+
#define dictmaker 308
54+
#define classdef 309
55+
#define arglist 310
56+
#define argument 311

Objects/accessobject.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2222
2323
******************************************************************/
2424

25+
#ifdef SUPPORT_OBSOLETE_ACCESS /* This object type is no longer supported */
26+
2527
/* Access object implementation */
2628

2729
/* XXX TO DO LIST
@@ -358,3 +360,5 @@ typeobject Anymappingtype = {
358360
0, /*ob_size*/
359361
"*mapping*", /*tp_name*/
360362
};
363+
364+
#endif /* SUPPORT_OBSOLETE_ACCESS */

Objects/classobject.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ newclassobject(bases, dict, name)
3737
object *dict;
3838
object *name; /* String; NULL if unknown */
3939
{
40+
#ifdef SUPPORT_OBSOLETE_ACCESS
4041
int pos;
4142
object *key, *value;
43+
#endif
4244
classobject *op, *dummy;
4345
static object *getattrstr, *setattrstr, *delattrstr;
4446
if (dictlookup(dict, "__doc__") == NULL) {
@@ -73,11 +75,13 @@ newclassobject(bases, dict, name)
7375
XINCREF(op->cl_getattr);
7476
XINCREF(op->cl_setattr);
7577
XINCREF(op->cl_delattr);
78+
#ifdef SUPPORT_OBSOLETE_ACCESS
7679
pos = 0;
7780
while (mappinggetnext(dict, &pos, &key, &value)) {
7881
if (is_accessobject(value))
7982
setaccessowner(value, (object *)op);
8083
}
84+
#endif
8185
return (object *) op;
8286
}
8387

@@ -151,12 +155,14 @@ class_getattr(op, name)
151155
err_setval(AttributeError, name);
152156
return NULL;
153157
}
158+
#ifdef SUPPORT_OBSOLETE_ACCESS
154159
if (is_accessobject(v)) {
155160
v = getaccessvalue(v, getowner());
156161
if (v == NULL)
157162
return NULL;
158163
}
159164
else
165+
#endif
160166
INCREF(v);
161167
if (is_funcobject(v)) {
162168
object *w = newinstancemethodobject(v, (object *)NULL,
@@ -173,7 +179,9 @@ class_setattr(op, name, v)
173179
object *name;
174180
object *v;
175181
{
182+
#ifdef SUPPORT_OBSOLETE_ACCESS
176183
object *ac;
184+
#endif
177185
char *sname = getstringvalue(name);
178186
if (sname[0] == '_' && sname[1] == '_') {
179187
int n = getstringsize(name);
@@ -187,9 +195,11 @@ class_setattr(op, name, v)
187195
"classes are read-only in restricted mode");
188196
return -1;
189197
}
198+
#ifdef SUPPORT_OBSOLETE_ACCESS
190199
ac = mappinglookup(op->cl_dict, name);
191200
if (ac != NULL && is_accessobject(ac))
192201
return setaccessvalue(ac, getowner(), v);
202+
#endif
193203
if (v == NULL) {
194204
int rv = mappingremove(op->cl_dict, name);
195205
if (rv < 0)
@@ -260,6 +270,7 @@ issubclass(class, base)
260270

261271
/* Instance objects */
262272

273+
#ifdef SUPPORT_OBSOLETE_ACCESS
263274
static int
264275
addaccess(class, inst)
265276
classobject *class;
@@ -295,6 +306,7 @@ addaccess(class, inst)
295306
}
296307
return 0;
297308
}
309+
#endif
298310

299311
object *
300312
newinstanceobject(class, arg, kw)
@@ -315,8 +327,11 @@ newinstanceobject(class, arg, kw)
315327
INCREF(class);
316328
inst->in_class = (classobject *)class;
317329
inst->in_dict = newdictobject();
318-
if (inst->in_dict == NULL ||
319-
addaccess((classobject *)class, inst) != 0) {
330+
if (inst->in_dict == NULL
331+
#ifdef SUPPORT_OBSOLETE_ACCESS
332+
|| addaccess((classobject *)class, inst) != 0
333+
#endif
334+
) {
320335
DECREF(inst);
321336
return NULL;
322337
}
@@ -382,8 +397,12 @@ instance_dealloc(inst)
382397
if ((del = instance_getattr1(inst, delstr)) != NULL) {
383398
object *res = call_object(del, (object *)NULL);
384399
DECREF(del);
385-
XDECREF(res);
386-
/* XXX If __del__ raised an exception, it is ignored! */
400+
if (res == NULL) {
401+
writestring("exception in __del__ method ignored\n",
402+
sysget("stdout"));
403+
}
404+
else
405+
DECREF(res);
387406
}
388407
/* Restore the saved exception and undo the temporary revival */
389408
err_restore(error_type, error_value, error_traceback);
@@ -438,12 +457,14 @@ instance_getattr1(inst, name)
438457
return NULL;
439458
}
440459
}
460+
#ifdef SUPPORT_OBSOLETE_ACCESS
441461
if (is_accessobject(v)) {
442462
v = getaccessvalue(v, getowner());
443463
if (v == NULL)
444464
return NULL;
445465
}
446466
else
467+
#endif
447468
INCREF(v);
448469
if (class != NULL) {
449470
if (is_funcobject(v)) {
@@ -492,10 +513,12 @@ instance_setattr1(inst, name, v)
492513
object *name;
493514
object *v;
494515
{
516+
#ifdef SUPPORT_OBSOLETE_ACCESS
495517
object *ac;
496518
ac = mappinglookup(inst->in_dict, name);
497519
if (ac != NULL && is_accessobject(ac))
498520
return setaccessvalue(ac, getowner(), v);
521+
#endif
499522
if (v == NULL) {
500523
int rv = mappingremove(inst->in_dict, name);
501524
if (rv < 0)

Objects/moduleobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ module_getattr(m, name)
127127
if (res == NULL)
128128
err_setstr(AttributeError, name);
129129
else {
130+
#ifdef SUPPORT_OBSOLETE_ACCESS
130131
if (is_accessobject(res))
131132
res = getaccessvalue(res, getglobals());
132133
else
134+
#endif
133135
INCREF(res);
134136
}
135137
return res;
@@ -141,14 +143,18 @@ module_setattr(m, name, v)
141143
char *name;
142144
object *v;
143145
{
146+
#ifdef SUPPORT_OBSOLETE_ACCESS
144147
object *ac;
148+
#endif
145149
if (name[0] == '_' && strcmp(name, "__dict__") == 0) {
146150
err_setstr(TypeError, "read-only special attribute");
147151
return -1;
148152
}
153+
#ifdef SUPPORT_OBSOLETE_ACCESS
149154
ac = dictlookup(m->md_dict, name);
150155
if (ac != NULL && is_accessobject(ac))
151156
return setaccessvalue(ac, getglobals(), v);
157+
#endif
152158
if (v == NULL) {
153159
int rv = dictremove(m->md_dict, name);
154160
if (rv < 0)

0 commit comments

Comments
 (0)
0