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

Skip to content

Commit 81daa32

Browse files
committed
Access checks now work, at least for instance data (not for methods
yet). The class is now passed to eval_code and stored in the current frame. It is also stored in instance method objects. An "unbound" instance method is now returned when a function is retrieved through "classname.funcname", which when called passes the class to eval_code.
1 parent 2583165 commit 81daa32

14 files changed

Lines changed: 655 additions & 150 deletions

Include/accessobject.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/***********************************************************
2+
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
3+
Amsterdam, The Netherlands.
4+
5+
All Rights Reserved
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both that copyright notice and this permission notice appear in
11+
supporting documentation, and that the names of Stichting Mathematisch
12+
Centrum or CWI not be used in advertising or publicity pertaining to
13+
distribution of the software without specific, written prior permission.
14+
15+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/
24+
25+
/* Access object interface */
26+
27+
/* Access mode bits (note similarity with UNIX permissions) */
28+
#define AC_R 0444
29+
#define AC_W 0222
30+
31+
#define AC_PRIVATE 0700
32+
#define AC_R_PRIVATE 0400
33+
#define AC_W_PRIVATE 0200
34+
35+
#define AC_PROTECTED 0070
36+
#define AC_R_PROTECTED 0040
37+
#define AC_W_PROTECTED 0020
38+
39+
#define AC_PUBLIC 0007
40+
#define AC_R_PUBLIC 0004
41+
#define AC_W_PUBLIC 0002
42+
43+
extern typeobject Accesstype;
44+
45+
#define is_accessobject(v) ((v)->ob_type == &Accesstype)
46+
47+
object *newaccessobject PROTO((object *, object *, typeobject *, int));
48+
object *getaccessvalue PROTO((object *, object *));
49+
int setaccessvalue PROTO((object *, object *, object *));
50+
51+
void setaccessowner PROTO((object *, object *));
52+
object *cloneaccessobject PROTO((object *));
53+
54+
extern typeobject Anynumbertype, Anysequencetype, Anymappingtype;

Include/ceval.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ object *call_object PROTO((object *, object *));
2828

2929
object *getglobals PROTO((void));
3030
object *getlocals PROTO((void));
31+
object *getclass PROTO((void));
3132
void mergelocals PROTO((void));
3233

3334
void printtraceback PROTO((object *));

Include/classobject.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ It should be possible to use other object types as base classes,
3030
but currently it isn't. We'll see if we can fix that later, sigh...
3131
*/
3232

33+
typedef struct {
34+
OB_HEAD
35+
object *cl_bases; /* A tuple of class objects */
36+
object *cl_dict; /* A dictionary */
37+
object *cl_name; /* A string */
38+
} classobject;
39+
3340
extern typeobject Classtype, Instancetype, Instancemethodtype;
3441

3542
#define is_classobject(op) ((op)->ob_type == &Classtype)
@@ -38,9 +45,12 @@ extern typeobject Classtype, Instancetype, Instancemethodtype;
3845

3946
extern object *newclassobject PROTO((object *, object *, object *));
4047
extern object *newinstanceobject PROTO((object *, object *));
41-
extern object *newinstancemethodobject PROTO((object *, object *));
48+
extern object *newinstancemethodobject PROTO((object *, object *, object *));
4249

4350
extern object *instancemethodgetfunc PROTO((object *));
4451
extern object *instancemethodgetself PROTO((object *));
52+
extern object *instancemethodgetclass PROTO((object *));
4553

4654
extern object *instance_convert PROTO((object *, char *));
55+
56+
extern int issubclass PROTO((object *, object *));

Include/eval.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2424

2525
/* Interface to execute compiled code */
2626

27-
object *eval_code PROTO((codeobject *, object *, object *, object *));
27+
object *eval_code
28+
PROTO((codeobject *, object *, object *, object *, object *));

Include/frameobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef struct _frame {
3636
codeobject *f_code; /* code segment */
3737
object *f_globals; /* global symbol table (dictobject) */
3838
object *f_locals; /* local symbol table (dictobject) */
39+
object *f_class; /* class context (classobject or NULL) */
3940
object *f_fastlocals; /* fast local variables (listobject) */
4041
object *f_localmap; /* local variable names (dictobject) */
4142
object **f_valuestack; /* malloc'ed array */
@@ -55,7 +56,7 @@ extern typeobject Frametype;
5556
#define is_frameobject(op) ((op)->ob_type == &Frametype)
5657

5758
frameobject * newframeobject PROTO(
58-
(frameobject *, codeobject *, object *, object *, int, int));
59+
(frameobject *, codeobject *, object *, object *, object *, int, int));
5960

6061

6162
/* The rest of the interface is specific for frame objects */

0 commit comments

Comments
 (0)