1. Pypy
  2. Untitled project
  3. pypy


Brian Kearns  committed b78e000

fix usage of bufferstr_w in _winreg

  • Participants
  • Parent commits a6ca15a
  • Branches default

Comments (0)

Files changed (2)

File pypy/module/_winreg/interp_winreg.py

View file
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.interpreter.error import OperationError, wrap_windowserror
+from pypy.interpreter.error import OperationError, wrap_windowserror, oefmt
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib import rwinreg, rwin32
 from rpython.rlib.rarithmetic import r_uint, intmask
             buf = lltype.malloc(rffi.CCHARP.TO, 1, flavor='raw')
             buf[0] = '\0'
-            value = space.bufferstr_w(w_value)
+            try:
+                value = w_value.readbuf_w(space)
+            except TypeError:
+                raise oefmt(space.w_TypeError,
+                            "Objects of type '%T' can not be used as binary "
+                            "registry values", w_value)
+            else:
+                value = value.as_str()
             buflen = len(value)
             buf = rffi.str2charp(value)

File pypy/module/_winreg/test/test_winreg.py

View file
             assert 0, "Did not raise"
     def test_SetValueEx(self):
-        from _winreg import CreateKey, SetValueEx
+        from _winreg import CreateKey, SetValueEx, REG_BINARY
         key = CreateKey(self.root_key, self.test_key_name)
         sub_key = CreateKey(key, "sub_key")
         for name, value, type in self.test_data:
             SetValueEx(sub_key, name, 0, type, value)
+        exc = raises(TypeError, SetValueEx, sub_key, 'test_name', None,
+                                            REG_BINARY, memoryview('abc'))
+        assert str(exc.value) == ("Objects of type 'memoryview' can not "
+                                  "be used as binary registry values")
     def test_readValues(self):
         from _winreg import OpenKey, EnumValue, QueryValueEx, EnumKey