@@ -740,8 +740,11 @@ static int
740740symtable_lookup (struct symtable * st , PyObject * name )
741741{
742742 PyObject * o ;
743-
744- o = PyDict_GetItem (st -> st_cur -> ste_symbols , name );
743+ PyObject * mangled = _Py_Mangle (st -> st_private , name );
744+ if (!mangled )
745+ return 0 ;
746+ o = PyDict_GetItem (st -> st_cur -> ste_symbols , mangled );
747+ Py_DECREF (mangled );
745748 if (!o )
746749 return 0 ;
747750 return PyInt_AsLong (o );
@@ -753,49 +756,57 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag)
753756 PyObject * o ;
754757 PyObject * dict ;
755758 int val ;
759+ PyObject * mangled = _Py_Mangle (st -> st_private , name );
756760
761+ if (!mangled )
762+ return 0 ;
757763 dict = st -> st_cur -> ste_symbols ;
758- if ((o = PyDict_GetItem (dict , name ))) {
764+ if ((o = PyDict_GetItem (dict , mangled ))) {
759765 val = PyInt_AS_LONG (o );
760766 if ((flag & DEF_PARAM ) && (val & DEF_PARAM )) {
767+ /* Is it better to use 'mangled' or 'name' here? */
761768 PyErr_Format (PyExc_SyntaxError , DUPLICATE_ARGUMENT ,
762769 PyString_AsString (name ));
763770 PyErr_SyntaxLocation (st -> st_filename ,
764771 st -> st_cur -> ste_lineno );
765- return 0 ;
772+ goto error ;
766773 }
767774 val |= flag ;
768775 } else
769776 val = flag ;
770777 o = PyInt_FromLong (val );
771778 if (o == NULL )
772- return 0 ;
773- if (PyDict_SetItem (dict , name , o ) < 0 ) {
779+ goto error ;
780+ if (PyDict_SetItem (dict , mangled , o ) < 0 ) {
774781 Py_DECREF (o );
775- return 0 ;
782+ goto error ;
776783 }
777784 Py_DECREF (o );
778785
779786 if (flag & DEF_PARAM ) {
780- if (PyList_Append (st -> st_cur -> ste_varnames , name ) < 0 )
781- return 0 ;
787+ if (PyList_Append (st -> st_cur -> ste_varnames , mangled ) < 0 )
788+ goto error ;
782789 } else if (flag & DEF_GLOBAL ) {
783790 /* XXX need to update DEF_GLOBAL for other flags too;
784791 perhaps only DEF_FREE_GLOBAL */
785792 val = flag ;
786- if ((o = PyDict_GetItem (st -> st_global , name ))) {
793+ if ((o = PyDict_GetItem (st -> st_global , mangled ))) {
787794 val |= PyInt_AS_LONG (o );
788795 }
789796 o = PyInt_FromLong (val );
790797 if (o == NULL )
791- return 0 ;
792- if (PyDict_SetItem (st -> st_global , name , o ) < 0 ) {
798+ goto error ;
799+ if (PyDict_SetItem (st -> st_global , mangled , o ) < 0 ) {
793800 Py_DECREF (o );
794- return 0 ;
801+ goto error ;
795802 }
796803 Py_DECREF (o );
797804 }
798805 return 1 ;
806+
807+ error :
808+ Py_DECREF (mangled );
809+ return 0 ;
799810}
800811
801812/* VISIT, VISIT_SEQ and VIST_SEQ_TAIL take an ASDL type as their second argument.
@@ -849,17 +860,22 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
849860 if (!symtable_exit_block (st , s ))
850861 return 0 ;
851862 break ;
852- case ClassDef_kind :
863+ case ClassDef_kind : {
864+ PyObject * tmp ;
853865 if (!symtable_add_def (st , s -> v .ClassDef .name , DEF_LOCAL ))
854866 return 0 ;
855867 VISIT_SEQ (st , expr , s -> v .ClassDef .bases );
856868 if (!symtable_enter_block (st , s -> v .ClassDef .name , ClassBlock ,
857869 (void * )s , s -> lineno ))
858870 return 0 ;
871+ tmp = st -> st_private ;
872+ st -> st_private = s -> v .ClassDef .name ;
859873 VISIT_SEQ (st , stmt , s -> v .ClassDef .body );
874+ st -> st_private = tmp ;
860875 if (!symtable_exit_block (st , s ))
861876 return 0 ;
862877 break ;
878+ }
863879 case Return_kind :
864880 if (s -> v .Return .value )
865881 VISIT (st , expr , s -> v .Return .value );
0 commit comments