Commits

Amaury Forgeot d'Arc committed a79459e

Add space argument to all instances of w_obj.getdict()

  • Participants
  • Parent commits 93ae975
  • Branches getdict-signature

Comments (0)

Files changed (21)

File pypy/module/__builtin__/interp_classobj.py

             w_inst = cache.cls_without_del(space, self)
         return w_inst
 
-    def getdict(self):
+    def getdict(self, space):
         return self.w_dict
 
     def setdict(self, space, w_dict):
         name = space.str_w(w_attr)
         if len(name) >= 8 and name[0] == '_':
             if name == "__dict__":
-                return self.getdict()
+                return self.getdict(space)
             elif name == "__class__":
                 return self.w_class
         return self.getattr(space, name)

File pypy/module/__builtin__/test/test_classobj.py

             py.test.skip("can only be run on py.py")
         def is_strdict(space, w_class):
             from pypy.objspace.std.dictmultiobject import StrDictImplementation
-            w_d = w_class.getdict()
+            w_d = w_class.getdict(space)
             return space.wrap(isinstance(w_d, StrDictImplementation) and w_d.r_dict_content is None)
 
         cls.w_is_strdict = cls.space.wrap(gateway.interp2app(is_strdict))

File pypy/module/_io/interp_bytesio.py

         return space.newtuple([
             w_content,
             space.wrap(self.pos),
-            self.getdict()])
+            self.getdict(space)])
 
     def setstate_w(self, space, w_state):
         self._check_closed(space)
                 "position value cannot be negative"))
         self.pos = pos
         if not space.is_w(w_dict, space.w_None):
-            space.call_method(self.getdict(), "update", w_dict)
+            space.call_method(self.getdict(space), "update", w_dict)
 
 W_BytesIO.typedef = TypeDef(
     'BytesIO', W_BufferedIOBase.typedef,

File pypy/module/_io/interp_iobase.py

         self.w_dict = space.newdict()
         self.__IOBase_closed = False
 
-    def getdict(self):
+    def getdict(self, space):
         return self.w_dict
 
     def _closed(self, space):

File pypy/module/cpyext/eval.py

         w_globals = caller.w_globals
         w_builtins = space.getitem(w_globals, space.wrap('__builtins__'))
         if not space.isinstance_w(w_builtins, space.w_dict):
-            w_builtins = w_builtins.getdict()
+            w_builtins = w_builtins.getdict(space)
     else:
-        w_builtins = space.builtin.getdict()
+        w_builtins = space.builtin.getdict(space)
     return borrow_from(None, w_builtins)
 
 @cpython_api([], PyObject, error=CANNOT_FAIL)

File pypy/module/cpyext/modsupport.py

 def PyModule_GetDict(space, w_mod):
     if PyModule_Check(space, w_mod):
         assert isinstance(w_mod, Module)
-        w_dict = w_mod.getdict()
+        w_dict = w_mod.getdict(space)
         return borrow_from(w_mod, w_dict)
     else:
         PyErr_BadInternalCall(space)

File pypy/module/cpyext/state.py

             return None
         w_mod = PyImport_AddModule(self.space, name)
         assert isinstance(w_mod, Module)
-        w_mdict = w_mod.getdict()
+        w_mdict = w_mod.getdict(self.space)
         self.space.call_method(w_mdict, 'update', w_dict)
         return w_mod
 
             msg = "fixup_extension: module '%s' not loaded" % name
             raise OperationError(space.w_SystemError,
                                  space.wrap(msg))
-        w_dict = w_mod.getdict()
+        w_dict = w_mod.getdict(space)
         w_copy = space.call_method(w_dict, 'copy')
         self.extensions[path] = w_copy

File pypy/module/cpyext/sysmodule.py

     """Return the object name from the sys module or NULL if it does
     not exist, without setting an exception."""
     name = rffi.charp2str(name)
-    w_dict = space.sys.getdict()
+    w_dict = space.sys.getdict(space)
     w_obj = space.finditem_str(w_dict, name)
     return borrow_from(None, w_obj)
 
     case name is deleted from the sys module. Returns 0 on success, -1
     on error."""
     name = rffi.charp2str(name)
-    w_dict = space.sys.getdict()
+    w_dict = space.sys.getdict(space)
     space.setitem_str(w_dict, name, w_obj)
     return 0

File pypy/module/cpyext/test/test_dictobject.py

         assert space.unwrap(w_d) == dict(a='b', c='d', e='f')
 
     def test_iter(self, space, api):
-        w_dict = space.sys.getdict()
+        w_dict = space.sys.getdict(space)
         py_dict = make_ref(space, w_dict)
 
         ppos = lltype.malloc(Py_ssize_tP.TO, 1, flavor='raw')

File pypy/module/exceptions/interp_exceptions.py

     args_w = []
 
     def __init__(self, space):
-        self.space = space
         self.w_message = space.w_None
 
     def descr_init(self, space, args_w):
     def descr_getitem(self, space, w_index):
         return space.getitem(space.newtuple(self.args_w), w_index)
 
-    def getdict(self):
+    def getdict(self, space):
         if self.w_dict is None:
-            self.w_dict = self.space.newdict(instance=True)
+            self.w_dict = space.newdict(instance=True)
         return self.w_dict
 
     def setdict(self, space, w_dict):
         return space.newtuple(lst)
 
     def descr_setstate(self, space, w_dict):
-        w_olddict = self.getdict()
+        w_olddict = self.getdict(space)
         space.call_method(w_olddict, 'update', w_dict)
 
     def descr_message_get(self, space):
         return self.w_message
 
     def descr_message_set(self, space, w_new):
-        space.setitem(self.getdict(), space.wrap("message"), w_new)
+        space.setitem(self.getdict(space), space.wrap("message"), w_new)
 
     def descr_message_del(self, space):
         w_dict = self.w_dict

File pypy/module/thread/os_local.py

     """Thread-local data"""
 
     def __init__(self, space, initargs):
-        self.space = space
         self.initargs = initargs
         ident = thread.get_ident()
         self.dicts = {ident: space.newdict()}
 
-    def getdict(self):
+    def getdict(self, space):
         ident = thread.get_ident()
         try:
             w_dict = self.dicts[ident]
         except KeyError:
             # create a new dict for this thread
-            space = self.space
             w_dict = self.dicts[ident] = space.newdict(instance=True)
             # call __init__
             try:

File pypy/objspace/fake/checkmodule.py

     ModuleClass = __import__(basepath + '.%s' % modname,
                              None, None, ['Module']).Module
     module = ModuleClass(space, space.wrap(modname))
-    w_moduledict = module.getdict()
+    w_moduledict = module.getdict(space)
 
     gateways = find_gateways(modname, basepath, module)
     functions = [gw.__spacebind__(space) for gw in gateways]

File pypy/objspace/std/bytearraytype.py

 def descr_bytearray__reduce__(space, w_self):
     from pypy.objspace.std.bytearrayobject import W_BytearrayObject
     assert isinstance(w_self, W_BytearrayObject)
-    w_dict = w_self.getdict()
+    w_dict = w_self.getdict(space)
     if w_dict is None:
         w_dict = space.w_None
     return space.newtuple([

File pypy/objspace/std/dictproxyobject.py

 from pypy.objspace.std.register_all import register_all
 
 def descr_get_dictproxy(space, w_obj):
-    return W_DictProxyObject(w_obj.getdict())
+    return W_DictProxyObject(w_obj.getdict(space))
 
 class W_DictProxyObject(W_Object):
     from pypy.objspace.std.dictproxytype import dictproxy_typedef as typedef

File pypy/objspace/std/fake.py

         def __init__(w_self, space, val):
             w_self.val = val
             w_self.space = space
-        def getdict(w_self):
+        def getdict(w_self, space):
             try:
                 d = w_self.val.__dict__
             except AttributeError:
-                return W_Object.getdict(w_self)
-            return w_self.space.wrap(d)
+                return W_Object.getdict(w_self, space)
+            return space.wrap(d)
         def unwrap(w_self, space):
             return w_self.val
         if cpy_type is types.FunctionType:

File pypy/objspace/std/frame.py

     if w_value is None:
         builtins = f.get_builtin()
         assert isinstance(builtins, Module)
-        w_builtin_dict = builtins.getdict()
+        w_builtin_dict = builtins.getdict(f.space)
         assert isinstance(w_builtin_dict, W_DictMultiObject)
         w_value = w_builtin_dict.get_builtin_indexed(num)
     if w_value is None:

File pypy/objspace/std/mapdict.py

 class DevolvedDictTerminator(Terminator):
     def _read_terminator(self, obj, selector):
         if selector[1] == DICT:
-            w_dict = obj.getdict()
             space = self.space
+            w_dict = obj.getdict(space)
             return space.finditem_str(w_dict, selector[0])
         return Terminator._read_terminator(self, obj, selector)
 
     def _write_terminator(self, obj, selector, w_value):
         if selector[1] == DICT:
-            w_dict = obj.getdict()
             space = self.space
+            w_dict = obj.getdict(space)
             space.setitem_str(w_dict, selector[0], w_value)
             return True
         return Terminator._write_terminator(self, obj, selector, w_value)
     def delete(self, obj, selector):
         from pypy.interpreter.error import OperationError
         if selector[1] == DICT:
-            w_dict = obj.getdict()
             space = self.space
+            w_dict = obj.getdict(space)
             try:
                 space.delitem(w_dict, space.wrap(selector[0]))
             except OperationError, ex:
         self._become(new_obj)
         return True
 
-    def getdict(self):
+    def getdict(self, space):
         w_dict = self._get_mapdict_map().read(self, ("dict", SPECIAL))
         if w_dict is not None:
             assert isinstance(w_dict, W_DictMultiObject)
             return w_dict
-        w_dict = MapDictImplementation(self.space, self)
+        w_dict = MapDictImplementation(space, self)
         flag = self._get_mapdict_map().write(self, ("dict", SPECIAL), w_dict)
         assert flag
         return w_dict
     def setdict(self, space, w_dict):
         from pypy.interpreter.typedef import check_new_dictionary
         w_dict = check_new_dictionary(space, w_dict)
-        w_olddict = self.getdict()
+        w_olddict = self.getdict(space)
         assert isinstance(w_dict, W_DictMultiObject)
         if w_olddict.r_dict_content is None:
             w_olddict._as_rdict()
 
 def materialize_r_dict(space, obj, w_d):
     map = obj._get_mapdict_map()
-    assert obj.getdict() is w_d
+    assert obj.getdict(space) is w_d
     new_obj = map.materialize_r_dict(space, obj, w_d)
     _become(obj, new_obj)
 

File pypy/objspace/std/proxyobject.py

         def __init__(self, space, w_type, w_controller):
             self.w_type = w_type
             self.w_controller = w_controller
-            self.space = space
     
         def descr_call_mismatch(self, space, name, reqcls, args):
             args_w = args.arguments_w[:]
                     raise
                 return False
         
-        def getdict(self):
-            return self.getdictvalue(self.space, '__dict__')
+        def getdict(self, space):
+            return self.getdictvalue(space, '__dict__')
         
         def setdict(self, space, w_dict):
             if not self.setdictvalue(space, '__dict__', w_dict):

File pypy/objspace/std/test/test_mapdict.py

     obj.setdictvalue(space, "a", 51)
     obj.setdictvalue(space, "b", 61)
     obj.setdictvalue(space, "c", 71)
-    assert obj.getdict() is obj.getdict()
-    assert obj.getdict().length() == 3
+    assert obj.getdict(space) is obj.getdict(space)
+    assert obj.getdict(space).length() == 3
 
 
 def test_materialize_r_dict():
 def get_impl(self):
     cls = Class()
     w_obj = cls.instantiate(self.fakespace)
-    return w_obj.getdict()
+    return w_obj.getdict(self.fakespace)
 class TestMapDictImplementation(BaseTestRDictImplementation):
     ImplementionClass = MapDictImplementation
     get_impl = get_impl
 # ___________________________________________________________
 # tests that check the obj interface after the dict has devolved
 
-def devolve_dict(obj):
-    w_d = obj.getdict()
+def devolve_dict(space, obj):
+    w_d = obj.getdict(space)
     w_d._as_rdict()
 
 def test_get_setdictvalue_after_devolve():
     obj.setdictvalue(space, "b", 6)
     obj.setdictvalue(space, "c", 7)
     obj.setdictvalue(space, "weakref", 42)
-    devolve_dict(obj)
+    devolve_dict(space, obj)
     assert obj.getdictvalue(space, "a") == 5
     assert obj.getdictvalue(space, "b") == 6
     assert obj.getdictvalue(space, "c") == 7
     obj.setdictvalue(space, "a", 5)
     obj.setdictvalue(space, "b", 6)
     obj.setdictvalue(space, "c", 7)
-    w_d = obj.getdict()
+    w_d = obj.getdict(space)
     obj2 = cls.instantiate()
     obj2.setdictvalue(space, "d", 8)
-    obj.setdict(space, obj2.getdict())
+    obj.setdict(space, obj2.getdict(space))
     assert obj.getdictvalue(space, "a") is None
     assert obj.getdictvalue(space, "b") is None
     assert obj.getdictvalue(space, "c") is None

File pypy/objspace/std/typeobject.py

             del w_self.lazyloaders
         return False
 
-    def getdict(w_self): # returning a dict-proxy!
+    def getdict(w_self, space): # returning a dict-proxy!
         if w_self.lazyloaders:
             w_self._freeze_()    # force un-lazification
-        space = w_self.space
         newdic = space.newdict(from_strdict_shared=w_self.dict_w)
         return W_DictProxyObject(newdic)
 

File pypy/objspace/taint.py

     def __init__(self, w_obj):
         self.w_obj = w_obj
 
-##    def getdict(self):
-##        return taint(self.w_obj.getdict())
+##    def getdict(self, space):
+##        return taint(self.w_obj.getdict(space))
 
 ##    def getdictvalue(self, space, attr):
 ##        return taint(self.w_obj.getdictvalue(space, attr))