@@ -87,7 +87,7 @@ static int import_from PROTO((object *, object *, object *));
8787static object * build_class PROTO ((object * , object * , object * ) );
8888static void locals_2_fast PROTO ((frameobject * , int ) );
8989static void fast_2_locals PROTO ((frameobject * ) );
90- static int access_statement PROTO ((object * , int , frameobject * ) );
90+ static int access_statement PROTO ((object * , object * , frameobject * ) );
9191
9292
9393/* Pointer to current frame, used to link new frames to */
@@ -184,7 +184,8 @@ eval_code(co, globals, locals, class, arg)
184184 object * trace = NULL ; /* Trace function or NULL */
185185 object * retval ; /* Return value iff why == WHY_RETURN */
186186 char * name ; /* Name used by some instructions */
187- int needmerge = 0 ;
187+ int needmerge = 0 ; /* Set if need to merge locals back at end */
188+ int defmode = 0 ; /* Default access mode for new variables */
188189#ifdef LLTRACE
189190 int lltrace ;
190191#endif
@@ -760,7 +761,22 @@ eval_code(co, globals, locals, class, arg)
760761 w = GETNAMEV (oparg );
761762 v = POP ();
762763 u = dict2lookup (f -> f_locals , w );
763- if (u != NULL && is_accessobject (u )) {
764+ if (u == NULL ) {
765+ if (defmode != 0 ) {
766+ if (v != None )
767+ u = (object * )v -> ob_type ;
768+ else
769+ u = NULL ;
770+ x = newaccessobject (v , class ,
771+ (typeobject * )u ,
772+ defmode );
773+ DECREF (v );
774+ if (x == NULL )
775+ break ;
776+ v = x ;
777+ }
778+ }
779+ else if (is_accessobject (u )) {
764780 err = setaccessvalue (u , class , v );
765781 DECREF (v );
766782 break ;
@@ -1190,7 +1206,10 @@ eval_code(co, globals, locals, class, arg)
11901206 case ACCESS_MODE :
11911207 v = POP ();
11921208 w = GETNAMEV (oparg );
1193- err = access_statement (w , (int )getintvalue (v ), f );
1209+ if (getstringvalue (w )[0 ] == '*' )
1210+ defmode = getintvalue (v );
1211+ else
1212+ err = access_statement (w , v , f );
11941213 DECREF (v );
11951214 break ;
11961215
@@ -1995,7 +2014,28 @@ call_function(func, arg)
19952014 object * self = instancemethodgetself (func );
19962015 class = instancemethodgetclass (func );
19972016 func = instancemethodgetfunc (func );
1998- if (self != NULL ) {
2017+ if (self == NULL ) {
2018+ /* Unbound methods must be called with an instance of
2019+ the class (or a derived class) as first argument */
2020+ if (arg != NULL && is_tupleobject (arg ) &&
2021+ gettuplesize (arg ) >= 1 ) {
2022+ self = gettupleitem (arg , 0 );
2023+ if (self != NULL &&
2024+ is_instanceobject (self ) &&
2025+ issubclass ((object * )
2026+ (((instanceobject * )self )-> in_class ),
2027+ class ))
2028+ /* self = self */ ;
2029+ else
2030+ self = NULL ;
2031+ }
2032+ if (self == NULL ) {
2033+ err_setstr (TypeError ,
2034+ "unbound method must be called with class instance argument" );
2035+ return NULL ;
2036+ }
2037+ }
2038+ else {
19992039 int argcount ;
20002040 if (arg == NULL )
20012041 argcount = 0 ;
@@ -2380,11 +2420,12 @@ build_class(methods, bases, name)
23802420}
23812421
23822422static int
2383- access_statement (name , mode , f )
2423+ access_statement (name , vmode , f )
23842424 object * name ;
2385- int mode ;
2425+ object * vmode ;
23862426 frameobject * f ;
23872427{
2428+ int mode = getintvalue (vmode );
23882429 object * value , * ac ;
23892430 typeobject * type ;
23902431 int fastind , ret ;
@@ -2415,7 +2456,7 @@ access_statement(name, mode, f)
24152456 type = value -> ob_type ;
24162457 else
24172458 type = NULL ;
2418- ac = newaccessobject (value , ( object * ) NULL , type , mode );
2459+ ac = newaccessobject (value , f -> f_class , type , mode );
24192460 if (ac == NULL )
24202461 return -1 ;
24212462 if (fastind >= 0 )
0 commit comments